solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } const int MAXN = 250 ...
10
#include <bits/stdc++.h> using namespace std; char a[200]; int weed[160][160]; int main() { int n, m, i, j, f = 0; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%s", &a); for (j = 0; j < m; j++) if (a[j] == 'W') weed[i][j] = 1; } for (; n > 0; n--) { for (i = 0; i < m; i++) i...
7
#include <bits/stdc++.h> using namespace std; long long N; int K; bool ask(long long l, long long r) { cout << l << " " << r << "\n"; fflush(stdout); string ret; cin >> ret; return ret == "Yes"; } int main() { ios::sync_with_stdio(0); srand(time(NULL)); cin >> N >> K; long long lo = 1, hi = N; while...
13
#include <bits/stdc++.h> using namespace std; int cg[111111]; int cn[111111]; char wc[111111]; int wi[111111]; bool cb[111111]; const string OK = "Truth"; const string LIE = "Lie"; const string ND = "Not defined"; int main() { int n, m; scanf("%d%d", &n, &m); int an = 0; for (int i = 0; i < n; i++) { char c...
8
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> digits(long long int a) { map<long long int, long long int> mp; vector<long long int> v; long long int mini = LONG_LONG_MAX; long long int maxi = LONG_LONG_MIN; while (a) { long long int rem = a % 10; mini = min(mini, rem...
4
#include <bits/stdc++.h> using namespace std; struct side { int to, next; } a[400001]; long long f[200001], siz[200001], ans; int s[200001], n, root, cnt; inline void mem(int q, int w) { a[++cnt].to = w; a[cnt].next = s[q]; s[q] = cnt; return; } inline void dfs(int x, int fa, long long len) { f[root] += len...
11
#include <bits/stdc++.h> using namespace std; int main() { int x[300000], i, rem, n; while (cin >> n) { rem = 0; for (i = 0; i < n; i++) cin >> x[i]; for (i = 0; i < n; i++) { if (rem == 1) { x[i]--; if (x[i] < 0) { rem = 1; break; } else if (x[i] % 2 !=...
3
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); } long long int dp[100005], num[100005], sum[100005]; long long int pro(lon...
13
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long minf = -(1e18); int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); string str; cin >> str; int l = str.length(); long long sum = 0; int num = 0; int j = 0; for (int i = str.length() - 1; ...
3
#include <bits/stdc++.h> using namespace std; void GO() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } const long long INF = 1e9 + 7; const long long mod = (1e9); const int maxn = (int)2001; const long double PI = acos(-1.0); const long double eps = 0.000000001; mt19937 rnd(time(0)); void solve() { in...
9
#include <bits/stdc++.h> using namespace std; int n; int a, b, c, d; set<int> posicoes; int resp[107]; vector<int> espera; int main() { int pos = 1; cin >> n; assert(true); for (int i = 1; i <= n; i++) { posicoes.insert(i); } while (((int)(posicoes).size())) { int last = *prev(posicoes.end()); e...
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2e5; long long Power(int x, int y) { long long ans = 1; for (long long t = x; y; y >>= 1) { if (y & 1) ans = (ans * t); t = (t * t); } return ans; } int Rev(int x) { return Power(x, mod - 2); } int n, k; int a[2 * N + 5...
12
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base ::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } cout << max_element(arr, arr + n) - arr + 1 << ' '; sort(arr, arr + n); cout << arr[n - 2] << '\n'; retur...
0
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > V; int rem[10], ans[100005]; int main() { int main_flag = 1; scanf("%d%d%d%d%d%d", &rem[1], &rem[2], &rem[3], &rem[4], &rem[5], &rem[6]); map<string, int> M; M["S"] = 1; M["M"] = 2; M["L"] = 3; M["XL"] = 4; M["XXL"] = 5; ...
10
#include <bits/stdc++.h> using namespace std; long long N, M, L, ans; signed main() { scanf("%lld%lld", &N, &M); L = M + N; for (long long i = 1, j, g; i <= L; i = j + 1) { g = L / i, j = L / g; if (N < g || M < g) continue; long long ln = (N + g) / (g + 1), hn = N / g; long long lm = (M + g) / (g...
19
#include <bits/stdc++.h> using namespace std; inline int cmp(long double x, long double y) { if (x == y) return 0; return (x < y) ? -1 : 1; } struct Point { long double x, y; Point() {} Point(long double a, long double b) : x(a), y(b) {} Point operator-(Point b) { return Point(x - b.x, y - b.y); } bool op...
23
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define trav(a, x) for(auto& a:x) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define f first #define s second #define nl "\n" #define pb push_back typedef long long ll; typedef vector<int> vi; typedef pair<int,...
10
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; reverse((a).begin(), (a).end()); reverse((b).begin(), (b).end()); long long int ans = 0; for (long long int i = 0; i < min(a.length(), b.length()); i++) { ...
1
#include <bits/stdc++.h> using namespace std; int p1[100010], p2[100010]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) scanf("%d", &p1[i]); for (int i = 0; i < m; i++) scanf("%d", &p2[i]); sort(p1, p1 + n); sort(p2, p2 + m); int i, j; for (i = j = 0; i < n && j < m;...
8
#include <bits/stdc++.h> using namespace std; vector<int> gph[1005], dfn; int n, m, bad, col[1005]; void dfs(int x, int c) { if (col[x]) { if (col[x] != c) bad = 1; return; } dfn.push_back(x); col[x] = c; for (auto &i : gph[x]) { dfs(i, 3 - c); } } int bfs(int x) { int dis[1005] = {}; memset...
18
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const double PI = acos(-1.); const double eps = 1e-9; vector<int> G[100005]; int fa[100005]; int v[100005]; int a[100005]; vector<int> Ans; int fail = 0; void dfs(int u, int f) { if (a[u] == u) { v[u] = 1; } else if (~f && a[u] == a...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, m; struct E { int v, w; }; vector<E> G[N], g[N]; int cnt, bel[N]; int sta[N], top, ins[N], dfn[N], low[N], clk; long long val[N], f[N]; void dfs(int u) { sta[++top] = u, ins[u] = 1; dfn[u] = low[u] = ++clk; for (E e : G[u]) { int v...
13
#include <bits/stdc++.h> using namespace std; int a[100000], b[100000]; int main() { int n, x; scanf("%d%d", &n, &x); multiset<int> as, bs; for (int i = 0; i < n; ++i) { scanf("%d", a + i); as.insert(a[i]); } for (int i = 0; i < n; ++i) { scanf("%d", b + i); bs.insert(b[i]); } sort(a, a ...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; int mp[10][10]; int main() { int n, m, a, b; scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d %d", &a, &b); mp[a][b] = true; mp[b][a] = true; } if (n <= 6) { printf("%d\n", m); return 0; } int d = ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const double Max = 2e9; const double eps = 1e-6; int n, T; double a, k, b, xx, yy, jx, ans, kx, ky; inline double dis(double X1, double Y1, double X2, double Y2) { return sqrt((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)); } struct node { double...
24
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); int a[6][1010]; for (int i = 0; i < k; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } int ref[6][1010]; for (int i = 0; i < k; i++) { for (int j = 0; j < n; j++) ref[i][a[i][j]] = j; } int ...
11
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:64000000") const int infi = 1e9 + 7; const long long infl = 1e18; const long double eps = 1e-7; const long double eps1 = 1e-10; const int mod = (1e9 + 7); const long long mod1 = 1e9 + 7; const long long mod2 = 1e9 + 7; const long long p1 = 31...
7
#include <bits/stdc++.h> using namespace std; template <class T> string tostring(T x) { ostringstream out; out << x; return out.str(); } long long toint(string s) { istringstream in(s); long long x; in >> x; return x; } struct cmp { bool operator()(const pair<int, int> &a, const pair<int, int> &b) const...
8
#include <bits/stdc++.h> using namespace std; pair<int, int> a[1010]; int ans[1010] = {-999999999}; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; if (a[i].first < a[i].second) swap(a[i].first, a[i].second); } sort(a, a + n); int s = 0; for (int i = 0...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 6, nBits = 2e8 + 5, M = (1 << 16), MAX = 1111, OO = 0x3f3f3f3f, MOD = 1e9 + 7, inf = 1 << 30; const long long INF = (long long)1e18; long long GCD(long long a, long long b) { return !b ? a : GCD(b, a % b); } long long LCM(long long x, long long...
4
#include <bits/stdc++.h> using namespace std; using lli = long long; using ld = long double; mt19937 rnd(time(nullptr)); const lli inf = 1e18; lli Bit(lli mask, lli i) { return (mask >> i) & 1; } lli SetBitZero(lli mask, lli i) { if (Bit(mask, i) == 1) mask ^= (1LL << i); return mask; } inline void Solve() { lli ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[100001], i, j, k; cin >> n; for (i = 1; i <= n; i++) cin >> arr[i]; i = 1; while (arr[i] < arr[i + 1] && i < n) i++; if (i == n) { cout << "yes\n"; cout << 1 << " " << 1; } else { j = i; while (arr[j] > arr[j + 1] && j <...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 152020; const int maxm = 50000; long long a[maxn], b[maxn], t[maxn]; long long dp[2][maxn]; inline long long f(long long bi, long long ai, long long xi) { return bi - abs(ai - xi); }; struct node { long long val; int id; node(){}; node(long long v...
13
#include <bits/stdc++.h> using namespace std; int N, M; vector<pair<int, int> > b; vector<int> a[110000]; int f[110000], c[110000]; bool vis[110000]; int gf(int x) { return f[x] == x ? x : f[x] = gf(f[x]); } int main() { int N, M, i, x, u, v; scanf("%d%d", &N, &M); for (i = 1; i <= N; i++) { scanf("%d", &x); ...
11
#include <bits/stdc++.h> using namespace std; int grundy[2000005]; long long minLimit[] = {1, 4, 16, 82, 6724, 50626, 2000000}; int gVals[] = {0, 1, 2, 0, 3, 1, 1}; int findCleverGrundy(long long x) { int j; long long i, rt4, rt2; int avl[4] = {0, 0, 0, 0}; if (x < 4) return 0; rt4 = (long long)(sqrt(sqrt(x))...
14
#include <bits/stdc++.h> using namespace std; map<int, int> mx, my; vector<int> a; int shx[100005], shy[100005]; vector<pair<int, int> > vx[100005], vy[100005]; int cntx, cnty, m, n; void vertical(int x, int y1, int y2) { if (y1 > y2) swap(y1, y2); if (mx.find(x) == mx.end()) mx[x] = cntx++; shx[mx[x]] = x; vx[...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int a[n + 1], ar[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> ar[i]; int arr[n + 1]; if (ar[0] == 1) { arr[0...
4
#include <bits/stdc++.h> using namespace std; template <typename T, typename SS> ostream& operator<<(ostream& ofs, const pair<T, SS>& p) { ofs << "( " << p.first << " , " << p.second << " )"; return ofs; } template <typename T> void update_max(T last, T& mx) { mx = max(mx, last); } template <typename T> void upda...
12
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; long long a[N], pre[N], mx[N]; int main() { int n, x, m, ok = 0; scanf("%d", &n); m = (n + 1) / 2; for (int i = 1; i <= m; i++) scanf("%lld", &pre[i]), pre[i] += pre[i - 1]; scanf("%d", &x); for (int i = m + 1; i <= n; i++) pre[i] = pre[i ...
16
#include <bits/stdc++.h> using namespace std; long long mod = 1000000000 + 7; long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; return gcd(b, a % b); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t-...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> indices; int32_t main() { int t; cin >> t; while (t--) { int n; ll W; cin >> n >> W; ll mini = (W + 1) / 2; ll weight = 0; int count = 0; int x; for (int i = 1; i <= n; i++) { cin >> x; if (...
5
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int w = 1, c = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); return w * c; } signed main() { int _ = read(); while (_--) { ...
0
#include <bits/stdc++.h> const int mxn = 2e5 + 100; char ch[mxn]; long long p[mxn], s[mxn], d[mxn], m, r; long long mult(long long x, long long y) { long long z = 1LL * x * y; return z >= m ? z % m : z; } long long add(long long x, long long y) { x += y; while (x >= m) x -= m; return x; } long long sub(long l...
15
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int M = 200 + 5; char s[N][N]; int xd[5] = {0, 0, 1, -1}; int yd[5] = {1, -1, 0, 0}; string d = "><v^"; int mx, me[5] = {1, 0, 3, 2}, visited = 0; int cnt[N][N], n, m; bool taken[N][N]; queue<int> q; int get(int x, int y) { for (int i = 0; i < 4;...
12
#include <bits/stdc++.h> using namespace std; long long arr[50009][9]; int main() { long long n, m, ans = 0; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> arr[i][j]; for (int i = 2; i <= n; i++) arr[i][1] += arr[i - 1][1]; for (int i = 2; i <= m; i++) { for (int j = 1...
5
#include <bits/stdc++.h> using namespace std; int main() { int w, h; while (scanf("%d%d", &h, &w) >= 1) { int ans = 1; if (w == 1 || h == 1) { ans = max(ans, w * h); } else if (w == 2 || h == 2) { int x = max(w, h); int cnt = x / 4, rem = x % 4; int cans = cnt * 4 + min(rem, 2) *...
10
#include <bits/stdc++.h> using namespace std; int n, m; int c[100005], t[100005], v[100005]; vector<int> times(100005, 0); int solve(int t) { int hi = n - 1; int lo = 0; while (hi > lo) { int mid = (hi + lo) / 2; if (times[mid] >= t) hi = mid; else lo = mid + 1; } return lo + 1; } int ...
4
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; const long long N = 3e5 + 7; const long long INFL = 0x3f3f3f3f3f3f3f3fLL; const int INFI = 0x3f3f3f3f; using namespace std; void Solve() { string a, b, tmp; long long n, i, j; vector<long long> ans; cin >> n; cin >> a >> b; for (i = n - 1; i >= 0; i--)...
5
#include <bits/stdc++.h> using namespace std; long long n, m; vector<long long> a; long long t[1600000], lazy[1600000]; void build(int id, int l, int r) { if (l == r) { t[id] = a[l]; return; } int m = (l + r) / 2; build(2 * id, l, m); build(2 * id + 1, m + 1, r); t[id] = min(t[2 * id], t[2 * id + 1]...
14
#include <bits/stdc++.h> using namespace std; int n, a, b, c; char str[2000000 + 5]; vector<int> G[10000 + 5]; vector<int> per[10000 + 5]; int siz[10000 + 5], dfn[10000 + 5], low[10000 + 5], dcnt; int blo[10000 + 5], bgcd[10000 + 5], blocnt; int stk[10000 + 5], t; int num[10000 + 5], mx[10000 + 5], mn[10000 + 5]; bool ...
26
#include <bits/stdc++.h> using namespace std; bool isprime[0]; void Sieve_Atkin(int N) { int sqrtN = sqrt((double)N); for (int x = 1; x < sqrtN + 1; x++) for (int y = 1; y < sqrtN + 1; y++) { int n = 4 * x * x + y * y; if (n <= N && (n % 12 == 1 || n % 12 == 5)) isprime[n] ^= 1; n = 3 * x * x ...
6
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, k, d, p[N], dis[N]; vector<int> adj[N], ind[N], ans; queue<int> que; void bfs() { while (!que.empty()) { int v = que.front(); que.pop(); for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; if (dis[u] == -1) {...
13
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, m; cin >> s; n = (s[0] - 48 + 1) * pow(10, s.size() - 1); m = 0; for (int i = 0; i < s.size(); i++) { m = m * 10 + s[i] - 48; } cout << n - m; }
1
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; struct PT { int a, b, c, d, e, id; }; bool check(PT p1, PT p2, PT p3) { int x = (p2.a - p1.a) * (p3.a - p1.a) + (p2.b - p1.b) * (p3.b - p1.b)...
9
#include <bits/stdc++.h> using namespace std; int n, x, min1 = 101, min2 = 101; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x < min1) { min2 = min1, min1 = x; } else if (x != min1 && x < min2) { min2 = x; } } cout <...
0
#include <bits/stdc++.h> using namespace std; void task(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); task(); return 0; } const int N = 1e5; void solve() { long long n, x; cin >> n >> x; long long a, b; long long m = -2e9; long long m1 = -2e9; int d = n; while...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int main() { long long i, n, j, c = 0; cin >> n; pair<long long, long long> a[n]; for (i = 0; i < n; i++) { long long x, y; cin >> x >> y; a[i].first = x, a[i].second = y; } sort(a, a + n); for (i = 0; i < n; i++) {...
5
#include <bits/stdc++.h> using namespace std; const int N = 3000 * 6001 + 1; bool prime[N]; int main() { memset(prime, 1, sizeof(prime)); prime[1] = 0; int n; cin >> n; int x = n * (n + 1) / 2; int m = sqrt(x); for (int i = 2; i <= m; i++) if (prime[i]) for (int j = i * i; j <= x; j += i) prime[...
14
#include <bits/stdc++.h> using namespace std; int a[200]; int main() { int n, l; cin >> n >> l; for (int i = 1; i <= n; i++) cin >> a[i]; int ans = 0; for (int i = l; i <= 100; i++) { int tot = 0; for (int j = 1; j <= n; j++) tot += a[j] / i; if (tot * i > ans) ans = tot * i; } cout << ans << ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long a[N], n, r, r2, r3, d, dp[N][3]; long long solve(long long i, long long lst) { if (i > n) return 0; if (dp[i][lst] != -1) return dp[i][lst]; long long tmp = 0, tmpLst = 0, ans = 1e18; if (lst) { tmp = min({r * a[i] + r, r2, r3 * ...
15
#include <bits/stdc++.h> using namespace std; template <typename... Ts> void do_nothing(Ts &&...vals) {} constexpr long long MOD = 1000000007; constexpr int INF = 0x7f7f7f7f; constexpr double EPS = 1e-8; long long fastPow(long long num, long long exp) { if (exp == 0) return 1; if (exp == 1) return num; else {...
16
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t, class... A> in...
12
#include <bits/stdc++.h> using namespace std; const int maxm = 3e5 + 120; char que[maxm]; bool check(int l, int r) { for (int i = l; i <= r; i++) for (int j = i + 1; j <= r && (j << 1) - i <= r; j++) if (que[i] == que[j] && que[j] == que[(j << 1) - i]) return true; return false; } int main() { scanf("%s...
11
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0'; x *= f; } int n, m; int head[N]...
14
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; while (N--) { string S; cin >> S; S = S.substr(4); int vv = stoi(S); int latte = 0, fact = 10; for (int i = 1; i < S.size(); i++) { latte += fact; fact *= 10; } while (vv < 1989 + latte) vv += f...
12
#include <bits/stdc++.h> using namespace std; int a[300010], p[300010]; int ch[9000010][2]; int num[9000010]; int sz = 1; void insert(int x) { int u = 0; bool v; for (int i = 30 - 1; i >= 0; i--) { v = (1 << i) & x; if (!ch[u][v]) ch[u][v] = sz++; u = ch[u][v]; num[u]++; } } int del(int x) { i...
10
#include <bits/stdc++.h> using namespace std; vector<long long> prime(2750132, 0); vector<long long> prr; void pri(void) { long long i, j, k, l, p, n; for (i = 2; i <= 2750131; i++) { if (prime[i] == 0) { p = 2; n = p * i; while (n <= 2750131) { prime[n] = 1; p++; n = p...
10
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; vector<pair<long long int, long long int>> v; while (t--) { long long int a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()...
7
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} int in() { return scanf("%d%d", &x, &y); } } p[110000]; int n, id[110000]; vector<int> v[2 * 110000]; double dist(Point &a, Point &b) { return hypot(a.x - b.x, a.y - b.y); } bool cmpx(int a, int b) {...
14
#include <bits/stdc++.h> using namespace std; int a[101][101]; int main() { int n, k; cin >> n >> k; int i; for (i = 0; k && i < n; i++) { a[i][i] = 1; k--; for (int j = i + 1; k && j < n; j++) { if (k >= 2) { a[i][j] = 1; a[j][i] = 1; k -= 2; } } } if (k ...
6
#include <bits/stdc++.h> using namespace std; long long i, j, k; int main() { int n; cin >> n; map<pair<int, string>, int> mp; for (i = 0; i < n; i++) { string s; cin >> s; int l = s.size(); mp[make_pair(l, s)]++; } map<int, int> m2p; for (auto x : mp) { m2p[x.first.first]++; if (m...
3
#include <bits/stdc++.h> using namespace std; long long a, n, b, x, num, k, s, p; int main() { cin >> k >> n >> s >> p; if (n > s) { if (n % s == 0) { num = n / s; } else { num = n / s + 1; } } else { num = 1; } if ((k * num) % p == 0) { cout << k * num / p; return 0; } e...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 9; const int MAXV = 1 << 20; const int MAXB = 20; bool flag[MAXV]; int pos[MAXB]; bool cmp(pair<int, int> prev, pair<int, int> next) { return prev.second > next.second; } int main() { int n, rx, x, ans; vector<pair<int, int> > v; memset(pos, -...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long q; cin >> q; long long n, k; long long sum; long long minsum; string second; vector<long long> wrong; for (int j = 0; j < q; j++) { wrong.clear(); cin >> n >> k; cin >> second; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a[2005]; int n; while (cin >> n) { for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int ans = 1; for (int j = 1; j <= n; j++) { if (a[i] < a[j]) ans++; } if (i < n) cout << ans <<...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> v, t, r; map<int, int> m; cin >> n; for (int i = 1; i <= n; i++) { v.push_back(i); int b; cin >> b; t.push_back(b); m[b]++; } r = t; int f = 1; sort(t.begin(), t.end()); if (v == t) { for (int i = 0...
4
#include <bits/stdc++.h> using namespace std; const int K = 100; int n; vector<int> p; int sum(int x) { int cnt = 0; if (x <= 0) return 0; while (x) { cnt += x % 10; x /= 10; } return cnt; } int main() { cin >> n; for (int i = 1; i <= K; i++) { if (sum(n - i) == i) p.push_back(n - i); } so...
4
#include <bits/stdc++.h> using namespace std; int m, n; int main() { cin >> m >> n; int d = max(m, n); int ats = 0; int a, b; for (a = 0; a <= d; a++) { for (b = 0; b <= d; b++) { if (m == a * a + b && n == b * b + a) ats++; } b = 0; } cout << ats; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; int a[300005]; int pos[300005]; int main() { int t; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pos[a[i]] = i; } bool ok = false; for (int i = 2; i < n; i++) { for (int j = i + 1; j <= min(i + 100, n); j++) { int ...
19
#include <bits/stdc++.h> using namespace std; int const lim = 40; long long inf = 1e18; long long dp[lim + 3][lim + 3][lim + 3]; long long solve(int hi, int l, int r) { if (!hi && r < l) return 1; if (hi < 0 || r < l) return 0; long long &ret = dp[hi][l][r]; if (ret != -1) return ret; ret = 0; for (int i = ...
11
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int n = a.size(); int k; cin >> k; for (int i = 0; i < n; i++) { int mx = a[i]; int index = -1; if (k == 0) break; for (int j = i + 1; j < n && j <= i + k; j++) { if (mx < a[j]) { mx = a[j]; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0, i = 0; cin >> n; vector<int> a(n * n); for (int i = 0; i < n * n; i++) { a[i] = i + 1; } k = n / 2; for (int j = 0; j < n; j++) { for (i; i < k; i++) { cout << a[i] << " " << a[n * n - i - 1] << " "; } k = k + n...
2
#include <bits/stdc++.h> using namespace std; int n, m, k; int f, t; string a; int main() { cin >> n; while (n--) { t = 10, f = 0; cin >> a; k = a.length() - 4; a = a.substr(4, k); stringstream ss(a); ss >> m; for (int i = 1; i < k; i++) f += t, t *= 10; while (m < 1989 + f) m += t; ...
12
#include <bits/stdc++.h> using namespace std; int size_check(string root) { for (int i = 10; i >= 0; i--) { bool flag = true; for (int j = 0; j < pow(2, i); j++) { string str; for (int k = 0; k < i; k++) { if (j & (1 << k)) str += '1'; else str += '0'; } ...
14
#include <bits/stdc++.h> using namespace std; long long t, n, m, a, s; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n >> m; s = 0; for (long long i = 0; i < n; i++) { cin >> a; s += a; } if (s == m) { cout << "YES" << "\n"; ...
0
#include <bits/stdc++.h> using LL = long long; bool func(int m, int k, int n) { if (k <= 30 && (1 << k) < n) return false; LL binom = 1; LL sum = 0; int cnt = 0; for (int i = 0; i <= k; ++i) { int val = std::min<LL>(n - cnt, binom); cnt += val; sum += val * 1LL * i; if (cnt == n) break; bi...
18
#include <bits/stdc++.h> using namespace std; int n; string s, t; bool u[1001]; int main() { getline(cin, s); getline(cin, t); bool bo; for (int i = 0; i <= t.length() - 1; i++) { bo = 0; if (t[i] == ' ') continue; for (int j = 0; j <= s.length() - 1; j++) { if (s[j] == t[i] && !u[j]) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n; int f[2][N], fa[N]; vector<int> e[2][N]; struct Op { int a, b, c, d; }; vector<Op> ans; int getfa(int x) { for (; x != fa[x]; x = fa[x] = fa[fa[x]]) ; return x; } void dfs(int u, int fa, int t) { f[t][u] = fa; for (int v : e[t][u]...
24
#include <bits/stdc++.h> using namespace std; int main() { short Size; bool Ans = true; cin >> Size; int* arr = new int[Size]; for (int i = 0; i < Size; i++) cin >> arr[i]; for (int i = 0; i < Size; i++) { int Duplicated = 0; for (int j = 0; j < Size; j++) { if (arr[i] == arr[j]) ++Duplicated;...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; const int inf = INT_MAX; const int MOD = 1e9 + 7; const int mod = 1e9 + 9; void solve() { long long int n, m, k, x; cin >> n >> m >> k; long long int p[k + 1]; for (long long int i = 1; i <= k; i++) cin >> x, p[x] = i; long long int a[n + 1]...
6
#include <bits/stdc++.h> using namespace std; struct edge { int r, nxt, w; } e[300100 << 1]; int n, m, d[300100], sz[300100], head[300100], esz, tg[300100], vis[300100]; map<pair<int, int>, int> st; int dfs(int u, int f) { if (f != -1) sz[u] = 1; else sz[u] = 0; vis[u] = 1; for (int s, t = head[u]; t;...
13
#include <bits/stdc++.h> using namespace std; template <typename... T> void pp(T... args) { ((cout << args << " "), ...); cout << "\n"; } template <typename... T> void po(T... args) { ((cout << args << " "), ...); cout << ""; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int test = 1; for (in...
9
#include <bits/stdc++.h> using namespace std; long long n, m, seed, vmax, op, x, y; long long a[1000001]; struct node { long long l, r; mutable long long v; node(long long ll, long long rr = -1, long long vv = 0) : l(ll), r(rr), v(vv) {} bool operator<(const node &u) const { return l < u.l; } }; set<node>...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, z, s1 = 0, s2 = 0, s3 = 0; cin >> n; while (n--) { cin >> x >> y >> z; s1 += x; s2 += y; s3 += z; } if (s1 == 0 && s2 == 0 && s3 == 0) cout << "YES"; else cout << "NO"; return 0; }
2
#include <bits/stdc++.h> using namespace std; unsigned long long int N, k; string tgt; string toStr(unsigned long long int x) { string res = ""; while (x) { res = (char)(x % 2 + '0') + res; x /= 2; } return res; } unsigned long long int f(string str) { string cmp = tgt.substr(0, str.length()); unsig...
13
#include <bits/stdc++.h> using namespace std; typedef long long arr[153][2][2][153][153]; arr f, sum; const int MOD = 1000000007; void fix(long long &x) { while (x < 0) x += MOD; x %= MOD; } int main() { int n, m; cin >> n >> m; for (int(k) = (int)(1); (k) <= (int)(n); ++(k)) { for (int(i) = (int)(1); (i)...
16
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& input, const string& reText) { regex re(reText); sregex_token_iterator first{(input).begin(), (input).end(), re, -1}, last; return {first, last}; } void solve() { int n, m; cin >> n; vector<string> names(n); for (auto& a : na...
14
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; const long long mod = 998244353; char str[N]; long long dp[N], que[N]; int main() { long long n; long long ans = 0; int tot = 0; int zi = -1, zj = -1; scanf("%lld", &n); scanf("%s", str); dp[1] = 1; for (int i = 2; i <= n; i++) { i...
5
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const int inf = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int n, arr[nax]; int main() { ios::sync_with_stdio(0); int k, x; cin >> n >> k >> x; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = n - k + 1; i <...
0
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <clas...
12