solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int l, start, end; cin >> l; cin >> start; end = start; for (int i = 1; i < l; i++) { cin >> end; } if (!((start & 1) && (end & 1)) || !(l & 1)) { cout << "No"; } else { cout << "Yes"; } }
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, Magic = 666; int n, m; int L[N], R[N], s[N], num; pair<int, int> a[N]; void gao(int id) { for (int i = R[id]; i >= L[id]; i--) { int newpos = i + s[i]; if (newpos > R[id]) { a[i] = {-1, 1}; } else { if (a[newpos].first == -1)...
19
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v, V; while (n--) { int a; cin >> a; v.push_back(a); } int I = 1; int cnt = 0; V = v; vector<int> ans; while (1) { cnt++; if (I >= v.size() - 1) break; V.erase(V.begin() + I); int max ...
1
#include <bits/stdc++.h> using namespace std; bool ee(int k) { bool b = 1; while (k != 0) { if (k % 10 != 4 && k % 10 != 7) { b = 0; break; } k = k / 10; } return b; }; int main() { int l; cin >> l; int a[14] = {4, 7, 47, 74, 44, 77, 444, 447, 474, 477, 744, 747, 774, 777}; bool ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; int a[maxn], b[maxn]; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 0; i < 26; i++) { int mod = 1 << (1 + i); for (int j = 1; j <= n; j++) b[j] = a[j] % mod; sort(b +...
13
#include <bits/stdc++.h> using namespace std; const int mod = (1e9) + 7; const double eps = 1e-9; const int siz = 1e5 + 5, siz2 = 1e5 + 5; int t, co[siz], v[3], g[8]; vector<int> p[6]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { for (int i = 1; i <= 100000; i++) { for (long long j = ...
16
#include <bits/stdc++.h> using namespace std; int main() { int c, c1, c2, c3, m, m1, m2, m3, n; cin >> c1 >> c2 >> c3 >> m1 >> m2 >> m3; c = c1 + c2 + c3; m = m1 + m2 + m3; if (c % 5) c = c / 5 + 1; else c /= 5; if (m % 10) m = m / 10 + 1; else m /= 10; cin >> n; if (n >= m + c) ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int A = 22; long long f[N][A], ret; int a[N], cnt[N]; int n, m, l, r; void query_init() { memset(cnt, 0, sizeof cnt); l = 1, r = 0; ret = 0; } long long query(int ql, int qr) { while (r < qr) { ++r; ret += 1ll * cnt[a[r]]; +...
17
#include <bits/stdc++.h> using namespace std; int u[102][102]; int* lable(int i, int j) { static int v[10]; fill(v, v + 10, 0); v[u[i - 1][j]] = v[u[i - 1][j + 1]] = 1; v[u[i + 2][j]] = v[u[i + 2][j + 1]] = 1; v[u[i][j - 1]] = v[u[i + 1][j - 1]] = 1; v[u[i][j + 2]] = v[u[i + 1][j + 2]] = 1; return v; } in...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long dp[2222][2222]; long long arr[2222], n, h; long long fun(int pos, int cur) { if (pos == n) return cur == 0; long long& ret = dp[pos][cur]; if (ret != -1) return ret; ret = 0; if (arr[pos] == cur) { ret = fun(pos + 1,...
13
#include <bits/stdc++.h> using namespace std; int _mergeSort(int arr[], int temp[], int left, int right); int merge(int arr[], int temp[], int left, int mid, int right); int mergeSort(int arr[], int array_size) { int *temp = (int *)malloc(sizeof(int) * array_size); return _mergeSort(arr, temp, 0, array_size - 1); }...
10
#include <bits/stdc++.h> using namespace std; const int a[4] = {1, 6, 8, 9}; bool vis[4]; string M[7], ans; char s[1000010]; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar()) ; if (ch == '-') mark = -1, ch = getchar(); for (x = 0; ch >= '0' ...
8
#include <bits/stdc++.h> using namespace std; struct edge { int a, b; }; int a[5000], n; int father[5000 + 1]; int depth[5000 + 1]; inline int root(int node) { while (father[node]) { node = father[node]; } return node; } void unite(int a, int b) { if (depth[a] == depth[b]) { father[a] = b; depth[b...
4
#include <bits/stdc++.h> using namespace std; int k; int n; struct Lemming { int m; int v; int id; bool operator<(const Lemming &a) const { if (m < a.m) return true; if (m > a.m) return false; return v < a.v; } } l[111111]; int h; int ans[111111]; int a[111111]; bool isok(double t) { int len = 0...
12
#include <bits/stdc++.h> int main() { int long long n, a, b, k, i, x; scanf("%lld", &n); for (i = 1; i <= n; i++) { scanf("%lld%lld%lld", &a, &b, &k); if (k % 2 != 0) { x = (a * ((k / 2) + 1)) - (b * (k / 2)); printf("%lld", x); printf("\n"); } else { x = (a * ((k / 2))) - (b *...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 200005; int ft[N]; void add(int x, int val) { for (; x < N; x += x & -x) ft[x] += val; } int sum(int x) { int ans = 0; for (; x > 0; x -= x & -x) ans += ft[x]; return ans; } int sum(int i, int j) { return sum(j) - sum(i - 1); } in...
12
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int Minf = 0x7f7f7f7f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const long long MINF = 0x7f7f7f7f7f7f7f7fll; const int N = 55; vector<int> t[N]; double f[N][N]; double jc[N]; double C[N][N]; double g[N]; int siz[...
21
#include <bits/stdc++.h> using namespace std; string s[14]; double a[14]; vector<double> V; int main() { int i, in; double m; s[1] = "x^y^z"; s[2] = "x^z^y"; s[3] = "(x^y)^z"; s[5] = "y^x^z"; s[6] = "y^z^x"; s[7] = "(y^x)^z"; s[9] = "z^x^y"; s[10] = "z^y^x"; s[11] = "(z^x)^y"; double x, y, z; ...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; string str; cin >> str; n++; cout << n << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, *x; long long a, b; const long long INF = 1e16; long long solve(int d) { char* type = new char[n]; vector<int> pos; for (int i = 0; i < n; i++) { if (x[i] % d == 0) type[i] = 0; else if ((x[i] - 1) % d == 0 || (x[i] + 1) % d == 0) type[i] = ...
15
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const int MAXPOL = 100000; const int MAXQ = 100000; const int MAXPTOT = 300000; struct P { int x, y; P() {} P(int x, int y) : x(x), y(y) {} }; P operator-(const P &a, const P &b) { return P(a.x - b.x, a.y - ...
17
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; const int bian[4] = {1, 0, 3, 2}; int mod = 0, n, m, len = 3, stx, sty, cur = 0, finx, finy, step[20][20]; char grid[20][20]; queue<pair<pair<int, int>, int> > q; set<pair<pair<int, int>, int> > second; pair<...
14
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, m, ans; cin >> a >> b >> m; if (a > b) swap(a, b); if (m <= a || m <= b) cout << 0 << '\n'; else if (b <= 0) cout << -1 << '\n'; else { ans = 0; if (a < 0) { ans = -a / b; a += ans * b; } while (a ...
8
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf("%d %d", &n, &k); int res = 3 * n - k; printf("%d\n", res < 0 ? 0 : res); }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, x[200000], y[200000], w, o[200000]; pair<int, int> curx = make_pair(-200000, -200000), cury = make_pair(-200000, -200000); map<int, set<pair<int, int> > > a; vector<pair<int, int> > ans; scanf("%d", &n); for (int i = 0; i < n...
9
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[300001], b[300001], c[300001]; long long p1[300001], p2[300001], p3[300001], dp[300001]; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; long long p = 0, q = 0, r = 0; for (long long i = 1; i ...
15
#include <bits/stdc++.h> using namespace std; int n, m; string name[100111]; int region[100111]; int score[100111]; vector<pair<int, int> > v[100111]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> name[i] >> region[i] >> score[i]; v[region[i] - 1].push_...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 5000 + 100; int x[maxn][maxn], p[maxn], tx[maxn]; int n; int ask(int i, int j) { cout << "? " << i << ' ' << j << endl; int r; cin >> r; return r; } void answer(int k) { cout << "!" << endl; cout << k << endl; for (int i = 0; i < n; ++i) cout ...
12
#include <bits/stdc++.h> const int maxn = 5e3 + 10; const int inf = 0x3f3f3f3f; using namespace std; int n, m; int k, head[maxn], cntson = 0; int dp[maxn][maxn][2]; int siz[maxn], root, in[maxn]; struct edge { int v, next, w; } e[maxn << 1]; void adde(int u, int v) { e[k].v = v; e[k].next = head[u]; head[u] = k...
16
#include <bits/stdc++.h> using namespace std; int A[2000005]; int main() { int n; while (scanf("%d", &n) == 1) { for (int i = 1; i <= n; i++) scanf("%d", &A[i]); int num = 0; long long ans = 0; for (int i = n; i >= 1; i--) { if (A[i]) ans += num; else num++; } pri...
8
#include <bits/stdc++.h> using namespace std; const int N = 1010; const int K = 8; const int M = (1 << K) + 5; int a[N]; int b[K][N]; int n; int dp[M][K + 1]; int findPos(int v, int val) { if (b[v][n] < val) return -1; return lower_bound(b[v], b[v] + n + 1, val) - b[v]; } bool solve(int X) { int Y = X / K; for ...
14
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; ...
5
#include <bits/stdc++.h> using namespace std; const int ms = int(1e5) + 10; int n; int c[3][ms]; vector<int> adj[ms]; int a[ms], go[ms], pos = 0; int isline() { int st = -1; for (int i = 0; i < n; i++) { if (adj[i].size() == 1) st = i; else if (adj[i].size() > 2) return -1; } return st; } vo...
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int N = 2 * 5000000; bool isexist[N + 1] = {false}; long long solve(long long b, long long c) { long long ret = 0; long long tmp1 = (long long)sqrt(b * b - 1), tmp2 = (long long)sqrt(b * b - min(b * b, c + 1)); ret = 2 * (mi...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 5; const long long mod = 1e9 + 7; const long long inf = 3e18 + 5; const double eps = 1e-8; const double pi = acos(-1); void test() { long long n, m; cin >> n >> m; set<pair<int, int> > s; for (int i = 0; i < (1001); i++) { if (i * i > n) brea...
0
#include <bits/stdc++.h> using namespace std; long long H, M, K; long long cn, mn, cc, mc; int dif_0(long long w) { int ret = 0; while (w) { if (w % 10) ++ret; w /= 10; } return ret; } long long POW(int step) { long long ret = 1; while (step > 0) { ret *= 10; --step; } return ret; } long...
19
#include <bits/stdc++.h> using namespace std; int a[7][1010], b[7][1010], n, k, dp[1010]; int main() { scanf("%d%d", &n, &k); int tmp; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &tmp); a[i][j] = tmp; b[i][tmp] = j; } } int ans = 0; for (int i = 1; i <...
11
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int n, x; cin >> n; v.push_back(0); for (int i = 1; i <= n; i++) { cin >> x; v.push_back(x); } if (v[1] % 2 == 0 || v[n] % 2 == 0) { cout << "NO" << endl; return 0; } else if (n % 2 != 0) { cout << "YES" << endl;...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, r; cin >> n >> r; double t = sin(3.141592653589 / n); double R = r * t / (1 - t); cout << fixed << setprecision(7) << R << "\n"; return 0; }
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/stack:200000000") using namespace std; struct pt { int x; int y; int id; }; bool compx(struct pt& a, struct pt& b) { return (a.x < b.x) || (a.x == b.x &&...
14
#include <bits/stdc++.h> using namespace std; char c[105]; int main() { int a, b; scanf("%d%d", &a, &b); if ((a == 0) && (b == 0)) { printf("Yes\n"); return 0; } int lx = 0, ly = 0; int i; scanf("%s", c); int x = strlen(c); for (i = 0; i < x; i++) { if (c[i] == 'U') ly++; if (c[i] == '...
9
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, m, p; vector<int> edge[200000]; int d[200000]; long long s[200000]; long long s2[200000]; void back(int now, int par, int dep) { d[dep]++; for (auto next : edge[now]) { if (par == next) continue; back(next, now, dep + 1); ...
15
#include <bits/stdc++.h> using namespace std; int main() { int t[3]; for (int i = 0; i < 3; i++) { cin >> t[i]; } sort(t, t + 3); if (t[0] + t[1] > t[2]) cout << "0\n"; else { int c = t[2] + 1 - t[1] - t[0]; cout << c << '\n'; } }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int t = 50; int n; char s[maxn]; long long ans; int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; i++) { int lc = n + 1; for (int j = i + 2; j <= min(i + t, n) && lc == n + 1; j++) for (int k = i...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr1(n + 1); bool scan = true; int key = n; for (int i = 1; i <= n; i++) { int x; cin >> x; arr1[x]++; if (x == key) while (arr1[key]) { cout << key << " "; key--; } cout <...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); for (int i = 0; i < s.size(); i++) if (s[i] != ' ' || s[i + 1] >= 'a') { cout << s[i]; if (s[i] > ' ' && s[i] < 'a') { s[i] = ' '; i--; } } return 0; }
5
#include <bits/stdc++.h> using namespace std; int cost, n; char str[100010]; long long a, b, c, d; int main() { int n; cin >> n; scanf("%s", str + 1); for (int i = 1; i <= n; i++) { cin >> cost; if (str[i] == 'h') a += cost; else if (str[i] == 'a') b = min(a, b + cost); else if (str[...
10
#include<bits/stdc++.h> using namespace std; const int maxn=500+10; int a[maxn],b[maxn]; int n,x; bool check(int x) { for(int i=x;i<=n;i++) { if(a[i]<a[i-1]) return false; } return true; } int main() { int T; cin>>T; while(T--) { int f1=1,f2=1; cin>>n>>x; for(int i=1;i<=n;i++) { cin>>a[i]; b[i]=...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n; int arr[n], a2[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<int> a, b; for (int i = n - 1; i >= 0; i--) { if (max_element(arr, arr + i + 1) - arr != i) { a.push_back(max_element(arr, arr + i + 1) - ar...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T1, typename T2> inline void chkmin(T1& x, const T2& y) { if (y < x) x = y; } template <typename T1, typename T2> inline void chkmax(T1& x, const T2& y) { if (x < y) x = y; ...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; bool vis[N]; vector<vector<int> > vv; int pm[N], n; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", pm + i); int pos1 = -1, pos2 = -1, _max = 1, _odd = 0; for (int i = 1; i <= n; ++i) { if (vis[i]) continue; vect...
13
#include <bits/stdc++.h> using namespace std; struct linkedInt { int val; linkedInt* next; linkedInt(int val = 0) : val(val) { next = NULL; } }; struct group { linkedInt* start; linkedInt* last; int size; group(int v = 0) { start = last = new linkedInt(v); size = 1; } } g[200005]; int n, k, belo...
20
#include <bits/stdc++.h> using namespace std; clock_t start_time = clock(), end_time; bool xdy(double x, double y) { return x > y + 1e-6; } bool xddy(double x, double y) { return x > y - 1e-6; } bool xcy(double x, double y) { return x < y - 1e-6; } bool xcdy(double x, double y) { return x < y + 1e-6; } int min3(int x, ...
9
/* /> フ | _ _| /`ミ _x 彡 * MEOW * / | / ヽ ノ / ̄| | | | | ( ̄ヽ__ヽ_)_) \二つ */ #include <bits/stdc++.h> #define ll long long #define llu long long unsigned int #define endl '\n' #define repi(i,n) for (int i = 0; i <n; i++) #...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int n, m; int a[MAXN][MAXN]; int row[MAXN], col[MAXN]; pair<int, int> check() { int min_row = min_element(row, row + n) - row; int min_col = min_element(col, col + m) - col; if (min(row[min_row], col[min_col]) >= 0) return {-1, -1}; if (row[min...
13
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long p, s, r, c, u, v; long long ans = -1e18; long long rr[1000001]; long long rc[1000001]; long long a[1001][1001]; priority_queue<long long> qr, qc; int main(void) { scanf("%I64d%I64d%I64d%I64d", &n, &m, &k, &p); for (long long i = (1); i <= (n...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; int x[5]; int k = 0; cin >> n; string nstr = to_string(n); if (nstr.size() == 1) { k = 1; cout << k << " " << endl << n << endl; } else { x[0] = n % 10; n = n - x[0]...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MAXN = 5e3 + 5; int a[MAXN]; int f[MAXN][MAXN]; int dp[MAXN][MAXN]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) f[i][i] = dp[i][i] = a[i]; for (int j = 2; j <=...
10
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int a, b, c, result; cin >> a >> b >> c; if (a == b) result = 2 * c + 2 * a; else if (a < b) result = 2 * c + 2 * a + 1; else result = 2 * c + 2 * b + 1; cout << result; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int S = 1005, D = 55, K = 10; const long long mod = 1000000007ll; int fail[S * D], ch[S * D][K], trans[S * D][K], tot = 0; bool vis[S * D]; int newnode() { int x = ++tot; fail[x] = 0, vis[x] = false; for (int i = 0; i < K; i++) ch[x][i] = trans[x][i] = 0; retu...
24
#include <bits/stdc++.h> using namespace std; const long long dd = 1e6; const long long inf = 1e9 + 7; const double eps = 1e-8; double sqr(double x) { return x * x; } int main() { int n; scanf("%d", &n); vector<pair<double, double> > pts(n); for (int i = 0; i < n; ++i) { scanf("%lf%lf", &pts[i].first, &pts[...
10
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = s * 10 + (ch - '0'), ch = getchar(); return s * w; } const int MAXN = 1e6 + 10; char ch[...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 205, maxm = 5005; int n, m, s, t, e, flg, ans, sum1, sum2, st, ed; int start[maxn], to[maxm], then[maxm], flow[maxm], rev[maxm], dep[maxn], vis[maxn], cur[maxn], res[maxn][maxn]; queue<int> q; inline void add(int x, int y, int f, int r) { then[++e] = ...
13
#include <bits/stdc++.h> int main() { char s[5000]; int acnt = 0, bcnt = 0, ccnt = 0, i, chk = 1; scanf("%s", s); for (i = 0; s[i] != '\0'; i++) { if (s[i] == 'a') acnt++; if (s[i] == 'b') bcnt++; if (s[i] == 'c') ccnt++; } if (((acnt == 0 && bcnt == 0) || (bcnt == 0 && ccnt == 0) || (ccn...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000000") using namespace std; const long long int INF = 10000; int n, m, k, fx, fy, tx, ty; pair<int, int> gone[4] = {make_pair(0, 1), make_pair(0, -1), make_pair(1, 0), make_pair(-1, 0)}; bool correct(int x, int y) { return x >...
16
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double pi = acos(-1.0); int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tt; tt = 1; while (tt--) { long long n; cin >> n; vector<pair<long long, long long>> v; for (long long i = 0...
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } long long ans = 0; for (int i = 0; i < n; ++i) { int value = v[i]; long long cnt = 0; while...
5
#include <bits/stdc++.h> using namespace std; const int N = 5 * 1000 + 5; int a[N]; int cnt[N][N]; int ans = 0; int per = 0; int maxi = 0; int n; void pre() { for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (a[j] > a[i]) { per++; } } } for (int i = 0; i < n; i++) { f...
11
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 2e3 + 5; int n, k, c[N][10]; int memo[N][N]; string s[N], t[] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}; int solve(int i, int j) { if (i == ...
9
#include <bits/stdc++.h> using namespace std; inline int read() { int x; char c; while ((c = getchar()) < '0' || c > '9') ; for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';) x = x * 10 + c - '0'; return x; } struct edge { int nx, t; } e[200000 * 2 + 5]; int h[200000 + 5], en; vector<unsigned long l...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 10; int tol = 0; int head[MAXN]; int net[MAXN]; int to[MAXN]; long long val[MAXN]; long long vval[MAXN]; int siz[MAXN]; struct node { int id; long long val; bool operator<(const node& b) const { return (vval[id] - vval[id] / 2) * siz[id] < ...
12
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int v[104]; int c[103]; int v1[104]; long long gcd(long long i, long long j) { if (i % j == 0) return j; return gcd(j, i % j); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long n; string s; cin >> n >> ...
5
#include <bits/stdc++.h> using namespace std; long long int mul(long long int x, long long int y) { return (x * y) % 1000000007; } long long int power(long long int x, long long int y) { long long int res = 1; x %= 1000000007; while (y) { if (y & 1) res = mul(res, x); y >>= 1; x = mul(x, x); } r...
4
#include <bits/stdc++.h> using namespace std; int a, b; int x(int* a, int* b) { if (*a < 2 || *b < 1) return 1; else { *a -= 2; *b--; return 0; } } int y(int* a, int* b) { if (*a < 1 || *b < 2) return 1; else { *a -= 1; *b -= 2; return 0; } } int main() { int t; cin >> t;...
4
#include <bits/stdc++.h> using namespace std; template <typename T> class graph { public: struct edge { int from; int to; T cost; }; vector<edge> edges; vector<vector<int>> g; int n; graph(int _n) : n(_n) { g.resize(n); } virtual int add(int from, int to, T cost) = 0; }; template <typename T>...
17
#include <bits/stdc++.h> using namespace std; inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x) { static bool io...
17
#include <bits/stdc++.h> using namespace std; int dp[330][330]; bool f(int a, int b) { if (a == 0 && b == 0) { return 0; } if (dp[a][b] != -1) return dp[a][b]; bool z; for (int i = 1; i <= a; i++) { z = f(a - i, b); if (!z) return dp[a][b] = 1; if (i <= b) z = f(a - i, b - i); if (!z) retu...
13
#include <bits/stdc++.h> const int Maxn = 2000; int sz[Maxn + 5]; int fa[Maxn + 5]; int head[Maxn + 5], arrive[Maxn + 5], e_nxt[Maxn + 5], tot; void add_edge(int from, int to) { arrive[++tot] = to; e_nxt[tot] = head[from]; head[from] = tot; } int n, Root; int c[Maxn + 5]; int nxt[Maxn + 5], pre[Maxn + 5]; int lea...
10
#include <bits/stdc++.h> using namespace std; unordered_map<int, pair<pair<int, int>, int> > ma1; int main() { std::ios::sync_with_stdio(false); int i, j, k, l, n, x; vector<long long int> a, b; long long int s = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x; s += x; a.push_back(s); } s = ...
22
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; int n, m, a[MAXN]; double f[MAXN][2]; void lucky() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } } int main() { lucky(); for (int i = 1; i < n; i++) { for (int j = i + 1; j <= n; j++) if (a[i] > a[j]) ...
11
#include <bits/stdc++.h> using namespace std; long long t, n; int main() { cin >> t; while (t--) { cin >> n; long long a[n], ans = 0; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = n - 1; i > 0; i--) { if (a[i] < a[i - 1]) { ans += a[i - 1] - a[i]; } } cout << ans ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int a, ta, b, tb; string str; cin >> a >> ta >> b >> tb >> str; int early = 5 * 60; int late = 23 * 60 + 59; int start = atoi(str.substr(0, 2).c_str()) * 60 + atoi(str.substr(3, 2).c_str()); int finish = s...
8
#include <bits/stdc++.h> using namespace std; const int M = (int)1e9 + 7; const int N = 4005; const int sq = 90; int v[N], ps[N], ss[N]; int dp[2][sq][sq][N]; int fun(int a, int b, int k, int d) { if (dp[d][k][b + sq - a][a] != M) return dp[d][k][b + sq - a][a]; if (d == 0) { if (a + k >= b) return ps[a] ...
17
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int MX = 1e6 + 7; int n, k; long long ans; int Xor[MX]; struct node { int cnt; node *next[2]; node() { cnt = 0; next[0] = next[1] = NULL; } } * trie; void insert(int x) { node *head = trie; for (...
13
#include <bits/stdc++.h> using namespace std; const int Size = 1024; const int mod = 998244353; const int INF = 2147483647; const int maxn = 1e5 + 15; long long a[maxn]; long long sum[50]; int main() { int n, i, j; scanf("%I64d", &n); for (i = 1; n >= i; i++) scanf("%I64d", &a[i]); long long tmp = a[1]; long ...
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") const int K = 19, M = (1 << 18) + 5; int n; int cnt[M]; long long g[K][M]; long long dp[M][K]; string str[K]; long long res[M]; vector<long long> d[M]; long long a[M]; vector<int> ps; vector<int> parts[1000]; ...
24
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000 + 7; const double esp = 1e-13; map<pair<int, int>, int> ff; int f[300000 + 10], c[300000 + 10], n, x, y, p; long long ans; int main() { ios_base::sync_with_stdio(false); cin.tie(); cin >> n >> p; for (int i = 1; i <= n; i++) { ci...
11
#include <bits/stdc++.h> using namespace std; int n, k; int a[200007]; long long tot[200007]; long long maxSum[200007 + 1]; int maxSumPos[200007 + 1]; void solution() { scanf("%d %d", &n, &k); for (int i = 0, _n = (n); i < _n; ++i) scanf("%d", a + i); for (int i = 0, _n = (k); i < _n; ++i) tot[0] += a[i]; for (...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<pair<pair<int, int>, int> > v; int l, r; for (int i = 0; i < (int)(n); i++) { cin >> l >> r; v.push_back(make_pair(make_pair(l, r), i)); } sort((v).begin(), (v).end()); int pos ...
11
#include <bits/stdc++.h> using namespace std; string s; long long grid[1000][1000], ka, kaa, visted[1000][1000], x, y; vector<long long> v[1000]; queue<pair<long long, long long>> q; int32_t main() { long long mx[10] = {0, 0, 1, -1}; long long my[10] = {1, -1, 0, 0}; cin >> s; long long n = s.size(); x = 200;...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, m; int i, j, k; int t; const int N = 1010; int a[N]; int main() { cin >> t; while (t--) { cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = n; i >= 1; i--) { ...
0
#include <bits/stdc++.h> using namespace std; int ask(int i, int j) { cout << "? " << i << " " << j << endl; int res; cin >> res; return res; } void solve(int test) { int n; cin >> n; vector<int> a(n + 1); int x = ask(1, 2); int y = ask(2, 3); int z = ask(1, 3); a[2] = (x + y - z) / 2; a[1] = x ...
6
#include <bits/stdc++.h> using namespace std; int c[2005][2005]; long long s[2005][2005]; long long dp[2005][2005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { scanf("%d", c[i] + j); if (j) s[i][j] = s[i][j - 1]; else s[i]...
11
#include <bits/stdc++.h> using namespace std; int main() { int t; vector<int> v; for (int i = 0; i < 4; i++) { cin >> t; v.push_back(t); } sort(v.begin(), v.end()); if (v[0] + v[1] > v[2] || v[0] + v[2] > v[3] || v[1] + v[2] > v[3]) { cout << "TRIANGLE" << endl; } else if (v[0] + v[1] == v[2] ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, t, i, j, k, a, b, c, cs = 1; cin >> n; long long num[n + 1]; for (i = 1; i <= n; i++) cin >> num[i]; for (i = 1; i <= n; i++) { bool ok[n + 1]; memset(ok, false, sizeof ok); a = i; while (true) { ok[a] = true; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, l; cin >> n >> l; vector<int> s; vector<int> k; int d; for (int i = 0; i < n; i++) { cin >> d; s.push_back(d); } for (int i = 0; i < n; i++) { cin >> d; k.push_back(d); } int r = 0; while (r != l) { if (s[0] == k...
5
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int n, m, ans; map<int, vector<int>> g; map<int, int> sz; vector<int> add; map<int, bool> vis; void add1(int a) { while (a) { sz[a]; a >>= 1; } } void add2(int &a, int b) { a += b; if (a >= M) a -= M; } int calc(int at) { int l = at,...
20
#include <bits/stdc++.h> using namespace std; void speedUP() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { speedUP(); int n; cin >> n; vector<int> one; vector<int> two; vector<int> three; for (int i = 1; i <= n; i++) { int temp; cin >> temp; if (temp =...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5; const int LOG = 16; int arr[MAXN + 1]; struct Aint { int l, r; } dp[LOG + 1][4 * MAXN + 1]; void update(int nod, int left, int right, int pos, int bit, pair<int, int> cur) { if (left > pos || right < pos) { return; } if (le...
21
#include <bits/stdc++.h> using namespace std; int arr[200005], to[200005]; bool done[200005]; map<int, int> mi; map<int, int>::iterator it; int main(int argc, char** argv) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int i = 0; i < n; i++) { scanf("%d", &to[i]);...
7