solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int a1[28], a2[28]; int main() { int n; cin >> n; string x1, x2; cin >> x1 >> x2; int pos1 = -1; while (x1[pos1 + 1] == x2[pos1 + 1] && pos1 + 1 <= n) pos1++; if (pos1 != -1) { x1.erase(0, pos1 + 1); x2.erase(0, pos1 + 1); } int psidad; int pos2 ...
5
#include <bits/stdc++.h> using namespace std; long long int inf = 1e5 + 7; long long int n, m, fin; vector<long long int> v; bool fine(long long int mid) { long long int prev = 0; for (long long int i = 0; i < n; ++i) { if (prev <= v[i]) { long long int k = m - (v[i] - prev); if (k > mid) prev = v[i...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,sse4,fma4,ssse3,popcnt,abm,aes,pclmul") #pragma comment(linker, "/STACK:66777216") using namespace std; static unsigned rnd() { static int second = 124612741; second ^= second << 13; second ^= second >> 17; return second ^= se...
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; int n, no, ye; vector<int> a[1000]; bool noo(int i, int j, int k) { for (int ii = 0; ii < a[i].size(); ++ii) if (a[i][ii] == j || a[i][ii] == k) return 0; return 1; } bool yes(int i, int j, int k) { bool q = 0, w = 0; f...
2
#include <bits/stdc++.h> using namespace std; int n, m, k; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { y = 1; x = 0; return a; } else { long long ret = exgcd(b, a % b, y, x); ...
5
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int MOD = (int)998244353; const int INF = (int)1e18; bool cmp(const pair<long long, long long>& a, const pair<long long, long long>& b) { return a.second < b.second; } string modify(string s, long long n, long long k) { strin...
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <typename T> void _R(T& x) { cin >> x; } template <typename T> void _R(vector<T>& x) { for (auto it = x.begin(); it != x.end(); it++) { _R(*it); } } void R() {} template <typename T, typename... K> void R(T& head, K&... tail) { ...
2
#include <bits/stdc++.h> const int maxn = 2e5 + 5; const long long mod = 1e9 + 7; using namespace std; char s[maxn]; long long ci(long long x, long long t) { long long res = 1; while (t) { if (t & 1) res *= x; t >>= 1; x *= x; } return res; } long long dd(int x) { long long res = 0; while (x) { ...
3
#include<iostream> #include<unordered_map> #include<algorithm> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; string s; cin>>s; int c=0; for(int i=0;i<n;i++){ int j=i; if(s[i]!=s[i+1]){ for(in...
0
#include <bits/stdc++.h> using namespace std; struct Node { int sum, add, lo, hi; Node *le, *ri; static Node* Build(int lo, int hi) { Node* root = new Node(); root->lo = lo, root->hi = hi; root->sum = root->add = 0; root->le = root->ri = NULL; if (lo != hi) root->le = Build(lo, (lo + hi)...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { string a, s; cin >> a >> s; int h[26] = {0}; int i = 0; while (i < a.length()) { int c = a[i] - 'a'; h[c]++; i++; } ...
1
#include <bits/stdc++.h> int main() { int sum = 0, a, n, m, i; scanf("%d %d", &n, &m); for (i = 1; i <= n; i++) { sum = sum + i; if (m > sum && i == n) { i = 0; } a = m - sum; if (a < i + 1) { printf("%d", a); break; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int x, sum = 0, t = 0, ans = 0; scanf("%d", &x); int y[x]; for (int i = 0; i < x; i++) { scanf("%d", &y[i]); sum += y[i]; } sort(y, y + x); for (int i = x - 1; i >= 0; i--) { t += y[i]; sum -= y[i]; ans++; if (t > sum) brea...
0
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline ostream &operator<<(ostream &os, const pair<A, B> &v) { return os << v.first << ' ' << v.second; } template <typename A> inline ostream &operator<<(ostream &os, const vector<A> &v) { auto it = v.begin(); os << *it; for (++it;...
6
#include <bits/stdc++.h> const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std; long long n, ans = 1; int main() { scanf("%I64d", &n); for (int i = n - 4; i <= n; i++) { ans *= i; } for (int i = 2; i <= 5; i++) { ans /= i; } ans = ans * ans; ans *= 120; printf("%I64d", ans...
3
#include <bits/stdc++.h> using namespace std; bool check(int n) { bool flags[10] = {false}; int cont = 0; while (n > 0) { if (!flags[n % 10]) cont++; flags[n % 10] = true; n /= 10; } return cont == 4; } int main() { int n; cin >> n; while (true) { n++; if (check(n)) break; } cout...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(register T& t) { register T f = 1; register char ch = getchar(); t = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar(); t ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> data(n); for (int i = 0; i < (n); ++i) cin >> data[i]; vector<int> tmp(n); for (int k = 0; k < (n - 1); ++k) { for (int j = 0; j < (n); ++j) tmp[j] = data[j]; ...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, sum = 0; cin >> n; long long arr[n]; for (long long i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + 1 + n); if (n == 1) cout << a...
2
#include <bits/stdc++.h> using namespace std; vector<string> s; string str; int isadj(string s) { if (s.size() >= 4 && !s.compare(s.size() - 4, 4, "lios")) return 2; else if (s.size() >= 5 && !s.compare(s.size() - 5, 5, "liala")) return 1; else return 0; } int isn(string s) { if (s.size() >= 3 && !s...
4
#include <bits/stdc++.h> using namespace std; vector<int> v; int arr[200001]; int dfs(vector<int> graph[], int k) { v.push_back(k); int a = 0; for (auto i : graph[k]) { a += 1 + dfs(graph, i); } arr[k] = a; return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; ci...
4
#include <bits/stdc++.h> using namespace std; const int N = 512345; long long a[N]; long long b; int n, k; long long a2[N]; int main() { cin >> n >> k >> b; for (int i = (1); i <= (int)(n); i++) cin >> a[i]; int ans = n; --n; for (int i = (1); i <= (int)(n); i++) a2[i] = a[i]; sort(a2 + 1, a2 + n + 1); re...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<string> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<pair<int, int> > ans; map<pair<int, int>, int> M; for (int i = 0; i < n; i++) ...
4
#include <bits/stdc++.h> using namespace std; const double INF = 1e100; const double EPS = 1e-9; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3)...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1510, MAXM = 1510; int n, m, sum; int ans[MAXN], son[MAXN], last[MAXN]; struct Edge { int link, to; } edge[MAXM << 1]; struct Node { int real; long long x, y; } a[MAXN], tmp; inline void add(int u, int v) { edge[++sum] = (Edge){v, last[u]}, last[u] ...
7
#include <bits/stdc++.h> using namespace std; long long A[2000005]; int main() { int n, m, L, T, i, j, k, l; double l1, ans = 0, xx, t1; scanf("%d%d%d", &n, &L, &T); xx = (((long long)2) * T) / L; t1 = ((((long long)2) * T) % L) / 2.0; for (i = 1; i <= n; i++) { scanf("%d", &j); A[i] = j; } sort...
6
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; using vi = vector<int>; using vii = vector<ii>; using vvi = vector<vi>; using iii = pair<int, ii>; using viii = vector<iii>; using ll = long long int; using vc = vector<char>; using vb = vector<bool>; using ib = pair<int, bool>; using vib = vector...
1
#include <bits/stdc++.h> using namespace std; vector<int> v[200010]; int subtree[200010][10], tree[200010][10], p[10], D[200010], odl[200010], n, k, a, b; bool bylem[200010]; long long sumka, suma, add, x; void DFSdp(int w) { bylem[w] = true; sumka += odl[w]; subtree[w][0] = D[w] = 1; for (int i = 0; i < v[...
6
#include <bits/stdc++.h> using namespace std; long long n, m, l; long long data[3009][2]; long long dp[3009][109][3]; void solve() { memset(dp, 0, sizeof dp); long long len; for (long long i = 1; i <= l; i++) { for (long long j = 0; j < n; j++) { for (long long o = 0; o < 2; o++) { len = data[j]...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t = 0, i = 0, j = 0, n = 0, m = 0, k = 0, num = 0, temp = 0, ans = 0; cin >> n >> k; string str; vector<int> v; int arr[100002] = {0}; if (k < n / 2) { cout << "-1"; return 0; } if (n == 1) { if (k ...
3
#include <bits/stdc++.h> using namespace std; int n, m, k, i, j, ans, q, R; int A[666][666], F[666][666]; string s[666]; int rectangleSum(int x1, int y1, int x2, int y2) { int res = 0; res = F[x2][y2] - F[x1 - 1][y2] - F[x2][y1 - 1] + F[x1 - 1][y1 - 1]; return res ? res : 0; } int getCount(int l, int r, int u, in...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, n, m; cin >> a >> b >> n >> m; if (a + b >= n + m && m <= min(a, b)) cout << "Yes\n"; else cout << "No\n"; } }
2
#include <bits/stdc++.h> using namespace std; vector<int> g[1000001]; bool used[1000001] = {}; vector<int> p; vector<int> pos, num; void dfs(int v) { used[v] = 1; pos.push_back(v); num.push_back(p[v]); for (int e = 0; e < g[v].size(); ++e) { if (!used[g[v][e]]) { dfs(g[v][e]); } } } int main() {...
4
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[10000000]; long long b[10000000]; long long ans[10000000]; int main() { cin >> n; for (int i = 0; i < n; i++) { long long x; scanf("%d", &x); a[x]++; } for (long long i = 1; i <= 3000000; i++) { for (long long j = 1; i * j...
7
#include <bits/stdc++.h> using namespace std; int n; vector<int> e[100200]; bool used[100200]; bool marked[100200]; void clearused() { for (int i = 0; i <= n; ++i) used[i] = 0; } pair<int, int> deepest(int ind, int depth) { used[ind] = 1; pair<int, int> ans = {ind, depth}; for (int x : e[ind]) { if (!used[x...
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") template <typename T> void printv(const T& t) { std::copy(t.cbegin(), t.cend(), std::ostream_iterator<typename T::value_type>(std::cout, ", ")); cout << endl; } long long int modpower(long long int a, long long int b, long long int...
0
#include <bits/stdc++.h> using namespace std; template <class T> inline void RST(T &A, char x = 0) { memset(A, x, sizeof(A)); } template <class T> inline void SRT(T &A) { sort(A.begin(), A.end()); } template <class T, class C> inline void SRT(T &A, C B) { sort(A.begin(), A.end(), B); } const int DX[8] = {1, -1, 0...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, p, sum = 0; cin >> n >> p; int a[n], i; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum < p) { cout << "-1"; return 0; } sort(a, a + n, greater<int>()); int ans, page, k; for (ans = 1; ans <= n; ans++) { ...
4
#include <bits/stdc++.h> using namespace std; const int N = 100010; int t, n; int a[N], s[100]; int check(int x) { int ans = 0; while (x) { ans++; x >>= 1; } return ans; } int main() { scanf("%d", &t); while (t--) { memset(s, 0, sizeof s); scanf("%d", &n); for (int i = 1; i <= n; i++) sc...
2
#include <bits/stdc++.h> using namespace std; int sk[100009]; int pref = 0; int suff = 0; int dp[2009][2009]; const int mod = (int)1e9 + 7; int main() { dp[0][0] = 1; for (int i = 1; i <= 2000; ++i) { for (int j = 0; j <= 2000; ++j) { if (j) dp[i][j] += dp[i - 1][j - 1]; if (dp[i][j] >= mod) dp[i][j...
6
#include <bits/stdc++.h> using namespace std; long long int n, m; char ch[1010][1010]; long long int x[] = {0, 0, -1, 1}; long long int y[] = {1, -1, 0, 0}; long long int d[1010][1010]; void bfs(long long int a, long long int b) { queue<long long int> q; q.push(a); q.push(b); q.push(0); while (!q.empty()) { ...
3
#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...
4
#include <bits/stdc++.h> using namespace ::std; const int maxn = 5e5 + 100; int p[maxn]; pair<int, int> g[maxn]; map<int, int> mp; pair<int, int> Q[maxn]; set<pair<int, int>> st[maxn]; bool vis[maxn]; struct UFS { int rt[maxn], sz[maxn]; void init() { for (int i = 0; i < maxn; i++) rt[i] = i, sz[i] = 1; } i...
9
#include <bits/stdc++.h> int n, k; char m[505][505]; int mem[505][505]; int sz[250005]; int maxid = 1; int mark[250005]; int state; int max(int a, int b) { return a > b ? a : b; } void cc(int x, int y, int id) { if (x < 0 || y < 0 || x >= n || y >= n) return; if (m[x][y] == 'X' || mem[x][y]) return; mem[x][y] = i...
8
#include <bits/stdc++.h> using namespace std; const long long BIG = 100000000; char p[1000005], s[2000005]; long long D[2000005]; int main() { gets(p); int sz = 0, g = 0, n = 0, i; for (i = 0; p[i]; i++) { s[n++] = p[i]; if (p[i] != 'X' && p[i] == p[i + 1]) s[n++] = 'X'; } if (s[0] == s[n - 1]) { ...
10
#include <bits/stdc++.h> #pragma GCC optimize("O2,unroll-loops") using namespace std; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 100010, LOG = 60; int n, m, k, u, v, x, y, t, a, b; long long A[MAXN], ans, fix, X; long long g[MAXN]; bitset<MAXN> B[...
9
#include <bits/stdc++.h> using namespace std; int Power(int base, int exp) { int ans = 1; while (exp > 0) { if (exp & 1) ans = (1LL * ans * base) % 1000000007; exp = exp >> 1; base = (1LL * base * base) % 1000000007; } return ans; } void solve() { long long int l, r; cin >> l >> r; long long i...
0
#include <bits/stdc++.h> using namespace std; int n, l; int mem[15][2]; int rec(int pos, int check) { if (pos >= l) { return 1; } if (mem[pos][check] != -1) return mem[pos][check]; int now = pow(10, pos); now = (n / now) % 10; int ans = 0; for (int i = 1; i <= 9; i++) { if (pos == l - 1) { i...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> P(n), D(n); for (int i = 0; i < n; ++i) { cin >> P[i]; P[i]--; } for (int i = 0; i < n; ++i) cin >> D[i]; vector<vector<int> > A(n, vector<int>(n, 0)); for (int i = 0; i < n; ++i) { int k1 = i - D[i]; ...
4
#include <bits/stdc++.h> using namespace std; const int NMAX = 1e2 + 5; int A[NMAX], N, X, Y, i, B[NMAX]; int main() { cin.tie(NULL); cin >> N >> X >> Y; for (int i = 1; i <= N; ++i) cin >> A[i]; if (X > Y) { cout << N << '\n'; return 0; } for (int i = 1; i <= N; ++i) if (A[i] <= X) B[++B[0]] = ...
2
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 200000 + 1000; const int maxm = 300000 + 100; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3; template <class T> inline bool scan(T &ret) { ret = 0; char c; int sgn; T bit = 0.1; if (c = getchar(), c ==...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10, M = 3e4 + 10; struct ed { int v, u, w, id; ed() { v = u = id = -1; w = 1e9 + 10; } ed(int v, int u, int w, int id) : v(v), u(u), w(w), id(id) {} } e[M]; bool vis[N], dp[N]; vector<pair<int, ed> > g[N]; vector<ed> tree; int ans, n, m, ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; const int inf = 1e9; string b; int a[N], n; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; cin >> b; int l = -inf, r = inf; for (int i = 4; i < n; ++i) { string tmp = b.substr(i - 4, 5); int mx = *max_element(a + i -...
4
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); ; int n; long long sum = 0; cin >> n; string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '2' || s[i] == '4' || s[i] == '6' || s[i] == '8' || s[i] == '0') su...
0
#include <bits/stdc++.h> using namespace std; long long a[100005], b[100005]; long long n, k; int judge(long long x) { long long ans = k; for (long long i = 0; i < n; i++) { if (x > b[i] / a[i]) { if (ans < a[i] * x - b[i]) return 0; else ans -= a[i] * x - b[i]; } } return 1;...
3
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; long long arr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; long long n; cin >> n; if (n == 1) return cout << '1', 0; long long ans = 1; long long cur = 0; vector<long long> xx; for (long long i...
6
#include <bits/stdc++.h> using namespace std; bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first && a.second < b.second) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >>...
1
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> void min_self(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> void max_self(T &x, U y) { if (y > x) x = y; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << '('...
2
#include <bits/stdc++.h> using namespace std; const int z = 1000; int fibs[z]; int max(int a, int b) { if (a > b) return a; else return b; } int fib(int n, int k) { if (n < k) return 0; else { if (n == k) return 1; else { int sum = 0; for (int i = max(n - k, k); i < n; ++i)...
4
#include <bits/stdc++.h> using namespace std; struct trie { int l; int w; char c; trie() { l = w = 0; c = '*'; } trie(int lo, int ww, char cc) { l = lo; w = ww; c = cc; } }; char p[302][302]; int x1, yt, x2, y2, x3, y3; vector<trie> tr; bool won = 0; int s = 0; bool t1(int x, int y, in...
4
#include <bits/stdc++.h> using namespace std; void Fastio() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } vector<int> arr[200005]; int diameter[200005], p[200005], vis[200005]; int resdep = 0, resnode; void dfs(int node, int dep) { vis[node] = 1; if (resdep < dep) { resdep = dep; resnode = nod...
5
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long m = a[1] - a[0]; for (long long i = 0; i < n - 1; i++) { i...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll DIM = 1e6 + 7; const ll INF = 1e16 + 7; const ll MODULO = 1e9 + 7; ll n,m,nt,k,q; ll val,val1,last,res,c0,c1,c2; int main() { ios_base::sync_with_stdio(); cin.tie(); cout.tie(); cin>>nt; for(int t=1; t<=nt; t++) ...
1
#include <bits/stdc++.h> using namespace std; const int nax = 1e5 + 200; vector<int> g[nax]; bool leave[nax]; bool dfs(int u, int p, int depth) { bool ans = false; for (int v : g[u]) { if (p == v) continue; ans |= dfs(v, u, depth + 1); } if (leave[u]) { ans |= (depth & 1); } return ans; } int ma...
5
#include <bits/stdc++.h> using namespace std; void delbit(int &a, int k) { a &= (~(1 << k)); } bool getbit(int a, int k) { return 1 & (a >> k); } int setbit(int &a, int k) { return a |= (1 << k); } bool is_polindrom(string str) { int len = str.length(); for (int i = 0; i < len / 2; i++) if (str[i] != str[len - ...
2
#include <bits/stdc++.h> using namespace std; int const N = 250000, B = 18; vector<int> tr1[N + 1], tr2[N + 1]; int n, dp[N + 1], pa[N + 1][B], gr[N + 1]; int P(int v) { return gr[v] ? gr[v] = P(gr[v]) : v; } void pl(int v = 1, int p = 0) { dp[v] = dp[p] + 1; pa[v][0] = p; int k = 1, z; while (k < B && (z = pa[...
12
#include <bits/stdc++.h> int main() { int arr[110]; int n; std::cin >> n; int result = 0; for (int i = 0; i < n; i++) std::cin >> arr[i]; int start = 0; while (start < n && arr[start] == 0) start++; for (int i = start; i < n; i++) { bool ok = true; for (int j = i; j < n; j++) { if (arr[j] ...
0
#include <bits/stdc++.h> using namespace std; int main() { string a; int n; cin >> n >> a; set<char> chars; for (char& c : a) { if (int(c) <= 90) { c = char(int(c) + 32); } chars.insert(c); } if (chars.size() == 26) { cout << "YES"; } else { cout << "NO"; } }
0
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9; const long long inf = (long long)3e18; const int base = 1000 * 1000 * 1000; const int maxn = 20; const long double pi = acosl(-1.0); const long double eps = 1e-5; void error() { exit(1); } int nod(int a, int b) { while (a != 0 && b != 0) a %= b, ...
8
#include <bits/stdc++.h> using namespace std; const double eps = 1e-2; long double fgcd(long double xx, long double yy) { long double x = fabs(xx), y = fabs(yy); while (x > eps && y > eps) { if (x > y) x = x - floor(x / y) * y; else y = y - floor(y / x) * x; } return x + y; } double myacos(d...
6
#include <bits/stdc++.h> using namespace std; string dw; bool alfabet[26]; int main() { string name; int n, m; cin >> n >> m; cin >> name; for (int i = 0; i < name.size(); i++) if (!alfabet[name[i] - 'a']) { alfabet[name[i] - 'a'] = true; dw.push_back(name[i]); } string t = dw; char c1...
2
#include <bits/stdc++.h> using namespace std; int main() { unordered_set<int> set; int n; cin >> n; int lone_pair = 0; int max_pair = 0; for (int i = 0; i < n * 2; i++) { int t; cin >> t; if (set.find(t) == set.end()) { set.insert(t); lone_pair++; max_pair = max(max_pair, lone_...
0
#include <bits/stdc++.h> using namespace std; int vet[5010], rnd, us[1000005], id[1000005], h[1000005], t[1000005]; pair<int, int> diff[1000005][10]; int find(int x) { if (id[x] == x) return x; return id[x] = find(id[x]); } void join(int x, int y) { if (h[x] > h[y]) id[y] = x; else id[x] = y; if (h[x]...
8
#include <bits/stdc++.h> using namespace std; long long int b[100000]; struct data { long long int reg, marks; char nm[1000]; }; struct data a[100009]; bool cmp(data x, data y) { if (x.reg < y.reg) { return true; } else { if ((x.reg == y.reg) && (x.marks > y.marks)) { return true; } else { ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2000000 + 10; const int mod = 998244353; long long dp[maxn], sum1[maxn], sum2[maxn]; int main(){ int n; cin >> n; n *= 2; dp[0] = 1; sum1[0] = 1; dp[2] = 1; sum1[2] = 2; for(int i = 2; i <= 2000000; i++){ int len = (i - 2) + i; for(int j = len ...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 1e9; const int MOD = 1e9 + 7; const long long INF = 1e18; const long double PI = 3.14159265358979323846; template <typename T> void read(vector<T>& a) { for (int i = 0; i < a.size(); ++i) cin >> a[i]; } template <typename T> void print(vector<T>& a) { fo...
3
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; for (int i = 1; i < a.length() - 2; i++) if (a[i] == 'a' && a[i + 1] == 't') { a[i] = '@'; a[i + 1] = '@'; break; } for (int i = 1; i < a.length() - 3; i++) if (a[i] == 'd' && a[i + 1] == 'o' && a[i + 2]...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; std::cin >> s; long long a = ((s[0] - 48) * 10 + (s[1] - 48)) * 60 + ((s[3] - 48) * 10 + (s[4] - 48)); long long b; std::cin >> b; a = a + b; a = a % 1440; if (a == 0) { co...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long x, n, i, k, z; cin >> x >> n; long long a[4]; long long c = x; for (i = 0; i < 4; i++) { k = i + 1; if (c & 1) ...
0
#include <bits/stdc++.h> using namespace std; const int N = 510; int n, m, u, v, w, c; bitset<N> f[65][2][N], p, tmp; long long ans; int main() { scanf("%d%d", &n, &m); bool fl = 0; for (int i = (1); i <= (m); ++i) scanf("%d%d%d", &u, &v, &w), f[0][w][u][v] = 1; for (int i = (1); i <= (60); ++i) { for (...
8
#include <bits/stdc++.h> using namespace std; int num[200010], nxt[200010 << 2], to[200010 << 2], head[200010], cnt; void add(int u, int v) { nxt[++cnt] = head[u]; to[cnt] = v; head[u] = cnt; } int id[2010][2010]; const int ux[5] = {0, 1, 0, -1}, uy[5] = {1, 0, -1, 0}; struct LCT { int ch[200010][2], fa[200010]...
12
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 2e5 + 5; const long long INF = 1e18; void solve() { int n; cin >> n; int ab[n][2]; for (int i = (0); i < (n); ++i) cin >> ab[i][0] >> ab[i][1]; int pa = 0, push_back = 0; long long ans = 1; ans += min(ab[0][0], ab[0][1]);...
3
#include <bits/stdc++.h> using namespace std; long long maximum = (long long)1e18; long long overflow = LLONG_MAX; void subset(vector<long long> &prime, vector<long long> &sets, int index, long long value) { if (index == prime.size()) sets.push_back(value); else { while (value <= maximum) { ...
8
/* 2021-03-02 22:38:38 */ #include <bits/stdc++.h> using namespace std; struct DSU { vector<int> lab; DSU(int n) { lab.assign(n + 1, -1); } int root(int u) { return lab[u] < 0 ? u : lab[u] = root(lab[u]); } void merge(int u, int v) { u = root(u); v = root(v)...
7
#include <bits/stdc++.h> using namespace std; class node { public: int index; long long diff; }; class comp { public: bool operator()(const node &lhs, const node &rhs) { if (lhs.diff < rhs.diff) return true; else return false; } }; int main() { long long n, flash; scanf("%I64d %I64d", ...
1
#include <bits/stdc++.h> using namespace std; int n, m, k, a[56], br; int main() { cin >> n >> m >> k; int i; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); if (k >= m) { cout << 0 << endl; return 0; } else m -= (k - 1); for (i = 0; i < n; i++) { if (m - a[i] <= ...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 1e5; const long long inf = 1e18; long long add(long long a, long long b) { long long res = (a + b) % mod; return (res < 0) ? res + mod : res; } long long mul(long long a, long long b) { long long res = (a * 1LL * b) %...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { string s; cin >> s; int n = s.length(); auto match = [&](string c) { int now = 0, res = 0; for (auto i : s) { if (i == c[now]) { res++; ...
3
#include <bits/stdc++.h> using namespace std; long long val[300001], dp[300001]; vector<vector<long long>> adj(300001); void dfs(long long node, long long par) { dp[node] = val[node]; for (long long v : adj[node]) { if (v != par) { dfs(v, node); dp[node] += max(dp[v], 0LL); } } } long long dfs...
8
#include <bits/stdc++.h> namespace { using namespace std; #define int long long template<typename T> inline bool whitespace(const vector<T> &) { return false; } template<typename T> inline bool whitespace(const T &) { return true; } inline bool whitespace(const char) { return false; } t...
10
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long inf = pow(10, 9); long long modulo = pow(10, 9) + 7; void deal() { long long t; cin >> t; while (t--) { map<char, vector<long long> > all; string a, b; cin >> a >> b; for (long long i = 0; i < a.length(...
4
#include <bits/stdc++.h> using namespace std; long long tab[1000005]; int MOD = 998244353; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a; cin >> a; for (int x = 0; x < a; x++) cin >> tab[x]; long long licz = tab[a - 1]; long long pom1 = 3, pom2 = 1; for (int x = a - 2; x >= 0; x--) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, g = 0; cin >> n; long long int a[n], b[n]; b[0] = 0; for (long long int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 1; i < n; i++) { b[i] = a[i] - a[i - 1]; if (b[i] != 0) { g++; } } ...
2
#include <bits/stdc++.h> using namespace std; int n; string a, b; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; int p1 = -1, p2 = -1; for (int i = 0; i < n; i++) { if (a[i] != b[i]) { p1 = i; break; } } for (int i = n - 1; i >= 0; i--) { if (a[i] != b[i...
5
#include <bits/stdc++.h> using namespace std; void solve() { int64_t n; cin >> n; vector<pair<int64_t, int64_t>> v(n); for (auto &[x, y] : v) cin >> x >> y; sort(v.begin(), v.end()); vector<int64_t> p(n); vector<bool> head(n); int64_t cnt = 0; set<pair<int64_t, int64_t>> st; for (int64_t i = 0; i < ...
7
#include <bits/stdc++.h> using namespace std; long long int n, a; vector<long long int> v; long long int kesilecek, maxsum = INT_MIN, sum, maxkesilecek, maxi, maxj; vector<long long int> kesilecekler, maxkesilecekler; int32_t main() { cin >> n; for (long long int i = 0; i < n; ++i) { cin >> a; v.push_back(a...
3
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) using std::cin; using std::cout; using std::string; using std::vector; static const int MOD = 1000000000 + 7; static const int N = 300000 + 8; extern "C" { __attribute__((always_inline)) inline static long long gcd(long long x, ...
8
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> v) { os << "( " << v.first << ", " << v.second << ")"; return o...
6
#include <bits/stdc++.h> int main() { char s[100000 + 5]; scanf("%s", s); int len = strlen(s); int falg = false; for (int i = 0; i < len; ++i) { if (s[i] == 'a' && falg) break; if (i == len - 1 && !falg) { s[i] = (s[i] - 'a' + 25) % 26 + 'a'; break; } if (s[i] != 'a') { falg ...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b)...
8