solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 7;
long long a[MX];
pair<int, pair<int, long long> > lr[MX];
int acc[MX];
long long acc2[MX];
int main() {
int n, m, k;
cin >> n >> m >> k;
int tp;
for (int i = 1; i <= n; ++i) {
scanf("%d", &tp);
a[i] = tp;
}
for (int i = 1; i <= m;... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int POWER[65];
void precompute() {
POWER[0] = 1;
for (int i = 1; i < 31; i++) POWER[i] = POWER[i - 1] << 1LL;
}
long long int power(long long int x, long long int y, long long int mod) {
long long int res = 1;
x %= mod;
wh... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
int data[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &data[i]);
int l = 1, r = n;
while (l < n && data[l] < data[l + 1]) l++;
while (r > 1 && data[r] < data[r - 1]) r--;
int flag = 1;
if (l > r)... | 2 |
#include <bits/stdc++.h>
using namespace std;
void testCase() {
long long n, m, k;
cin >> n >> m >> k;
long long mostEdges = n * max((n - 1), 0LL) / 2;
if (m < n - 1 || m > mostEdges) {
cout << "NO" << endl;
return;
}
if (k <= 1)
cout << "NO" << endl;
else if (k == 2)
cout << (n == 1 ? "YE... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, c[200005], id[200005], ans[200005], cnt, num, a;
unsigned long long n, w, l, sum;
bool flag;
int main() {
scanf("%d", &t);
for (int k = 1; k <= t; ++k) {
memset(ans, 0, sizeof(ans));
memset(c, 0, sizeof(c));
memset(id, 0, sizeof(id));
cnt = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long N = 2e6 + 100;
const long long mod = 1e9 + 7;
map<pair<long long, long long>, long long> m;
vector<pair<long long, long long> > e[N];
long long c[N], sum[N];
long long top, top1;
bool use[N];
long long f(long long x, long long c) {... | 18 |
#include <bits/stdc++.h>
using namespace std;
void IO() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
IO();
long long n, m, cnt = 0;
cin >> n >> m;
if (n > m) swap(n, m);
long long cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0, cnt0 = 0;
for (long long i = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, q, s, i;
cin >> n;
s = 0;
for (i = 1; i <= n; i++) {
cin >> p >> q;
if ((q - p) >= 2) s++;
}
cout << s << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 2003;
int n;
int a[N], b[N];
struct ban {
int i;
int u;
int x1, x2, x3, x4;
int d;
ban() {}
ban(int i, int u, int x1, int x2, int x3, int x4, int d) {
this-... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t = 1;
while (t--) {
int arr[3][3];
int b[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
cin >> arr[i][j];
b[i][j] = 1;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int rez;
int v[3001], c[3001], dr[3001], dp[3001];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = n; i >= 1; i--) {
int sol = 1000000000, ind = 0;
for (int j = i - 1; j >= 1; j--... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-10;
double zero(double d) { return d < EPS ? 0.0 : d; }
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template <typename... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1001];
int ans[1001];
int n, k;
int main() {
while (cin >> n >> k) {
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= n; i++) cin >> a[i];
int max = 10000;
for (int i = 1; i <= n; i++) {
int s = 0;
for (int t = 1; t <= n; t++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20000 + 10;
const int maxq = 30000 + 10;
const int maxm = 450000 + 10;
const int P = 1e7 + 19;
const int Q = 1e9 + 7;
struct Edge {
int next, v;
Edge() {}
Edge(int next, int v) : next(next), v(v) {}
} e[maxm];
struct Exhibit {
int l, r, v, w;
Exhi... | 20 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
int prev1 = 0;
int prev2 = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == 1) {
int k = 0;
int j = i;
while (arr[j] == 1 && j < n... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mN = 1e6 + 100;
int n, mxL[mN], mxR[mN], c, l[mN], r[mN], mnR[mN];
char x[6];
bool ok = 1;
int solve(int cur, int e) {
if (cur > e) return -1;
if (mxL[cur] == -1 && mxR[cur] == -1) return cur;
if (mxL[cur] == -1) {
int i;
for (i = cur; i < mxR[cur];)... | 16 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int maxn=2e5;
int a[N];
vector<int>e[N];
int mp[N];
int cnt[N];
int d[N],dis[N];
int tot;
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
tot=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k, lk = 0;
cin >> k;
long long j = 9, ch = 9, i = 1;
lk = 9;
while (lk < k) {
j *= 10;
i++;
lk += i * j;
ch += j;
}
ch -= ((lk - k) / i);
lk = k + ((lk - k) % i);
if (lk < k) lk += i;
while (lk > k) {
ch /= 10;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
const int MOD = 1e9 + 7;
struct Primes {
vector<int> lp, pr;
int n;
Primes(int n) : n(n), lp(n + 1) {
for (int i = 2; 1ll * i * i <= n; i == 2 ? i += 1 : i += 2) {
if (lp[i] == 0) {
for (long long j = 1ll * i * i; j <= n; j += i) {... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool asal(int x) {
int i;
if (x == 1) return 0;
for (i = 2; i * i <= x; i++)
if (x % i == 0) return 0;
return 1;
}
int cevir(int x) {
int on = 10000000;
int z, y = 0;
z = x;
while (z) {
y += (z % 10) * on;
on /= 10;
z /= 10;
}
return y / ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct _IO {
_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
}
} _io;
const int N = 2e6 + 5, M = 1e9 + 7;
int fa[N];
int fi(int x) { return fa[x] == x ? x : fa[x] = fi(fa[x]); }
int solve() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
int ans = 0;
for... | 9 |
#include <bits/stdc++.h>
using namespace std;
int mark[20], ct[20000];
vector<list<int> > adjlist(300000);
list<int>::iterator it;
int main() {
int p, q, n, i, f;
p = 0;
q = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> f;
adjlist[f].push_back(i + 1);
ct[f]++;
if (ct[f] >= 2) {
p++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string txt;
cin >> txt;
int counter = 0;
int length = txt.length();
int i = 0;
for (; i < length; i++) {
if (txt[i] == 'h') {
counter++;
i++;
break;
}
}
for (; i < length; i++) {
if (txt[i] == 'e') {
counter++... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l = 0, r = 0, u = 0, d = 0;
cin >> n;
char a[n];
int flag = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 'L') {
l += 1;
}
if (a[i] == 'R') {
r++;
}
if (a[i] == 'U') {
u++;
}
if (a[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, T, m, a, b, c;
long long goc, N, cl[100005];
void outp() {
for (long long i = 1; i <= n; i++) {
if (cl[i] < N) {
goc = i;
break;
}
}
for (long long i = 1; i <= n; i++) {
if (i != goc) {
cout << goc << " " << i << "\n";
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long sa[150005], pa[150005], na[150005], ea[150005];
unsigned long long root(unsigned long long n) {
if (pa[n] == n) return n;
return root(pa[n]);
}
void uni(unsigned long long a, unsigned long long b) {
unsigned long long ra = root(a), rb = root(b);
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct ahasan {
int val;
string s;
};
bool st(ahasan ob1, ahasan ob2) { return ob1.val < ob2.val; }
int main() {
int n, i, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0;
char ak[200009], t1[200009], t2[200009], t3[200009];
char t4[200009], t5[200009], t6[200009];... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
pair<int, int> rows[n];
pair<int, int> columns[m];
for (int i = 0; i < n; i++) rows[i].first = rows[i].second = 0;
for (int i = 0; i < m; i++) columns[i].first = columns[i].second = 0;
int t = 1;
while (... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int Set(int N, int pos) { return N = N | (1 << pos); }
inline int Reset(int N, int pos) { return N = N & ~(1 << pos); }
inline bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T>
T gcd(T a, T b) {
return (!b) ? a : gcd(b, a % b);
}
temp... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1E5 + 77;
set<pair<int, int> > S;
int N, p;
long long ans = 0;
struct SEG {
SEG *ch[2];
int v;
SEG() { memset(this, 0, sizeof(SEG)); }
void maintain() { v = (ch[0] ? ch[0]->v : 0) + (ch[1] ? ch[1]->v : 0); }
} * root;
void segSetVal(SEG *&tr, int L,... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d, e, cnt = 0, snt = 0, ans = 0, mx = 0;
vector<long long> v, vv;
map<long long, long long> mp;
string g;
set<char> st;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b;
v.push_back(b);
}
for (int i = 0; i < v.size()... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = 3.14159265358979323846;
const long double gammama = 0.57721566490153286060;
const long double eps = 1e-5;
const int INF = 1000 * 1000 * 1000 + 1;
const long long LINF = (long long)1000 * 1000 * 1000 * 1000 *... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n;
cin >> n;
if (n == 0) {
cout << "0 0 0" << endl;
return 0;
} else if (n == 1) {
cout << "0 0 1" << endl;
return 0;
} else if (n == 2) {
cout << "0 1 1" << endl;
return 0;
} else if (n == 3) {
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int inf = 1 << 30;
int f[maxn], s[maxn];
long long check(int x, int y) { return (s[y] < f[x]) ? 1LL : 0LL; }
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < maxn; i++) {
f[i] = inf;
s[i] = -1;
}
memset(s, -1, sizeof... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
double A[N];
int n;
bool target(double &t) {
auto i = upper_bound(A, A + n, A[0] + 2 * t);
if (i - A == n) return 1;
i = upper_bound(i, A + n, *i + 2 * t);
if (i - A == n) return 1;
i = upper_bound(i, A + n, *i + 2 * t);
if (i - A == n)
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<pair<int, int> > G[N];
vector<int> p, cycle;
bool vis[N];
long long dep[N], L[N];
int k;
long long pre1[N], pre2[N], suf1[N], suf2[N];
void solve(int u) {
for (int i = 0; i < p.size(); ++i)
if (p[i] == u) {
for (int j = i; j < p.si... | 17 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long a[n], b[n];
for (long long i = 0; i < n; i++) cin >> b[i];
for (long long i = 0; i < n; i++) a[i] = i + 1 - b[i];
map<long long, long long> mp;
for (long long i = 0; i < n; i++) mp[a[i]] += b[i];
long long x = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int T;
long long n;
long long a[333333];
long long twosum[333333];
long long tree[(1LL << 18) * 3];
long long ans[333333];
set<long long> s;
void update(long long x, long long y) {
x += (1LL << 18);
while (x > 0LL) {
tree[x] += y;
x /= 2LL;
}
}
long long sum(i... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n, k;
cin >> n >> k;
long long a[n];
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
long long i = 0, j = n - 1, mx = 0;
while (i <= j) {
if (k > (j + 1) / 2) {
if (mx < a[j]) {
mx = a[j];
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 300 * 1000 + 51;
struct point {
long double x, y;
point(long double _x, long double _y) {
x = _x;
y = _y;
}
point() {}
point operator+(const point that) { return point(x + that.x, y + that.y); }
point operator-(co... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long Mat[510][510], Ans[510];
int N, X[510];
bool Active[510];
int main() {
int i, j, k;
cin >> N;
for (i = 1; i <= N; ++i)
for (j = 1; j <= N; ++j) cin >> Mat[i][j];
for (i = 1; i <= N; ++i) cin >> X[i];
for (i = N; i; --i) {
Ans[i] = 0;
Active[X... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
long long max_v[2 * N];
long long add_v[2 * N];
int vals[N];
void push(int i) {
if (add_v[i]) {
max_v[i] += add_v[i];
if (i < N) {
add_v[2 * i] += add_v[i];
add_v[2 * i + 1] += add_v[i];
}
add_v[i] = 0;
}
}
void addInt(... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
set<int> arr2;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] & 1) {
arr2.insert(arr[i]);
arr2.insert(arr[i] + 1);
} else {
arr2.insert(arr[i] - 1);
arr2.insert(arr[i]);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> arr;
for (int i = 0; i < N; i++) {
int num;
cin >> num;
arr.push_back(num);
}
for (int i = 0; i < N; i++) {
int needAdd = 0;
while (arr[i] > 0) {
if (arr[i] % 2 == 0) {
arr[i] /= 2;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
long long n, m, k;
int a[N * 20];
int main() {
while (cin >> n >> m >> k) {
for (int i = 0; i < n; ++i) scanf("%d", a + i);
if (n % 2 == 0 || m < (n + 1) / 2) {
cout << 0 << endl;
continue;
} else {
int t = (n + 1) / 2;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T &a, const T &b) {
if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
if (a < b) a = b;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 1e8;
const int MOD = 1e9 + 7;
const int MAXSIZE = 1e6 + 5;
const double eps = 0.0000000001;
void fre() {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
const int MSIZE = 110;
struct Node {
int id, value;
} arr[MSIZE];
bool cmp(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int _ = 0; _ < t; _++) {
int n;
cin >> n;
cout << n / 2 + 1 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = INT_MAX;
const int lim = 1e5 + 5;
long long power(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret *= a;
a *= a;
if (ret >= mod) ret %= mod;
if (a >= mod) a %= mod;
b >>= 1;
}
r... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
int mod(int a) {
if (a < 0)
return (a + 2 * n) % n;
else
return a % n;
}
int ans[1000100];
int main() {
int q;
scanf("%d%d", &n, &q);
int a, b;
a = 0, b = 1;
for (int i = 0; i < q; i++) {
int t;
scanf("%d", &t);
if (t == 1) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<long long> a(n), b(n);
map<long long, long long> ma, mb;
for (int i = 0; i < n; i++) {
cin >> a[i];
ma[a[i]]++;
}
for (int i = 0; i < n; i++) {
cin >> ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, x, a[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int x = a[n];
for (int i = n - 1; i >= 1; i--)
if (a[i] != x) {
printf("%d\n", i);
return 0;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool primes[1000007];
void sieve(int n) {
for (long long i = 2; i <= n; i++) {
for (long long j = i * i; j <= n; j += i) {
primes[j] = 1;
}
}
}
int main() {
int n;
cin >> n;
sieve(1e6);
while (n--) {
long long tmp;
cin >> tmp;
long long... | 5 |
#include <bits/stdc++.h>
using namespace std;
int abc(int a) { return a < 0 ? -a : a; }
int main(void) {
int a, b, x1, y1, x2, y2;
scanf("%d%d%d%d%d%d", &a, &b, &x1, &y1, &x2, &y2);
int px1 = (x1 + y1) / (2 * a), py1 = (x1 - y1) / (2 * b);
int px2 = (x2 + y2) / (2 * a), py2 = (x2 - y2) / (2 * b);
if (x1 + y1 ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
n *= 2;
int *a = new int[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] == a[j])
if (((i % 2 != 0) && (j % 2 == 0)) || ((i % 2 == 0)... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[2];
long long maxi = -1, ans = 0;
bool update(int x) {
if (x < maxi) return false;
if (x > maxi) maxi = x, ans = 0;
return true;
}
int eq(int i, int x) {
return upper_bound(v[i].begin(), v[i].end(), x) -
lower_bound(v[i].begin(), v[i].end(), x... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
int t, n;
string s;
set<int> vec[2], cnt[2][2][2][2];
set<string> st;
map<string, int> mp;
bool fun(int fst) {
int cur = fst;
bool flag = true;
while (1) {
cnt[fst][cur][cur][0].clear();
if (cnt[fst][cur][cur ^ 1][0].s... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a[3100], b[3100], c[3100], dp[3100][3100];
int main() {
memset(dp, -0x3f3f3f3f, sizeof(dp));
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++) cin >> c[i];
dp[1][0] = 0;
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int _ = 0; _ < (int)(t); _++) {
int n;
int a[100];
cin >> n;
for (int i = 0; i < (int)(n); i++) cin >> a[i];
int ma = *max_element(a, a + n);
int sum = accumulate(a, a ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
register int c = getchar();
x = 0;
bool f = 0;
for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
}
template <typename T, typename... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
struct Data {
int x, y;
} d[N][N];
char ans[N][N];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
char c[4] = {'D', 'U', 'R', 'L'};
bool used[N][N];
void dfs(int x, int y) {
used[x][y] = 1;
for (int k = 0; k < 4; k++) {
int xx = x + dir[k][... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000 + 7;
const double esp = 1e-13;
int a[10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
for (long long i = 1; i <= 4; i++) cin >> a[i];
if (a[2] * 2 == a[1] + a[3] && a[3] * 2 == a[2] + a[4]) {
cout << a[4] * 2 - a[3]... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int M = 100000 + 10;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t, n, m, k, p, l, r, u, v;
int ans, cnt, flag, temp, sum;
int a[N], b[N];
char str;
struct node {};
int main... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
char c;
vector<char> in;
cin >> n;
for (i = 0; i < n; i++) {
cin >> c;
in.push_back(c);
}
if (n == 1) {
cout << in[0] << endl;
return 0;
}
if (n == 2) {
cout << in[1] << in[0] << endl;
return 0;
}
ve... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, fl = 0;
char s[1000];
scanf("%d", &n);
getchar();
gets(s);
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] == '?' && (i == 0 || i == n - 1))
fl = 1;
else if (s[i] == '?' && i > 0 && i < n - 1 && s[i - 1] == s[i +... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int INF = 0x3f3f3f3f;
template <class T>
inline bool RD(T &ret) {
char c;
in... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
if (n % 10 == 9) {
cout << (n / 10) + 1 << endl;
} else
cout << n / 10 << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[int(2e5) + 10];
int n;
long long calc(long long x) {
long long ans = 0;
long long xxx = 1;
for (int i = 0; i < n; i++) {
if (xxx > 1e14) return 1e18;
ans += abs(a[i] - xxx);
xxx *= x;
}
return ans;
}
int main() {
ios::sync_with_stdio(fals... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
struct edge {
int u;
int w;
int flow;
int capacity;
int cost;
char wha;
edge() = default;
edge(int a, int b, int cap, char c) {
u = a;
w = b;
flow = 0;
capacity = cap;
cost = 0;
wha = c;
}
};
vector<int> ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n == 2) {
if (m != 1)
cout << "5";
else
cout << "4";
return 0;
}
if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12) {
if (m == 6 || m == 7) {
cout << "6";
retu... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, n, c = 0, d = 0, sum = 0, e = 0, f = 0, k;
cin >> c >> d >> e;
c = abs(c);
d = abs(d);
e = abs(e);
if ((c + d) == e) {
cout << "YES";
} else if ((c + d) > e) {
cout << "NO";
} else {
f = e - (c + d);
if (f % 2 == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
double eps = 1e-8;
double pi = acos(-1);
const long long mod = 1000;
long long quick_pow(long long x, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
map<pair<int, int>, int> a, b;
int n, m, ans[MAX];
int main() {
scanf("%d%d", &n, &m);
pair<int, int> t, pre;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
t = make_pair(i, j);
scanf("%d", &a[t]);
}
}
fo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[111111], m[111111], t[111111];
int main() {
int n, k;
scanf("%d%d", &n, &k);
int num = 0, sum = 0;
for (int i = 1; i <= k; i++) {
scanf("%d", &m[i]);
for (int j = 0; j < m[i]; j++) {
scanf("%d", &t[j]);
}
if (t[0] == 1) {
num = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int na, ka;
int lowbit(int x) { return x & (-x); }
bool chk(int n, int k) {
if (k < 0) return 0;
if (!(n % 2)) return 0;
if (k && k * 2 + 3 > n) return 0;
if (lowbit(n + 1) == n + 1 && k == 1) return 0;
if (lowbit(n + 1) != n + 1 && k == 0) return 0;
if (n == 9 ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 2 != 0) {
if (n == 3 || n == 5)
cout << "-1" << '\n';
else {
for (long long int i = 2; i < (n / 2) + 2; i++) {
cout << "1 " << i << '\n';
}
for (long long int i = (n / 2) + 2; i < n + ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j;
string s, c;
long long a[27][200002], b[27][200002], sum;
int main() {
cout.setf(ios ::fixed | ios ::showpoint);
cout.precision(9);
cin >> n >> s >> c;
for (i = 0; i < n; i++) {
sum = i + 1;
a[c[i] - 'A'][i] = sum;
}
for (i = 0; i < n; i++)
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int main() {
long long t1, t2, x1, x2, t0;
cin >> t1 >> t2 >> x1 >> x2 >> t0;
long long ans1 = -1, ans2 = -1;
for (long long y1 = 0; y1 <= x1; y1++) {
long long ri = (y1 * (t0 - t1) + t2 - t0 - 1);
if (t2 == t0) {
if (y1 * (t0 - t... | 11 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef double db;
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
#define low(x) ((x)&-(x))
#define all(x) x.begin(),x.end()
#define mp make_pair
#define X first
#define Y second
#ifdef _DEBUG
const in... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, c = 0;
scanf("%d %d", &n, &k);
char te[100], s[100];
scanf("%s", &s);
set<char> se;
set<char>::iterator it;
int l = strlen(s);
for (int i = 0; i < l; i++) {
se.insert(s[i]);
}
for (it = se.begin(); it != se.end(); it++) {
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
x = 0;
char ch;
do ch = getchar();
while (ch < '0' || ch > '9');
do x = x * 10 + ch - '0', ch = getchar();
while (ch <= '9' && ch >= '0');
}
int n, m, k, q;
int used[2010], size[2010];
int rt[2010];
long long sm[2010 * 30];
int ls[2010 * 30],... | 16 |
#include <bits/stdc++.h>
using namespace std;
double dp[105][100010];
double sum[105][100010];
int main() {
int n, m, x;
scanf("%d%d", &n, &m);
dp[0][0] = sum[0][0] = m - 1;
int tot = n * m;
int p = 0;
for (int i = 1; i <= tot; i++) sum[0][i] = sum[0][i - 1] + dp[0][i];
double q = 1;
for (int i = 1; i <... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = FLT_MIN, inf = 1e60;
long double x, y, z;
long double f(int idx) {
if (idx == 1) return (x <= 1.) ? -inf : z * log(y) + log(log(x));
if (idx == 2) return (x <= 1.) ? -inf : y * log(z) + log(log(x));
if (idx == 3 || idx == 4)
return (x <= 1.... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
const ll M = 1e5 + 1;
const ll B = M * M;
vector<ll> caps(M, 1);
for (int j = 2; j < M; ++j) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
string s;
cin >> s;
string res;
long long n = s.size() - 1;
long long l = n / 2;
long long r = l + 1;
n++;
while (l >= 0 or r < n) {
if (l >= 0) res += s[l];
if (r < n) res += s[r];
l--;
r++;
}
cout << res << '\n';
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, k;
struct T {
int id, val;
} a[500000];
bool by_val(T x, T y) {
if (x.val < y.val)
return true;
else
return false;
}
bool by_id(T x, T y) {
if (x.id < y.id)
return true;
else
return false;
}
int main() {
cin >> n;
for (i = 1; i <= n; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, t, q;
struct unionset {
int fa[maxn];
int find(int x) {
if (fa[x] != x) {
fa[x] = find(fa[x]);
}
return fa[x];
}
int join(int x, int y) {
int ra = find(x);
int rb = find(y);
if (ra != rb) {
fa[r... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, mn = 11111111;
cin >> n;
vector<long long> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
long long sum = 15 * v[i];
for (int j = 0; j < v[i]; j++) {
long long c;
cin >> c;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int n, i, j, k, flag = 0, q, ans = 0;
cin >> q;
while (q--) {
long long int n, m;
cin >> n >> m;
vector<long long int> a(n);
vector<long long int> b(m);
map<lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 19999999;
string s1, s2;
int mat[50][50];
void floyd() {
int n = 'z' - 'a';
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int z = 0; z <= n; z++) {
if (mat[j][z] > mat[j][i] + mat[i][z]) {
mat[j][z] = mat[... | 10 |
#include <bits/stdc++.h>
inline long long inp() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
long long sum = 0;
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
return sum;
}
long long a[100010], b[100010], c[100010], d[100010], e[100010];
std::multiset<lo... | 21 |
#include <bits/stdc++.h>
struct sugar {
long long d, c;
};
int main() {
long long n, s, i, max = -1000000000, p = 1, ans;
struct sugar ar[105];
scanf("%lld%lld", &n, &s);
for (i = 0; i < n; i++) scanf("%lld%lld", &ar[i].d, &ar[i].c);
for (i = 0; i < n; i++) {
if (ar[i].d < s) {
p = 2;
ans = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000 + 19, mod = 1000 * 1000 * 1000 + 7;
int n, a[N];
bool mark;
int vis[N], h[N], tmp, cnt;
long long pw[N], ans = 1;
void prep();
void dfs(int, int);
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
prep();
cin >> n;
for (... | 11 |
#include <bits/stdc++.h>
using namespace std;
int const N = 200001;
int n;
vector<int> g[N], cmps;
bool vs[N], cyc, f;
void go(int u, int pa) {
vs[u] = true;
cmps.push_back(u);
for (auto i : g[u]) {
if (i == u) f = true;
if (vs[i] && i != pa) cyc = true;
if (!vs[i]) go(i, u);
}
}
int main() {
scan... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
vector<int> pos;
char toggle(char ch) {
if (ch == '0') return '1';
return '0';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
v.clear();
pos.clear();
int n, m;
cin >> n >> m;
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool isNumber(char x) { return x >= '0' && x <= '9'; }
string toSecond(string S) {
int row = 1;
int count = 26;
int i;
for (i = 1; !isNumber(S[i]); ++i) {
row += count;
count *= 26;
}
count /= 26;
for (i = 0; !isNumber(S[i]); ++i) {
row += 1u * (S[... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const int maxn = 555;
const int inf = 1e9;
int n, a[maxn];
int dp[maxn][maxn];
int go(int l, int r) {
if (l > r) return inf;
if (l == r) return dp[l][r] = 1;
if (l + 1 == r) {
if (a[l] == a[r]... | 11 |
#include <bits/stdc++.h>
using namespace std;
string dat[3];
int a, b, c;
void func() {
int i;
for (i = 0; i < 3; i++) {
if (dat[i][1] == '>') {
if (dat[i][0] == 'A') {
a++;
if (dat[i][2] == 'B')
b--;
else if (dat[i][2] == 'C')
c--;
} else if (dat[i][0] ==... | 4 |
#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const long long int INF = 1011111111;
const long long int LLINF = 1000111000111000111LL;
const long double EPS = 1e-10;
const long double PI = 3.14159265358979323;
using namespace std;
long long int power(long long int base, long long int exponent) {
long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.