func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; long long n, m, a[100005], sum, en; bool cheak(long long mid) { long long sum = 0, cnt = m; for (int i = 1; i <= n; ++i) { if (a[i]) { sum += a[i]; while (sum > mid - i) { sum -= (mid - i); cnt--; if (cnt < 0... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; int a[n], i; for (i = 0; i < n; ++i) cin >> a[i]; cin >> m; int b[m]; for (i = 0; i < m; ++i) cin >> b[i]; sort(a, a + n, greater<int>()); sort(b, b + m, greater<int>()); cout << a[0] << << b[0... |
#include<bits/stdc++.h> using namespace std; #define ll long long int #define M 1000000007 int main() { ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t,n,x; cin>>t; string str= 2020 ; while(t--) { int a,b,c,d,e,c1,c2,c3; cin>>... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; vector<vector<int>> row(n), col(m); for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < m; j++) { if (s[i][j] == # ) { row[i].... |
#include <bits/stdc++.h> using namespace std; class Solution { public: long long maximize(vector<int>& nums, int x) { int n = nums.size(); vector<vector<long long>> dp(3, vector<long long>(n + 1, 0)); long long res = 0; for (int i = 0; i < n; ++i) { long long num = nums[i]; ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int main() { int i, n, sum; while (scanf( %d , &n) != EOF) { sum = 0; while (n != 1) { sum += n; for (i = 2; i <= n; i++) { if (n % i == 0) { n /= i; break; } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long xa, ya, xb, yb, xc, yc, a, A; cin >> xa >> ya >> xb >> yb >> xc >> yc; if ((xa == xb) && (ya == yb)) cout << YES ; else if ((xb == ya) && (yb == -xa)) cout << YES ; else if ((xb == -xa) && (yb == -ya)) cout ... |
#include <bits/stdc++.h> using namespace std; char str[110]; long long ans = 0; int main() { cin >> str; int ll = strlen(str); long long k = 1, l = 1; for (int i = 1; i < ll; i++) { l = (l % 1000000007 * 2) % 1000000007; } k = l; for (int i = ll - 1; i >= 0; i--) { if (st... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long array1[n]; for (int i = 0; i < n; i++) { cin >> array1[i]; } long long a, b, c, d, e, sum = 0; cin >> a >> b >> c >> d >> e; map<long long, long long> mp; for (int i = 0; i < n; i++)... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int mod = 998244353; const int dx[] = {1, 1, 2, 2, -1, -1, -2, -2}; const int dy[] = {2, -2, 1, -1, 2, -2, 1, -1}; int A[1005][1005], B[1005][1005]; int C[1005][1005][2], D[1005][1005][2]; int main() { int n, m; scanf(... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a1, a2, b1, b2, c1, c2, s; cin >> n; cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; s = a1 + b1 + c1; n = n - s; if (n == 0) { cout << a1 << << b1 << << c1 << endl; return 0; } else { a2 = a2 ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, m, i, x, p = 0, kk = 100000000000000000, sum = 0; cin >> n >> k >> m; string me[n]; map<string, long long> fahim; for (i = 0; i < n; i++) { cin >> me[i]; } for (i = 0; i < n; i++) { cin >> fahim[me[i]]... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int sigma = maxn; const int HASH_CNT = 2; int n; char s[maxn]; unsigned long long Prime_Pool[] = {1998585857ul, 23333333333ul}; unsigned long long Seed_Pool[] = {146527, 19260817}; unsigned long long Mod_Pool[] = {1000000009... |
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } long long f[200009], dp[200009][2]; ... |
#include <bits/stdc++.h> using namespace std; const int N = 21; void solve() { int n, x; cin >> n; vector<int> cnt(N, 0); for (int i = 0; i < n; i++) { cin >> x; for (int j = 0; j < N; j++) { if (x >> j & 1) cnt[j]++; } } long long ans = 0; for (int i = 0; i <... |
#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]; int b[n]; b[0] = 0; for (int i = 1; i < n; i++) b[i] = abs(a[i] - a[i - 1]); long long int dp[n], dd[n]; dp[0] = 0; dd[0] = 0; for (int i = 1; i ... |
#include <bits/stdc++.h> using namespace std; char str[300005]; vector<int> idx[27]; int main() { int x; scanf( %s , str); int n = strlen(str); for (int i = 0; i < (int)(n); i++) { idx[str[i] - a ].push_back(i); } long long int ans[27] = {0}; int ansmax = 0; for (int i = 0... |
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return (a > b); } int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main(void) { long long int n, m, k; cin >> n >> m >> k; if (k > (n + m - 2)) { cout << -1 ; retu... |
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void... |
#include <bits/stdc++.h> using namespace std; int n, m, a[200005], b[200005], s[200005], t[200005], dp[200005]; vector<int> v[200005]; bool flag; void dfs(int x, int y) { s[x] = 1; dp[x] = t[x] = b[x]; int best = 0; for (int i = (0); i < (v[x].size()); i++) { int V = v[x][i]; if (V... |
#include <bits/stdc++.h> const int maxn = 5e5 + 5; using namespace std; int a[maxn]; int main() { int n; scanf( %d , &n); long long ans = 0, sum = 0; for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); int del = min((long long)a[i] >> 1, sum); ans += del; sum -= del; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; const int maxa = 10000000 + 10; const int inf = (-1u) >> 1; struct disjoint_set { int p[maxn]; void clear(int sz) { for (int i = (1); i <= (sz); ++i) { p[i] = i; } } int find(int x) { return x == p... |
#include <bits/stdc++.h> using namespace std; const int N = 1003; const int xx[4] = {0, 1, 0, -1}; const int yy[4] = {1, 0, -1, 0}; int x[3], y[3]; void pr(int x, int y, int fx, int fy) { while (x < fx) { ++x; printf( %d %d n , x, y); } while (x > fx) { --x; printf( %d %d... |
#include <bits/stdc++.h> using namespace std; int noOfOne(int n) { int c = 0; while (n) { c += (n & 1); n >>= 1; } return c; } unsigned long long int f(unsigned long long int n, unsigned long long int r) { if (n - r > r) { unsigned long long int temp = n, temp2 = r; u... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); long double a, b, c, d; pair<long double, long double> get(pair<long double, long double> a, pair<long double, long d... |
#include <bits/stdc++.h> using namespace std; long long n, p, k, pre[100005], f[100005][128]; struct mem { long long p[7], a; bool operator<(const mem &v) const { return a > v.a; } } c[100005]; int main() { scanf( %lld%lld%lld , &n, &p, &k); for (int i = 1; i <= n; i++) scanf( %lld , &c[i].a);... |
#include <bits/stdc++.h> using namespace std; struct __timestamper {}; vector<string> solve(vector<int> a) { int n = a.size(); for (int i = 0; i < n - 1; i++) assert(a[i] >= a[i + 1]); if (n == 0) return vector<string>(); if (a[0] == 1) { for (int x : a) assert(x == 1); vector<string> ... |
#include <bits/stdc++.h> using namespace std; int const K = 12; int const N = 5e4 + 123; int n, k; int s[N][K], maxi[N][K], mini[N][K]; int ans[N]; int cnt[N]; struct Player { int id, v; Player(){}; Player(int id, int v) : id(id), v(v){}; bool operator<(const Player &a) const { if ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n; cout << (((1ll << (n / 2)) - 1) * 2) << n ; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t = 1; cin >> t; while (t--) solve(); return 0; } |
#include <bits/stdc++.h> using namespace std; int n; long long ara[505][505]; bool row_check(long long val) { for (int i = 0; i < n; i++) { long long tmp = 0; for (int j = 0; j < n; j++) { tmp += ara[i][j]; } if (tmp != val) return false; } return true; } bool col... |
#include <bits/stdc++.h> using namespace std; int main() { long long int T, n, i, j, l, m, x, y, z, a, b, c, d, flag, count; cin >> a >> b >> c >> d; long long int sum1, sum2; sum1 = std::max((3 * a / 10), (a - ((a / 250) * c))); sum2 = std::max((3 * b / 10), (b - ((b / 250) * d))); if (sum1... |
#include <bits/stdc++.h> using namespace std; struct node { string name; int id; int taxi, pizza, girl; } arr[105]; int cmp1(node a, node b) { if (a.taxi == b.taxi) return a.id < b.id; return a.taxi > b.taxi; } int cmp2(node a, node b) { if (a.pizza == b.pizza) return a.id < b.id; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int MOD = 1e9 + 7; void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(m + 1), la(m + 1); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 1; i < m + 1; ++i) cin >> b[i]; int mid = 0, l = 0, r = n -... |
#include <bits/stdc++.h> using namespace std; int main() { int t; t = 1; while (t--) { stack<int> st; int n, x, ans = 0; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , &x); while (!st.empty()) { ans = max(ans, st.top() ^ x); if (st.... |
#include <bits/stdc++.h> unsigned bactery_count(unsigned num) { unsigned res = 0; while (num > 0) { (num & true) ? ++res, --num : num >>= 1; } return res; } int main() { unsigned num; std::cin >> num; std::cout << bactery_count(num) << std::endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int N; while (cin >> N) { int Store[31][31], i, j, SumR, SumC, Count = 0; vector<int> Row, Col; memset(Store, false, sizeof(Store)); for (i = 0; i < N; i++) for (j = 0; j < N; j++) cin >> Store[i][j]; for (i = 0... |
#include <bits/stdc++.h> using namespace std; const int lim = 400100; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const long long mod = 1000000007; long long a, b; int main() { cin >> a >> b; long long ans; ans = (b * (b - 1)) / 2; ans %= mod; ans *= (((b * (((a * (a + 1)) / 2)... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, m; cin >> n >> m; if (n == 1) { cout << 0 << endl; return; } if (n == 2) { cout << m << endl; return; } if (n > 2) { cout << 2 * m << endl; return; } } int main() {... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n = 0; cin >> n; vector<int> ans; int k = 0; if (n == 1) { cout << 1 << endl << 1; return 0; } for (int i = 1; i <= n; i... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; string lcp(string txt, string pat) { string S = pat + $ + txt; vector<int> Arr(S.size(), 0); int j = 0; for (int i = 1; i < S.size(); i++) { while (j > 0 && S[j] != S[i]) j = Arr[j - 1]; if (S[j] == S[i]) j++; ... |
#include <bits/stdc++.h> using namespace std; int qmin(int a, int b) { return (a < b) ? a : b; } int qmax(int a, int b) { return (a > b) ? a : b; } int n, m, k; int x[555], y[555]; int xl[555], xr[555], yl[555], yr[555]; set<int> stx, sty; map<int, int> mpx; int xpos[1010]; vector<int> l[1010], r[10... |
#include <bits/stdc++.h> namespace LYD { inline int read() { int x = 0, data = 1; char ch = getchar(); while ((ch > 9 || ch < 0 ) && ch != - ) ch = getchar(); if (ch == - ) { ch = getchar(); data = -1; } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch ... |
#include <bits/stdc++.h> using namespace std; vector<int> rs_needed[1000000 + 5]; int arr[1000000 + 5]; int main() { int i, j, k, n, idx = 0, rs, lst_pos, cminus = 0, cplus = 0; long long int dv = 0, mn; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &arr[i]); dv += abs(arr[... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct Item { int c; int x; Item() : c(), x() {} Item(int _c, int _x) : c(_c), x(_x) {} }; const long long INF = (long long)1e16; const int N = 505; int n, m, k; vector<Item... |
#include <bits/stdc++.h> using namespace std; int n, ans = 0, fac[1000010], inv[1000010], sq[1000010], sl[1000010], sr[1000010]; char s[1000010]; template <class T> void read(T &x) { char ch; bool ok; for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) ok = 1; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; long long mem[MAXN + 1][2]; int visited[MAXN + 1][2]; int b[MAXN + 1][2]; int a[MAXN + 1]; int n; int input() { int i; scanf( %d , &n); for (i = 2; i <= n; i++) scanf( %d , &a[i]); return 0; } int search(int x, in... |
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; vector<int> w, cn, c, d, p; vector<bool> used; int find(int x) { return (p[x] == x ? x : p[x] = find(p[x])); } void un(int x, int y) { x = find(x); y = find(y); if (rand() & 1) p[x] = y; else p[y] = x; } i... |
#include <bits/stdc++.h> using namespace std; long long n, d, i, j, m, l, t, sz = 1, a; long long cnt(long long p) { long long res = 1; for (i = 0; i < p; i++) res *= 2; return res; } int main() { cin >> t; for (int k = 0; k < t; k++) { long long h1 = 0, h0 = 0; cin >> n; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 21; const int N = int(1e5); const long long mod = int(1e9) + 7; const long long inf = 1e18; const double PI = 3.1415926536; inline int Set(int n, int pos) { return n = n | 1 << pos; } inline bool check(int n, int pos) { return n & 1 << ... |
#include <bits/stdc++.h> using namespace std; int getint() { unsigned int c; int x = 0; while (((c = getchar()) - 0 ) >= 10) { if (c == - ) return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - 0 ); } while (((c = getchar()) - 0 ) < 10); return x... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int position[21] = {0}; for (int i = 0; i < n; i++) cin >> position[i]; int head = 0, tail = n - 1, cost = 0; while (head <= tail) { if (position[head] != 2 && position[tail] != 2 && (... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, div = 1, ans = 0; cin >> n; long long int tt = log2(n); vector<long long int> w; if (log2(n) != tt) tt++; for (long long int i = 0; i < n; i++) w.push_... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200200; int n, k; int a[maxn]; vector<int> g[maxn]; int sz[maxn]; int dpd[maxn], dpu[maxn]; int mxd[maxn], mxu[maxn]; int mark[maxn], cnt[maxn]; int mxc[maxn], N; int ans; void dfs(int v, int par = -1) { sz[v] = 1; cnt[v] = m... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int INF = (int)1e9 + 7; const long long LINF = (long long)9e18 + 7; const long long P1 = 353251; const long long P2 = 239017; const long long MOD = 1e9 + 7; const long long MOD1 = 1e9 + 7; const long long M... |
#include <bits/stdc++.h> using namespace std; long long int dp[105][105][105]; long long int opti[105][105][105]; long long int lps[105]; string s, s1, s2, ans; long long int n, m, o; long long int rec(long long int i, long long int j, long long int k) { if (k >= o) return -1e16; if (i >= n || j >... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; template <typename T, int N> struct SuffixArray { T data[N + 1]; int result[N + 1], bucket[N + 1], count[N + 1], lcp[N + 1], n; pair<T, int> tmp[N + 1]; SuffixArray() : n(0) {} SuffixArray(T *source, int... |
#include <bits/stdc++.h> using namespace std; char A[5] = { a , e , i , o , u }; int main() { int k; cin >> k; int rol = 0, col = 0; for (int i = 5; i <= sqrt(k); ++i) { if ((k % i == 0) && (k / i >= 5)) { rol = i; col = k / i; break; } } if (rol == ... |
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin... |
#include <bits/stdc++.h> int main(void) { int n; std::cin >> n; std::vector<std::string> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } std::set<std::string> used; for (int i = n - 1; i >= 0; --i) { if (used.find(a[i]) == used.end()) { used.insert(a[i]); ... |
#include <bits/stdc++.h> using namespace std; int main() { string s, l, r; cin >> s; long long a, b, n; cin >> a >> b; n = s.size(); long long ar[n]; long long br[n]; ar[n - 1] = -1; br[0] = -1; ar[0] = (s[0] - 0 ) % a; br[n - 1] = (s[n - 1] - 0 ) % b; for (int i = ... |
#include <bits/stdc++.h> using namespace std; int main() { int q, w, e, r, t; char a[51]; cin >> a; if (a[0] == h ) { cout << http:// ; w = 4; } else { cout << ftp:// ; w = 3; } cout << a[w]; w++; while ((a[w] != r ) || (a[w + 1] != u )) { cout ... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e+5; bool vis[MAX_N] = {0}; char t = . ; int main() { int n, m, ans = 0, cnt = 0; string str; cin >> n >> m >> str; for (int i = 0; i < n; i++) { if (str[i] == t) { ans++; if (i == 0 || str[i - 1] != t) cnt... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string lan1, lan2; map<string, string> link; for (int i = 0; i < m; ++i) { cin >> lan1 >> lan2; link[lan1] = lan2; } for (int j = 0; j < n; ++j) { cin >> lan1; if (lan1.size() <= l... |
#include <bits/stdc++.h> using namespace std; const int Mo = (int)1e9 + 7; vector<int> v[100005]; void add(int x, int y) { v[x].push_back(y); } int i, n, x, y, f[100005][2], A, B, g[2][2]; int inc(int x, int y) { x += y; while (x >= Mo) x -= Mo; while (x < 0) x += Mo; return x; } void df... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while (T--) { int n, k; cin >> n >> k; string N = to_string(n); string ans = 99999999999999 ; set<char> S; for (auto c... |
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e15 + 88; const int maxn = (int)1e6 + 88; const int mod = 1000000007; long long a[maxn]; long long b[maxn]; long long myabs(long long a) { if (a > 0) return a; else return -a; } int main() { long lo... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n, w, h; struct Point { int d, p, id; bool operator<(const Point& r) const { return p < r.p; } }; vector<Point> px[N], py[N]; int ansx[N], ansy[N], tmpx[N], tmpy[N]; int main() { scanf( %d%d%d , &n, &w, &h); for (in... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> t; while (t--) { int count = 0; int ans; cin >> n; for (int i = 1; i <= 1666; i++) { if ((i % 10 != 3) && i % 3 != 0) { count++; } if (count == n) { ans = i; ... |
#include <bits/stdc++.h> using namespace std; vector<int> Arr; int main() { int N, K; cin >> N >> K; int Num, Acum; int i, j; for (i = 0; i < N; i++) { cin >> Num; Arr.push_back(Num); } sort(Arr.begin(), Arr.end()); j = 0; Acum = 0; for (i = 0; i < K; i++) { ... |
#include <bits/stdc++.h> using namespace std; int n, P, S; int s, t; vector<int> res1, res2; struct node { int to; int cap; int opp; int cost; }; vector<node> v[3500]; int d[3500]; bool in[3500]; int pre[3500], wh[3500]; void add(int x, int y, int cap, int cost) { node tmp; ... |
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a; cin >> b; sort(a.begin(), a.end()); for (int i = 0; i < a.size(); i++) { if (a[i] != 0 && a[0] == 0 ) { swap(a[i], a[0]); break; } } if (a == b) cout << OK << endl; ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, x; cin >> n >> x; long long int a[n]; set<long long int> s; long long int sum = 0; for (long long int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); sum += a[i]; } long long int y = *(s... |
#include <bits/stdc++.h> using namespace std; #pragma optimize( -O3 ) #define f first #define s second #define pb push_back #define endl n map<vector<int>, int>ma; map<vector<int>, bool>che; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); queue<v... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int Power(int n, int x) { int mul = n; int res = 1; while (x > 0) { if (x & 1) res = 1ll * res * mul % MOD; mul = 1ll * mul * mul % MOD; x /= 2; } return res; } int main() { ios::sync_with_stdio(... |
#include <bits/stdc++.h> using namespace std; bool odd(int N) { while (N < 0) { N += 2; } return N % 2 == 1 ? true : false; } bool even(int N) { while (N < 0) { N += 2; } return N % 2 == 0 ? true : false; } int main() { string s, t; cin >> s >> t; int N = s.si... |
#include <bits/stdc++.h> using namespace std; struct node { long long x, y; } A[100005]; int pos1[100005], pos2[100005], pos3[100005], pos4[100005]; int cmp1(int a, int b) { return A[a].x < A[b].x; } int cmp2(int a, int b) { return A[a].x > A[b].x; } int cmp3(int a, int b) { return A[a].y < A[b].y; } ... |
#include <bits/stdc++.h> using namespace std; template <class T> using v2d = vector<vector<T> >; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock:... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 1e6 + 5; const int mul = 9997; long long h[maxn]; long long p[maxn]; string s; vector<int> Z() { int L = 0, R = 0; vector<int> z(s.size()); z[0] = s.size(); for (int i = 1; i < s.size(); i++) { ... |
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; for (int u = 0; u < t; u++) { long long int n; cin >> n; n = 2 * n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long int b = a[(n / 2) - 1... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; const int D = 200 + 1; int n; pair<int, int> a[N]; int cn[N]; int cd[D]; long long sum, ans; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first; cn[a[i].fi... |
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[100086]; int x, y; int deg[100086], mxd; int ans[100086 << 3][2], cnt; void dfs(int i, int fa, int val) { int x = deg[i] - (i != 1); int fin = val - 1; ans[++cnt][0] = i, ans[cnt][1] = val; for (int j = 0; j < v[i].size(); ... |
#include <bits/stdc++.h> using namespace std; long long n, arr[100003], pre[100003], suf[100003]; int bitidx; bool cmp(long long a, long long b) { return ((a >> bitidx) & 1) < ((b >> bitidx) & 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; pre[0] = 0; for (int... |
#include <bits/stdc++.h> using namespace std; vector<int> gra[28]; char s[100005], re[100005]; int main() { int i, l, j, st, l1; while (scanf( %s , &s) == 1) { l = strlen(s); l1 = 0; for (i = 0; i < 26; i++) gra[i].clear(); for (i = 0; i < l; i++) gra[s[i] - a ].push_back(i); ... |
#include <bits/stdc++.h> using namespace std; int N, M; int A[200], B[200], D[200]; map<int, vector<int>> MM; set<int> S; struct mat { signed long long v[150][3] = {}; }; struct vec { signed long long v[3] = {}; }; void print(mat a, int n) { int x, y; for (x = 0; x < n; x++) { ... |
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; long long int p = sqrt(n); for (int i = 5; i <= p; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; retu... |
#include <bits/stdc++.h> int *ej[100000], eo[100000]; long long *ew[100000]; void append(int i, int j, long long w) { int o = eo[i]++; if (o >= 2 && (o & o - 1) == 0) { ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]); ew[i] = (long long *)realloc(ew[i], o * 2 * sizeof *ew[i]); } e... |
#include <bits/stdc++.h> using namespace std; template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T min(T a, T b, T c, T d) { return min(a, min(b, min(c, d))); } template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(NULL); long long tests = 1; cin >> tests; while (tests--) { long long n, k; cin >> n >> k; map<pair<long long, long long>, long long> timers; set<pair<long long, long long... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double PI = acos(-1.0); const long long int mod = 1e9 + 7; const int MAXN = 1e6 + 5; void cp() { int n, k; string s; cin >> n >> k >> s; vector<pair<int, int> > group; int l = 0, r = 0; while (l < n) { ... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int inf = 1e9 + 9; const long long int MOD = 1e9 + 696969; const long long INF = 4LL * 1000000LL * 1000000LL * 1000000LL; template <class T> int size(T &&x) { return int(x.size()); } template <class A, class B> ostrea... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, mp; cin >> n >> m >> k; mp = n / 2 + 1; if (n % 2 == 0 || mp > m) { cout << 0; return 0; } int ans = 0, i, a[10005]; for (i = 0; i < n; i++) cin >> a[i]; int min = a[0]; for (i = 0; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; bool is_Palindrome(string s) { long long int n = s.size(); for (long long int i = 0; i < n / 2; i++) { if (s[i] != s[n - i - 1]) { return 0; } } return 1; } void solve() { string a; cin >> a; long long int n = a.size()... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int a, b; cin >> a >> b; long long int c = 0; if (a % b == 0) cout << 0 << endl; if (a % b != 0) { long long int ans = b - (a % b); cout << ans << endl; } } int main() { int t; cin >> t; while ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1000000007; void solve() { string s; cin >> s; long long ans = INT_MAX; for (long long i = 0; i <= 9; i++) { long long count = 0; for (long long j = 0; j < (long long)s.size(); j++) { if (s[j] == (char)( 0 + i))... |
#include <bits/stdc++.h> using namespace std; const int MX_N = (1e3) + 3; int a[MX_N][MX_N]; int main() { int n; scanf( %d , &n); if (n == 4) puts( -1 ); else { for (int i = 0; i < n; ++i) { for (int j = i - 2; j >= 0; j -= 2) a[i][j] = 1; for (int j = i + 1; j < n; j... |
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ans = 0; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int a, b; cin >> a >> b; ; if (a == 1 || b == 1) ans++; } cout << ans; return 0; } |
#include <bits/stdc++.h> using namespace std; int n, m, l, r, cnt; long long ans; char s[101][10005]; int dfs(int x, int y, int d) { if (x == n - 1) return 1; if (s[x + 1][y] == . ) { l = y; r = y; ans++; cnt = 0; return dfs(x + 1, y, d); } if (s[x][y + d] == . ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); int d = arr[1] - arr[0]; d += arr[2] - arr[1]; cout << d; return 0; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.