solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } void solve() { int n, m, ans = 0; cin >> n >> m; for (int i = 0; i <= n; i++) { int cur = i; int leftn = n - i; int leftm = m - 2 * i; if (leftm >= 0) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int tmp = n / min(k, 26), sisa = n % min(k, 26); for (int i = 0; i < k; i++) { cout << string(tmp, (i + 'a')); } ...
0
#include <bits/stdc++.h> using namespace std; int main() { int K; char A[100005]; scanf("%s", A); scanf("%d", &K); int L[30]; memset(L, 0, sizeof L); int len = strlen(A); for (int i = 0; i < len; ++i) L[A[i] - 'a']++; priority_queue<pair<int, int> > Q; int cont = 0; for (int i = 0; i < 30; ++i) ...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t; cin >> t; while (t--) { long long n, k; cin >> n; cin >> k; string s; cin >> s; long long zer = 0, one = 0; bool chk = true; for (long long i = 0; i ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[110], r = 1000, c = 1100; cin >> n >> k; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { if (k % a[i] == 0) { c = k / a[i]; } if (c < r) { r = c; } } printf("%d", r); }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, s = 0; cin >> n; int a[7]; for (i = 0; i < 7; i++) { cin >> a[i]; } i = 0; while (1) { s += a[i]; i++; if (s >= n) { cout << i << endl; break; } if (i == 7) { i = 0; } } return 0; }
2
#include <bits/stdc++.h> using namespace std; long double dp[18][(1 << 18)]; long double A[18][18]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> A[i][j]; } } for (int i = 0; i < n; i++) { dp[i][(1 << n) - 1] = !i; } for (int mask = (1 <...
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; int main() { int m[10], w[10]; for (int i = 0; i < 5; i++) { scanf("%d", &m[i]); } for (int i = 0; i < 5; i++) { scanf("%d", &w[i]); } int ans = 0; int s, u; scanf("%d%d", &s, &u); for (int i = ...
2
#include <bits/stdc++.h> using namespace std; const int m = 1e9 + 7; int deg[200001]; int depth[200001]; vector<vector<int>> v; void dfs(int u, int p) { if (p != -1) depth[u] = depth[p] + 1; for (int i = 0; i < v[u].size(); ++i) { if (v[u][i] != p) dfs(v[u][i], u); } } int main() { int n; cin >> n; v.re...
12
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; cin >> s >> t; long long n = s.size(); long long m = t.size(); long long firstOccurence[m], lastOccurence[m]; long long j = 0; for (long long i = 0; i < n; i++) { if (j < m &...
8
#include <bits/stdc++.h> using namespace std; long long n, k, p; long long a[2000]; long long b[2001]; long long dp[1003][2004]; long long cnt = 0; long long solve(long long index1, long long index2) { if (index1 >= n) { return dp[index1][index2] = 0; } if (index2 >= k) { return dp[index1][index2] = LONG_...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; int oo = 0, ee = 0; for (int i = 0; i < n; i++) { int c = s[i] - '0'; if ((c % 2 == 1) && (i % 2 == 0)) oo++; else if ((c % 2 == 0) && (i...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a, b, suma = 0, sumb = 0; for (int i = 0; i < 2 * n; i++) { cin >> a >> b; suma += a; sumb += b; } cout << suma / n << " " << sumb / n; return 0; }
4
#include <bits/stdc++.h> using namespace std; int cas, n, m; char s[4][200]; int ok(int i, int j) { if (i == 0 || i == 4) return 0; if (j > n) return 1; if (s[i][j] == '.' || s[i][j] == 's') return 1; return 0; } int main() { scanf("%d", &cas); while (cas--) { scanf("%d%d", &n, &m); scanf("%s", s[1]...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long len = s.length(); char ar[len + 1]; for (long long i = 0; i < len; i++) ar[i + 1] = s[i]; long long t; cin >> t; while (t--) { long long l, ...
5
#include <bits/stdc++.h> using namespace std; const int N = 55; int n; long long s, dp[N][2 * N][2]; int main() { scanf("%lld", &s); long long ans = 0; for (int la = 0; la < 50; la++) { for (int lb = 0; lb < 50; lb++) { long long a = (1ll << (la + 1)) + (1ll << (lb + 1)) - 3; if (s < a) continue; ...
24
#include <bits/stdc++.h> using namespace std; int n, m, d[300005], x; bool check(int a) { x = 0; for (int i = 1; i <= n; i++) { if (d[i] + a >= m) { if ((d[i] + a) % m >= x) continue; x = max(d[i], x); continue; } if (d[i] + a >= x) { x = max(d[i], x); continue; } r...
9
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const long long linf = 4000000000000000000LL; const long long inf = 998244353; const long double pi = 3.1415926535; void pv(vector<int> a) { for (auto& x : a) cout << x << " "; cout << '\n'; } void pv(vector<long l...
19
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int MAXN = 200005; const int MAXM = 3005; long long modpow(long long x, int p) { if (p == 0) return 1; if (p % 2 == 1) return (modpow(x, p - 1) * x) % MOD; long long r = modpow(x, p / 2); return (r * r) % MOD; } long long modinv(long...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; double dist = 0; int prevx, prevy; cin >> prevx >> prevy; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; dist += sqrt((x - prevx) * (x - prevx) + (y - prevy) * (y - prevy)); prevx = x; prevy = y; ...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 3e5, M = N; long long ll_scan() { long long x; cin >> x; return x; } string str_scan() { string x; cin >> x; return x; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t = 1; cin >...
3
#include <bits/stdc++.h> using namespace std; int n, k, d, u, res; int vis[300007]; queue<int> Q; int a[300007]; int b[300007]; vector<int> G[300007]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> k >> d; for (int i = 1; i <= k; ++i) { cin >> u; if (!vis[u]) { vis[u] = ...
13
#include <bits/stdc++.h> using namespace std; int test, n, m, a[1111], b[1111], sum, cur, tt, xx, yy, ct; bitset<1000001> dp[1111]; vector<int> ax, ay, bx, by; void add(int x, int y) { if (tt == 0) printf("%d %d\n", x, y); else printf("%d %d\n", y, x); } int main() { scanf("%d", &test); while (test--) {...
21
#include <bits/stdc++.h> using namespace std; int arr[50]; bool vis[27]; int main() { memset(arr, -1, sizeof arr); ios_base::sync_with_stdio(0); cin.tie(0); int n, ans = 0; bool flag = 0; char c; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> c >> s; int cnt = 0, cntn = 0; for (i...
8
#include <bits/stdc++.h> template <typename _Tp> void read(_Tp &x) { char ch(getchar()); bool f(false); while (!isdigit(ch)) f |= ch == 45, ch = getchar(); x = ch & 15, ch = getchar(); while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar(); if (f) x = -x; } template <typename _Tp, typename... Args> void...
25
#include <bits/stdc++.h> using namespace std; int ans = 0; int main() { string a; cin >> a; int tmp = 0; while (tmp != a.size()) { if (a[tmp] == 'A') { ans += 1; ++tmp; continue; } if (a[tmp] == '2') { ans += 2; ++tmp; continue; } if (a[tmp] == '3') { ...
11
#include <bits/stdc++.h> using namespace std; int dp[2][60], a[60]; int main() { int n, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } dp[1][n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) { dp[1][i] = max(dp[1][i + 1], a[i] + dp[0][i + 1]); dp[0][i] = min(d...
7
#include <bits/stdc++.h> int n, m; int edge[100100][3]; int elist[200100][2]; int en[100100]; char tmp[20]; int resn; int res[100100]; int tresn; int tres[100100]; int chk[100100]; int root[100100]; int rn[100100]; int rs[100100]; void dfs(int loc, int col, int r) { if (chk[loc] == 1) return; chk[loc] = 1; root[l...
14
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 1; map<long long, long long> mp, pm; deque<long long> v, vc, ve, vv; deque<char> p, pe; deque<string> ts, ss, st; deque<double> sd, ds; long long a, b, c, d, e, f, cnt, ans, r, n, l, z; long double q, t, cnt1, cnt2; string g, h, w, o, m, s; char y,...
2
#include <bits/stdc++.h> int main() { int t; int n; int i; long long int h, x; scanf("%d", &t); while (t--) { h = 0; scanf("%d", &n); for (i = 1; i <= 9; i++) { x = i; while (x <= n) { h++; x = x * 10 + i; } } printf("%lld\n", h); } return 0; }
2
#include <bits/stdc++.h> using namespace std; static const int MAXN = 1e5; int data[MAXN]; vector<pair<int, int> > ans; multiset<int> mul; int n, k; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", data + i); int j = 0, mx = -1; for (int i = 0; i < n; ++i) { mul.insert(data[i]); ...
11
#include <bits/stdc++.h> using namespace std; const long double PI = 2 * acos(0.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, k; cin >> n >> m >> k; vector<vector<long long>> graph(n + 1); map<pair<long long, long long>, long long> edge; vector<long long> x(n + 1, 0); ...
10
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n, m; scanf("%d %d\n", &n, &m); char a[n + 1][m + 1]; int maxRight[n + 1][m + 1]; memset(maxRight, 0, sizeof(maxRight)); for (int i = 0; i < n; i++) gets(a[i]); for (int i = 0; i < n; i++) { for (int j = m - 1; j >= 0;...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int res = 0; for (int i = 0; i < s.size() + 1; i++) { res += 25; if (i == 0) res++; } cout << res << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string t, p; cin >> t >> p; int n = t.size(); vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; int low = 0; int high = n; int best = 0; while (low <= high) { int mid = l...
9
#include <bits/stdc++.h> using namespace std; int n, k; string s; int pref[100001]; int main() { iostream::sync_with_stdio(0); cin >> n >> k >> s; for (int i = 0; i < n; i++) { pref[i + 1] = pref[i] + (s[i] == '0' ? 1 : 0); } int L = 0; int R = n - 1; while (R - L > 1) { int M = (R + L) / 2; f...
8
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } istream &in = cin; int n, m; long long N[1001], M[1001]; int main() { memset(N, 0, sizeof(N)); memset(M, 0, sizeof(M)); in >> n >> m; for (int i = (0); i < (n); ++i) { long long sum = 0; for (int j = (0); j <...
10
#include <bits/stdc++.h> using namespace std; int ans[100000]; vector<int> v[100000]; bool centroid[100000]; int subtree_size[100000]; int compute_subtree_size(int x, int y) { int c = 1, i; for (i = 0; i < v[x].size(); i++) { if (v[x][i] == y) continue; if (centroid[v[x][i]]) continue; c += compute_subt...
13
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const long ...
15
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; const int sz = 2 * 1e6 + 50, inf = 1e9 + 10; void solve() { int n; cin >> n; set<int> st; vector<int> vis(n + 1, 1), match(n + 1); for (int i = 1; i <= n; i++) { int k; cin >> k; vector<int> a(k); for (int j = 0...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 2; vector<int> depth[N]; vector<pair<pair<int, int>, vector<int> > > temp; vector<pair<int, int> > edge; vector<pair<vector<int>, vector<int> > > lis; int ask[N], ans[N], ans1[N]; string s; void reset(int n) { for (int i = 1; i <= n; i++) { ask[i] ...
26
#include <bits/stdc++.h> using namespace std; long long a[210000]; int main() { int N, i, j, k; long long K, cur, tmp; scanf("%d%I64d", &N, &K); for (i = 0; i < N; i++) scanf("%I64d", &a[i]); cur = 0; for (i = j = k = 0; i < N; i++) { tmp = cur - a[i] * j * (N - i - 1); if (tmp < K) { printf("...
8
#include <bits/stdc++.h> using namespace std; double dp[5005][5005], p[5005]; int t[5005]; double quickPow(double a, int b) { double ans = 1.0; while (b) { if (b & 1) { ans = ans * a; } a = a * a; b >>= 1; } return ans; } int main() { int n, T; cin >> n >> T; for (int i = 1; i <= n; ...
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:268435456") #pragma warning(disable : 6031) #pragma warning(disable : 4244) #pragma warning(disable : 26451) #pragma GCC target("sse4.2") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = int(1e9) + 7;...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; const int INF = 1000 * 1000 * 1000; int best_hi[410][53]; int best_lo[410][53]; int n, k; int S[410]; int res; int main() { scanf("%d %d", &n, &k); --k; for (int i = (0); i < (n); ++i) scanf("%d", &S[i]); for (int r = (0); r < (k + 1); ++r)...
18
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int mod = 1e9 + 7; const int P = 1e9 + 7; const int N = 2e7; const int MAXN = 1e6 + 5; long long n, a[1005]; int main() { ios::sync_with_stdio(false); cin >> n; for (long long i = 1; i <= n; ++i) cin >> a[i]; ...
12
#include <bits/stdc++.h> using namespace std; int len = 0; int main() { string s, answer = string(100000, 'a'); cin >> s; for (int i = 0; i < s.length(); i++) { bool b = 1; if (len && answer[len - 1] < s[i]) { b = 0; int l = 0, r = len - 1; while (l != r) { int now = (l + r) / 2;...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<double> X(n), Y(n); for (int i = 0; i < (n); i++) scanf("%lf %lf", &X[i], &Y[i]); int m; scanf("%d", &m); vector<int> A(m), B(m); for (int i = 0; i < (m); i++) scanf("%d %d", &A[i], &B[i]); for (int i = 0; i < (m...
14
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 7; const long long int MOD = 1e9 + 7; inline long long int mod(long long int x) { return x % MOD; } long long int fexp(long long int a, long long int e) { long long int r = 1; while (e) { if (e & 1) r = mod(r * a); a = mod(a * a); e >>= 1...
14
#include <bits/stdc++.h> using namespace std; int a[100001]; vector<pair<double, int> > event; double d[100001]; int main() { int n, l, v1, v2; scanf("%d%d%d%d", &n, &l, &v1, &v2); for (int i = (0); i < (n); ++i) { scanf("%d", &a[i]); } double s = (double)v2 / (v1 + v2) * l; int cycle = 0; for (int i ...
13
#include <bits/stdc++.h> using namespace std; const int max_n = 1011111, mod = 1000000007; int n, a[max_n], sum[max_n], sum_sq[max_n], cnt[max_n], pw[max_n]; int z[max_n], g[max_n], res[max_n]; bool get_bit(int mask, int pos) { return (bool)(mask & (1 << pos)); } void prec() { pw[0] = 1; for (int i = 1; i < max_n; ...
19
#include <bits/stdc++.h> using namespace std; struct S { int a, b; S() {} S(int _a, int _b) { a = _a; b = _b; } const bool operator<(const S &o) const { return a < o.a; } }; priority_queue<int> pq; priority_queue<int, vector<int>, greater<int>> mpq; map<int, int> mp; stack<int> st; set<int> set_i; int...
5
#include <bits/stdc++.h> using namespace std; long long dp[2][5002][3]; int a[5002], b[5002], c[5002], d[5002], x[5002]; void update(long long &dest, long long val) { if (dest == 0 || dest > val) dest = val; } int main() { int n, s, e; scanf("%d%d%d", &n, &s, &e); s--, e--; for (int i = 0; i < n; i++) scanf("...
17
#include <bits/stdc++.h> inline long long area(const std::pair<long long, long long>& a, const std::pair<long long, long long>& b, const std::pair<long long, long long>& c) { return std::abs((b.first - a.first) * (c.second - a.second) - (b.second - a.secon...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 21; const int N = int(1e5); const long long mod = int(1e9) + 7; const long long inf = 1e18; const double PI = 3.1415926536; inline int Set(int n, int pos) { return n = n | 1 << pos; } inline bool check(int n, int pos) { return n & 1 << pos; } inline in...
9
#include <bits/stdc++.h> using namespace std; int n; int main() { int tt, cc, n; long long lt = 0, size = 0, ans = 0; scanf("%d", &n); while (n--) { scanf("%d%d", &tt, &cc); long long t = tt, c = cc; if (t - lt >= size) size = 0; else size -= t - lt; lt = t; size += c; an...
3
#include <bits/stdc++.h> using namespace std; int a[502][502], b[502][502]; int s[502][502]; int main() { int n, m, t; scanf("%d%d%d", &n, &m, &t); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%1d", &a[i][j]); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { b[i][j] ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<long long> x(n + m); vector<long long> t(n + m); for (int i = 0; i < n + m; i++) { cin >> x[i]; } vector<long long> r; vector<long long> d; for (int i = 0; i < n + m; i++) { cin >> t[i]; if (t[i]) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int a = s.length() / k, word = 0; for (int i = 0; i < k / 2; i++) { int cmax = 0; map<char, int> m; for (int j = 0; j < a; j++) { ...
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } ...
9
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); string s; while (cin >> s) { vector<int> a[s.size()]; int k = 0, kt = 1, ans = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == '0') a[k++].push_back(i + 1); else { if (k == 0) { ...
8
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } ...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; pair<long long, long long> a[MAXN]; long long ANS[MAXN]; int main() { long long m, n, i, j, k; scanf("%I64d %I64d", &m, &n); for (i = 1; i <= m; i++) scanf("%I64d", &a[i].first), a[i].second = i; sort(a + 1, a + 1 + m); long long ans = 99...
10
#include <bits/stdc++.h> using namespace std; const int primero = 1 << 17; const int tope = 1 << 18; int minimo[tope]; void inicializa() { for (int i = 0; i < tope; i++) minimo[i] = 0; } void inserta(int pos, int val) { pos += primero; minimo[pos] = val; while (pos > 1) { pos /= 2; minimo[pos] = min(min...
16
#include <bits/stdc++.h> using namespace std; long long L[1000000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string f0 = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; L[0] = f0.size(); string bla1 = "What are you doing while sending ...
9
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<int, int>> v; int x[3]; int y[3]; for (int i = 0; i < 3; i++) { cin >> x[i] >> y[i]; v.push_back(make_pair(x[i], y[i])); } sort(v.begin(), v.end()); sort(x, x + 3); sort(y, y + 3); cout << x[2] - x[0] + y[2] - y[0] + 1 << "...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; pair<long long int, long long int> solve(vector<long long int>& v) { long long int izq = 0, same = 0; for (int i = 0; i < v.size(); i++) { long long int sum = 0; for (int j = i + 1; j + 1 < v.size(); j++) { sum += v[j]; ...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; const int maxm = 1e5 + 10; int f[maxn][maxn], nxt[maxn][maxn], deg[maxn]; int a[maxm], b[maxm]; void find(int y, int c2, int c1) { int nx = nxt[y][c2]; if (nx == 0) { nxt[y][c1] = 0; return; } find(nx, c1, c2); f[nx][y] = f[y][nx] = ...
20
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; cout << -(n - 1) << " " << n << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) solve(); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1024; const int E = 31086; struct edge { int x, y, nxt; int c; } bf[E]; int ne, head[N], cur[N], ps[N], dep[N]; void addedge(int x, int y, int c) { bf[ne].x = x; bf[ne].y = y; bf[ne].c = c; bf[ne].nxt = head[x]; head[x...
6
#include <bits/stdc++.h> long long dp[205][25][25][25][2], cif[205], n, a, b; char ch[205]; long long calc(long long k, long long nr, long long m1, long long m2, long long ok) { if (k > n) if (!nr && (m1 & m2)) return 1; else return 0; long long &rasp = dp[k][nr + 9][m1][m2][ok]; ...
19
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<int> v; for (int i = 1; i < 2000; ++i) { if (i % 3 == 0 or i % 10 == 3) { continue; } else v.push_back(i); } int t; cin >> t; while (t--) { int n; cin >>...
0
#include <bits/stdc++.h> using namespace std; long long num[1000000]; long long k, n; int main() { long long i, j; while (cin >> n >> k) { for (i = 0; i < n; i++) scanf("%I64d", num + i); sort(num, num + n); k--; long long cnt = 1, r = 0, l = 0; for (i = 0; i < n && k >= 0; i++) { if (i < ...
9
#include <bits/stdc++.h> using namespace std; struct pii { int x, y; }; struct pll { long long x, y; }; const int MOD = 998244353; const int N = 25; inline int lowbit(int x) { return x & (-x); } long long getgcd(long long x, long long y) { return (y == 0) ? x : getgcd(y, x % y); } long long power(long long x, lon...
18
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long double PI = (long double)(3.1415926535897932384626433832795); inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); } template <class T> inline void cinarr(T a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } inline lon...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; int n; struct Point { int x, y, z; int id; bool operator<(const Point& a) const { if (x != a.x) return x < a.x; if (y != a.y) return y < a.y; return z < a.z; return x < a.x || (x == a.x && y < a.y) || (x == a.x && ...
9
#include <bits/stdc++.h> using namespace std; long long n, a[1001], m, cnt, cnt1, cnt2; bool ch1, ch2, ch, ok1, ok2, ok, checked; string s[1000100], s1, s2, anss[100100]; vector<string> ans, v; map<string, int> myMap; template <typename T> string NumberToString(T Number) { ostringstream ss; ss << Number; return s...
0
#include <bits/stdc++.h> struct BCJ { int f[200005]; void init(int n) { for (int i = (1); i <= (n); i++) f[i] = i; } int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } bool ask(int x, int y) { return find(x) == find(y); } void uset(int x, int y) { f[find(x)] = find(y); } } bcj; int N, X[20000...
9
#include <bits/stdc++.h> using namespace std; #define int long long int #define yes cout<<"YES\n"; #define no cout<<"NO\n"; #define fl(n) for(int i=0;i<n;i++) #define mii map<int,int> #define mci map<char,int> #define V vector<int> #define vp vector<pair<int,int>> #define pb push_back int32_t main() { int t=1; cin>>t;...
0
#include <bits/stdc++.h> using namespace std; const int B = 131; const unsigned long long P = 1e9 + 7; int n, m; char s[200005]; unsigned long long t[26][200005], p[200005], a[26], b[26]; int main() { scanf("%d%d", &n, &m); scanf("%s", s + 1); p[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < 26;...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, x, y; cin >> a >> x >> y; pair<int, int> cor = {-a / 2, a / 2}, bigcor = {-a, a}; if ((x < bigcor.second && x > bigcor.first) && (y > 0)) { if (y % a == 0) { cout <<...
6
#include <bits/stdc++.h> using namespace std; multiset<int> a; int u[1000000]; int ar[1000000], dp[5002][5002]; int main() { int n, k; cin >> n >> k; for (long long i = 0; i < n; i++) scanf("%d", &u[i]); sort(u, u + n); memset(ar, 0, sizeof(ar)); int l = n % k, sz = n / k; dp[0][0] = 0; for (long long i...
12
#include<iostream> using namespace std; #define C const int #define I inline #define INF 9999999 I int Min(int x,int y){ return x<y?x:y; } struct SegmentNode{ int MinF,Lazy; }t[500000]; int a[100001]; I void Init(int p,int lf,int rt){ if(lf==rt){ if(lf!=0){ t[p].MinF=INF; } }else{ int mid=lf+rt>>1; Init(...
13
#include <bits/stdc++.h> using namespace std; int const N = 100000, inf = 1e9; int n, a, b, mns, mxs, ln; vector<int> tr[N + 1], sn; vector<pair<int, int> > mxdp[N + 1]; bool vis[N + 1], good[N + 1]; int D; bool go1(int v, int p = 0) { if (v == D) { sn.push_back(v); return true; } for (int u : tr[v]) ...
22
#include <bits/stdc++.h> using namespace std; const int md = 1e9 + 7; const int N = 2e5 + 5; vector<int> g[N]; int a[N], dwn[N], sz[N]; int n, ans; void dfs1(int u, int p) { sz[u] = 1; dwn[u] = a[u]; for (int v : g[u]) { if (v == p) continue; dfs1(v, u); sz[u] += sz[v]; dwn[u] = (dwn[u] + 1ll * a[...
15
#include <bits/stdc++.h> using namespace std; const int N = 123460; vector<int> adj[N]; int u, v, m, n, curmax, posmax, cnt; int par[N], a[N]; bool is[N], visit[N]; void dfs(int u, int h) { if (is[u]) { if (curmax < h) curmax = h, posmax = u; else if (curmax == h) posmax = min(posmax, u); } fo...
14
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; vector<pair<long long, long long> > vp; vector<long long> v; bool used[n + 1]; for (long long i = 1; i <= n; i++) used[i] = false; for (long long i = 0; i < m; i++) { char ch; long long num; cin >> ch >> ...
10
#include <bits/stdc++.h> using namespace std; long long egcd(long long a, long long b, long long& x, long long& y) { x = 1; y = 0; long long r = 0, s = 1; while (b != 0) { long long c = a % b, quot = a / b; a = b; b = c; long long new_r = x - quot * r, new_s = y - quot * s; x = r; y = s;...
11
#include <bits/stdc++.h> using namespace std; int n, ans; void qry(int k) { vector<int> v1, v2; for (int i = 1; i <= n; ++i) { int x = i % (2 * k); if (0 <= x && x < k) v1.push_back(i); else v2.push_back(i); } if (v1.empty() || v2.empty()) return; cout << v1.size() << ' ' << v2.size() ...
9
#include <bits/stdc++.h> using namespace std; vector<int> a[5]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; if (n >= 4 && m >= 4) { cout << -1; return 0; } if (n == 1 || m == 1) { cout << 0; return 0; } for (int i = 0; i < n; i++) { fo...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; cin >> n >> m; char arr[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) cin >> arr[i][j]; } int c = 0; for (i = 0; i < n; i++) { int flag = 0; for (j = 0; j < m; j++) { if (arr[i][j] == 'S') { fla...
0
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0), eps = 1e-8; int xp, yp, vp, x, y, v, r, it; long double s, h, le, ri, L, R, D, xc, yc, st, angp, angl, dstp, dstl, tm; long double sqr(long double x) { return x * x; } long double solve(long double a1, long double a2) { long double x = a...
16
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; else return gcd(b, a % b); } void doit(int& x1, int& x2, int xx, int x, int n) { x1 = x - xx / 2; x2 = x + xx / 2; if (xx % 2 == 1) x1--; if (x1 < 0) { x2 -= x1; x1 = 0; } if (x2 > n) { x1...
9
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); const int maxn = 1e3 + 10; const int mod = 1e9 + 7; int main() { int q; cin >> q; while (q--) { int len; scanf("%d", &len); char s[500]; scanf("%s", s); if (len == 2 && s[0] >= s[1]) printf("NO\n"); else {...
1
#include <bits/stdc++.h> using namespace std; long long dp[2][5005]; int n, i, j, k, mod = 1000000007; int fhdjskdhdf[5005][26], c[5005][5005]; bool used[30], ok = 0; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(); cin >> n >> s; c[0][0] = 1; for (i = 1; i <= n; i++) { for (j = 1; j <= i; ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; map<int, bool> display; deque<int> d; for (int i = 0; i < n; i++) { int id; cin >> id; if (display[id]) continue; display[id] = true; d.push_front(id); if ((...
2
#include <bits/stdc++.h> using namespace std; const int N = 200300; int n, m, a[N], v[N], sum[N]; long long ans; inline void read(int &x) { x = 0; char c = getchar(); int f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = 10 * x + c - '0...
14
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + ...
22
#include <bits/stdc++.h> using namespace std; const int mod = (1e9 + 7); int dig[100010]; vector<int> v[100010]; int pw[100010]; int val[100010]; char s[100010]; char ss[100010]; int main() { scanf("%s", s + 1); int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%s", ss + 1); dig[i] = ss[1] -...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10; const int mod = 1000000000 + 7; long long a[maxn], trans[maxn], c[maxn], ret_trans[maxn]; int n; void mul(long long *A, long long *B) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0; j <= i; j++) c[i] = (c[i] + A[j] ...
11