solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; struct P { int s, e, k, i; }; P a[100010]; P b[100010]; int cmp(P x, P y) { return x.s == y.s ? (x.e < y.e) : (x.s < y.s); } vector<int> w[400010], in[400010], out[400010], q[400010]; int ans[100010]; int main() { int n; scanf("%d", &n); vector<int> v; for (int i ...
13
// Problem : A. String Generation // Contest : Codeforces - Codeforces Round #689 (Div. 2, based on Zed Code Competition) // URL : https://codeforces.com/contest/1461/problem/A // Memory Limit : 256 MB // Time Limit : 1000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> usin...
0
#include <bits/stdc++.h> using namespace std; int n; vector<pair<long long int, long long int> > clients, answer, true_answer; int main() { cin >> n; clients.resize(n); for (int i = 0; i < n; i++) { cin >> clients[i].first >> clients[i].second; } answer.push_back(make_pair(0, 0)); for (int i = 0; i < n;...
8
#include <bits/stdc++.h> using namespace std; const int MAX = 8e4; int seg[3][3][MAX * 4], n, q, m[3][3], x, v, ans, MOD = 777777777, pw[MAX]; void upd(int x, int v, int s = 0, int e = n, int id = 0) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) seg[i][j][id] = 0; if (e - s == 1) { if (!v) ...
16
#include <bits/stdc++.h> int f[260][260]; int main() { int n, m; f[1][1] = 0; f[1][1] = 0; f[2][1] = 2; f[2][2] = 1; f[4][1] = 32; f[4][2] = 30; f[4][3] = 80; f[4][4] = 109; f[8][1] = 6824; f[8][2] = 59808; f[8][3] = 147224; f[8][4] = 415870; f[8][5] = 1757896; f[8][6] = 1897056; f[8][7]...
19
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pli = pair<ll, int>; using pil = pair<int, ll>; using pll = pair<ll, ll>; template <typename T> using vec = vector<T>; using vi = vec<int>; using vl = vec<ll>;...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; long long k = 0; while (k * (k - 1) / 2 <= n) ++k; k -= 1; if (k * (k - 1) / 2 == n) { cout << '1'; for (int i = 0; i ...
11
#include <bits/stdc++.h> using namespace std; string s; int a, i, n; int main() { cin >> s, n = s.size(); for (i = 0; i < n; i++) if (s[i] != s[(i + 1) % n]) { if (s[i] != s[(i + 2) % n]) a++; else if (s[i] != s[(i + 3) % n]) i++, a++; } cout << a; }
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, m; int s[100009], nt[200009], e[200009]; int out[100009], vis[100009][2], v, ss; int cnt, flag[100009]; struct node { int x, y; } pre, nt1; int dfs(int k) { flag[k] = 1; for (int i = s[k]; ~i; i = nt[i]) { if (flag[e[i]] == 1) ...
13
#include <bits/stdc++.h> using namespace std; template <class T1> inline void read(T1 &); template <class T1> inline void write(T1); int s[10005]; int b[10005]; int main() { int t; read(t); while (t--) { int n; double mini = 100000000000; int ansa, ansb; read(n); memset(s, 0, sizeof(s)); f...
8
#include <bits/stdc++.h> using namespace std; long long cnt(long long k, long long n, vector<long long> &pfxlen, vector<long long> &pfxcnt) { if (k > n) return 0; return pfxlen[n] - pfxlen[k - 1] - (k - 1) * (pfxcnt[n] - pfxcnt[k - 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL...
7
#include <bits/stdc++.h> using namespace std; long long int expo_fast(long long int a, long long int b) { a = a; long long int result = 1; while (b) { if (b & 1) result = (result * a); b >>= 1; a = (a * a); } return (result); } void take_in(vector<long long int>* arr) { for (int i = 0; i < arr->...
8
#include <bits/stdc++.h> using namespace std; const double eps = 1e-11; const int maxn = 2e5 + 9; const double pi = 3.14159265358979323846264; const int inf = 2e9; const int mod = 998244353; char a[maxn], b[maxn]; int op[maxn]; int main() { ios::sync_with_stdio(false); int n; cin >> n; cin >> a >> b; int tmp ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int T; cin >> T; for (int i = 0; i < T; ++i) { long long N, K; cin >> N >> K; long long step = 0; while (N > 0) { if (N % K == 0) { N /= K; ++step; } else { long long newN ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a, b, h[1000] = {0}, c; scanf("%d", &n); c = n; while (n--) { scanf("%d", &a); for (i = 0; i < a; i++) { scanf("%d", &b); h[b]++; } } for (i = 1; i <= 100; i++) { if (h[i] == c) printf("%d ", i); } }
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; char mat[110][10010]; int f[110][10010]; int main() { int n, m; while (cin >> n >> m) { for (int i = 0; i < n; i++) { cin >> mat[i]; for (int j = 0; j < m; j++) { f[i][j] = mat[i][j] == '1' ? 0 : INF; } } ...
7
#include <bits/stdc++.h> using namespace std; int inf_int = 2e9; long long inf_ll = 2e18; const double pi = 3.1415926535898; template <typename T, typename T1> void prin(vector<pair<T, T1> >& a) { for (int i = 0; i < a.size(); i++) { cout << a[i].first << " " << a[i].second << "\n"; } } template <typename T, ty...
8
#include <bits/stdc++.h> using namespace std; const pair<int, int> queen[8] = {pair<int, int>(-1, 0), pair<int, int>(-1, 1), pair<int, int>(0, 1), pair<int, int>(1, 1), pair<int, int>(1, 0), pair<int, int>(1, -1), pair<...
14
#include <bits/stdc++.h> using namespace std; pair<int, int> seg[100009]; int n, m, k; vector<pair<int, int> > add; vector<pair<int, int> > er; int segtobit[100009]; int bittoseg[100009]; int dp[(1 << 9)]; void addnew(int x) { for (int i = 0; i < 8; ++i) if (bittoseg[i] == 0) { bittoseg[i] = x; segtob...
17
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; if (a > b) return gcd(a % b, b); else return gcd(b % a, a); } int main() { long long t1, t2, x1, x2, t0, temp1, temp2, temp, y1, y2, ttt; double a, b, c, d, x, tt, dif; int t; double...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getcha...
15
#include <bits/stdc++.h> using namespace std; int read() { register int x = 0; register char f = 1, ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = !f; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0'); return f ? x : -x; } int n, d[250005], X, vis[250005]; l...
26
#include <bits/stdc++.h> int seg[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int cal(int x) { int sum = 0; while (x) { sum += seg[x % 10]; x /= 10; } return sum; } int main() { int a, b, sum = 0; scanf("%d%d", &a, &b); for (int i = a; i <= b; i++) sum += cal(i); printf("%d\n", sum); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int i, j, ok, k; char c; vector<char> mas, mas2; vector<int> use; while ((c = getchar()) != '\n') if (c != ' ') { mas.push_back(c); use.push_back(0); } while ((c = getchar()) != '\n') if (c != ' ') mas2.push_back(c); for (i...
3
#include <bits/stdc++.h> using namespace std; long long dp[1010][1010]; long long komm[1010][1010]; int n, m; vector<int> t[501]; vector<int> v; long long mod = 998244353; long long solve(int a, int b); long long kom(int a, int b) { if (komm[a][b] != 0) { return komm[a][b]; } long long ans = 0; for (int i =...
14
#include <bits/stdc++.h> using namespace std; priority_queue<long long> qa, qb; long long n; int main() { ios::sync_with_stdio(false); long long inp; cin >> n; for (long long i = 1; i <= n; ++i) { cin >> inp; qa.push(inp); } for (long long i = 1; i <= n; ++i) { cin >> inp; qb.push(inp); } ...
5
#include <bits/stdc++.h> using namespace std; const int maxk = 100, maxv = 300001; int a[110]; long long n, mas[maxk][maxv]; int k; long long fun(int pos, long long n) { if (pos == k) return 0; if (n < maxv) { if (mas[pos][n] != -1) return mas[pos][n]; return mas[pos][n] = fun(pos + 1, n) + n...
18
#include <bits/stdc++.h> using namespace std; int n, m, num; struct xp { int u, v; } ans[100000 + 5]; int gcd(int m1, int n1) { while (m1 > 0) { int c = n1 % m1; n1 = m1, m1 = c; } return n1; } void print() { printf("Possible\n"); for (int i = 1; i <= num; i++) printf("%d %d\n", ans[i].u, ans[i].v);...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1000002013, maxn = 1006; long long INF = 100000000000ll; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int l[maxn], p[maxn]; long long walk[maxn][35]; int from[maxn]; int main() { int t, af, n, k, b, d; string a, c; cin >> b >> d; cin >> a >> c...
12
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[1000010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const long long maxn = 1e3 + 10; const long long base = 29; const long long mod = 1e9 + 7; const long long INF ...
15
#include <bits/stdc++.h> using namespace std; vector<int> graph[2010]; int a[2010]; int dfs(int v) { int r = 0; for (int i = 0; i < graph[v].size(); i++) { r = max(r, dfs(graph[v][i])); } return r + 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++)...
1
#include <bits/stdc++.h> using namespace std; const int nmax = 1010; string a[nmax]; int id[nmax][nmax]; int ans[nmax][nmax]; vector<vector<int> > g, gr; void add(int u, int v) { g[u].push_back(v); g[v ^ 1].push_back(u ^ 1); gr[v].push_back(u); gr[u ^ 1].push_back(v ^ 1); } vector<bool> used; vector<int> order;...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll M = 998244353; ll n, x, a = 0; int main() { cin >> n; x = n; for (ll i = 0; i < n - 1; ++i) { a += ((x * (n - i - 1)) % M) * (i + 1) + M - x; a %= M; x = (x * (n - i)) % M; } ll ans = x * (x - n + 2) - 2 * a + M; ans %=...
25
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s[102]; while (cin >> a >> b) { for (int i = 0; i < a; i++) cin >> s[i]; sort(s, s + a); cout << s[a - b] << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, sum = 0, max_sum = 0, max_sum1 = 0; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long int l = 0, r = n - 1; l...
0
#include <bits/stdc++.h> using namespace std; void solve() { int x, y, z, t1, t2, t3; cin >> x >> y >> z >> t1 >> t2 >> t3; int s = abs(x - y) * t1; int e = abs(z - x) * t2 + abs(x - y) * t2 + 3 * t3; e <= s ? cout << "YES\n" : cout << "NO\n"; } int main() { solve(); }
0
#include <bits/stdc++.h> template <typename A, typename B> A& remax(A& a, B b) { return a = (a < b ? b : a); } const auto io_sync_off = []() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); return 0; }(); using vi = std::vector<int>; template <typename T> std::ostream& operator<<(std::ostream& os, const st...
11
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, m, j, cnt; cin >> n >> m; for (int i = 1; i <= n; i++) { int t; cin >> t; int sum = m - t; int use = 0; for (int j = 1; j <= 100; j++) { int ans = min(a[j], sum / j); use += ans; sum -= ans * j; ...
4
#include <bits/stdc++.h> using namespace std; class PrimeFactorizeHelper { private: int lim; vector<int> nextPrime; vector<int> primeList; public: void primeProcess(int desiredLimit) { lim = desiredLimit; nextPrime = vector<int>(lim + 1, 0); nextPrime[1] = 1; for (int i = 2; i <= lim; i++) { ...
13
#include <bits/stdc++.h> using namespace std; const int inf = (int)1.01e9; const long long infll = (long long)1.01e18; const long double eps = 1e-9; const long double pi = acos((long double)-1); mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x) { return mrand() % x; } void precalc() ...
23
#include <bits/stdc++.h> using namespace std; struct item { int x; int pos; item(int x, int pos) : x(x), pos(pos) {} item() : x(0), pos(0) {} }; bool operator<(item a, item b) { return a.x < b.x || (a.x == b.x && a.pos < b.pos); } const int MAX_N = 100 * 1000 + 5; const int shft = 2 * 100 * 1000 + 5; const in...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, k; cin >> n >> m >> k; map<long long, vector<long long>> mymap; for (long long i = (0); i < (n); i++) { long long j; cin >> j; mymap[j].push_back(i); } long lon...
10
#include <bits/stdc++.h> using namespace std; long long qwe[2][105]; long long tim[2][105]; int main() { string s1, s2; cin >> s1 >> s2; long long n; cin >> n; for (long long i = 0; i < n; i++) { long long t; char c; long long num; char y; cin >> t >> c >> num >> y; if (qwe[(c == 'h' ?...
5
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) class UnionFind { private: unsigned size_; std::vector<unsigned> par, rank; public: UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()){}; UnionFind(unsigned size__) : size_(size__) { par.r...
12
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, ty...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long powmod(long long a, long long b) { if (b == 0) return 1; else if (b % 2 == 0) { long long x = powmod(a, b / 2); return (x * x) % mod; } else return (powmod(a, b - 1) * a) % mod; } int main() { string s; cin >> ...
8
#include <bits/stdc++.h> using namespace std; int res(int a, int b, int c, int d, int va) { if (a > va) { a -= va; b -= va; } if (c > va) { c -= va; d -= va; } if (a > b or c > d) return 0; if (c < a) { swap(a, c); swap(b, d); } if (b >= d) return d - c + 1; if (b < va and d < ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char c; for (int i = 0; i < n * m; i++) { cin >> c; if (c == 'C' || c == 'Y' || c == 'M') { cout << "#Color"; return 0; } } cout << "#Black&White"; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long x, dp[55][55][55][55]; long long countCost(int n, int m, int k) { if (n * m == k || k == 0) return 0; if (n * m < k || k < 0) return 1e15; if (dp[n][m][k][x] != -1) return dp[n][m][k][x]; dp[n][m][k][x] = 1e15; for (int i = 1; i < n; i++) dp[n][m][k]...
12
#include <bits/stdc++.h> using namespace std; int n, k; int a[105]; int mi, ma; int ans[105][105]; int flag; void ini() { int i; ma = 0; mi = 1000; flag = 1; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); ma = max(ma, a[i]); mi = min(mi, a[i]); } } void solve() { int i, j, o; int te = ma - m...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, m, k; cin >> n >> m >> k; if (k < 2) cout << "NO\n"; else if (n == 1 && m == 0) cout << "YES\n"; else if (m < n - 1 || m > (n * (n - 1)) / 2) cout << "NO\n"; else { ...
4
#include <bits/stdc++.h> using namespace std; long long getSum(long long BITree[], long long index) { long long sum = 0; while (index > 0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(long long BITree[], long long n, long long index, long long val) { ...
15
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long xnot, ynot, ax, ay, bx, by; cin >> xnot >> ynot >> ax >> ay >> bx >> by; long long curx = xnot; long long cury = ynot; vector<pair<long long, long long> > vp; long l...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int n; int main() { cin >> n; int cnt = 1; while (n) { if (n == 3) { cout << cnt << " " << cnt << " " << 3 * cnt; return 0; } for (int i = 1; i <= (n + 1) / 2; i++) cout << cnt << " "; cnt *= 2; n = n / 2; } ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, a[26] = {0}, ans = 1e9, i; string s; cin >> n >> k >> s; for (i = 0; i < n; i++) { a[s[i] - 'A']++; } for (i = 0; i < k; i++) { ans = min(ans, a[i]); } cout << ans * k << "\n...
0
#include <bits/stdc++.h> using namespace std; long long solve(long long a, long long b, long long c, long long l) { long long maxx = a + b + c + l; long long ans = 0; for (long long i = a; i <= a + l; i++) { if (b + c > i) continue; else { long long x = min(i, maxx - i) - (b + c); ans +=...
13
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; inline long long read() { long long s = 0, w = 1; register char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + (ch ^ 48), ch = get...
18
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long aux = n; vector<long long> v; if (n == k) { cout << "YES" << endl; for (int i = 0; i < n; i++) { cout << "1 "; } return 0; } if (n % 2 != 0) { n--; k--; aux--; long lon...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[10001]; a[n] = 0; int c[10000]; int i, j; for (i = 1; i < n; i++) a[i] = 1; for (j = 0; j < k; j++) { for (i = 1; i <= n; i++) { if (a[i] == n - i) c[i] = n; else { if (a[i] * 2 > n ...
8
#include <bits/stdc++.h> using namespace std; string s1, s2; int n, m; int dp[1010][1010]; void dfs(int x, int y) { if (x == 0 && y == 0) return; if (s2[x] == s1[y]) dfs(x - 1, y - 1); else { if (x != 0 && y != 0 && dp[x - 1][y - 1] == dp[x][y] - 1) { cout << "REPLACE " << y << ' ' << s2[x] << '\n';...
13
#include <bits/stdc++.h> using namespace std; map<string, int> mp; char pt[20]; void make_pt(long long a) { for (int i = 0; i < 18; i++) { pt[i] = a % 10 % 2 + '0'; a /= 10; } pt[18] = '\0'; } int main() { int q; char str[20]; while (scanf("%d", &q) == 1) { mp.clear(); char tp[10]; long ...
6
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } long long arr[100009], path[100009], ans, dp[100009]; vector<int> adj[1000...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 4000; int k[4000]; int main() { int n; cin >> n; int a[n]; int b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; k[i] = a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; k[i + n] = b[i]; } sort(k, k + 2 * n); bool c = tru...
3
#include <bits/stdc++.h> using namespace std; int N, D, H; int main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> N >> D >> H) { if (D > H * 2 || ((D == 1 && H == 1) && 3 <= N)) { cout << -1 << endl; continue; } int ii = 2; for (int i = 0; i < H; i++) { cout << (ii -...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ara[n]; for (int k = 0; k < n; k++) { cin >> ara[k]; } int count = 0; int min_count = 999999999; for (int k = 0; k < n; k++) { int j; count = 0; for (int i = 0; i < ara[k]; i++) { cin >> j; count ...
1
#include <bits/stdc++.h> using namespace std; void quickSort(int a[], int l, int r) { if (l <= r) { int i = l, j = r; int x = a[(l + r) / 2]; while (i <= j) { while (x > a[i]) i++; while (x < a[j]) j--; if (i <= j) { swap(a[i], a[j]); i++; j--; } } i...
0
#include <bits/stdc++.h> using namespace std; char str[100005]; int Tree[27][400005], Lazy[27][400005], alpha[27], S, E; void build(int ind, int s, int e) { if (s == e) { Tree[str[s] - 'a'][ind] = 1; return; } build(ind * 2, s, (s + e) / 2); build(ind * 2 + 1, (s + e) / 2 + 1, e); for (int j = 0; j < ...
15
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; bool v[MAX]; int n, k, l, dp[MAX], cnt[MAX]; int solve(int cost) { for (int i = n; i--;) { dp[i] = v[i] + dp[i + 1]; cnt[i] = cnt[i + 1]; if (i + l <= n && cost + dp[i + l] < dp[i]) { dp[i] = cost + dp[i + l]; cnt[i] = 1 + ...
20
#include <bits/stdc++.h> using namespace std; int n, k; int a[8]; int sum; int cnt; void check() { int i, j, curr = 0; for (i = 0; i < n; i++) for (j = i; j < n; j++) if (a[i] > a[j]) curr++; sum += curr; cnt++; } void go(int x) { if (x == k) { check(); return; } int i, j, t; for (i = ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int num[1111]; int s[1111]; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &num[i]); } for (int i = 0; i < n; i++) { scanf("%d", &s[i]); } int maxi = 0; int temp = 0; int ans = 0; for (int i = 0; i < ...
5
#include <bits/stdc++.h> using namespace std; int n, v[100000], c[100000]; int q, a, b; long long f[100000 + 1]; bool m[100000 + 1]; int x, y; long long query(long long a, long long b) { memset(f, 0, sizeof(f)); memset(m, 0, sizeof(m)); f[0] = x = y = 0; long long res = 0; for (int i = 0; i < n; ++i) { lo...
12
#include <bits/stdc++.h> using namespace std; long long num1[200100]; long long num2[200100]; int vis[200100]; struct node { int val; int num; } cha[200100]; bool cmp(node a, node b) { return a.val < b.val; } int main() { int n, k; memset(vis, 0, sizeof(vis)); scanf("%d%d", &n, &k); for (int i = 0; i < n; i...
4
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 333; const long long linf = 1e18 + 333; long long mod; map<long long, long long> fib; long long f(long long n) { if (n < 2) return 1; if (fib.find(n) != fib.end()) return fib[n]; return fib[n] = (f((n + 1) / 2) * f(n / 2) + f((n - 1)...
13
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); string o = ""; for (int i = 0; i < s.length(); i++) { if (s[i] == ',') { if (i != s.length() - 1) { o += ", "; } else o += ","; } else if (s[i] == '.') { if (o.length()) { if (...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_wit...
12
#include <bits/stdc++.h> using namespace std; const int mxN = 1.5e5; int n, p[mxN]; vector<int> v[mxN]; int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; iota(p, p + n, 0); for (int i = 0; i < n; ++i) v[i] = {i}; ...
9
#include <bits/stdc++.h> using namespace std; long long INF = 1e9; long long MOD = 1e9 + 7; long long N, M, D, a, b; vector<pair<long long, long long> > A, B; long long curwgt, cursgf, curindA, curindB, ans; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second...
13
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; const double eps = 1e-7; const double pi = acos(-1.0); const long long INF = (long long)2e9 + 1; const long long LINF = (long long)8e18; const long long inf = (long long)2e9 + 1; const long long linf = (long long)8e18; const long l...
16
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; ...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 100; int dp[1 + MAX_N][1 + MAX_N]; int comb[1 + 2 * MAX_N][1 + 2 * MAX_N]; int n, m, k, p; void prec_comb(int n) { for (int i = 0; i <= n; i++) { comb[i][0] = 1; for (int j = 1; j <= i; j++) comb[i][j] = (comb[i - 1][j...
18
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 1000000010 const int N = 250 ; const int M = 65 ; int n; string s; int dp[2][N][N][2 * M]; int main(){ cin >> s; reverse(s.begin(),s.end()); s += "000"; n = (int)s.size(); for(int a = 0 ; a < N;a++){ for(int b = 0 ; b < ...
21
#include <bits/stdc++.h> using namespace std; long long *arr, n; long long** dp; long long func(long long i, long long j) { long long t = arr[i], u = arr[j], x = i, y = j; if (arr[i] == arr[j]) { while (i <= n && arr[i] == t) i++; while (j > 0 && arr[j] == u) j--; if (i > j) return 0; return dp[x][y...
11
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int ans = 0; for (int i = 0; i < a.length(); i++) { for (int j = i + 1; j < a.length(); j++) { auto s = a.substr(i, j - i + 1); string wow = s; reverse(wow.begin(), wow.end()); if (s != wow) { ans ...
1
#include <bits/stdc++.h> using namespace std; vector<int> graph[100005]; int dp[20][100005], level[100005], sum[100005], parent[100005], done[100005], answer[100005]; void dfs0(int v) { for (int i = 0; i < graph[v].size(); i++) { int u = graph[v][i]; if (u != dp[0][v]) { dp[0][u] = v; level[u]...
16
#include <bits/stdc++.h> using namespace std; int n, k; bool vis[1024]; bool g[1024][1024]; void go(int v, vector<pair<int, int> >& ans, vector<int>& c) { for (int v = 1; v <= n; v++) { for (int i = 1; i <= n; i++) { if (i != v && g[i][v] == 0) { if (c[v]) { c[v]--; g[i][v] = g[v...
6
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<map> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; using ll=long long; using pii=pair<int,int>; constexpr int N=300010; int h[N],e[2*N],ne[2*N],idx; void add(int a,int b){e[idx]...
18
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = getchar(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); ...
13
#include <bits/stdc++.h> using namespace std; template <typename T> using pq = priority_queue<T>; template <typename T> using pqr = priority_queue<T, vector<T>, greater<T>>; const long long INF = LLONG_MAX / 2; constexpr long long MOD = 1e9 + 7; using P = pair<long long, long long>; using vec = vector<long long>; using...
1
#include <bits/stdc++.h> using namespace std; const int SIZE = 512; const long long INF = 1e18; int n, m, k; long long a[SIZE][SIZE], normal[SIZE][SIZE], normal_copy[SIZE][SIZE], reversed[SIZE][SIZE], reversed_copy[SIZE][SIZE]; long long ps_row[SIZE][SIZE], ps_col[SIZE][SIZE]; long long ans; long long get_sum_row(i...
11
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {0, 4, 8, 15, 16, 23, 42}; int ans[5]; for (int i = 1; i <= 4; i++) { cout << "?" << " " << i << " " << i + 1 << endl; cout.flush(); cin >> ans[i]; } do { int flag = 0; for (int i = 1; i <= 4; i++) { ...
6
#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]; } bool b = true; for (int i = 0; i < n && b; i++) { b = a[i] % k == a[0] % k; } if (b) { sort(a, a + n); long long sum = 0; for (int i = 0; i < n...
1
#include <bits/stdc++.h> using namespace std; int n; int stx, sty, enx, eny; int dx[100001], dy[100001]; string str; bool solve(long long mid) { long long a = mid / n; long long b = mid % n; long long x = a * dx[n] + dx[b] + stx; long long y = a * dy[n] + dy[b] + sty; long long res = abs(x - enx) + abs(y - en...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[50], count = 0, i; cin >> n >> k; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (a[i] >= a[k - 1] && a[i] > 0) count++; } cout << count; }
0
#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...); } con...
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int nax = 1e6 + 10; long long int i, j, x, y, k, f, z, cnt; long long int p = 0; int main() { long long int t = 1; cin >> t; while (t--) { string s; cin >> s; long long int n = s.length(); long long int ans = n; long ...
5
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const long long int INFLL = 0x3f3f3f3f3f3f3f3fll; long long int getint() { long long int ret = 0; bool f = 0; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') f ^= 1; while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = get...
19
#include <bits/stdc++.h> using namespace std; int main(void) { char in[2], out[2]; int steps[2], directions[2]; int x1, y1, x2, y2, dif_x, dif_y, abs_dif_x, abs_dif_y; int n = 0, index = -1; cin >> in >> out; x1 = in[0] - 96; y1 = in[1]; x2 = out[0] - 96; y2 = out[1]; dif_x = x1 - x2; dif_y = y1 -...
2
#include <bits/stdc++.h> using namespace std; const int N = 15005; const int inf = 1000 * 1000 * 1000; const int mod = 1000 * 1000 * 1000 + 7; int n; vector<int> g[N]; vector<int> cycle; bool used[N], mark[N]; int parent[N]; void dfs(int v, int p) { used[v] = true; for (int i = 0; i < (int)g[v].size(); i++) { i...
20
#include <bits/stdc++.h> using namespace std; int main() { int a[27] = {0}, n; string s; cin >> n >> s; if (n == 1) { cout << "Yes"; return 0; } for (int i = 0; i < n; i++) { cin >> s[i]; a[int(s[i]) - int('a') + 1]++; } for (int i = 1; i < 27; i++) { if (a[i] > 1) { cout << "Y...
1