solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 1067; int a[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int nho = 0; for (int i = 1; i <= n; i++) { a[i] -= nho; nho = 0; if (a[i] < 0) { ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long flag = 0; long long maxsize = -1, t1 = -1, t2 = -1; string s; getline(cin, s); long long m = s.size(); for (long long i = 0; i < m; i++) { if (s[i] == '[') { for (i = i + 1; i < m; i++) { if (s[i] == ':') { t1 =...
5
#include <bits/stdc++.h> using namespace std; long int req[30][30][5000], hum = 193, som[30]; int main() { double q, r; map<double, int> map2; map<double, int>::iterator fin; long int a, b = 0, c, d = 0, i, n, k = 3, s = 0; map<pair<char, char>, long int> map1, map3; map<pair<char, char>, long int>::iterato...
8
#include <bits/stdc++.h> using namespace std; const int M = 100005; int K, T; struct Suffix_Automaton { int ch[M << 1][27], pre[M << 1], mx_step[M << 1], mark[M << 1]; int sz, last, ntype[M << 1]; void init() { sz = 0; last = 1; memset(flag, 0, sizeof(flag)); newnode(0); } void extend(int x) {...
20
#include <bits/stdc++.h> using namespace std; long long Set(long long N, long long pos) { return N = N | (1 << pos); } long long reset(long long N, long long pos) { return N = N & ~(1 << pos); } bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); } void CI(int &_x) { scanf("%d", &_x); } void CO(long...
10
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; int arr[n][n]; for (int i = 0; i < n; ++i) { arr[i][0] = 1; arr[0][i] = 1; } int max = 1; for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { arr[i][j] = arr[i - 1][j] + arr[i]...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long c[1 << 10][1 << 11]; void initialize() { c[0][0] = 1; for (int i = 0; i < (1 << 10); i++) { c[i][0] = c[i][i] = 1; for (int j = 1; j < i; j++) { c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } } } int ma...
12
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; long long dp[N][2]; long long sol(vector<long long> &v, int pos, int f) { if (pos >= v.size()) return 0; if (dp[pos][f] != -1) return dp[pos][f]; long long &ans = dp[pos][f]; ans = 0; if (f == 1) { ans = max(v[pos] + sol(v, pos + 1...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.length() > 19 || s == "9223372036854775808" || (s.length() == 19 && s > "9223372036854775808")) cout << "BigInteger"; else if (s.length() > 10 || (s.length() == 10 && s >= "2147483648")) cout << "long"; else { ...
5
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } ret...
15
#include <bits/stdc++.h> using namespace std; struct node { long long a, b; } num[200005]; int main() { int n; long long m; cin >> n; num[0].a = 0; num[0].b = 0; for (int i = 1; i <= n; i++) { cin >> m; if (i % 2 == 1) num[i].a += m; else num[i].b += m; num[i].a += num[i - 1].a...
4
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; const int inf = numeric_limits<int>::max(); struct SegmentTree { int N; vector<vector<int>> ST; SegmentTree(int N, vector<int>& arr) : N(N) { ST.resize(N << 1); for (int i = 0; i < N; ++i) ST[N + i].push_back(arr[i]); for (int i = N...
3
#include <bits/stdc++.h> struct matrix { int g[2][2]; }; const int p = 1000000007; matrix first, result; int i, n; long long t; inline int power(int x, int y) { if (!y) return 1; int t = power(x, y / 2); t = 1LL * t * t % p; if (y & 1) t = 1LL * t * x % p; return t; } inline void buildfirstmatrix() { firs...
12
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1000000007; const ll M = 1000000000000000000ll; inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); } inline ll mult(ll a, ll b) { return (((a % mod)...
9
#include <bits/stdc++.h> using namespace std; const int N = 109; int q[N], n, s[N], K, t[N]; int p[N][N]; void out(int a[]) { for (int i = 1; i <= n; ++i) cout << a[i] << " "; cout << endl; } void read(int a[]) { for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); } bool eq(int a[], int b[]) { for (int i = 1; i <=...
10
#include <bits/stdc++.h> using namespace std; const int inf = 1100; int a, b; int is_okay(int row, int nr) { int l = 0, r = inf, last = 0; while (l <= r) { int mid = (l + r) / 2; if (mid * mid + row * row <= nr * nr) { last = mid; l = mid + 1; } else r = mid - 1; } if (last * last ...
8
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const double eps = 1e-8; const int INF32 = 0x3f3f3f3f; const long long INF64 = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const unsigned long long mod2 = 1610612741; const int N = 2e5 + 5; const int sz =...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char s[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> s[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i][j] == '.') { if (((i + j) % 2...
4
#include <bits/stdc++.h> using namespace std; inline int red() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f; } const int N = 2e4 + 10; const int INF = 0x3f3f3f3f; int cnt[5], ot[...
14
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int memo[5000][5000]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int &e : a) cin >> e; for (int i = 0; i < n; i++) memo[i][i] = a[i]; for (int i = 1; i < n; i++) for...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, INF = 1e9; struct T { int l, r, d[3], mn[3], mx[3]; } t[N]; int n, m, q, a, b, c, lx, rx, ly, ry, lz, rz, rt, h[N], D; inline bool cmp(int a, int b) { return t[a].d[D] < t[b].d[D]; } inline void update(int x) { int l = t[x].l, r = t[x].r; for (i...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n][m]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a[i][j]; } } int ans = 0; for (int i = n - 2; i > 0; --i) { for (int j = m - 2; j > 0; --j) { if (a[i][j] == 0) { ...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e7 + 7; const long long maxm = 1e7 + 7; char mmap[20][20]; bool check(int i, int j) { bool fa = true; if (j <= 5) { int t = 0; for (register int k = j; k <= j + 4; k = k + 1) { if (mmap[i][k] == 'O') { fa = false; br...
8
#include <bits/stdc++.h> using namespace std; int maxl[1100000]; int minr[1100000]; int maxr[1100000]; vector<int> ans; int n, c; int build(int root, int maxChild) { int maxLeft = root; if (maxl[root] > root) { maxLeft = build(root + 1, maxl[root]); } ans.push_back(root); if (maxLeft >= minr[root]) { ...
16
#include <bits/stdc++.h> using namespace std; int a[50], n; int main() { scanf("%d", &n); int sum = 0, t; for (int i = 1; i <= n; ++i) { scanf("%d", &t); sum ^= t; for (int j = 1; j <= *a; ++j) t = min(t, t ^ a[j]); if (t) a[++*a] = t; } printf("%d\n", sum ? *a : -1); }
15
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } map<int, int> mp; if (find(arr, arr + n, q) == arr + n) { for (int i = 0; i < n; i++) { if (arr[i] == 0) { arr[i] = q; break; }...
9
#include <bits/stdc++.h> using namespace std; int sqr(int a) { return a * a; } int main() { int n = 6; int a[n], i; for (i = 0; i < n; i++) cin >> a[i]; int ans = 0; ans = sqr(a[0] + a[2] + a[1]) - sqr(a[0]) - sqr(a[2]) - sqr(a[4]); cout << ans << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; const int MaxN = 200005; struct Edge { int to, next; }; Edge E[MaxN << 1]; int head[MaxN], Ecou; int N; bool vis[MaxN]; bool in[MaxN << 1], use[MaxN << 1]; int fa[MaxN]; void init() { Ecou = 0; memset(head, -1, sizeof(head)); } inline void addEdge(int u, int v) { E[...
15
#include <bits/stdc++.h> using namespace std; using DB = long double; const DB EPS = 1e-7; const DB PI = acos(-1); inline DB sqr(DB x) { return x * x; } struct PT { DB x, y; PT(DB x = 0, DB y = 0) : x(x), y(y) {} void in() { cin >> x >> y; } bool operator<(const PT &p) const { if (fabs(x - p.x) < EPS) retur...
23
#include <bits/stdc++.h> using namespace std; const long long INF = (1e12); long long val[200012]; bool rev(deque<long long> vect) { for (int i = 0; i < vect.size(); ++i) { if (vect[(i + 1) % vect.size()] == 0) return false; if (val[i] != vect[i] % vect[(i + 1) % vect.size()]) { return false; } } ...
16
#include <bits/stdc++.h> using namespace std; const long long maxn = 100003; const long long maxk = 1003; set<long long> si[maxn]; long long n, m; long long aib[maxn]; long long next(long long x) { return x & -x; } void update(long long x, long long adder) { for (long long i = x; i <= n; i += next(i)) { aib[i] +=...
8
#include <bits/stdc++.h> using namespace std; long long t, n, u, v, m, q, r, ql, qr, k, l, s, x, y, w, h, c, a, b; const int N = 3e5 + 1; const int SN = 1000; const long long mod = 1e9 + 7; const long long INF = 1LL << 57LL; const bool JUDGE = false; long long sum[N]; long long Ans[N]; vector<pair<int, int> > f[SN][SN]...
13
#include <bits/stdc++.h> using namespace std; int main() { char ga[110], gc[110]; char gb[110]; for (int i = 0; i < 110; i++) { ga[i] = '0'; gc[i] = '0'; } int a, c; scanf("%d%d", &a, &c); int cnt = 0, cnt1 = 0; while (a > 0) { ga[cnt++] = a % 3 + '0'; a = a / 3; } while (c > 0) { ...
3
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; int ROUND(double x) { return (int)(x + 0.5); } bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; } bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); } double SQSUM(double x, double y) { r...
14
#include <bits/stdc++.h> using namespace std; long long n, i, j, k, l, t = 1, flag = 0, m, a[100005]; vector<pair<long long, long long> > tree(400000); map<long long, vector<pair<long long, long long> > > ans; map<long long, vector<pair<long long, long long> > >::reverse_iterator it; void build(int node, int low, int h...
11
#include <bits/stdc++.h> using namespace std; int n, ans, x[105], y[105]; bool used[105]; void dfs(int j) { used[j] = true; for (int i = 1; i <= n; i++) { if (!used[i] and (x[i] == x[j] or y[i] == y[j])) dfs(i); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (in...
4
#include <bits/stdc++.h> int a[1005][1005]; int main() { int m, n, i, k, b[1005], c[1005], m1[1005], m2[1005]; long long sum; while (~scanf("%d%d", &m, &n)) { memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); memset(m1, 0, sizeof(m1)); memset(m2, 0, sizeof(m2)); sum = 0; for (i = 0; i < m;...
4
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC target("avx,avx2,fma") using namespace std; const long long MOD = 1e9 + 7; const int N = 2020; int n, h, l, r, s, x; vector<vector<int>> a(N, vector<int>(N, INT_MIN)); bool check(int z) { return l <= z && z <= r; } int main() { ios::sync_with_stdio(false...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using db = long double; using row = vector<int>; using ii = pair<int, int>; const int N = 1e5 + 5, M = 1e6 + 5, LG = 17, MOD = 1e9 + 7; const int BLOCK = 1900; const int BLOCKN = N / BLOCK...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 200005, mod = 2000000007; int x[maxn], y[maxn]; signed main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } if (n % 2 == 1) cout << "no" << endl; else { int midx = x[1] + x[n / 2 + 1], midy = y[1] + y[1 + n...
10
#include <bits/stdc++.h> using namespace std; string ans, a[200001]; int n; bool check(string &s) { for (int i = 1; i <= n; ++i) if (a[i].find(s) != string::npos) return 0; return 1; } void rec(int len, int pos) { if (pos == len) { if (check(ans)) { cout << ans; exit(0); } } else { f...
7
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, ans, sum, k; bool ok; int main() { ios::sync_with_stdio(0); cin >> n; while (n) { ok = true; if (n % 2 == 0) { ans += n / 2; cout << ans << endl; return 0; } for (i = 3; i * i <= n; i++) { if (n % i == 0) {...
4
#include <bits/stdc++.h> inline void read(int &x) { scanf("%d", &x); } inline void read(long long &x) { scanf("%I64d", &x); } inline void read(double &x) { scanf("%lf", &x); } inline void read(long double &x) { double tmp; read(tmp); x = tmp; } template <class T> inline void read(T *a, int n) { for (long long i...
13
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const int MAXN = (int)3e5 + 5; void solve() { int arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); if (arr[0] == 1) { cout << "YES" << "\n"; return; } if (arr[1] == 2) { c...
6
#include <bits/stdc++.h> using namespace std; const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1}; const int dc[]{0, 1, 1, 1, 0, -1, -1, -1}; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { run(); int n, x; cin >> n >> x; vector<int> v(n), first(x + 2, n), last(x + 1, -1); ...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int sq = 316; int n, maxy[2 * sq], sz[2 * sq], ready, go[MAXN]; vector<int> link[2 * sq]; void insert(int id, int v, int u) { link[id].push_back(v); int me = sz[id]; while (me && u && (v > link[id][me - 1])) { u--; me--; sw...
15
#include <bits/stdc++.h> int main() { int n, b, k, l, m, g, sumx = 0, sumy = 0, x = 0, y = 0, suth = 0, j = 0; scanf("%d", &n); int arr[n][2]; for (int i = 1; i <= n; i++) { scanf("%d %d", &arr[i][0], &arr[i][1]); sumx += arr[i][0]; sumy += arr[i][1]; if (arr[i][0] - arr[i][1] > x) { x = a...
3
#include <bits/stdc++.h> using namespace std; double ans = 0; vector<int> edgeList[100005]; bool visited[100005]; int dfsNumber = 0; double city = 0; vector<int> lengths; double DFS(int node, int parent) { double res = 0; int child = 0; for (int i = 0; i < edgeList[node].size(); i++) { if (edgeList[node][i] =...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 300050; long long n, k; struct node { long long num; int id; bool operator<(const node &rhs) const { return num < rhs.num; } }; priority_queue<node> a; long long ans[maxn]; long long sum = 0, x[maxn]; bool vis[maxn << 1]; int main() { ios::sync_with...
7
#include <bits/stdc++.h> using namespace std; using LL = long long; const LL base = 1e9 + 7; const int N = 2e5 + 5; LL cache[3][N]; LL x[3]; int n; LL dp(int k, int r) { if (k == n) { return r == 0; } if (cache[r][k] != -1) return cache[r][k]; LL rv = 0; rv += x[0] * dp(k + 1, r) % base; rv %= base; r...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> a(k), b(k), ada(k), sudah(n, 0), wis(k, 0); vector<vector<int>> g(n); for (int i = 0; i < k; i++) { cin >> a[i] >> b[i]; ada[i] = 2; a[i] -= ...
9
#include <bits/stdc++.h> int dp[5010][5010]; int n; int main() { char ch; scanf("%d", &n); dp[1][0] = 1; for (int i = 1; i <= n; i++) { scanf("\n%c", &ch); if (ch == 'f') { dp[i + 1][0] = 0; for (int j = i; j >= 1; j--) dp[i + 1][j] = dp[i][j - 1] % 1000000007; } else if (ch == 's') { ...
10
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 5; const int S = 1 << 8; int n; int a[N]; int nxt[N][8]; int ptr[N][8]; int lst[8]; int f[N][S + 1]; int ans; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; a[i]--; } for (int i = 0; i < 8; ++i) { lst[i] =...
14
#include <bits/stdc++.h> using namespace std; inline unsigned int lowbit(unsigned int x) { return x & (-x); } int a[100 + 5][100 + 5], ans = 0, ln[100000 + 5], n, m, k; unsigned int s[100 + 5]; bool vis[100 + 5], cant[100 + 5][100 + 5][10]; int dfs(int x, int y) { if (x > n) return 1; if (y > m) return dfs(x + 1, 1...
19
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int_fast64_t n; cin >> n; if (n % 2 == 0) { cout << (1ull << (n / 2)) << '\n'; } else { cout << 0 << '\n'; } }
2
#include <bits/stdc++.h> using namespace std; int n; int h[2000]; map<int, vector<int> > m; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(11); cout.setf(ios::fixed); cin >> n; for (int i = 0; i < n; ++i) { int a; cin >> a; m[a].push_back(i + 1); } bool b1 = ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; const int inf = 1000000000; int n, m, c; int a[1005]; int main() { cin >> n >> m >> c; int l = 1; int r = n; memset(a, 0, sizeof(a)); for (int i = 1; i <= m; ++i) { int p; scanf("%d", &p); if (p <= (c + 1) / 2) { ...
12
#include <bits/stdc++.h> using namespace std; int a[1111], b[1111]; long long calval(int i, int j) { long long ret_a = 0, ret_b = 0; for (int k = i; k <= j; ++k) ret_a = (long long)(ret_a | a[k]); for (int k = i; k <= j; ++k) ret_b = (long long)(ret_b | b[k]); return ret_a + ret_b; } int main() { int n; sca...
1
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; int n, m, cell[20][20], len, sx, sy, cn, sn, gx, gy; char chr; map<int, int> mp; queue<pair<int, int> > que; inline bool bound(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); } int main() { cin >...
14
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 50, inf = 1e9; int n, k, a[N], b[N], val[N], mx; long long ans; struct node { int l, r, t; bool operator<(const node &b) const { return l < b.l; } }; set<node> s; set<node>::iterator it; vector<pair<int, int> > v[N]; void split(int x) { it = --s.up...
27
#include <bits/stdc++.h> using namespace std; int main() { int n, x; set<int> bag; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x != 0) bag.insert(x); } cout << bag.size() << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int fp[maxn], ep[maxn]; int L[maxn], R[maxn]; bool book[2][maxn]; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x =...
13
#include <bits/stdc++.h> using namespace std; int n, tmp; vector<pair<int, int> > v; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> tmp; v.push_back(make_pair(tmp, i + 1)); } sort(v.begin(), v.end()); cout << n / 2 << '\n'; for (int i = 1; i < n; i = ...
7
#include <bits/stdc++.h> using namespace std; long long fac[1000009] = {1}, dp[1000009], qs[1000009], inv[1000009]; long long powermod(long long a, long long m) { if (m == 0) return 1; long long ret = powermod(a, m / 2); if (m % 2) return ret * ret % 1000000007ll * a % 1000000007ll; return ret * ret % 100000000...
16
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 502; int n, a[N], k, memo[N][N], maxx; int pr(int pos, int cnt) { if (pos == n) return 1; int &ret = memo[pos][cnt]; if (ret != -1) return ret; ret = 0; if ((cnt + 1) * maxx < k) ret = (ret + pr(pos + 1, cnt + 1)) % mod; ...
13
#include <bits/stdc++.h> using namespace std; int n; const int inf = 1000 * 1000 * 1000; size_t MAXN = 400 * 1000 + 100; vector<vector<int>> g(MAXN); vector<int> sz(MAXN); vector<int> mxd(MAXN); vector<int> mxu(MAXN); vector<int> answer(MAXN); int timer = 0; void dfs1(int v, int p = -1) { sz[v] = 1; mxd[v] = 0; f...
15
#include <bits/stdc++.h> using namespace std; const int N = 2e5; const int oo = 1e9 + 5; int du[] = {-1, 0, 0, 1}; int dv[] = {0, -1, 1, 0}; const long long mod = 1e9 + 7; long long sqr(long long x) { return x * x; } int n, f[N + 5][4], dad[N + 5]; vector<int> a[N + 5]; void dfs(int u, int p) { dad[u] = p; if (u ==...
13
#include <bits/stdc++.h> using namespace std; int n, m, q; int a[45][45], s[45][45], dp[45][45][45][45]; map<pair<pair<int, int>, pair<int, int> >, int> mp; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n; i++) { scanf("\n"); for (...
11
#include <bits/stdc++.h> using namespace std; const int N = 3005; int T, n, m, a[N], s[N]; std::pair<long long, long long> dp[N][N], tmp[N]; vector<int> f[N]; void upd(std::pair<long long, long long> &a, std::pair<long long, long long> t) { if (t > a) a = t; } void dfs(int x, int fa) { s[x] = 1; dp[x][1]...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<pair<int, int>, int> > points[1005]; for (int i = (int)(1); i <= (int)(n); i++) { int x, y; cin >> x >> y; points[x / 1000].push_back({{y, x}, i}); } for (...
13
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } int...
7
#include <bits/stdc++.h> using namespace std; void solve(); int main() { solve(); return 0; } void solve() { string s; int i; cin >> s; if (s[0] == '4') { cout << "NO"; } else if (s.find("444") != s.npos) { cout << "NO"; } else { for (i = 0; i < s.length(); i++) { if (s[i] != '1' && s[...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; cin >> n; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int mul = i * i + j * j; if ((int)(sqrt(mul)) * (int)(sqrt(mul)) == mul && (int)(sqrt(mul)) <= n) cnt++; } } cout << cnt << endl; }...
4
#include <bits/stdc++.h> using namespace std; int main() { long n, l; cin >> n >> l; vector<long> lanterns(n); for (long p = 0; p < n; p++) cin >> lanterns[p]; sort(lanterns.begin(), lanterns.end()); double d = max((double)(l - lanterns[n - 1]), (double)lanterns[0]); for (long p = 1; p < n; p++) { if ...
4
#include <bits/stdc++.h> int main() { int n, m, cnta = 0, cntb = 0, tmp, l, r; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &tmp); if (tmp == -1) ++cnta; else ++cntb; } for (int i = 0; i < m; ++i) { scanf("%d%d", &l, &r); tmp = r - l + 1; puts((tmp % 2)...
0
#include <bits/stdc++.h> using namespace std; int mx[8000001], lson[8000001], rson[8000001], root[300001], top, cnt, n, m, k; struct point { int l, r, x; } num[300001]; bool cmp(point a, point b) { return a.l > b.l; } void init(int &pos, int l, int r, int v) { pos = ++cnt; mx[pos] = v; if (l == r) return; ini...
16
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); long long n, k; cin >> n >> k; vector<long long> v(n); for (int i = 0; i < int(n); ++i) cin >> v[i]; long long x = 0; for (long long i = 60; i >= 0; i--) { x += (1ll << i); long long sum = 0; vector<vector<b...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); long long hl = accumulate(a.begin(), a.begin() + n / 2, 0); long long hr = accumulate(a.begin() + n...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, M, T; cin >> n >> M >> T; char temp; map<int, double> timeUs; int idUser = 0; double time; multiset<double> timeVisit; vector<int> ans; double hh, mm, ss; int countUser = 0; bool answer = false; for (int i = 0; i < n; i++) { c...
13
#include <bits/stdc++.h> const int MAXN = 5000 + 5; bool vis[MAXN]; char str[233]; inline void query(int x) { if (vis[x]) return; printf("? %d\n", x); std::fflush(stdout); scanf("%s", str + 1); if (str[1] == 'Y') vis[x] = 1; } inline void reset() { puts("R"); std::fflush(stdout); } int main() { int n, k...
22
#include <bits/stdc++.h> using namespace std; long long int num[1000005], ans[1000005], sum, n, k, temp, c[1000005][2], tree[1000005], cnt; long long int build(int s, int e, int t) { if (s == e) { if (num[s] != 0) return tree[t] = s; else return tree[t] = -1; } return tree[t] = max(build(s...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; while (t--) { int x, y, i; set<int> a, b; set<pair<int, int>> s; for (i = 0; i < 8; i++) { cin >> x >> y; a.insert(x); b.insert(y); ...
6
#include <bits/stdc++.h> int main(void) { int t; scanf("%d\n", &t); while (t--) { int n, m; scanf("%d %d\n", &n, &m); int a[n], b[m]; for (int i = 0; i < n; i++) scanf("%d ", a + i); for (int i = 0; i < m; i++) scanf("%d ", b + i); int flag = 0, ans = 0; for (int i = 0; i < n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = (1ll << 21); long long sum[MAXN], mins[22]; vector<vector<long long>> vm; long long dp[MAXN]; long long f(long long x) { long long &res = dp[x]; if (res >= 0) return res; if (x == (1ll << ((int)vm.size())) - 1) return res = 0; res = 0; long long s...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; bool first[maxn]; bool second[maxn]; int main() { ios::sync_with_stdio(false); int n, s; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> first[i]; } for (int i = 0; i < n; i++) { cin >> second[i]; } if (s == 1) { cout <...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long mod = 1e9 + 7; int main() { int t; cin >> t; while (t--) { int n, x; scanf("%d%d", &n, &x); vector<int> a, b; for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); a.push_back(temp)...
0
#include <bits/stdc++.h> using namespace std; int main() { char a[50]; cin >> a; int c = 0; for (int i = 0; i < strlen(a); i++) { if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') c++; else if (a[i] >= '0' && a[i] <= '9') { int x = (int)a[i]; if (x % 2 == 1) ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; struct edge { int to, cap; int cost; int rev; }; template <typename T> class min_cost_flow { public: using pti = pair<T, int>; vector<vector<edge> > G; vector<T> h, dist; vector<int> prevv, preve; T inf; int V; min_cost_flow(int no...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int c = 0, num = 0; for (int i = 0;;) { if (num == k) { if (a[i] == num) { c++; } break; } if (a[i] != num)...
2
#include <bits/stdc++.h> namespace IO { char gc() { return getchar(); } template <typename Tp> bool get1(Tp &x) { bool neg = 0; char c = gc(); while (c != EOF && (c < '0' || c > '9') && c != '-') c = gc(); if (c == '-') c = gc(), neg = 1; if (c == EOF) return false; x = 0; for (; c >= '0' && c <= '9'; c =...
27
#include <bits/stdc++.h> using namespace std; int main() { long long int n, temp, xorVal = 0, maxXorVal = 0; cin >> n; stack<long long int> st; for (int i = 0; i < n; i++) { cin >> temp; if (st.empty() || st.top() > temp) { if (!st.empty()) xorVal = temp ^ st.top(); } else { while (!st.e...
10
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; vector<long long> V, H; unordered_map<long long, vector<long long>> G; unordered_map<long long, long long> sz; unordered_map<long long, vector<long long>>::iterator it; long long a[N][3], ans[N]; bool comp(int i, int j) { pair<long long, long ...
11
#include <bits/stdc++.h> using namespace std; char a[1005]; int g[1005]; int main() { int n; cin >> n; for (int i = 0; i < n - 1; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { int l, r; l = r = 1; for (int j = i; j < n; ++j) { if (a[j] == 'R') break; else if (a[j] == ...
10
#include <bits/stdc++.h> using namespace std; char a[105]; int main() { cin >> a + 1; int len = strlen(a + 1); int flag = 5; for (int i = 1; i <= len; i++) { if (a[1] == 'h') { cout << "http://"; break; } else { cout << "ftp://"; flag = 4; break; } } int v = 0; in...
3
#include <bits/stdc++.h> using namespace std; int ara[100004], ara2[100004]; int main() { int n, i, j, k, l, ans = 0; cin >> n; for (i = 0; i < n; i++) cin >> ara[i]; for (i = n - 1; i >= 0; i--) { ara2[i] = max(ara2[i + 1], ara[i + 1]); } for (i = 0; i < n; i++) { ans = max(ara2[i] - ara[i] + 1, 0)...
3
#include <bits/stdc++.h> const int N = 3e5 + 10; const int mod = 1e9 + 7; using namespace std; int p[66], pr[66], u[66], cnt; bool isp[66]; void init(int n) { u[1] = 1; for (int i = 2; i <= n; i++) { if (isp[i] == 0) pr[++cnt] = i, u[i] = -1; for (int j = 1; j <= cnt && i * pr[j] <= n; j++) { int x = ...
16
#include <bits/stdc++.h> using namespace std; long long n, a[300069], sm; void chk(long long x, long long u) { if (a[x] > a[x - 1] && a[x] > a[x + 1]) sm += a[x] * u; else if (a[x] < a[x - 1] && a[x] < a[x + 1]) sm -= a[x] * u; } int main() { long long tt, rrr, t, rr, i, j, ii, u, k, l; scanf("%lld", &t...
13
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, m, k; char s1[25], s2[25]; int x[N], y[N], q1[N], q2[N]; int mn[1 << 20 | 5][22], p[25]; int main() { scanf("%d%d%d", &n, &m, &k); scanf("%s%s", s1 + 1, s2 + 1); for (int i = (int)(1); i <= (int)(n); i++) scanf("%d%d", &x[i], &y[i]); fo...
21
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<tuple<long long, long long, long long>> v; long long curb = -1; for (int i = 0; i < n; i++) { long long a, b; cin >> a >> b; if (curb == -1) curb = a; v.em...
10
#include <bits/stdc++.h> using namespace std; queue<pair<pair<int, int>, int> > v; vector<pair<int, int> > ans; int main() { ios_base::sync_with_stdio(0); cout.tie(0); int n, m, k, d, t = 0, a[500100] = {0}; cin >> n >> d >> k; if (k == 1 && d == 1 && n == 2) { cout << "YES\n1 2\n"; return 0; } else...
13