solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, m, b[200100], a[200100]; int f[200100], id[200100]; int vis[200100]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> f[i]; vis[f[i]]++; id[f[i]] = i; } for (int i = 1; i <= ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> int sz(const T &a) { return int(a.size()); } const int MAXN = 5e5 + 1; pll st[MAXN]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; ...
16
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } long long P[(1 << 17) >> 1] = {2}, L(1), cn[1 + ((1 << 17) >> 6)]; void gen() { (cn[0 >> 6] |= 1ULL << ((0 & 63))), (cn[1 >> 6] |= 1ULL << ((1 & 63))); int Q(1 + sqrt((1 << 17))); for (long lo...
15
#include <bits/stdc++.h> using namespace std; map<int, vector<pair<pair<int, int>, int> > > M; map<int, vector<pair<pair<int, int>, int> > >::iterator it; vector<pair<int, int> > Ans, Extra, Temp1, Temp2; bool MyCompare(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) { if (x.first.first < y.first.first) ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1234567; vector<int> g[maxn]; int N; int level[maxn], fa[maxn][30]; namespace LCA { void dfs(int u, int f) { cout << "u" << " = "; cout << u << endl; ; fa[u][0] = f; if (~f) level[u] = level[f] + 1; for (int(i) = (int)(1); (i) <= (int)(25...
16
#include <bits/stdc++.h> using namespace std; const unsigned long long p = 19260817; const unsigned long long p2 = 20111203; const long long maxn = 1e10; long long T; long long ls[100000 + 5], rs[100000 + 5]; long long val[100000 + 5]; long long mark[100000 + 5]; unordered_map<long long, int> mp; long long ans = 0; voi...
13
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; const double E = 1e-6; int main() { long long int n; cin >> n; vector<long long int> a; long long int x; long long int sum = 0; for (long long int i = 1; i <= n; i++) { cin >> x; a.push_b...
1
#include <bits/stdc++.h> using namespace std; const int N = 112345; int n, k; int v[N]; pair<int, int> gr[300]; bool ok[300]; int main(void) { ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i <= 255; i++) { gr[i].first = i; gr[i].second = 1; }...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; long long int a[2 * n], i; for (i = 0; i < 2 * n; ++i) cin >> a[i]; vector<pair<long long int, long long int>> v1, v2; set<long long int> s1, s2; for...
4
#include <bits/stdc++.h> using namespace std; void printv(vector<long long>& a) { cerr << "v:\n"; for (auto aa : a) cerr << aa << " "; cerr << endl; } int32_t main() { long long n; cin >> n; vector<long long> a(n), b(n); for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < n; ++i) ci...
10
#include <bits/stdc++.h> using namespace std; int main() { long long m, n, s; cin >> n >> m >> s; if (s > n && s > m) cout << m * n << endl; else { long long a = (((n - 1) / s) + 1) * (((m - 1) / s) + 1) * (((n - 1) % s) + 1) * (((m - 1) % s) + 1); cout << a << endl; } }
9
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q, r; cin >> n; int a[n + 5]; cout << "? 1 2" << endl; cout.flush(); cin >> p; cout << "? 2 3" << endl; cout.flush(); cin >> q; cout << "? 1 3" << endl; cout.flush(); cin >> r; a[2] = (r + q - p) / 2; a[0] = r - a[2]; a[1...
6
#include <bits/stdc++.h> using namespace std; char a[505][505]; char res[1000000]; int xx[1000000], yy[1000000], v, m, n; inline void dfs(int i, int j, int x, int y) { if (a[i][j] != '.' || i < 1 || j < 1 || i > m || j > n) return; v++; a[i][j] = 'B'; res[v] = 'B'; xx[v] = i; yy[v] = j; dfs(i + 1, j, i, j...
11
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n; cin >> n; long long ans = 0; for (long long i = 0; i < n; ++i) { string s; cin >> s; if (s == "Tetrahedron") ans += 4; else if (s == "Cube") ans += 6; else if (s == "Octahedron") ans += 8; else ...
0
#include <bits/stdc++.h> using namespace std; int n, m; string s[150]; map<string, int> mp; string s2[150]; int len, temp; string ans; int main(void) { len = 0; temp = 1; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> s[i]; mp[s[i]]++; } string temp = "-1"; for (int i = 1; i <= n; ++i) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100000; const int LOGK = 41; int par[LOGK][N]; long long sum[LOGK][N]; int mini[LOGK][N]; int main() { int n; long long k; scanf("%d %lld", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &par[0][i]); for (int i = 0; i < n; i++) scanf("%d", &sum[0][...
13
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long b[n]; for (int i = 0; i < n; i++) { cin >> b[i]; } long long a[n]; a[0] = b[0]; a[1] = b[1] + a[0]; long long maxm = max(a[0], a[1]); for (int i = ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int pos = 0; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { pos = i + 1; break; } } int c = 0; for (int i = pos; i < n; i++) { ...
4
#include <bits/stdc++.h> using namespace std; inline int ID(char x) { return x - '0'; } struct trie { public: int root = 0; int cnt = 0; vector<int> val; vector<vector<int>> ch; trie() { ch.push_back(vector<int>(2, -1)); val.push_back(0); cnt = 0; } void add(string s) { int now = root; ...
11
#include <bits/stdc++.h> using namespace std; int n; struct Foo { int n, k, p; Foo() { this->n = 0; } Foo(int n, int p, int k) { this->n = n; this->k = k; this->p = p; } }; Foo foo[2 << 20]; int answer[1 << 20]; int main() { cin >> n; for (int p = 0; p < n; p++) { foo[p + 2] = Foo(p + 1, p, ...
14
#include <bits/stdc++.h> using namespace std; const long long int inf = 9e18; vector<long long int> fac(2e5 + 5), twos(2e5 + 5); vector<pair<long long int, long long int>> compress_array( vector<long long int> a, long long int n) { vector<pair<long long int, long long int>> ans; long long int i = 0; long long...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n[10], a[10][1000], i, j, b[2000]; cin >> k; for (i = 0; i < k; i++) { cin >> n[i]; for (j = 0; j < n[i]; j++) { cin >> a[i][j]; } sort(a[i], a[i] + n[i]); } for (i = 0; i < k; i++)...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int T = 1; while (T--) { int n, mxx = 0, mnx = 1e9, mxy = 0, mny = 1e9, x[51] = {0}, y[51] = {0}; cin >> n; pair<int, int> p[4 * n + 1]; for (int i = 0; i < 4 * n + 1; i++)...
8
#include <bits/stdc++.h> using namespace std; const int N = 1550; const int inf = 1e9 + 7; int a[N]; int seg[N], dp[N][N]; vector<int> st; struct BIT { int mx[N]; void init() { for (int i = 0; i < N; i++) mx[i] = -inf; } BIT() { init(); } void Set(int i, int f) { i++; for (; i; i -= i & -i) mx[i] ...
17
#include <bits/stdc++.h> using namespace std; int main() { long long int x; cin >> x; long long int n = 2 * x; long long int arr[n + 5]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); long long int m = 1000000009; for (int i = 0; i < n; i++) { for (int k = i + 1; k < n; k++...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, c, s = 0, k = 1; cin >> n >> a >> b >> c; vector<long long> v; s = 4 - (n % 4); if (s == 1) { cout << min(a, min(b + c, 3 * c)); } else if (s == 2) { cout << min(b, min(2 * a, 2 * c)); } else if (s == 3) { cout << mi...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int mod = 1e9 + 7; const int N3 = 1e3 + 10; const int INF = 2e9 + 10; const long long LINF = 2e18; int n, k, a[N], prv[N], last[N]; struct SegTree { int mx[N * 2], add[N * 2]; void push(int x, int tl, int tr) { if (tl < tr) { add[...
14
#include <bits/stdc++.h> const int P = 1e9 + 7; int x, y; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { if (i & 1) x = (x + y + 1) % P; else y = (x + y + 1) % P; } printf("%d\n", (x + y) % P); return 0; }
8
#include <bits/stdc++.h> using namespace std; #define int long long int #define watch(x) cout << (#x) << " is " << (x) << endl #define MOD 1000000007 void solve(int T) { int n,q,k; cin>> n >> q >> k; vector<int> arr(n+2); for(int i=1;i<=n;i++){ cin>>arr[i]; } arr[0] = 0; arr[n+1] = k+1; int H[n+1]...
4
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n; struct Edge { ...
20
#include <bits/stdc++.h> using namespace std; long long a[10010]; map<long long, long long> ma; int num = 0; long long sum = 1; void getprime(long long x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) a[++num] = i; while (x % i == 0) x /= i; } if (x > 1) a[++num] = x; } long long fastpow(long long ...
9
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int x = max(2, abs(x1 - x2) + 1); int y = max(2, abs(y1 - y2) + 1); cout << 2 * x + 2 * y << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; const long long N = 4005; const long long Mod = 1000000007; long long n, res, dp[N][N][2]; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = ...
11
#include <bits/stdc++.h> using namespace std; class Point; class Circle; const long double EPS = 1e-14; long double sqr(long double x) { return (x * x); } long double ldabs(long double x) { return (x >= 0 ? x : -x); } long double ldmax(long double a, long double b) { return (a > b ? a : b); } long double ldmin(long dou...
18
#include <bits/stdc++.h> using namespace std; long long n, i, sum, t; long long a[10000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 2; i < n; i++) { if (a[i - 1] < a[i] && a[i] > a[i + 1]...
1
#include <bits/stdc++.h> int n; int main() { scanf("%d", &n); printf("%d", n % 2); }
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long a[101]; struct Matrix { long long mat[101][101]; } dp; Matrix mul(Matrix a, Matrix b) { Matrix g; for (int i = 1; i <= 100; i++) for (int j = 1; j <= 100; j++) g.mat[i][j] = 0; for (int i = 1; i <= 100; i++) for (i...
11
#include <bits/stdc++.h> using namespace std; int main() { int size, *arr1, *arr2, index1, index2; bool a, first; while (cin >> size) { a = true, first = true; index1 = index2 = 1; arr1 = new int[size]; arr2 = new int[size]; for (int i = 0; i < size; i++) { cin >> arr1[i]; arr2[i] ...
5
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a == 1) { int d; cin >> d; if (d == 0) { cout << "UP"; return 0; } if (d == 15) { cout << "DOWN"; return 0; } cout << "-1"; return 0; } int d, e; cin >> d; int diff = 0; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, t, k, d, ans1, ans2; cin >> n >> t >> k >> d; ans1 = ceil((float)n / k) * t; ans2 = t + d; if (ans2 < ans1) cout << "YES"; else cout << "NO"; return 0; }
3
#include <bits/stdc++.h> using namespace std; int a[1000006]; int main() { int n, m, c; cin >> n >> m >> c; int b = 0; int e = n + 1; a[e] = INT_MAX; for (int i = 0; i < m; i++) { int x; scanf("%d", &x); if (x <= c / 2) { int up = upper_bound(a, a + b + 1, x) - a; a[up] = x; b ...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vs = vector<string>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios_base::sync_wit...
14
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5, SQRT = 317; int n, m, q; long long Arr[MAX_N]; vector<int> S[MAX_N]; int Map1[MAX_N], Map2[SQRT], Size; int cum[SQRT][MAX_N]; long long Sum[SQRT]; long long Add[SQRT]; bool Mark[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0); cin...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int r = n - n / 2; int b[n]; int j = 0; for (int i = 0; i < n; i += 2) { b[i] = a[j]; j++; } for (int i = 1; i < n; i += 2) { b[i] = a[r]; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000; long long a, b, lcm; vector<long long> Time; long long get_gcd(long long a, long long b) { if (!b) return a; return get_gcd(b, a % b); } int main() { cin >> a >> b; lcm = a * b / get_gcd(a, b); for (long long i = 0; i <= lcm; i += a) { ...
7
#include <bits/stdc++.h> #pragma optimize("O2") using namespace std; const int inf = 1e7; int n, m, k, xx1, xx2, yy1, yy2; int a, b, c, d; const int N = 1004; int dp[N][N][4]; bool vis[N][N][4]; char s[N][N]; bool safe(int r, int c) { return (r >= 0 && c >= 0 && r < n && c < m && s[r][c] == '.'); } struct Q { int r...
13
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1; cin >> s2; int i, j; for (i = 0; i < s1.length(); i++) { s1[i] = tolower(s1[i]); } for (j = 0; j < s2.length(); j++) { s2[j] = tolower(s2[j]); } if (s1 < s2) { cout << "-1"; } else if (s1 == s2) { co...
0
#include <bits/stdc++.h> using namespace std; mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); int rng(int l, int r) { return uniform_int_distribution<int>(l, r)(gen); } const long long p = rng(100001, 200000); const long long mod = 1000000007; const int N = 100005; const int M = 2000005; vector<lon...
25
#include <bits/stdc++.h> using namespace std; int f[1000050], x[1000050], y[1000050], d[1000050]; int F(int x) { if (f[x] != x) f[x] = F(f[x]); return f[x]; } int main() { int n, m, i, now, ones; long long ans; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) f[i] = i; ones = 0; for (i = 1; i <= m; i++) ...
13
#include <bits/stdc++.h> using namespace std; int n, k, m, res; int p[102]; int main() { scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= k; ++i) { int x; scanf("%d", &x); p[x] = i; } res = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { int a; scanf("%d", &a); ...
6
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int inf = 2147483647; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10ll + ch - '0', ch = getchar()...
17
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll inf = 1e18; const ll mod = 1e9 + 7; int n; string s; int found[30]; bool esp[1005]; void init() {} void input() { cin >> s; n = int(s.size()); } bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i...
5
#include <bits/stdc++.h> int main() { char a[5005]; scanf("%[^\n]", &a); char b[3]; int c[3] = {}; int z = 0, ula = 0; ; bool hurufa = true, hurufb = true, hurufc = true; for (int i = 0; a[i] != '\0'; i++) { if (a[i] == 'a' and hurufa == true) { b[z] = 'a'; hurufa = false; z++; ...
4
#include <bits/stdc++.h> using namespace std; int n, ci[300005], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &ci[i]); int i1 = 1; int j1 = n; while (ci[i1] == ci[n]) i1++; ans = n - i1; while (ci[1] == ci[j1]) j1--; printf("%d\n", max(ans, j1 - 1)); return 0; }
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int mod = 998244353; const int maxn = 2e6 + 100; const int maxm = 2e6 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); int n, m, k; int a[1111][1111]; bool ck(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } int d...
18
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int maxn = 65005; const int N = 5005, M = 2 * 30005; char second[maxn]; int main() { int n; scanf("%d", &n); scanf("%s", &second); long long ans = 0; for (int i = 0; i < n; ++i) if (!((second[i] - '0') & 1)) ans += (i + 1ll) * ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1000000007; const int MOD2 = 998244353; const int INF = 1 << 30; const ll INF2 = (ll)1 << 60; void scan(int& a) { scanf("%d", &a); } void scan(long long& a) { scanf("%lld", &a); } template <class T, class L> void scan(pair<T, L>& p) { ...
5
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > p, A, B; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int binSearch(int s, int e, int v) { if (s > e) return -1; int md = (s + e) / 2; if (p[md].second == v) return md; else if (p[md].second < v) return...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; const int maxk = 100010; const long long mo = (long long)1e9 + 7; long long p[maxk], p2[maxk]; long long dp[maxn][maxn]; long long sum[maxn], sumr[maxn][maxn], suml[maxn][maxn], sumpl[maxn]; long long fac[maxk], inv[maxk]; long long pl[maxn], pr[maxn]...
23
#include <bits/stdc++.h> using namespace std; const int N = 220; int n, m; pair<int, double> a[N]; double Dp[N][N][N]; double Rec(int i, int j, int k) { k = min(k, n); if (k < 0) return 0.0; if (i == n) return j >= m; if (Dp[i][j][k] == Dp[i][j][k]) return Dp[i][j][k]; return Dp[i][j][k] = a[i].second * Rec(i...
10
#include <bits/stdc++.h> using namespace std; bool dd[5000005]; long long n, a[5000005], b[5000005], avail[5000005], pos[5000005]; vector<long long> v, ans, pri, vec; multiset<long long> s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); dd[1] = true; for (long long i = 2; i < 5000000; i++)...
10
#include <bits/stdc++.h> using namespace std; map<int, int> mp; map<int, int>::iterator one, two; int main() { int n, x; cin >> n; for (int i = 0; i < n; i++) cin >> x, mp[x]++; one = mp.begin(); two = ++mp.begin(); if (mp.size() == 2 && one->second == two->second) printf("YES\n%d %d\n", one->first, two...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { int n, m; cin >> n >> m; for (int i = (int)(0); i < (int)(n); ++i) { if (i % 2 == 0) for (int j = (int)(0); j < (int)(m); ++j) printf("#"); ...
0
#include <bits/stdc++.h> using namespace std; inline long long rd() { register long long res = 0, lab = 1; register char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') lab = -lab; ch = getchar(); } while (ch >= '0' && ch <= '9') res = (res << 3) + (res << 1) + (ch & 15), ch = getcha...
13
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T> inline void gmax(T &a, T b) { if (b > a) a = b; } template <class T> inline void gmin(T &a, T b) { if (b < a) a = b; } const int N = 100 + 5, M...
15
#include <bits/stdc++.h> using namespace std; int n, b[150000]; long long a[150000]; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &b[i]); b[n + 1] = b[1]; int g = -1; for (int i = 1; i <= n; i++) if (b[i] < b[i + 1]) { g = i; break; } if (g < 0) { if (b[1] > 0) { ...
16
#include <bits/stdc++.h> using namespace std; struct Node { int x, y; } a[100010]; long long mx[320], Ans, T, r[320]; int i, j, k, n, m, p[320], S, t[320], w, b[100010], f[100010], Cnt, M, x; inline bool Cmp(Node a, Node b) { return a.y < b.y; } inline long long Max(long long x, long long y) { return x < y ? y : x; }...
22
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (!y) return x; return gcd(y, x % y); } bool check(int x) { while (x % 2 == 0) x /= 2; if (x == 1) return true; return false; } int main() { int a, m; while (cin >> a >> m) { if (a % m == 0) cout << "Yes" << endl; else {...
6
#include <bits/stdc++.h> using namespace std; long long n; vector<string> arr; int main() { cin >> n; for (int i = 0; i < n; i++) { string h; cin >> h; arr.push_back(h); } char x = arr[0][0]; for (int i = 0; i < n; i++) { if (arr[i][i] != x) { cout << "NO" << endl; return 0; } ...
2
#include <bits/stdc++.h> using namespace std; int getint() { int f = 1, x = 0; char ch = getchar(); while ('0' > ch || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return f * x; } int head[1123456]; int tot; ...
14
#include<bits/stdc++.h> using namespace std; const int maxn = 100000+10; int cnt=0; int ask(int l,int r){ cnt++; if(l==r) return 0; printf("? %d %d\n",l,r); fflush(stdout); int x; scanf("%d",&x); return x; } int qask(int l,int r,int pos){ int rr=ask(l,pos); if(rr==pos){//l-pos l=l; r=pos; while(r-l>1...
11
#include <bits/stdc++.h> using namespace std; template <class T> bool ckmax(T& x, T y) { return x < y ? x = y, 1 : 0; } template <class T> bool ckmin(T& x, T y) { return x > y ? x = y, 1 : 0; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch =...
11
#include <bits/stdc++.h> using namespace std; map<int, int> mp, mpp; int main() { std: ios_base::sync_with_stdio(false); int n, i, ans1, ans2, tmp; map<int, int>::iterator it; cin >> n; for (i = 0; i < n; i++) { cin >> tmp; mp[tmp]++; } for (i = 0; i < n - 1; i++) { cin >> tmp; mpp[tmp]++;...
3
#include <bits/stdc++.h> using namespace std; char arr[1000010]; int cnt[10]; int main() { int n; cin >> n; int x; for (x = 1; x <= n; x++) { cin >> arr[x]; cnt[(int)(arr[x] - '0')]++; } if (cnt[0] == cnt[1]) { cout << "2" << endl; for (x = 1; x < n; x++) { cout << arr[x]; } co...
0
#include <bits/stdc++.h> using namespace std; long long t, n, m, dp[200050]; pair<long long, long long> v[200050]; vector<pair<long long, long long> > grafo[200050]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (long long i = 1, a, b, c; i <= m; i++) { cin >> a >> b >> c; ...
12
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } a[400010]; int fa[200010]; int A[200010][2], al; int v[200010], w[200010], n, s, t, ds, dt; int Find(int x) { if (fa[x] != x) fa[x] = Find(fa[x]); return fa[x]; } void add(int x, int y) { A[++al][0] = x; A[al][1] = y; } bool check1(int su...
15
#include <bits/stdc++.h> using namespace std; vector<int> v; bool solve(int n, map<int, int> m) { if (n == 0) { return (true); } if (m[n] == 1) { return (false); } long long int i; for (i = 1; i <= n; i++) { if (m[i] != 1) { m[i] = 1; if (solve(n - i, m)) { v.push_back(i); ...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") using namespace std; bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); } void solve() { long long int n; cin >> n; string arr[n]; for (long long int i = 0; i < n; i++) cin >> a...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long n, x, y, idx1, idx2; char LR[2] = {'R', 'L'}, UD[2] = {'U', 'D'}; vector<pair<long long, pair<long long, char> > > v; pair<long long, pair<long long, long long> > arr[N]; int main() { scanf("%lld", &n); for (int i = 0; i < n; ++i) { ...
8
#include <bits/stdc++.h> using namespace std; const int M = 10007; const int MaxNL = 200; int n, nL, m, nR, nG, nB, len; char s[MaxNL + 5]; int f[MaxNL + 1][MaxNL + 1][MaxNL + 1]; __attribute__((optimize("-O2"))) int solve(const int &nR, const int &l, const int &r) { if (nR ...
22
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
0
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cout.tie(0); vector<long long> a; for (long long i = 0; i < 6; ++i) { long long x; cin >> x; a.push_back(x); } vector<vector<long long> > p; long long n; cin >> n; vector<long long> b; for (long l...
11
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n; cin >> n; int sum = 0; list<int> coins; int coin; for (int i = 0; i < n; ++i) { cin >> coin; sum += coin; coins.push_back(coin); } coins.sort(); int me = 0; int num = 0; while (2 * me <= sum) ...
1
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, ans = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); } return f * ans; } const long l...
16
#include <bits/stdc++.h> using namespace std; const int MAX = 100000 + 10; const int MOD = 1000000007; long long dp[MAX]; long long sum[MAX]; int main() { dp[0] = 1; int t, k; scanf("%d %d", &t, &k); for (int i = 1; i < MAX; ++i) { if (i < k) { dp[i] = 1; } else { dp[i] = (dp[i - k] + dp[i -...
9
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 5; int n; int cost[5]; char s[4][N]; int a[4][N]; bool prevMark[1 << 9]; int prevCost[1 << 9]; bool nextMark[(1 << 9)]; int nextCost[(1 << 9)]; int go[(1 << 8)][(1 << 4)][150]; int goCost[(1 << 8)][(1 << 4)][150]; int topGo[(1 << 8)][(1 << 4)]; int c[4]...
14
#include <bits/stdc++.h> using namespace std; int w[8]; int b[8]; int main() { vector<string> v; for (int i = 0; i < 8; i++) { string s; cin >> s; v.push_back(s); } int bm = 110, wm = 110; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (v[i][j] == 'B') { int cnt =...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const long long MD = 1000000007; long long inc[2050][2050]; long long sum[2050][2050]; int n, m; long long inc_big[2050][2050][2]; long long cur_sum[2050], cur_sum1[2050]; int make_inc(int n, int m) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tc; cin >> tc; while (tc--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << b << " " << c << " " << c << endl; } }
0
#include <bits/stdc++.h> using namespace std; class segment { public: long long int s, sum; segment() { s = sum = 0; } }; long long int n, len, k, RES, a[200000], b[200000], arr[200000], maxi[200000], A[200000]; segment kd[800000]; map<long long int, int> yer; segment merge(segment a, segment b) { a.s += b.s...
12
#include <bits/stdc++.h> const double eps = 1e-19; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const int MAXN = 100005; using namespace std; int n, h; pair<int, int> a[MAXN]; vector<int> p1, p2; int ans[MAXN]; int f() { if ((int)p1.size() < 2) return 0; int max_res = p1[(int)p1.size() - 1]...
10
#include <bits/stdc++.h> using namespace std; template <typename T> inline void debug(vector<T> v) { cout << "\ndebug(vector)\n"; long long i; for (i = 0; i < v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } inline bool prime(int n) { int i; for (i = 2; i * i <= n; i++) if (n % i == 0) return false...
4
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-9; int t, n, p; bool graph[25][25]; void build(int step) { bool visited[25] = {0}; while (p) { int st = -1; for (int i = 0; i < (int)(n); i++) if (!visited[i]) { st = i...
7
#include <bits/stdc++.h> using namespace std; long long t, n, k, b, c; const long long inf = 1e9 + 10; const long long maxn = 1e5 + 10; void solve() { cin >> k; long long i; for (i = 1; i < 100000; i++) { if (i * i <= k && (i + 1) * (i + 1) > k) { break; } } if (i * i == k) { cout << i << " ...
0
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(12); long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >...
6
#include <bits/stdc++.h> using namespace std; template <class t> ostream &operator<<(ostream &tout, const vector<t> &s) { tout << '['; for (long long i = 0; i < s.size(); i++) if (i + 1 == s.size()) tout << s[i]; else tout << s[i] << ','; tout << ']'; return (tout); } template <class a, clas...
19
#include <bits/stdc++.h> using namespace std; bool a[2][100010]; int main() { int n, q; cin >> n >> q; for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) a[i][j] = false; } long long res = 0; for (int i = 0; i < q; i++) { int r, c; cin >> r >> c; r--; c--; if (!a[r][c]) { ...
6
#include <bits/stdc++.h> const int ha = 998244353; const int MAXN = 1e6 + 5; inline int qpow(int a, int n = ha - 2) { int res = 1; while (n) { if (n & 1) res = 1ll * res * a % ha; a = 1ll * a * a % ha; n >>= 1; } return res; } int fac[MAXN], inv[MAXN]; inline void prework() { fac[0] = 1; for (in...
17
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, s, d, n, m, a[1000]; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; j = n; i = 1; k = 0; m = 0; s = 0; d = 0; while (i <= j) { if (a[i] >= a[j]) { m = a[i]; i++; } else { m = a[j]; j--; }...
0
#include <bits/stdc++.h> using namespace std; int main() { int N, x, M, y; cin >> N >> x >> M >> y; int d = abs(x - y); if (N < M) { swap(N, M); } long long ret = 0; for (int i = 1; i <= N; i++) { if (i <= d) { if (M > d - i) { if (M >= d + i) { int c = 2 * i; ret...
15