solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long long q, w, w1, e, r, t, c, v, f[5002], f1[5002], ans = 0; char a[5002]; cin >> a; q = strlen(a); f[q + 1] = 1; f1[q + 1] = 0; for (w = q - 1; w > 0; w -= 2) { f[w] = f[w + 2] * (a[w] - 48); f1[w] = f1[w + 2]; if (a[w - 1] == '+') ...
13
#include <bits/stdc++.h> using namespace std; int ara[5005]; int main() { int n; cin >> n; int x, y, z; cout << "? 1 2" << endl; cin >> x; cout << "? 1 3" << endl; cin >> y; cout << "? 2 3" << endl; cin >> z; int temp = x - y; int sum = temp + z; ara[2] = sum / 2; ara[1] = x - ara[2]; ara[3]...
6
#include <bits/stdc++.h> using namespace std; void file() {} void test_case() { int n, i, ans; cin >> n; ans = n / 2 + 1; printf("%d", ans); for (i = 1; i <= ans; ++i) printf("\n%d 1", i); for (i = 2; i <= n - ans + 1; ++i) printf("\n%d %d", ans, i); } int main() { ios_base::sync_with_stdio(0); cin.tie(...
3
#include <bits/stdc++.h> using namespace std; template <class T> void cmin(T &a, T b) { if (b < a) a = b; } template <class T> void cmax(T &a, T b) { if (b > a) a = b; } template <class T> int len(const T &c) { return (int)c.size(); } template <class T> int len(char c[]) { return (int)strlen(c); } string itos(l...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; template <class T> inline bool read(T& n) { T x = 0, tmp = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if (c == EOF) return false; if (c == '-') c = getchar(), t...
13
#include <bits/stdc++.h> using namespace std; int divv[10000005], n; long long ans[10000005]; int prr[10000005], c; int f[256]; int main() { cin >> n; for (int i = 0; i < 256; i++) f[i] = __builtin_popcount(i); for (int i = 2; i <= 10000000; i++) { if (divv[i] != 0) continue; if (i * 2 <= n) { prr[c...
19
#include <bits/stdc++.h> using namespace std; int main() { int k, r, c = 0; int a[4]; for (int i = 0; i < 4; i++) { cin >> a[i]; } sort(a, a + 4); for (int i = 0; i < 3; i++) { if (a[i] == a[i + 1]) { c++; } } cout << c << endl; }
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10; const long long INF = 0x3f3f3f3f; const long long Mod = 1e9 + 7; int n, m, x, y, t; struct node { int a; int b; } n1[maxn], n2[maxn]; int cmp(node a, node b) { return (a.a < b.a); } int ans[maxn]; int main() { cin >> n; for (long lon...
4
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { f |= (ch == '-'); ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x ...
23
#include <bits/stdc++.h> using namespace std; long long pp[1005]; long long key[2005]; int main() { long long n, m, k; cin >> n >> m >> k; long long sum = 0; for (int i = 0; i < n; i++) { cin >> pp[i]; } for (int i = 0; i < m; i++) { cin >> key[i]; } sort(pp, pp + n); sort(key, key + m); lon...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long n; cin >> n; vector<long> a(n); unordered_map<long, long> b; for (long j = 0; j < n; j++) { cin >> a[j]; b[a[j]]++; } long ma = 0; for (auto x : b) { if (x.second > ma) ma = x...
3
#include <bits/stdc++.h> using namespace std; int n; pair<double, double> A[100010]; bool compare_y(pair<double, double> a, pair<double, double> b) { return a.second < b.second; } int closest_pair(pair<double, double> *a, int n) { if (n <= 1) return 1000000000; int m = n / 2; double x = a[m].first; int d = mi...
14
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long r = 1; while (b != 0) { if (b % 2 != 0) { r = r * a; r %= 998244353ll; } a = a * a; a = a % 998244353ll; b = b / 2; } return r; } void solve() { long long n; cin >> n; for (l...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n >> a; if (a % 2 == 0) a = n + 1 - a; cout << (a + 1) / 2; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n; long long int k; cin >> n >> k; long long int ar[26]; for (int i = 0; i < 26; i++) ar[i] = 0; string s; cin >> s; for (int i = 0; i < n; i++) { ar[s[i] - 'A']++; } sort(ar, ar + 26); long long int ans = 0; for (int i...
5
#include <bits/stdc++.h> using namespace std; void solve() { int n, s, t; cin >> n >> s >> t; cout << n - min(s, t) + 1 << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { solve(); } }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string a[m]; string b[m]; for (long long i = 0; i < m; i++) { cin >> a[i] >> b[i]; } string c[n]; for (long long i = 0; i < n; i++) { cin >> c[i]; } int k = 0; int i = 0; for (long long i = 0; i < n; i++)...
2
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize "-O3" const int N = (1e5 + 5); const int64_t MOD = (1e9 + 7); const int64_t INF = (1e18 + 18); int n, m; vector<tuple<int64_t, int, int>> vt; struct DSU { vector<int> sz; vector<int> par; DSU(int x) { sz.resize(x + 5); par.resize(x + 5); ...
11
#include <bits/stdc++.h> using namespace std; void solve() { int n, a, b, c; cin >> n >> a >> b >> c; int sum = 0; int x1 = n / a; int x2 = n / b; for (int i = 0; i <= x1; i++) { for (int j = 0; j <= x2; j++) { int x3 = n - i * a - j * b; if (x3 % c != 0 || x3 < 0) continue; int x4 = x...
5
#include <bits/stdc++.h> using namespace std; long long ans = -1; int main() { long long n, k, l, r; cin >> n >> l >> r >> k; long long len = (l <= r ? (r - l + 1) : (n - l + 1 + r)); if (n <= 1000000) { for (int i = n; i <= 2 * n; i++) { long long s = k % i; if (!s) { s = i; } ...
18
#include<bits/stdc++.h> using namespace std; #define loop(i, l, r) for(int i = (int) l; i <= (int) r; i++) #define rloop(i, r, l) for(int i = (int) r; i >= (int) l; i--) #define vi vector<int> #define ii pair<int, int> #define eb emplace_back #define all(x) begin(x), end(x) #define fi first #define se second #defin...
18
#include <bits/stdc++.h> using namespace std; using namespace chrono; #define ll long long typedef unsigned long long ull; typedef long double lld; #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define print_upto(a, n) \ for (ll i = 1; i <= n; i++) \ ...
0
#include <bits/stdc++.h> using namespace std; string s; int cnt = 1, ans; int main() { cin >> s; for (int i = 1; i < s.size(); i++) { if (s[i] == s[i - 1]) cnt++; else { ans += (cnt + 4) / 5; cnt = 1; } } return cout << ans + (cnt + 4) / 5 << '\n', false; }
1
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (b = 0 ? a : gcd(b, a % b)); } int lcm(int a, int b) { return (a * (b / gcd(a, b))); } struct pto { double x; double y; pto() {} pto(double _x, double _y) { x = _x; y = _y; } }; int resp(int v[101][101], int n, int m) { boo...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1 << endl; cout << 1; } else if (n == 2) { cout << 1 << endl; cout << 1; } else if (n == 3) { cout << 2 << endl; cout << "1 3"; } else if (n == 4) { cout << 4 << endl; cout << "2...
3
// Black lives matter #include <bits/stdc++.h> /// 500 485 462 A4 using namespace std; typedef long long int ll; typedef complex<double> point; typedef long double ld; #define pb push_back #define pii pair < ll , ll > #define F first #define S second //#define endl '\n' #define int long long #define sync ios_base::sync...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int mod = 1e9 + 7; char s[maxn]; char t[maxn]; int f[maxn]; int w[maxn]; int dp[maxn]; int q[maxn]; int r[maxn]; int dp2[maxn]; int dp3[maxn]; void getFail(char *P, int *f) { int m = strlen(P); f[0] = 0; f[1] = 0; for (int i = 1; i < m...
12
#include <bits/stdc++.h> using namespace std; int n, m, t, p[3009]; bool mk[3009]; pair<int, int> s[3009]; int l = -1; void do_turn(int u) { if (u == 1) { for (int i = 0; i < m; i++) { if (mk[s[i].first] && !mk[s[i].second]) { mk[s[i].second] = true; cout << s[i].second << endl; retu...
9
#include <bits/stdc++.h> using namespace std; int n; vector<int> edge[100005]; long long dp[100005][2]; void calc(int v) { long long tmp[2][2]; int cur = 0, nxt = 1; tmp[cur][0] = 0; tmp[cur][1] = 1; for (int j = 0; j < edge[v].size(); j++) { tmp[nxt][0] = 0; tmp[nxt][1] = 0; calc(edge[v][j]); ...
19
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { int x = 0; char ch = getchar(); bool positive = 1; for ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int rank[10] = {0}; string str[10]; while (cin >> n >> k) { for (int i = 0; i < k; i++) rank[i] = i; for (int i = 0; i < n; i++) cin >> str[i]; int ans = 1000000000; do { int min_ = 1000000000; int max_ = -1; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int arr[n + 5]; for (int i = 0; i < n; i++) scanf("%d", &arr[i]); int mx = 1; int pos[n + 5]; for (int i = 0; i < n + 5; i++) pos[i] = 0; for (int i = 0; i < n; i++) { if (pos[arr[i] - 1]) { pos[arr[i]] = pos[ar...
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; vector<int> p, h, val; int flag = 0; int main() { int n; cin >> n; vector<int> v(n); map<int, long long> mp; long long ans = 0; for (int i = 0; i < n; i++) { cin >> v[i]; ans = max(ans, mp[i - v[i]] += v[i]); } cout << ans << ...
6
#include <bits/stdc++.h> using namespace std; long long read() { char cc = getchar(); long long cn = 0, flus = 1; while (cc < '0' || cc > '9') { if (cc == '-') flus = -flus; cc = getchar(); } while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar(); return cn * flus; } const long long ...
19
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, h[N], q[N], d[N], s[N], vis[N], sg[N]; vector<int> g[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v);...
24
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(int i, T X) { return (X & (1 << (i - 1))); } template <class T> T onbit(int i, T X) { return (X | (1 << (i - 1))); } template <class T> T offbit(int i, T X) { return (X | (1 << (i - 1)) - (1 << (i - 1))); } template <class T> T sqr(T x) {...
13
#include <bits/stdc++.h> using namespace std; int n, ans; vector<int> a[2]; map<int, int> quantity[2]; long long cnt; int main() { ios::sync_with_stdio(0); int m, x, y; cin >> n >> m; while (m--) { cin >> x >> y; a[x].push_back(y); quantity[x][y]++; } sort(a[0].begin(), a[0].end()); sort(a[1]....
20
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return {i, j}; } struct printer { ~printer() { cerr << endl; } template <class c> printer& operator,(c x) { cerr << boolalpha << x; return *this; } printer& operator...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 5e5 + 50; const long long LINF = 0x3f3f3f3f3f3f3f3f; const long long MOD = 1e9 + 7; const double EPS = 1e-6; const double Pi = acos(-1); void test() { cerr << "\n"; } template <typename T, typename... Args> void test(T x, Args......
11
#include <bits/stdc++.h> using namespace std; char temp[1000005]; int qtds[256]; int qtdt[256]; int main() { scanf("%s", temp); string s = temp; scanf("%s", temp); string t = temp; priority_queue<pair<int, char>> prox; for (int i = 0; i < s.size(); i++) { qtds[s[i]]++; } for (int i = 0; i < t.size()...
7
#include <bits/stdc++.h> using namespace std; const int P[26] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; int A[3000050], f[3000050]; bool vis[3000050]; int l, r, p, tot; void dfs(int i, int x) { if (i > 25) { tot++; A[tot] = x...
20
#include <bits/stdc++.h> using namespace std; int cnt[100001][2]; int main() { int t; cin >> t; while(t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]][i % 2]++; } sort(a.begin(), a.end())...
7
#include <bits/stdc++.h> using namespace std; int main() { int m; int a[1001]; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &a[i]); } sort(a, a + m); if (a[0] == 1) printf("-1\n"); else printf("1\n"); return 0; }
2
#include <bits/stdc++.h> using namespace std; struct node { int point; char name[15]; } p1[1005], p2[1005]; int n, m; char ans[1005][2][15], *d[5] = {"noob", "random", "average", "hardcore", "pro"}; bool cmp1(const node& a, const node& b) { if (!strcmp(a.name, b.name)) return a.point > b.point; if (strcmp(a.nam...
6
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } int n, m, k, ary[1010][1010]; int indx[1010], indy[1010]; int main(void) { ios_base::sync_with_stdio(0); cin >> n >> m >>...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, n, k, i, c = 0, i1 = 0; vector<pair<int, int> > v; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a; v.push_back(make_pair(a, i + 1)); } sort(v.begin(), v.end()); while (c <= k) { c += v[i1].first; if (i1 < n && c <= k) ...
2
#include <bits/stdc++.h> char str[1111]; int main() { int a, b, c, d, e, f, g, h; scanf("%d", &b); while (b--) { scanf("%s", str); int len = strlen(str); for (d = 0, a = 0; d < len; d++) { if (d && str[d] >= '0' && str[d] <= '9' && str[d - 1] >= 'A' && str[d - 1] <= 'z') a++; ...
8
#include <bits/stdc++.h> using namespace std; const long long N = 100010, M = 1000010, INF = 0x3f3f3f3f; inline long long max(long long x, long long y) { return x > y ? x : y; } inline long long min(long long x, long long y) { return x < y ? x : y; } inline void swap(long long &x, long long &y) { x ^= y ^= x ^= y; } lo...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m, s, e; int a[maxn], b[maxn], dp[305]; vector<int> bv[maxn]; int main() { scanf("%d%d%d%d", &n, &m, &s, &e); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) { scanf("%d", &b[i]); bv[b[i]].push_back...
15
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int casos; string txt; cin >> casos; while (casos--) { cin >> txt; if (txt.size() <= 10) cout << txt << "\n"; else cout << txt[0] << txt.size() - 2 << txt[txt.size() - 1] << "\n"; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a; multimap<int, int, greater<int>> m1; for (int i = 0; i < n; i++) { int p; cin >> p; a.push_back(p); } for (int i = 0; i < n; i++) { int p; ...
6
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; int n; long long x, y, sumx = 0, sumy = 0, qx = 0, qy = 0; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%I64d %I64d", &x, &y); sumx += x; sumy += y; qx += x * x; qy += y * y; } printf("%I64d\n", n *...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int n; long long c, p[maxn], s[maxn], f[maxn], ans, sum; int main() { cin >> n >> c; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) { f[i] = 1e18; for (int j = i; j >...
21
#include <bits/stdc++.h> const long double eps = 1e-9; const double pi = acos(-1.0); const long long inf = 1e18; using namespace std; int n, x, a, ans = 0, pp[111111], h = 11111, t = 11110; int used[111111], pref[111111]; int main(int argc, const char* argv[]) { scanf("%d%d", &n, &x); for (int i = 0; i < n; i++) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, s1, s2; cin >> s; int i, j; cin >> s1; string s3 = "6789TJQKA"; cin >> s2; if (s1[1] == s[0] && s2[1] != s[0]) cout << "YES"; else if (s1[1] == s[0] && s2[1] == s[0]) { for (...
2
#include <bits/stdc++.h> #pragma GCC optimize("fast-math") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC diagnostic ignored "-Woverflow" using namespace std; const short INF16 = ~(1 << 15); const int INF32 = 2e9 + 11; const int SZ = 4e5 + 11; const int SZ2 = int(1e6 + 11); const int mod...
18
#include <bits/stdc++.h> char s[100005]; int cnt[26], n, i, cur = 0, tot = 0; char t[100005]; int main() { scanf("%s", s); n = strlen(s); for (i = 0; i < n; i++) cnt[s[i] - 'a']++; for (i = 25; i >= 0; i--) { while (cnt[i]) { while (s[cur] != 'a' + i) cnt[s[cur] - 'a']--, cur++; t[tot++] = 'a' +...
3
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { int n, x; cin >> n >> x; n = n % 6; a[x] = 1; while (n > 0) { if (n % 2 == 0) { swap(a[1], a[2]); } else swap(a[0], a[1]); n--; } for (int i = 0; i <= 10; i++) { if (a[i] == 1) { cout << i; break;...
2
#include <bits/stdc++.h> int main() { int h1, h2, a, b; scanf("%d %d", &h1, &h2); scanf("%d %d", &a, &b); if (h2 - h1 <= 8 * a) printf("%d", 0); else if (a <= b) printf("%d", -1); else { h1 = h1 + a * 8 - b * 12; int count = 1; while (h1 + 12 * a < h2) { h1 = a * 12 + h1 - b * 12; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 101; int n, m, k, a[N]; int read() { int d = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') d = (d << 3) + (d << 1) + c - 48, c = getchar(); return d * f; } voi...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int k; int main() { scanf("%d", &k); if (k & 1) puts("-1"), exit(0); for (int i = 1; i <= k; ++i) { for (int j = 1; j <= k; ++j, puts("")) for (int p = 1; p <= k; ++p) { int tmp = min(min(j, p), min(k - j + 1, k - p + 1)); ...
8
#include <bits/stdc++.h> using namespace std; struct BO { int a, b; } a[300]; int n, tot, mt, tt; int f[110][11000]; int cmp(const BO &x, const BO &y) { return x.b < y.b; } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].a; tot += a[i].a; } for (int i = 1; i <= n; i++) { cin >> a...
11
#include <bits/stdc++.h> using namespace std; int flag[20]; bool fun(int a) { while (a) { if (flag[a % 10]) return true; a = a / 10; } return false; } int main() { int n, t, i, sum; while (scanf("%d", &n) != EOF) { memset(flag, 0, sizeof(flag)); t = n; while (t) { flag[t % 10] = 1; ...
5
#include <bits/stdc++.h> using namespace std; const int NO = 1000005; const int MOD = 1000000007; long long value[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, bit[10] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}; string p[NO]; string s; int main() { cin >> s; int n; scanf("%d", &n); for (int i = 1; i <= n; i++...
13
#include <bits/stdc++.h> using namespace std; const int N = 1000; int q, k, n, a, b; bool check(int mid) { int s = 0; s += mid; int kk = k - mid * b; s += (kk) / a; if (kk % a == 0) s--; return s >= n; } int main() { ios::sync_with_stdio(false); cin >> q; while (q--) { cin >> k >> n >> a >> b; ...
6
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long ZERO = 0LL; const long long INF64 = 1e18; const lo...
5
#include <bits/stdc++.h> using namespace std; bool comp(long long a, long long b) { if (a >= b) return true; else return false; } bool solve(long long a[], long long n) { long long sz = 1 << n - 1; for (long long i = 0; i <= sz; i++) { long long sum = 0; for (long long j = 0; j < n; j++) { ...
4
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; const long long INF = 1e9; const long long MOD = INF + 7; string s; vector<string> ask(long long lo, long long hi) { cout << "? " << lo << " " << hi << endl; long long len = hi - lo + 1; long long cnt = len * (len + 1) / 2LL; vector<stri...
16
#include <bits/stdc++.h> using namespace std; int n, ans; void f(int x) { if (x > n) return; ans++; f(x * 10); f(x * 10 + 1); } int main() { cin >> n; f(1); cout << ans << endl; }
4
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<long long>> adj(n + 1, vector<long long>(n + 1)); for (int q = 1; q <= n; q++) { for (int w = 1; w <= n; w++) { cin >> adj[q][w]; } } v...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { long long n, m, k, b, o = 2, f = 1; cin >> n >> m >> k; b = m * n; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= m; j++) { if (o == 2) { if (k > 1) { b -= 2; o = 0; ...
7
#include <bits/stdc++.h> using namespace std; long long tot[1010], individu[1010]; int main(void) { int n; scanf("%d", &n); int arr[1010]; for (int i = 0; i < n; i++) scanf("%d", &arr[i]), arr[i]--; memset(tot, 0, sizeof(tot)); tot[0] = 2; individu[0] = 2; for (int i = 1; i < n; i++) { tot[i] = tot[...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int m = max(a, b); if (m == 1) { cout << "1/1"; } if (m == 2) { cout << "5/6"; } if (m == 3) { cout << "2/3"; } if (m == 4) { cout << "1/2"; } if (m == 5) { cout << "1/3"; } if (m == 6) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 201; int n, k; int w[N]; vector<int> g[N]; int dp[N][N]; int cur[N]; void dfs(int v, int last = -1) { for (int u : g[v]) { if (u != last) { dfs(u, v); } } fill(cur, cur + N, 0); for (int u : g[v]) { if (u != last) { for (int h =...
10
#include <bits/stdc++.h> using namespace std; void read(int &k) { k = 0; char x = getchar(); while (x < '0' || x > '9') x = getchar(); while (x >= '0' && x <= '9') { k = k * 10 - 48 + x; x = getchar(); } } double D, U, yw, xb, yb, r; int main() { cin >> D >> U >> yw >> xb >> yb >> r; yw -= r; yb...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long INF = 2e18; long long a[maxn], b[maxn]; int n, k; int main() { scanf("%d%d", &n, &k); for (int i = 0; i <= n; i++) scanf("%I64d", &a[i]); b[n] = a[n]; for (int i = 0; i < n; i++) { long long t = b[i] + a[i]; b[i + 1]...
14
#include <bits/stdc++.h> using namespace std; int main() { long long n, p; while (cin >> n >> p) { long long ans = 0; long long tmp = n, cnt = 0, tmp1; bool l = 0; while (tmp > 0) { tmp1 = 0; for (int i = 0; i < 32; ++i) { if ((1ll << i) & tmp) { ++tmp1; } ...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; bool sortinrev(const pair<long long int, string> &a, const pair<long long int, string> &b) { return (a.first > b.first); } long long int A[100][100], B[100][100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cou...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr + 0, arr + n); if (n == m) { cout << arr[0] - 1 << " " << arr[0] << endl; return 0; } if (m > n) cout << -1 << endl; else { cout...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 100009; int arr[MAX]; int main() { int n, t; scanf("%d%d", &n, &t); int sum = 0; for (int k = 0; k < n; k++) { scanf("%d", arr + k); sum += arr[k]; } int lo(0), hi(0), res(0), ans(0); while (hi < n) { res += arr[hi++]; while (re...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 110; pair<int, int> _[maxn]; int n, a[maxn], L[maxn], R[maxn], l[maxn], t[maxn * 3], tot; int dp[maxn][maxn * 3]; int getid(int x) { return int(lower_bound(t + 1, t + tot + 1, x) - t); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) sca...
22
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long int i) { return n & (1LL << i); } inline long long int setBit(long long int n, long long int i) {...
11
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long a[N], S[N]; int n; struct convex { deque<int> q; long long ans, c; int z; void init(long long c) { this->c = c; ans = 0; q.clear(); } long long get_move(long long c, int left) { init(c); z = left; int ibeg...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; const int INF = 1000000000; int n, m; int obe[MAXN]; int add[MAXN]; vector<int> t1, t2, t3, t4; void fad(int l, int r, int res) { for (int i = l; i <= (r); ++i) add[i] += res; } void fma(int l, int r, int res) { for (int i = l; i <= (r); ++i) { ...
9
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("2") #pragma GCC optimize("3") using namespace std; const int N = 1200; int n, m, s[N], book[N], a[N][N], b[N * 10]; bool o[N]; double c[N][N], f[2][N]; int R() { int x = 0; char ch; do { ...
18
#include <bits/stdc++.h> using namespace std; char s[1000001]; bool b1[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b, c, d; scanf("%s%d%d", s, &a, &b); n = strlen(s); c = 0; for (int i = 0; i < n; ++i) b1[i] = (c = (c * 10 + s[i] - 48) % a) || s[i + 1]...
9
#include <bits/stdc++.h> using namespace std; bool isSubsetSum(vector<long long int>& set, long long int n, long long int sum) { bool subset[n + 1][sum + 1]; for (int i = 0; i <= n; i++) subset[i][0] = true; for (int i = 1; i <= sum; i++) subset[0][i] = false; for (int i = 1; i <= n; i++) { ...
10
#include <bits/stdc++.h> using namespace std; const int inf = 2147483647; int a[111111]; int mx; int main() { int num; cin >> num; for (int i = 1; i <= num; i++) { cin >> a[i]; mx = max(mx, a[i]); } cout << (mx ^ a[num]) << endl; return 0; }
10
#include <bits/stdc++.h> using namespace std; int n, k, i, p, m, p2, ii, j, nr; int aib[3000005], nxt[3000005]; char s[3000005], sol[3000005]; vector<int> sv[5005], sw[5005]; pair<int, int> v[5005]; void update(int x, int val) { for (; x <= k; x += (x & -x)) { aib[x] += val; } } int query(int x) { int p = 0, ...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10, maxm = 1e7 + 10; int n, m; int visit[maxn], col[maxn]; vector<int> e[maxn]; vector<int> p[maxn]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); e[u].push_back(v); e[v].push_b...
9
#include <bits/stdc++.h> using namespace std; void solve(int test_ind) { int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < k; i++) { bool z = false, o = false; for (int j = i; j < n; j += k) { if (s[j] == '1') { o = true; } if (s[j] == '0') { z = true; ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long long; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> v(n), sv(n); vector<vector<int>> g(31, vector<int>(n)); for (int j = 0; j < n; j++) { int x; cin >> x; sv[j] = x; int cnt = 0; ...
16
#include <bits/stdc++.h> using namespace std; const int inf = 111111111; const int ldx[] = {1, -1, 0, 0}; const int ldy[] = {0, 0, 1, -1}; const int kdx[] = {0, 1, -1, 0, 0, 1, 1, -1, -1}; const int kdy[] = {0, 0, 0, 1, -1, 1, -1, 1, -1}; struct xxx { int x, y; void read() { char c; cin >> c >> y; x = c...
9
#include <bits/stdc++.h> using namespace std; const int MaxN = 500000; int n, m; int a[MaxN], g[32][MaxN]; int ans[MaxN], ans_len; int len; int gcd(int a, int b) { while (a > 0 && b > 0) if (a > b) a %= b; else b %= a; return a + b; } int main(void) { scanf("%d", &n); for (int i = 1; i <= n;...
12
#include <bits/stdc++.h> using namespace std; int n; int a[1111][1111]; int main() { cin >> n; for (int k = 3; k <= 1000; ++k) if ((k + 1) * (k) / 2 > n) { int now = 0; for (int i = 1; i <= k; ++i) for (int j = i + 1; j <= k; ++j) a[i][j] = a[j][i] = ++now; printf("%d", k); for (...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int ans = 1; int l, r, d, u, x, y, x1, y1, x2, y2; cin >> l >> r >> d >> u >> x >> y >> x1 >> y1 >> x2 >> y2; int totx, toty; totx = r - l + x; toty = u - d + y; if (totx < x1 || totx > x2) { ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const double EPS = 1e-10; const double PI = acos(-1.0); int n, m; int src[100000], dst[100000]; char mark[100000]; int data[1024]; void init(int n) { for (int i = 0; i < (n); i++) data[i] = i; } int find(int x) { if (data[x] != x) data[x] = f...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using gr = vector<vll>; using wgr = vector<vpll>; struct d_ { template <typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *th...
18
#include <bits/stdc++.h> using namespace std; long long hi1[1000000], hi2[1000000], l[1000000]; int main() { long long n, m, a, b; cin >> n >> m >> a >> b; for (long long i = 0; i < n; i++) cin >> hi1[i]; for (long long i = 0; i < m; i++) cin >> hi2[i]; for (long long i = 0; i < m; i++) cin >> l[i]; long lo...
11
#include <bits/stdc++.h> using namespace std; char col[] = {'R', 'O', 'Y', 'G', 'B', 'V'}, str[7]; int main(int argc, char **argv) { map<char, int> hs; for (int i = 0; i < 6; ++i) hs[col[i]] = i + 1; scanf("%s", str); vector<int> v; set<vector<int> > st; for (int i = 0; i < 6; ++i) v.push_back(hs[str[i]]); ...
9