solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> int trie[100004][26] = {{0}}; int win[100004] = {0}; int lose[100004] = {0}; int num_node = 1; void dfs(int node) { int isLeaf = 1; int i; for (i = 0; i < 26; i++) { int child = trie[node][i]; if (child) { isLeaf = 0; dfs(child); if (!win[child]) win[node] = 1; ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 15; int n; char s[maxn]; int dp[27][27]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s + 1); int len = strlen(s + 1); int fir = s[1] - 'a', en = s[len] - 'a'; for (int j = 0; j < 26; j++) if (dp[j][fir]...
7
#include <bits/stdc++.h> using namespace std; char s[200005], t[200005]; int n, m; int dp[200005], dp2[200005]; int prosli[200005]; int main() { scanf("%s", s); scanf("%s", t); n = strlen(s); m = strlen(t); int najduzi = 0; int tren = 0; for (int i = 0; i < 26; i++) prosli[i] = -m * 3 - 5; for (int i = ...
11
#include <bits/stdc++.h> using namespace std; void swapp(int& a, int& b) { int t = a; a = b; b = t; } int main() { int n; cin >> n; vector<int> v; int sum = 0; for (int i = 1; i <= 2 * n; ++i) { int k; cin >> k; v.push_back(k); } for (int i = 0; i < v.size(); i += 2) { for (int j = i...
6
#include <bits/stdc++.h> using namespace std; int main() { char a[100], flag = 1, flag1 = 0; cin >> a; for (int i = 0; i < strlen(a); i++) { if (a[0] != a[i]) { flag = 0; break; } } if (flag) { flag1 = 2; cout << "1"; } else { for (int i = 0; i < strlen(a) / 2; i++) { i...
1
#include <bits/stdc++.h> using namespace std; struct node { int pos; int id; } k[1000005]; bool cmp(node x, node y) { return x.pos < y.pos; } int main() { string s; cin >> s; int len = s.size(); int minn = 0; int maxx = len; for (int i = 1; i <= len; i++) { k[i].id = i; if (s[i - 1] == 'l') { ...
4
#include <bits/stdc++.h> int main() { int x, y; scanf("%d%d", &x, &y); int sum; sum = x + y; int rem; rem = (x * y) / 2; printf("%d", (rem)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; bool x; int cnt = 1; cin >> s; for (int i = 1; i < s.length(); i++) { x = true; for (int v = i - 1; v >= 0; v--) { if (s[i] == s[v]) { x = false; break; } } if (x) cnt++; } if (cnt % 2 == 0) ...
0
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } int k = 0; int vi[301], e, v, n, a[301], b[301], te[301], num, s1[1600...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int x; int tE = 0, tO = 0, kE = 0, kO = 0; for (int i = 0; i < n; i++) { cin >> x; if (x % 2 == 0) tE++; else tO++; } for (int i = 0; i < m; i++) { cin >> x; if (x % 2 == 0) kE++; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); cout << "1" << " " << v[0] << endl; int ct = 0; while (v[ct] < 0) ct++; if (ct >= 3) { cout << ...
3
#include <bits/stdc++.h> using namespace std; long long a[200005]; long long r[200005]; long long o[200005]; long long w[200005]; long long n, k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (long long i = 1; i <= n; i++) { cin >> a[i]; } long long cnt...
14
#include <bits/stdc++.h> using namespace std; using LL = long long; using pii = pair<int, int>; const int N = 2e5 + 10; vector<int> edge[N]; LL sum[2], num[2], ans; void up(int d) { ans += (d * num[d & 1] + sum[d & 1]) / 2; } int dfs(int x, int fa, int d) { int sz = 1; LL k = 0; up(d); up(d + 1); sum[d & 1] +...
12
#include <bits/stdc++.h> using namespace std; int n; const int MAXN = 100005; struct Edge { int a, b; } e[MAXN]; bool vis[MAXN]; int x, y; int cmp(Edge a, Edge b) { return a.a < b.a; } int main() { while (scanf("%d", &n) != EOF) { int i, j, k; memset(vis, 0, sizeof(vis)); for (i = 1; i <= n; i++) { ...
7
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for (auto e : v) out << e << ' '; return out; } template <class T> ostream& operator<<(ostream& out, vector<T> v) { return prnt(out, v); } template <cla...
18
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<long long> v; vector<long long> dif, ans; for (long long i = 1; i <= 1000000; i++) { v.push_back(i * i); } dif.push_back(1); for (int i = 1; i < v.size();...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, coverd = 0; cin >> n >> k; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; coverd += (y - x) + 1; } if (coverd % k == 0) cout << 0; else cout << k - (coverd % k); return 0; }
3
#include <bits/stdc++.h> using namespace std; const bool MULTITEST = 0; const long long MOD = 998244353; long long mul(long long a, long long b) { return a * b % MOD; } long long add(long long a, long long b) { return (a + b) % MOD; } long long solve() { long long n, k; cin >> n >> k; vector<vector<long long>> c(...
13
#include <bits/stdc++.h> using namespace std; char str[2][100001]; int n, cost[26][26]; int main(void) { scanf("%s %s %d", str[0], str[1], &n); for (int i = 0; i < 26; i++) { cost[i][i] = 0; for (int j = i + 1; j < 26; j++) cost[i][j] = cost[j][i] = 1000000002; } for (int i = 0; i < n; i++) { char t...
10
#include <bits/stdc++.h> using namespace std; const int M = 100000; const unsigned long long mod = 1ULL << 58; struct element { unsigned long long coef[5]; element(void) { memset(coef, 0, sizeof coef); } void operator+=(const element &rhs) { for (int i = 0; i < 5; i++) { coef[i] += rhs.coef[i]; } ...
26
#include <bits/stdc++.h> using namespace std; int t; int n, p; int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> t; while (t--) { cin >> n >> p; int cnt = 0; int flag = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { cout << ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], b[1000]; int o1 = 0, o2 = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], o2 |= a[i]; for (int i = 0; i < n; i++) cin >> b[i], o1 |= b[i]; cout << o1 + o2; return 0; }
1
#include <bits/stdc++.h> const long long Infll = 0x3f3f3f3f3f3f3f3f; const int MN = 1005; inline void Add(long long &x, long long y) { x = (x += y) >= Infll ? Infll : x; } long long K; int N, M, C, lcp[MN][MN]; char str[MN]; struct dat { int s, l; } seq[500505]; long long f[MN], g[MN]; long long Solve(dat now) { ...
20
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } vector<vector<long long>> v; v.resize(n, vector<long long>(n)); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> v[i][j]; long long c = ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int INF = 1e17; long long int fun(string s) { long long int i; long long int l = s.length(); long long int temp[l]; long long int coun = 0; for (i = l - 1; i >= 0; i--) { if (s[i] == 'h') { coun++; } temp[...
10
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n; long long ans = n * n; vector<pair<long long, long long> > a; for (long long i = 0; i < n; i++) { cin >> m; vector<long long> tmp(m); for (long long j = 0; j < m; ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long x1, y1, x2, y2, le, le2; cin >> x1 >> y1 >> x2 >> y2; long long to = ((y2 - y1) / 2) + 1, to2 = to - 1; if ((x2 - x1) % 2 == 0) { le = ((x2 - x1) / 2) + 1; le2 = le - 1; } else ...
11
#include <bits/stdc++.h> using namespace std; long long ans; int n, now, a[200035], f[200035]; struct node { int a, i; } p[200035]; bool cmp(node x, node y) { return x.a < y.a; } int lowbit(int x) { return x & -x; } void ins(int x, int c) { for (; x <= n + 1; x += lowbit(x)) f[x] += c; } int query(int x) { int re...
11
#include <bits/stdc++.h> using namespace std; struct segtree_max_add { const pair<long long, long long> INF = {-1e9, -1e9}; vector<pair<long long, long long> > st; vector<long long> lz; long long n; segtree_max_add(long long N) : n(N) { st.assign((n << 2) + 5, {0, 0}); lz.assign((n << 2) + 5, 0); ...
16
#include <bits/stdc++.h> int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int a, b, max, c; scanf("%d%d", &a, &b); if (b > a) max = b; else max = a; max = 6 - max + 1; c = gcd(max, 6); printf("%d/%d", max / c, 6 / c); return 0; }
0
#include <bits/stdc++.h> using namespace std; bool belong(string s) { if (s.length() < 3) return false; if (s.substr(s.length() - 3, 3) == "etr") return true; if (s.length() < 4) return false; string s1 = s.substr(s.length() - 4, 4); if (s1 == "lios" || s1 == "etra") return true; if (s.length() < 5) return ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long a[5]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if ((a[1] - a[0]) % 2 == 0) cout << a[1] << endl; else cout << a[2] << endl; return 0; }
13
#include <bits/stdc++.h> using namespace std; int n, col[100001], tot, rt[100001 * 40], ls[100001 * 40], rs[100001 * 40], sum[100001 * 40], mark[100001]; void update(int &rt, int od, int l, int r, int x, int a) { rt = ++tot, ls[rt] = ls[od], rs[rt] = rs[od], sum[rt] = sum[od] + a; if (l == r) return; int mid ...
16
#include <bits/stdc++.h> template <class T> inline void rd(T &x) { char c = getchar(), f = 0; x = 0; while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x = f ? -x : x; } const int MAXN = 1e5 + 7; int n, m, L, R, l[MAXN], r[MAXN], col[MAXN]; std::vector<i...
24
#include <bits/stdc++.h> const long long INF = 1000000000; const long long N = 300005; const long long MOD = 1000000007; const long long MAXN = 100005; const long long rootval = 319; using namespace std; vector<long long> adj[N]; vector<long long> v; long long dfs(long long u, long long par) { long long curr = 1; f...
12
#include <bits/stdc++.h> using namespace std; int oo = (int)(2e9); long long dp[5005][5005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); string t, s; cin >> s >> t; long long ans = 0; for (int i = 0; i < s.length(); i++) for (int j = 0; j < t.length(); j++) { if (...
9
#include <bits/stdc++.h> using namespace std; string s; int low[1000010], high[1000010]; int main(void) { int N, i; cin >> s; N = s.length(); reverse(s.begin(), s.end()); low[N] = 0; high[N] = 1; for (i = N - 1; i >= 0; i--) { if (s[i] == '0') { low[i] = low[i + 1]; high[i] = min(low[i + 1...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, w, W[maxn], S[maxn]; int main() { while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; ++i) { scanf("%d", &w); S[w - 1] = i; } set<pair<int, int> > P, Q; for (int i = 0; i < n; ++i) { scanf("%d", &w); ...
13
#include <bits/stdc++.h> using namespace std; const int N = 105; const int inf = 1000 * 1000 * 1000 * 2; char a[15] = {'a', 'e', 'i', 'o', 'u', 'y'}; int x[N]; char s[505]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i]; bool flag = true; for (int i = 0; i <= n; i++) { cin.getline(s,...
4
#include <bits/stdc++.h> using namespace std; const int N = 250005; int n, kk, P; using ll = long long; ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % P; a = a * a % P; b >>= 1; } return ret; } inline int lowbit(int x) { return x & -x; } ll fac[N], inv[N], dp[26][N]; ll dfs...
20
#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> inline void write(t x){ if(x<0) putchar('-'),wr...
23
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k, a, sum(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a; sum += a; } cout << min(sum, k) << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 101000; const long long MOD = 1e9 + 7; vector<int> v[MAX_N]; int col[MAX_N]; long long dp[MAX_N][2]; bool have[MAX_N]; long long ans = 1; void dfs(int x, int fa) { int i; dp[x][0] = 1; dp[x][1] = 0; for (i = 0; i < v[x].size(); i++) { int y = v...
12
#include <bits/stdc++.h> #include <unistd.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid (l+r)/2 typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; int main(){ ios_b...
0
#include <bits/stdc++.h> using namespace std; void priv(vector<double> &v) { for (auto x : v) cout << x << " "; } unsigned long long power(unsigned long long n, unsigned long long y, unsigned long long p) { if (y == 0) return 1; unsigned long long x = power(n, y / 2, p); x = (x * x) % p...
8
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f; const double eps = 1e-6; const double pi = 3.14159265358979; const int maxn = 2e5 + 5; const int maxm = 2e5 + 5; const long long mod = 1e9 + 7; int a[maxn], preodd[maxn], preeven[maxn]; int odd, even; bool...
4
#include <bits/stdc++.h> using namespace std; int n, k; string s; int solve() { vector<int> holes; int cur = 0; int tt = 0; bool start = false; int iscore = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') { if (i > 0 && s[i - 1] == 'W') iscore += 2; else iscore++; if ...
6
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int maxn = 205; const int chset = 26; class ACAutomata { private: class Node { public: long long val; int fail; int son[chset]; Node() : val(0), fail(0) { memset(son, 0, sizeof(son)); return; } } node...
17
#include <bits/stdc++.h> using namespace std; map<string, int> m; vector<string> ans; int N[5]; int k; map<string, int> sz; string tran[5]; int main() { for (int i = 0; i <= 4; i++) { cin >> N[i]; if (i == 0) { m["S"] += N[i]; sz["S"] = i; tran[i] = "S"; } if (i == 1) { m["M"] ...
3
#include <bits/stdc++.h> using namespace std; int a[1500]; int n; bool isPrime(int n) { for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } int main() { scanf("%d", &n); vector<int> ans; for (int i = 2; i <= n; i++) { if (isPrime(i)) { ans.push_back(i); for (int j = i ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> cnt; for (int i = 1; i < n + 1; ++i) { int a; cin >> a; cnt[a] = i; } int res = 1e9, tmp = -1; for (auto i : cnt) { if (i.second < res) { tmp = i.first; res = i.second; } } cout <<...
2
#include <bits/stdc++.h> using namespace std; int n, m; int b[1000005] = {0}; int f[15][15] = {0}; int g[15][15] = {0}; int ans = 0; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) { int o; cin >> o; b[o]++; } for (int i = 1; i <= m; i++) { if (b[i] >= 10)...
14
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; string s; cin >> s; string t; cin >> t; map<char, int> found; map<char, int> found2; bool match = false; for (int i = 0; i < (int)(n); i++) { if (found[s[i]]) ma...
12
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); map<long long, long long> m1; long long CeilIndex(std::vector<long long>& v, long long l, long long r, long long key) { while (r - l > 1) { long long m = l + (r - l) / 2; if (v[m] >= key) r = m; else...
2
#include <bits/stdc++.h> int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1}; using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; template <class T> T sq(T n) { return n * n; } template <cl...
13
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932; const int MAXN = 1e5 + 10; const long long mod = 1e9 + 7; long long inline mpow(long long a, long long b) { long long ans = 1; a %= mod; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod, b >>= 1; } retur...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n, h, a, b, k, x1, x2, y1, y2; cin >> n >> h >> a >> b >> k; for (int i = 0; i < k; i++) { cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) cout << abs(y1 - y2); else if (y1 < a && y2 < a) ...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, oo = inf; inline long long read() { register long long x = 0, f = 1; register char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return ...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); int m = INT_MAX; for (int i = 0; i < n; i++) { cin >> a[i]; m = min(m, a[i]); } for (int i = 0; i < n; i++) { a[i] -= m; } int c = 0; for (int i = m % n; i < n; i++) { if (a[i] <= c) { ...
5
#include <bits/stdc++.h> using namespace std; int arr[100007]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 31; i >= 0; i--) { vector<int> v; for (int j = 0; j < n; j++) if ((arr[j] >> i) & 1) v.push_back(arr[j]); int And = (1 << 30) - 1; for (int j...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:2000000") #pragma comment(linker, "/HEAP:2000000") using namespace std; void print_width(long long x) { std::cout << std::fixed; std::cout << std::setprecision(x); } long long power(long long x, long long y, long long p = 1000000007) { long long res = 1; ...
10
#include <bits/stdc++.h> using namespace std; int n, m = 62; bool hv[64][64]; long long a[100001]; int cnt[64]; vector<int> b[64]; bool vis[64]; int d[128][128], w[128][128]; map<int, int> mp; int q = 0; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; for (i...
11
#include <bits/stdc++.h> using namespace std; struct _ { _() { ios_base::sync_with_stdio(0); cin.tie(0); } } _; template <class A, class B> ostream &operator<<(ostream &o, pair<A, B> t) { o << "(" << t.first << ", " << t.second << ")"; return o; } template <class T> T convert(string s) { T first; st...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, a[105], m, x, y; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } cin >> m; for (int i = 0; i < m; i++) { cin >> x >> y; if (x == n) { a[x - 2] += (y - 1); } else if (x == 1) { a[x] += (a[x - 1] - y); } e...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 5; const int MOD = 998244353; long long fact[N]; long long inv_fact[N]; int cal_p(long long s, long long p) { long long base = s; long long val = 1; long long tmp = p; while (tmp > 0) { if (tmp & 1) { val *= base; val %= MOD; ...
17
#include <bits/stdc++.h> using namespace std; int main() { int ara[102]; int n, m, i, j, x; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &ara[i]); } sort(ara, ara + n); if (m > n) printf("-1\n"); else printf("%d %d\n", ara[n - m], ara[n - m]); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long k; int n; cin >> n >> k; vector<int> a(n); for (int &x : a) cin >> x; map<long long, int> kuroni; for (int &x : a) ++kuroni[x]; while (k > 0) { auto p = kuroni.begin(); auto ...
12
#include <bits/stdc++.h> using namespace std; int n, x[100010], y[100010]; int u[100010]; int main() { scanf("%d", &n); for (int i = 0; i <= n; ++i) scanf("%d%d", &x[i], &y[i]); int ans = 0; for (int i = 1; i <= n; ++i) { if (!u[i]) { ++ans; u[i] = 1; int X = x[i] - x[0], Y = y[i] - y[0]; ...
6
#include <bits/stdc++.h> using namespace std; long long n, m, k, d[5][2][100][100]; char a[100][100]; bool was[100][100]; string s; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> s; m = s.length(); for (int j = 0; j < m; j++) { a[i][j] = s[j]; } } for (int i = 0; i < n; i...
13
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long two[300300]; long long sum[300300]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); two[0] = 1; for (int i = 1; i < 300300; i++) two[i] = (two[i - 1] * 2) % MOD; int n; cin >> n; vector<long...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> sum(n + 1, 0); for (int x, i = 0; i < n; i++) { cin >> x; sum[i + 1] = sum[i] + x; } int max = 0; for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (sum[j] - sum[i] > 100 * (j - i) ...
6
#include <bits/stdc++.h> using namespace std; long long n, m, t; double k; long long a, b, c; long long dp[4001]; bool test = false, test1 = false; long long const N = 1e9 + 7; long long const oo = 1000000007; vector<long long> v, v1, s1, s; vector<vector<long long> > vv; vector<pair<long long, long long> > vp; map<lon...
1
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { int t; cin >> t; while (t--) { long long int n, m, i, ans = 0, k, x, y, z = 0, z1 = 0; cin >> n >> k; map<long long int, long long int> mp; for (i = 0; i < n; i++...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, a, b, n, p, q, x, m, y, t; cin >> t; for (i = 0; i < t; i++) { cin >> n >> m; if (n % m == 0) { cout << "YES\n"; } else { cout << "NO\n"; } } }
0
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } struct node { int a[2][2]; } f[50...
23
#include <bits/stdc++.h> int n, m; char a[1111][1111]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", a[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m - 1; j++) if (a[i][j] == '.' && a[i][j + 1] == '.') a[i][j] = a[i][j + 1] = (((i + j) & 1) ? ('0...
14
#include <bits/stdc++.h> using namespace std; void count() {} int ret(int x) { int a[10] = {false}; int h = 0; while (x > 0) { int b = x % 10; x /= 10; if (b != 0) { a[h++] = b; } } int t = 0; reverse(a, a + h); for (int i = 0; i < h; ++i) { t *= 10; t += a[i]; } return t...
2
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; string second; cin >> second; vector<vector<int> > v(26); int pos = 0; for (int i = 0; i < k; ++i) { for (int j = 0; j < second.size(); ++j) { v[second[j] - 'a'].push_back(pos++); } } int n; cin >> n; while (...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2048; const long long MOD = 1000000007; bool visited[MAXN][MAXN]; long long cache[MAXN][MAXN]; long long factorial[MAXN]; void factorial_init() { factorial[0] = 1; for (int i = 1; i < MAXN; i++) { factorial[i] = (factorial[i - 1] * i) % MOD; } } l...
12
#include <bits/stdc++.h> using namespace std; int N, M, Q; const int MAXN = 1024; const int MAXM = 200200; int A[MAXN]; int ed[MAXM][2]; tuple<int, int, int, int, int> que[MAXM]; bool res[MAXM]; int main() { int t1, t2, n1, n2, id; scanf("%d%d%d", &N, &M, &Q); for (int i = (0); i < (M); i++) scanf("%d%d", &(ed[i]...
20
#include <bits/stdc++.h> const int maxn = 2e6 + 10; const int maxval = 1e9 + 10; using namespace std; int n, m, a[maxn], b[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; sort(...
5
#include <bits/stdc++.h> using namespace std; int n, m; int a[100], b[100]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]); int max = 0, ans = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) ...
1
#include <bits/stdc++.h> using namespace std; int dist(pair<int, int>& a, pair<int, int>& b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } int main() { int r, b; pair<int, int> x[15], y[15]; vector<int> v; cin >> r >> b; if (r != b) { puts...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, a, x, cnt = 0; vector<int> v; cin >> n >> a; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } if (v[a - 1] == 1) cnt++; for (int i = a - 2, j = a; i >= 0 || j < n; i--, j++) { if (i >= 0) { if (v[i] == 1) { ...
2
#include <bits/stdc++.h> using namespace std; string a; bool f(int pos, string b) { bool res = false; if (pos == a.size()) return true; if (b.size() == 0) return false; if (a[pos] == b[0]) res |= f(pos + 1, b.substr(1)); else res |= f(pos, b.substr(1)); return res; } int main() { a = "hello"; st...
2
#include <bits/stdc++.h> using namespace std; int modulo = 1000000007; const int limite = 1 << 24; long long int rutas[limite]; long long int suma[limite]; int k; int bad[2]; int n; int a[30]; void generasuma(int b, long long int sum, int c) { if (b == n) { suma[c] = sum; return; } generasuma(b + 1, sum, ...
15
#include <bits/stdc++.h> using namespace std; int fst[666666], nxt[666666], vb[666666], ff[666666], M = 1, N = 0; long long cap[666666]; void _ad_dl(int a, int b, long long c) { ++M; nxt[M] = fst[a]; fst[a] = M; vb[M] = b; cap[M] = c; } void ad_dl(int a, int b, long long c) { _ad_dl(a, b, c); _ad_dl(b, a,...
23
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<bool> used; vector<vector<pair<int, int>>> lol; int n; int change(int x, int y) { if (x == y) return 0; return 1; } int main() { int x; cin >> n; vector<pair<int, int>> v(n * n); for (int i = 0; i < n; i++) { for (int j = 0; j <...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { string s; cin >> s; int n = s.size(), countA = 0, countB = 0, countC = 0; for (int i = 0; i < n; i++) { countA += (s[i] == 'A'); countB += (s[i] =...
0
#include <bits/stdc++.h> using namespace std; int main() { for (int i = 1; i <= 1; ++i) { long long n, ans = 0, ans2 = 0; string s; cin >> n >> s; for (int i = 0; i < s.size(); ++i) { if (s[i] == '0') ans++; if (s[i] == '1') ans2++; } if (ans != ans2) { cout << 1 << "\n"; ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; vector<int> depth[maxn]; vector<int> G[maxn]; int used[maxn], dist[maxn]; int pp[maxn]; void dfs(int now, int p, int d) { used[now] = 1; pp[now] = p; depth[d...
18
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int b[N]; int prime[N]; bool is_prime[N + 1]; void sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) is_prime[i] = 1; is_prime[0] = is_prime[1] = 0; for (int i = 2; i <= n; i++) { if (is_prime[i]) { prime[p++] = i; for...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int s = 0; int n, x1, x2, y1, y2, a, b; cin >> n; for (int i = 1; i <= n; i++) { cin >> x1 >> y1 >> x2 >> y2; a = x1 - x2; b = y1 - y2; if (a < 0) a *= -1; if (b < 0) b *= -1; a++; b++; s += a * b; } cout <<...
2
#include <bits/stdc++.h> using namespace std; long long int x[1000007], y[1000007], z[1000007], n; string s, S; vector<long long int> v; void space(int p) { long long int i; for (i = 0; i < p; i++) cout << " "; } int main() { { long long int a = 0, b = 0, c = 0, d, e, f, g, i, j, k = 0, l, m, p, q, r, ...
2
#include <bits/stdc++.h> using namespace std; int n, d, h; int main() { scanf("%d%d%d", &n, &d, &h); if (d - h < 0 || d + 1 > n || d > 2 * h || (d == 1 && n > 2)) return printf("-1") * 0; for (int i = 1; i <= h; i++) printf("%d %d\n", i, i + 1); if (d == h) { for (int i = h + 2; i <= n; i++) printf("2 %...
8
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m; cin >> n >> m; if (n == 1) { cout << 1 << endl; return 0; } if (m <= n / 2) { cout << m + 1 << endl; } else { cout << m - 1 << endl; } }
5
#include <bits/stdc++.h> using namespace std; int const N = 1000000 + 100, MOD = 1e9 + 7; int n, q; void update(string &x) { for (int i = 0; i < (int)x.size(); ++i) { x[i] = ((x[i] - '0') % 2 == 0) ? '0' : '1'; } } void reUpdate(string &x) { while (x.size() < 18) x = '0' + x; } long long trie[N + 1][12], sz[N...
6
#include <bits/stdc++.h> using namespace std; const int N = 1000005; char str[N]; int cnt[10], tmp[10]; int len, n; bool judge(int x) { for (int i = 0; i < 10; i++) tmp[i] = cnt[i]; if (!x) tmp[0]--; int ca = 0, xx = x; while (x) { ca++; tmp[x % 10]--; if (tmp[x % 10] < 0) return false; x /= 10;...
15
/******************************************************************** * * * * * Coded By colin! * * ...
7
#include <bits/stdc++.h> using namespace std; template <class T> void chmax(T &a, T b) { if (a < b) a = b; } template <class T> void chmin(T &a, T b) { if (a > b) a = b; } const int N = 1e5 + 10; const long long INF = 1LL << 60; long long iv[N]; long long powM(long long a, long long b) { long long res = 1; for ...
9