func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &n) { n = 0; T f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1, c = getchar(); while (isdigit(c)) n = n * 10 + c - 0 , c = getchar(); n *= f; } template <... |
#include <bits/stdc++.h> using namespace std; int main() { int long long n, i, k = 0; cin >> n; double a[n + 5], s = 0, b[n + 5]; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } for (i = 0; i < n; i++) { double r = (s - a[i]) / (n - 1); if (r == a[i]) { b[... |
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b, d, i, j, k = 0, h, c, p1, p2, q1, q2, A, B, c1, c2, l, m = 0, n, t = 1, q = 0, r, e, x = 0, y = 0, o, s, mx1, mx2 = 0, mx = 0, p = 0, v, mn = 0, z, w; string s1, s2, s3, s4;... |
#include <bits/stdc++.h> using namespace std; int nvertices, nedges; vector<vector<pair<int, int>>> adjList(110); vector<bool> visited; void dfs(int u, int c) { visited[u] = true; for (auto e : adjList[u]) { if (!visited[e.first] && (e.second == c)) { dfs(e.first, c); } } } ... |
#include <bits/stdc++.h> using namespace std; int readint() { char c; while (c = getchar(), (c < 0 || c > 9 ) && c != - ) ; bool flag = (c == - ); if (flag) c = getchar(); int x = 0; while (c >= 0 && c <= 9 ) { x = x * 10 + c - 48; c = getchar(); } return fl... |
#include <bits/stdc++.h> using std::cerr; using std::cin; using std::cout; using std::deque; using std::endl; using std::fixed; using std::ios_base; using std::list; using std::make_pair; using std::make_tuple; using std::map; using std::nth_element; using std::pair; using std::queue; usin... |
#include <bits/stdc++.h> using namespace std; long long a[101][101]; long long b[101]; int main() { int m, n; cin >> m >> n; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i < m; i++) { long long minn = 100000000000000; for (int j = 0; j... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d , &(n)); scanf( %d , &(k)); int A[101]; for (int(i) = 0; (i) < (n); (i)++) { scanf( %d , &(A[i])); } int x, y, ans = 0; for (int(i) = 0; (i) < (k); (i)++) { x = 0; y = 0; for (int(j... |
#include <bits/stdc++.h> const int MAX_VAL = 1000000; struct AInt { int sum; int minSum; }; AInt aInt[1 << 21]; void update(int index, int left, int right, int addIndex, int addValue) { if (left == right) { aInt[index].sum += addValue; aInt[index].minSum += addValue; } else { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; for (int i = 0; i <= t / (1234567); i++) { for (int j = 0; j <= t / 123456; j++) { if (t - (i * 1234567) - (j * 123456) >= 0 && ((t - (i * 1234567) - (j * 123456)) % 1234 == 0)) { cout <... |
#include <bits/stdc++.h> using namespace std; long long findGCD(long long a, long long b) { return ((b == 0) ? a : findGCD(b, a % b)); } map<long long, long long> width; long long wit = 0; vector<pair<long long, long long> > rect[200005]; int main() { long long n; scanf( %lld , &n); for (l... |
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 11; const int MAXN = 5e7 + 1; const int BITMAX = 18; const int INF = 2e9 + 88; const long long LLINF = 1e17 + 3; const int MOD = 1e9 + 7; const long double Pi = acos(-1); int a[MAX]; int main() { int n, m; scanf( %d , &n); ... |
#include <bits/stdc++.h> using namespace std; void init() { cin.tie(0); cin.sync_with_stdio(0); } int main() { init(); int n, z; cin >> n >> z; for (int i = 0; i < z; i++) { (n % 10 == 0) ? n /= 10 : n -= 1; } cout << n << endl; } |
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const int mod = 998244353; char str[N]; char s[2][N]; int nxt[2][N]; int extend[2][N]; void get_nxt(char *s, int *nxt) { int n = strlen(s), r = 0, pos = 1; nxt[0] = n; while (r + 1 < n && s[r] == s[r + 1]) ++r; nxt[1] =... |
#include <bits/stdc++.h> using namespace std; long long n, t; std::vector<pair<long long, long long> > v; long long dp[(1 << 15) + 5][226][4]; long long solve(long long x, long long y, long long z) { if (x == 0) return 1; if (x < 0) return 0; if (dp[y][x][z] != -1) return dp[y][x][z]; long lon... |
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, pair<int, int> > p; int res[100 + 10][100 + 10]; int main() { int n, m, q, k, d, t, tem1, tem2, tem3, tem4, y = 1, sum = 0, ans = 0; string s, c; scanf( %d%d%d , &n, &m, &q); for (int i = 0; i < n; i++) { for (int j = 0; j <... |
#include <bits/stdc++.h> using namespace std; int d[1000], q[1000], l[1000], r[1000], p[1000]; vector<int> dd[1000]; int main() { int n; cin >> n; int i, j; fill(d, d + n, -1); d[0] = 0, dd[0].push_back(0); int x = 0, z; while ((1 << x) < n) x++; for (i = 1; i < n; i++) l[i] = 1,... |
#include <bits/stdc++.h> using namespace std; struct square { int r1, c1, r2, c2; square(int R1, int C1, int R2, int C2) { r1 = R1; c1 = C1; r2 = R2; c2 = C2; } bool same(int R1, int C1, int R2, int C2) { if (R1 != r1) return false; if (C1 != c1) return false; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 333333; int ans[maxn]; int fa[maxn]; int nx[maxn]; int visit[maxn]; int n, m; inline int query(int a) { return a == fa[a] ? a : fa[a] = query(fa[a]); } inline void conbine(int a, int b) { a = query(a), b = query(b); if (a != b) fa[... |
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); const long long INF = 2e18; template <typename T, typename T1> void amax(T &a, T1 b) { if (b > a) a = b; } template <typename T, typename T1> void amin(T &a, T1 b) {... |
#include <bits/stdc++.h> using namespace std; long long n, m; int s, p, i, j, k, z; string s1, s2; int const md = 1000000; stack<char> st; int a[5]; int main() { int k1 = 0, k2 = 0, k3 = 0; cin >> k1 >> k2; for (i = 1; i <= k1; i++) { cin >> k3; n = n * k2 + k3; } cin >> ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; inline long long read() { long long k = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { k = k * 10 + ch - 0 ; ... |
#include <bits/stdc++.h> using namespace std; const int MN = 1e4 + 20; vector<int> adj[MN], topo; vector<pair<int, int>> edge; int scc, st, s[MN], h[MN], t[MN]; bool os[MN]; stack<int> ms; int n, m; void add(int u, int v) { adj[u + m].push_back(v); adj[v + m].push_back(u); adj[u].push_back... |
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v, cap, cost, next; } edge[555 * 1111]; int head[555]; int NV, NE, vs, vt; void addEdge(int u, int v, int cap, int cost) { edge[NE].u = u; edge[NE].v = v; edge[NE].cap = cap; edge[NE].cost = cost; edge[NE].next = head... |
#include <bits/stdc++.h> using namespace std; int x; int f(int a, int b) { return (a * b + 1) / 2; } bool ok(int n) { if (x == 3 && n == 3) return false; if (n % 2 == 0 && x % 4) return false; if (n % 2 == 0) { if (x / 4 <= f(n / 2 - 1, n / 2 - 1)) return true; return false; } in... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long cdiff, d, diff, rem, c, n, m, i, k = 0, j, flag = 0, x, minstep = 10000000000; cin >> n; long long b[n]; for (i... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline int get_power(int a, int n) { int res = 1; while (n > 0) { res = n & 1 ? 1ll * res * a % mod : res; a = 1ll * a * a % mod; n >>= 1; } return res; } inline int get_inv(int x) { return get_power(x, ... |
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ... |
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { if (a < b) { swap(a, b); } T t; while (b > 0) { t = a % b; a = b; b = t; } return a; } template <class T> T gcdL(vector<T>& v) { int l = v.size(); if (l == 1) return v[0... |
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, input = 0, temp = 0, sum = 0, c = 0; cin >> n; for (int i = 0; i < 2 * n; i++) { cin >> temp; } if (sum % 2 == 0) { cout << Karen ; } else cout << Koyomi ; } |
#include <bits/stdc++.h> using namespace std; int main() { int K; vector<int> a(5, 0); for (int i = 0; i < 5; i++) cin >> a[i]; cin >> K; vector<int> b(K); for (int i = 0; i < K; i++) { string temp; cin >> temp; if (temp == XXL ) b[i] = 4; else if (temp == X... |
#include <bits/stdc++.h> using namespace std; int output(int n) { int sum = 0; while (n != 1) { int i; for (i = 2; i * i <= n; i++) if (n % i == 0) { sum += n; n /= i; break; } if (i * i > n) { sum += n; break; } } ... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; long long a, b, c, s; long long gao(long long a, long long b, long long xl, long long xr) { if (xl > xr) return 0; if (a * xl + b < 0 && a * xr + b < 0) return 0; double key = -b * 1.0 / a; long long keyx; if (a > 0) { ... |
#include <bits/stdc++.h> using namespace std; struct node { long long l, r; int now; vector<pair<int, int> > v; } st[250005 * 4]; int pi, ri, n, N; int p[250005], m[250005]; long long r, sp[250005]; pair<long long, int> d[250005]; queue<int> q; vector<long long> rr; bool vis[250005]; v... |
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; for (int i = 1; i < str.size() - 1; i++) { if (str[i + 1] != . && str[i - 1] != . && str[i] != . ) { if (str[i + 1] != str[i - 1] && str[i - 1] != str[i] && str[i + 1] != str[i]) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; int mem[MAXN + 10]; int main() { int N; cin >> N; mem[0] = 0, mem[1] = 1, mem[2] = 2, mem[3] = 4; for (int i = 4; i <= N; ++i) { mem[i] = i + mem[i - 2]; } cout << mem[N] << n ; } |
#include <bits/stdc++.h> using namespace std; long long modexp(long long base, long long exp) { if (exp == 1) return base; else if (exp == 0) return 1; else { if (exp % 2 == 0) { long long base1 = pow(modexp(base, exp / 2), 2); if (base1 >= 1000000007) return ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; bool valid; int n, p[maxn], a[maxn], head, tail; int main() { int T; scanf( %d , &T); while (T--) { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &p[i]); a[p[i]] = i; } ... |
#include <bits/stdc++.h> using namespace std; const int N=2e5+10; int a[N],tt; int cnt[N]; int pre[N]; int main(){ int t; scanf( %d ,&t); while(t--){ int n; tt=0; scanf( %d ,&n); for(int i=1;i<=n;i++) scanf( %d ,&a[i]); sort(a+1,a+n+1); ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; while (cin >> t) { string a; cin >> a; int s = 0; for (int i = 0; i < t - 1;) { if (a.at(i) == a.at(i + 1)) { if (a.at(i) == a ) a.at(i) = b ; else a.at(i) = a ; ... |
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<long long, short> > mass; long n, k; scanf( %li %li , &n, &k); long long a, b; for (long i = 0; i < n; i++) { scanf( %I64d %I64d , &a, &b); mass.push_back(make_pair(a, -1)); mass.push_back(make_pair(b, 1)); ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const long long _INF = 0x7ffffffffffffffll; const double EPS = 1e-9; const double PI = acos(-1.0); template <class T, class INT> inline T pow(T x, INT y) { T res(1); for (T tt(x); y; y /= 2) { if (y & 1) res *= tt; ... |
#include <bits/stdc++.h> using namespace std; int n, m, a[1001][1001]; set<int> r[1001], c[1001]; map<int, int> r_m[1001], c_m[1001]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf( %d , &a[i][j]); r[i].insert(a[i][j]); ... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)(2e9); const long long linf = (long long)(2e18); void solve(); signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(20); solve(); return 0; } void solve() { int n = 8; unor... |
#include <bits/stdc++.h> using namespace std; vector<int> v; int extgcd(int a, int b, long long &x, long long &y) { int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int main() { int n; scanf( %d , &n... |
#include <bits/stdc++.h> using namespace std; int a[5050]; int solve(int l, int r, int h) { int m, i; if (l > r) return 0; else if (l == r) return (a[l] > h); else for (i = m = l; i <= r; i++) if (a[m] > a[i]) m = i; return min(r - l + 1, a[m] - h + sol... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; tuple<long long, long long, long long> arr[n - 1]; long long s1, e1; cin >> s1 >> e1; for (long long i = 0; i < n - 1; ++i) { long long s2, e2; cin >> s2 >> e2; arr[i] = make_tuple(e2 ... |
#include <bits/stdc++.h> const long double pi = 3.141592654; using namespace std; int n, k; int dx[] = {0, 0, 1, -1, 1, -1, -1, 1}; int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1}; bool valid(int r, int c) { return r >= 0 && c >= 0 && r < n && c < n; } char grid[120][120]; bool vis[100074]; vector<int> initial... |
#include <bits/stdc++.h> using namespace std; string s[9], v[35], k[35]; bool in[9]; int len, a[9], l[9], ans; char c[35][35]; bool check2() { if (ans == 0) return 1; for (int i = 1; i <= min(len, ans); i++) if (v[i] < k[i]) return 1; else if (v[i] > k[i]) return 0; i... |
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> inline istream& operator>>(istream& fin, pair<T1, T2>& pr) { fin >> pr.first >> pr.second; return fin; } template <class T0, class T1, class T2> inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) { fin >> get... |
#include <bits/stdc++.h> using namespace std; struct node { int left, right, size; } t[600000]; int n; int a[200005], b[200005], sa[200005], sb[200005], s[200005], ans[200005]; int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ... |
#include <bits/stdc++.h> using namespace std; int a[1000100], g[1000100]; int main() { for (int i = 1; i < 20; i++) { int msk = (1 << i) - 1; for (int j = (1 << i - 1); j < (1 << i); j++) { g[j] = (1 << i - 1) | g[j ^ msk]; } } int n, x; scanf( %d , &n); for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 4e5 + 10; int n, a[MAX]; int f(int x) { vector<int> v(n); for (int i = 0; i < n; ++i) { v[i] = (a[i] == -1 ? x : a[i]); } int ret = 0; for (int i = 0; i < n - 1; ++i) { ret = max(ret, abs(v[i] - v[i + 1])); } r... |
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f;... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; while (scanf( %d%d%d , &n, &m, &k) != EOF) { if (n == m) { if (n == 2 && k == 1) { printf( 4 n ); printf( 1 2 3 4 n ); } else { printf( %d n , 2 * k + 1); printf( 1 ); ... |
#include <bits/stdc++.h> using namespace std; struct EDGE { int u, v, l, next; bool train; EDGE() {} EDGE(int a, int b, int c, int d, bool bo) { u = a; v = b; l = c; next = d; train = bo; } } edge[1000000]; int n, m, k; int edgenumber, head[200100], visit[2001... |
#include <bits/stdc++.h> using namespace std; int main() { int s; cin >> s; while (s--) { string t; cin >> t; int f = 0; for (int i = 1; i < t.length(); i++) { if (t[i] != t[i - 1]) { f = 1; break; } } if ((f == 0) || (t.length() ==... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin >> t; while(t--) { string s; cin >> s; char c = a ; int n = s.size(); if(n&1) { for(int i=0;i<=n/2;i++) { if(s[n-i-1... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx2,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using pi = pair<ll, ll>; const int mod = 1e9 + 7; co... |
#include <bits/stdc++.h> using namespace std; int __gcd(int x, int y) { if (!y) return x; return __gcd(y, x % y); } const long long linf = 1e18 + 5; int mod = (int)1e9; const int logN = 18; const int inf = 1e9 + 9; const int N = 1e5 + 5; int ff, h[N], n, a[N], x, y, z, p; int main() { sc... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int dp[55][8], d1[55], d2[55], d3[55], n, m; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> s; d1[i] = inf; d2[i] = inf; ... |
#include <bits/stdc++.h> using namespace std; const int N = 5007; const int MX = 1e9 + 7; const long long int INF = 1e18 + 9LL; int n, m; int in[N]; vector<int> cows[N]; int Left[N], Right[N]; int take[N], poss[N], New[N]; void update(int t) { int canTake = 0; if (cows[t][0] <= Left[t] || co... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int inf = 0x3fffffff; const int maxn = 200005; int n; unsigned long long m; struct P { int x, y; } p[maxn]; bool cmp(P a, P b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } int main() { scanf(... |
#include <bits/stdc++.h> using namespace std; template <class T> void show(const vector<T> &a) { for (T x : a) cout << x << ; cout << n ; } const long long N = 1e5 + 10, oo = 1e18 + 500; const long long mod = 1e9 + 7; const long double eps = 1e-9, PI = 2 * acos(0.0); long long n, m, k; lo... |
#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 (... |
#include <bits/stdc++.h> using namespace std; const long long sz = 1e5 + 5; vector<long long> A(sz, 0), Lazy(4 * sz, 0), Tree(4 * sz, 0); long long n, m; void Built(long long Node, long long I, long long F) { if (I == F) { Tree[Node] = A[I]; return; } long long M = (I + F) / 2; Bui... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 2222; int n, K; long long sum[N][N], tail[N], f[N][N]; char s[N]; long long work() { long long ret = 0; tail[n + 1] = 1; for (int i = n; i >= 1; i--) tail[i] = tail[i + 1] * (s[i] - a + 1) % MOD; if (K =... |
#include <bits/stdc++.h> using namespace std; const int kd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int n, i, j; char s[666666]; int cnt[42][42][42]; int mx, ad, am, ay; int main() { scanf( %s , s); int n = strlen(s); memset(cnt, 0, sizeof(cnt)); for (i = 0; i + 9 < n; i+... |
#include <bits/stdc++.h> using namespace std; int a[1000100], b[1000100], cnt[32]; int solve(int n, int m) { int i, j, k, ret = 0; memset(cnt, 0, sizeof(cnt)); for (i = 0; i < n; ++i) { for (j = 0; (1 << j) <= a[i]; ++j) { if (a[i] & (1 << j)) ++cnt[j]; } } sort(b, b + m); ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 10; const long long BINF = 1e18 + 10; long long get(long long l, long long r) { if (l > r) { swap(l, r); } return r * (r + 1) / 2 - l * (l - 1) / 2; } long long solve(long long a, long long b, long long lim) { lo... |
#include <bits/stdc++.h> using namespace std; int main() { int num; int arr[110]; cin >> num; for (int i = 0; i < num; i++) { cin >> arr[i]; } for (int i = 1; i <= num; i++) { for (int j = 0; j < num; j++) { if (arr[j] == i) { cout << j + 1 << ; } ... |
#include <bits/stdc++.h> using namespace std; int n, m; string we, ns, sol = ; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); cin >> n >> m; cin >> we; cin >> ns; sol += we[0]; sol += we.back(); sol += ns[0]; sol += n... |
#include <bits/stdc++.h> using namespace std; const long long logN = 20; const long long M = 1000000007; const long long INF = 1e12; const long long N = 100005; void solve() { long long n, k; cin >> n >> k; set<long long> s; while (s.size() < 30 and s.size() < (n - 1)) { long long i = ... |
#include <bits/stdc++.h> using namespace std; long long int sum[100010], bsum[100010], arr2[100010]; pair<long long int, long long int> arr[100010]; void scanStr(char *str) { long long int i = 1; char ch; for (ch = getchar(); ch != n && ch != ; ch = getchar()) str[i++] = ch; str[i] = 0 ;... |
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } void ... |
#include <bits/stdc++.h> using namespace std; int main() { int T = 1; while (T--) { int n, m; cin >> n >> m; map<int, int> mp; vector<pair<int, int> > pp; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; pp.push_back({a, b}); if (a != b) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; map<int, int> l, r; int a[maxn << 1]; int sum[maxn << 1]; int main() { int t; cin >> t; while (t--) { l.clear(); r.clear(); int n; cin >> n; for (int i = 1; i <= 2 * n; i++) cin >> a[i]; f... |
#include <bits/stdc++.h> using namespace std; int m[10000000]; int func(int v) { int r = 1; while (v != 1) { if (v % 2 == 0) { v /= 2; } else { v--; r++; } } return r; } int main() { int n, a; long long r = 0; scanf( %d , &n); for (int ... |
#include <bits/stdc++.h> using namespace std; long long solve(long long A, long long B, long long C) { if (B == 0) { return 0; } long long N = A % B; long long X = solve(B, N, C); long long Y = (-C - A * X) / B; if (A != 0) { Y %= A; } return Y; } int abs(int a) { ret... |
#include <bits/stdc++.h> int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; bool flag = false; for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; vector<int> adj[N]; int numDiv[N]; int a[N]; bool cand[N]; int sz[N], dsu[N]; int f(int x) { if (x == dsu[x]) { return x; } return dsu[x] = f(dsu[x]); } void merge(int x, int y) { x = f(x), y = f(y); if (x... |
#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]... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(0); long long n, i, k, m, a[4005], v[4005], d[4005], p[4005], j; cin >> n; for (i = 0; i <= n - 1; i++) { cin >> v[i] >> d[i] >> p[i]; } long long cnt = 0; for (i = 0; i <= n - 1; i++) { ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, c = getchar(), f = 0; for (; c > 9 || c < 0 ; f = c == - , c = getchar()) ; for (; c >= 0 && c <= 9 ; x = (x << 1) + (x << 3) + c - 0 , c = getchar()) ; return f ? -x : x; } inline void write(int x) ... |
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double eps = 1e-9; long long gcd(long long a, long long b); int main() { int n; long long maxi = 0, num, g; cin >> n; for (int i = 0; i < n; i++) { cin >> num; maxi = max(maxi, num); g = gcd(g, num);... |
#include <bits/stdc++.h> const int maxn = 0x3f3f3f3f; const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427; const double PI = 3.141592653589793238462643383279; using namespace std; struct node { int l, r; double x, y, a; } tree[... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; string s; cin >> s; long long int oc = 0, zc = 0, fpos = -1, lpos; for (in... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long a[n + 1]; long long diff[n]; long long max_count = INT_MIN; for (long long i = 1; i <= n; i++) cin >> a[i]; multiset<long... |
#include <bits/stdc++.h> int main() { int n, i, j, count = 0; scanf( %d , &n); int ara[n]; for (i = 0; i < n; i++) { scanf( %d , &ara[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (ara[i] == 0) { continue; } if (ara[i] == ar... |
#include <bits/stdc++.h> using namespace std; char s[450000]; int main() { scanf( %s , &s); vector<string> list; char cur, last = ! ; string word = ; int len = strlen(s); for (int i = 0; i < len; i++) { cur = s[i]; if (last == ! ) { if (cur != . ) { word ... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1.0e-8; struct Point { double x, y; Point(double _x = 0, double _y = 0) { x = _x; y = _y; } friend Point operator+(const Point &a, const Point &b) { return Point(a.x + b.x, a.y + b.y); } friend Point operato... |
#include <bits/stdc++.h> using namespace std; #define fast_io ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define lli long long #define loop(i, l, r) for (lli i = l; l < r ? i < r : i > r; l < r ? i += 1 : i -= 1) #define itr(it, a) for (auto it = a.b... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; vector<vector<int>> selfloops; vector<vector<pair<int, int>>> adjlist; vector<vector<int>> otherIdx; vector<int> cycle, validIdx; void swapEdges(int n, int a, int b) { int neighA = adjlist[n][a].first, neighB... |
#include <bits/stdc++.h> using namespace std; int main() { long long x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; cout << ((y2 - y1 + 1) >= 0 ? (y2 - y1 + 1) : 0) * (((x2 - x1 + 2) / 2) >= 0 ? ((x2 - x1 + 2) / 2) : 0) - ((y2 + 1 - y1) / 2 >= 0 ? (y2 + 1 - y1) / 2 : 0)... |
#include <bits/stdc++.h> using namespace std; int main() { string word, type; int n; cin >> n; int j; int cur = 0, real = 0, sreal = 0; bool t = false, b = false; getline(cin, word); for (int i = 0; i < n; ++i) { getline(cin, word); for (j = 0; j < (int)word.size() && wor... |
#include <bits/stdc++.h> using namespace std; int n, L, m, head[1000005], cnt, root, sz[1000005], sum, mx; long long t[1000005], ans; struct edge { int to, next, cost; } e[1000005 << 1]; struct dist { int len, dis; bool operator<(const dist &p) const { return dis < p.dis; } } dis[1000005], q[1... |
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0, n, a[120], x, y, i; cin >> n; for (i = 0; i < n - 1; ++i) { cin >> a[i]; } cin >> x >> y; for (i = x - 1; i < y - 1; ++i) { sum += a[i]; } cout << sum << n ; } |
#include <bits/stdc++.h> using namespace std; const int N = 1100, M = 2 * 1e5 + 10, INF = 1e9 + 10; pair<int, int> e[M]; int dp[N][N]; vector<pair<pair<int, int>, pair<int, int> > > que[M]; bool ans[M]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q;... |
#include <bits/stdc++.h> using namespace std; int col[5001], mid, n, dis[5001][5001], ans; bool v[5001]; long long mod = 1e9 + 7; bool dfs(int x) { v[x] = 1; for (int i = 1; i <= n; ++i) if (i != x && dis[x][i] > mid) if (!v[i]) { col[i] = col[x] ^ 1; if (dfs(i)) retu... |
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 13; const long long INF64 = 1e18; int n, m; long long a[N]; vector<pair<int, long long>> g[N]; long long dist[N]; void Dijkstra() { set<pair<long long, int>> q; for (int i = 0; i < int(n); i++) { dist[i] = a[i]; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.