func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int t[n + 1]; for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < n; i++) { int tt = t[i]; for (int j = 1; j <= tt; j++) cout << j << ; cout << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 77, Mod = 1000000007; struct SegmentTree { int nn; vector<int> LC, RC, S, lz; int cur = 0; inline void __init() { AddNode(); } inline void AddNode() { ++cur; LC.push_back(-1); RC.push_back(-1); S.push_... |
#include <bits/stdc++.h> using namespace std; struct Q { int r1, r2, c1, c2, idx; }; int n, m, k, q; Q qs[200000]; vector<int> qAtRow[100001]; vector<int> qAtCol[100001]; vector<int> atCol[100001]; vector<int> atRow[100001]; bool must[200000]; bool res[200000]; int v[100001]; int Z = 40000... |
#include <bits/stdc++.h> using namespace std; pair<int, int> a[300005]; vector<int> v[300005]; int cnt; int main(int argc, char** argv) { int T; cin >> T; while (T--) { int n; cin >> n; a[0] = {-1, 0}; for (int i = 1; i <= n; i++) scanf( %d , &a[i].first), a[i].second = i; ... |
#include <bits/stdc++.h> using namespace std; long long spf[21]; long long fac[21]; void sieve() { spf[1] = 1; for (long long i = 2; i < 21; i++) spf[i] = i; for (long long i = 4; i < 21; i += 2) spf[i] = 2; for (long long i = 3; i * i < 21; i++) { if (spf[i] == i) { for (long long... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int NAX = 2e5 + 5, MOD = 1000000007; struct Solution { Solution() {} void solveCase() { set<string> ss; for (size_t i = 0; i <= 100; i += 4) { auto I = to_string(i); ss.insert(I); if (i < 10) { ... |
#include <bits/stdc++.h> using namespace std; int dp[(1 << 22)], a[1000000]; int main() { int N; while (scanf( %d , &N) != EOF) { memset(dp, -1, sizeof(dp)); for (int i = int(0); i < int(N); i++) { scanf( %d , a + i); dp[a[i]] = a[i]; } for (int i = int(0); i < int(... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:200000000 ) using namespace std; template <typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; } template <typename T> inline T sqr(T x) { return x * x; } template <typename T> string toStr(T x) { stringstream st; st << x... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return f * x; } inlin... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int k[3]; scanf( %d%d%d , k, k + 1, k + 2); sort(k, k + 3); if (k[0] == 1) printf( YES n ); else if (k[0] == 2) { if (k[1] == 2) printf( YES n ); else if (k[1] == 4 && k[2] == 4) ... |
#include <bits/stdc++.h> using namespace std; int main() { char c[51]; int n; scanf( %s , c); scanf( %d , &n); for (int i = 0; i < strlen(c); i++) { if (c[i] < a ) c[i] += a - A ; if (c[i] < 97 + n) c[i] += A - a ; } printf( %s , c); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int h, m; scanf( %d:%d , &h, &m); double dm = (m) / 60.0, dh = (h % 12 + dm) / 12; cout << 360 * (dh) << << 360 * (dm) << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { scanf( %d , &b[i]); } int ans = 0; for (int i = 0; i < n; i++) { int p = 0; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = LLONG_MAX; void IO() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout.setf(ios::fixed); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); } long long pw(long l... |
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, cnt = 0, p = 0, n; cin >> n; cin >> s; for (i = 0; i < n; i++) if (s[i] == 0 ) cnt++; else p++; if (p > 0) { cout << 1; for (i = 0; i < cnt; i++) cout << 0; cout << endl... |
#include <bits/stdc++.h> const long long int MOD = 1e9 + 7; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; using namespace std; void vok() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);... |
#include <bits/stdc++.h> using namespace std; const int N = 100005, M = 50005; const int inf = 0x3f3f3f3f; const long long INF = 1000000000000000000ll; const long long mod = 998244353; const double pi = acos(-1.0); const double eps = 1e-6; vector<int> rec; struct OP { char str[4]; int num; ... |
#include <bits/stdc++.h> using namespace std; namespace io { void _(int &k) { char c; int e = 1; k = 0; while ((c = getchar()) > 9 || c < 0 ) if (c == - ) e = -1; k = c - 0 ; while ((c = getchar()) <= 9 && c >= 0 ) { k *= 10; k += c - 0 ; } k *= e; } ... |
#include <bits/stdc++.h> using namespace std; const long long N = 100010; long long n, a[N]; double bit[N]; inline void add(long long x, double val) { for (; x <= n; x += x & -x) bit[x] += val; } inline double ask(long long x) { double sum = 0; for (; x; x -= x & -x) sum += bit[x]; return ... |
#include <bits/stdc++.h> using namespace std; int mas[100][100], n, used[100], p = 0, s = 0, to; vector<vector<int> > g; void dfs(int from) { used[from] = 1; for (int i = 0; i < 2; i++) { to = g[from][i]; if (!used[to]) { p += mas[from][to]; dfs(to); } } } int m... |
#include <bits/stdc++.h> using namespace std; long long int insig; void Out(vector<long long int> x) { for (long long int i = 0; i < x.size(); i++) { cout << x[i] << ; } cout << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int N; ... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; const long long INF = (long long)1e9; struct Point { long long x, y; Point() : x(), y() {} void scan() { scanf( %lld%lld , &x, &y); } bool operator<(const Point &a) const { return y < a.y || (y == a.y && x < a.x); ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( avx2 ) #pragma GCC optimize( unroll-loops ) using namespace std; const long long MN = 3005; long long a[2], b[2], c[2], d[8], first[8], ra[2], rb[2], rc[2]; inline bool check(long long f3, long long f5, long long f6) { for (long l... |
#include <bits/stdc++.h> using std::sort; int n; char s[100000 + 1]; struct SH { unsigned int s, h; }; struct SH cnt[100000 + 1]; unsigned long long ans; void read() { scanf( %d , &n); ans = 0; for (int i = 1; i <= n; ++i) { scanf( %s , s); int l = strlen(s); unsigned i... |
#include <bits/stdc++.h> using namespace std; struct Data { long long l, r; } a[200100]; long long n, s, rmax, lmin; void Docfile() { scanf( %lld%lld , &n, &s); rmax = 0; lmin = 1e18; for (int i = 1; i <= n; i++) { scanf( %lld%lld , &a[i].l, &a[i].r); rmax = max(rmax, a[i].r); ... |
#include <bits/stdc++.h> using namespace std; template <typename T> int size(T& a) { return (int)a.size(); } template <typename T> T sqr(T a) { return a * a; } #pragma comment(linker, /STACK:60777216 ) const int INF = int(1e9); char s[10][10]; bool can(int i, int j) { return i >= 0 && i <... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int dot = -1; for (int i = 0; i < (int)(s).size(); ++i) { if (s[i] == . ) { dot = i; } } int deg = 0; if (dot == -1) { deg = (int)(s).size(); string t = 0. + s; s = t; ... |
#include <bits/stdc++.h> using namespace std; namespace node_tre { int tre[100005] = {}; void update(int x, int val) { tre[x] += val; } int ask(int x) { return tre[x]; } void cover(int x) { tre[x] = 0; } }; // namespace node_tre using namespace node_tre; struct node { int ty; int id; int ... |
#include <bits/stdc++.h> int main() { int m, n, i, j, c; int coordenadas[3][2]; scanf( %d%d , &n, &m); char ciudad[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { scanf( n%c , &ciudad[i][j]); } } c = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; ... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; string s; cin >> s; long long x = -1; for (long long i = 97; i <= 122; ++i) { char c = char(i); long long cnt = 0; for (long... |
#include <bits/stdc++.h> struct vertex { long long x, y; int adj[4], k; } vv[30]; void dfs(int p, int v, long long x, long long y, long long a, int d) { int i; vv[v].x = x; vv[v].y = y; d = (d + 2) % 4; for (i = 0; i < vv[v].k; i++) if (vv[v].adj[i] != p) { long long x_ =... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 300000 + 10; int n, m, s; struct edge { bool t; int u, v; } es[maxn]; bool vis[maxn]; vector<int> G[maxn]; char ans[maxn]; int cnt; void dfsmax(int u) { vis[u] = true; cnt++; for (int i =... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int c[maxn], up[maxn], h[maxn]; bool visited[maxn]; set<int> s[maxn]; vector<int> g[maxn]; void dfs(int v, int par = -1) { c[v] = v; visited[v] = 1; up[v] = h[v]; int cnt = 0; for (auto u : g[v]) { if (u == ... |
#include <bits/stdc++.h> using namespace std; int n, tt[1005]; vector<int> a[1005]; void dfs(int u) { if (tt[u] == 1) { printf( %d , u); return; } tt[u] = 1; for (int i = 0; i < a[u].size(); ++i) dfs(a[u][i]); } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) ... |
#include <bits/stdc++.h> using namespace std; long long a[1000005]; long long c[2000015]; long long n; int main() { ios_base::sync_with_stdio(0); cin >> n; long long ma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; c[a[i]]++; ma = max(ma, a[i]); } long long ans = 0;... |
#include <bits/stdc++.h> using namespace std; int ct[300005]; vector<pair<int, int> > val; int n, m; bool check(int vl) { for (int i = 0; i < 300005; i++) ct[i] = 0; int count = 0; for (int i = 0; i < m; i++) { if (vl != val[i].first && vl != val[i].second) { count++; ct[val[... |
#include <bits/stdc++.h> using namespace std; long long l[5001], dp[5001][5001]; void solve() { int n, k, ans = 0; cin >> n >> k; vector<int> v(n, 0); for (int i = 0; i < (int)(n); ++i) cin >> v[i]; sort(v.begin(), v.end()); for (int i = 0, j = 0; i < n; ++i) { while (v[i] - v[j] > 5... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, data, prev = 0, energy = 0; cin >> n; vector<long long int> v1(n); long long int ans = 0; for (long long int i = 0; i < n; i++) { cin >> data; if (energy < (data - prev)) { ans += ((data - prev) - ene... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10, M = N, INF = 0x3f3f3f3f, mod = 1e9 + 7, base = 131; long long n, t, ans; long long a[N], s[N]; long long phi(long long n) { long long res, a; res = a = n; for (long long i = 2; i <= a / i; i++) { if... |
#include <bits/stdc++.h> using namespace std; int n, x, y, t, l[205], qd[205 + 205], qn[205 + 205], h[205], b1, b2, d1, d2, ret; void build(int x, int y) { qd[++t] = y, qn[t] = l[x], l[x] = t; } void dfs(int x, int y, int *d) { h[x] = 0; int mx1 = 0, mx2 = 0; for (int i = l[x]; i; i = qn[i]) {... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int maxn = 510005; int n, m; vector<int> g[maxn]; char s[maxn]; vector<int> dep[maxn]; vector<int> op[maxn]; int id[maxn][2]; int deep[maxn]; int mx[maxn]; int dfs_clock = 1; void dfs(in... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; const int MAXN = 155; int i, j, n, m, k, it1, it2, dp[MAXN][MAXN][MAXN][2][2], ans; int partSum[2][2][MAXN][MAXN]; void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int getSum(int mon1, int mon2, int ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = (1e5 + 5) * 2; void Max(int &x, int y) { if (x < y) x = y; } int n, m; int a[MAXN]; int dp[MAXN]; bool chk1(int s, int x) { memset(dp, 0, sizeof(dp)); for (int i = s, iend = s + n - 1; i <= iend; ++i) { int d = a[i + 1] - a... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char a[n][m]; int c = 0; int column_no; int row_number; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] == B && c == 0) { column_no ... |
#include <bits/stdc++.h> using namespace std; const int MAXn = 3000; vector<pair<int, bool> > adj[MAXn + 2]; int d[MAXn + 2][MAXn + 2], c[MAXn + 2][MAXn + 2], root; bool mark[MAXn + 5]; void DFS(int v) { int sum = 0, Min = INT_MAX; mark[v] = true; for (int i = 0; i < (int)adj[v].size(); i++) ... |
#include <bits/stdc++.h> using namespace std; const int N = 1010, M = 200200; int i, j, k, n, m, ch, now, q; int a[N][N], ans[M]; struct cc { int x, y; } A[M]; struct dd { int l, r, s, t, q; } Q[M]; void R(int &x) { x = 0; ch = getchar(); while (ch < 0 || 9 < ch) ch = getchar()... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == - ) flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = ... |
#include <bits/stdc++.h> using namespace std; bool Check(int X1, int Y1, int X2, int Y2, int a, int b) { bool answ = false; if (X1 <= a && X2 <= a && Y1 <= b && Y2 <= b) if (!(X1 + X2 > a) || !(Y1 + Y2 > b)) answ = true; if (Y1 <= a && X2 <= a && X1 <= b && Y2 <= b) if (!(Y1 + X2 > a) || !(X... |
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 2e5 + 10; const int mod = 998244353; int a[N], b[N], p[N], l[N]; int getMin(int l, int r) { int x = a[l]; for (int i = l; i <= r; i++) x = min(x, a[i]); retur... |
#include <bits/stdc++.h> using namespace std; int dp[100100][102]; int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(0); long long n; cin >> n; int ans = 0; while (n) { ans += (n % 10 == 7 || n % 10 == 4); n /= 10; } cout << (ans == 4 || ... |
#include <bits/stdc++.h> using namespace std; namespace fgraph { const int MAXV = 50; const int MAXE = 10 * MAXV * MAXV; const int INF = (1 << 30); struct edge { int to, cap, flow, cost; edge *nxt, *rev; } edges[MAXE + 5], *adj[MAXV + 5], *cur[MAXV + 5], *ecnt = edges; void addedge(int u, int v,... |
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; const int INF = 1e9 + 9; const int B = 1e9 + 7; long long p[N], s[N]; int fp(int first) { return first == p[first] ? first : p[first] = fp(p[first]); } void u(int a, int b, int d) { s[fp(a)] += 4 * d; if (fp(a) == fp(b)) r... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1e8; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int tcase; cin >> tcase; while (tcase--) { int n, k; cin >> n >> k; vector<int> a(n + 1), b(n + 1), id(n + 1); for (int i = 1; i <= n;... |
#include <bits/stdc++.h> using namespace std; struct edge { int v, to, cap, scap; edge(int a, int b, int c) { v = a, to = b, cap = c, scap = c; } edge() {} }; struct rect { int x1, y1, x2, y2; }; struct tri { int y1, y2, x; }; bool operator<(const tri &a, const tri &b) { return a.y1 ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5+5; const long long inf = 0x3f3f3f3f3f3f3f3f; typedef long long ll; #define pb push_back int n, m; int a[N]; int g[N], v[N<<1], nxt[N<<1], tot, fa[N]; vector<int> c[N]; ll f[N], ans; inline void add(int x, int y) { v[++t... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[200005]; int v[200005]; int c[200005], lower; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int sol = 123123123; cin >> n >> m; for (int i = 1; i <= n; i++) cin ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mo = 998244353; const long long N = 2e6 + 5; long long n, m, noden, tot; set<long long> S; long long sum, pre1, pre2, ans, cnt; struct node { long long lc, rc, rnd, val, sz; } a[N]; long long giao[N]; ... |
#include <bits/stdc++.h> using namespace std; const int N = 888888; int n, m, i, j, e; int ss[N], ff[N], dd[N], x[N], last[N], pred[N], good[N], deg[N], used[N]; int main() { scanf( %d %d , &n, &m); for (i = 1; i <= m; i++) { scanf( %d %d %d , ss + i, ff + i, dd + i); ss[i + m] = ff[i]; ... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } char s[100100], ss[4][100100]; int nxt[100100][26], N[4]; int dp... |
#include <bits/stdc++.h> using namespace std; long long binaryExponentiation(long long x, long long m) { if (x == 1) { return 0; } else { return 1 + (((binaryExponentiation((x / 2), m)))); } } long long sumd(long long a) { long long ans = 0; while (a != 0) { ans += a % 10; ... |
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, Execution time: %.3lf s. n , (double)clock() / CLOCKS_PER_SEC); ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000; int main() { int t, n; cin >> t; for (int i = 0; i < t; i++) { cin >> n; string s, t; if (n & 1) { if (n == 1) cout << a << n ; else { s = string(n / 2, a ) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; vector<int> v; string s; cin >> n >> s; s += ; k = 1; for (int i = 0; i < s.length() - 1; i++) { if (s[i + 1] == s[i]) { k++; } else { if (s[i] == B ) { v.push_back(k); ... |
#include <bits/stdc++.h> using namespace std; double pi = 3.141592653589793238462; string numkey = 0123456789 ; string uni = abcdefghijklmnopqrstuvwxyz ; bool check(char ch) { string s = aeiou ; for (long long int i = 0; i < s.size(); i++) { if (s[i] == ch) return true; } return false... |
#include <bits/stdc++.h> using namespace std; int q, s, t, n, m, i, j, k, l; int main() { cin >> t >> s >> q; int t1; while (s < t) { s = q * s; i++; } cout << i << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1000; long long n; long long sqrt2(long long n) { long long r = max((long long)sqrt(n) + 1, 0LL); while (r * r > n) { r--; } return r; } int sum(long long n) { int result = 0; while (n) { result += n % 10; ... |
#include <bits/stdc++.h> using namespace std; int t[4000050], tag[4000050]; vector<int> v[1005000]; inline void refresh(int now) { t[now] = max(t[now << 1], t[now << 1 | 1]); } void pushdown(int l, int r, int now) { if (l == r) { tag[now] = 0; return; } tag[now << 1] += tag[now]; t... |
#include <bits/stdc++.h> using namespace std; int n; vector<pair<long long, long long> > a; set<int> extr; set<int>::iterator it; vector<int> e; int f[300005]; long long mnx = 999999999999999999, mny = 999999999999999999, mxx = -999999999999999999, mxy = -999999999999999999; int main() { ... |
#include <bits/stdc++.h> using namespace std; int a[100005]; map<int, int> s; int main(void) { long long ans = 0, z = 0; int k, b, n; scanf( %d%d%d , &k, &b, &n); int zcnt = 0; s[0]++; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); zcnt = (a[i] ? 0 : zcnt + 1); z +=... |
#include <bits/stdc++.h> using namespace std; int fen[100100]; int n, ans = -1, a[100100]; int calc(int ind) { int ans = 0; for (int i = ind; i >= 1; i -= i & (-i)) ans ^= fen[i]; return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; memset(fen, 0... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using std::cin; using std::cout; const int maxn = 100100; int n, m, s; long long t; int f[2][maxn], *to = f[0], *lol = f[1]; int j... |
#include <bits/stdc++.h> using namespace std; int d(int a, int b, int a1, int b1) { return abs(a - a1) + abs(b - b1); } int main() { int n; cin >> n; int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; if (y1 == y2 && (y1 == 0 || y1 == n)) { cout << abs(x1 - x2) << endl; return 0; ... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int rand(int x, int y) { ++y; return (rng() % (y - x)) + x; } int n, m; string A; int ind(char ch) { if (ch == A ) return 0; if (ch == T ) return 1; if (ch == G ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const int MOD = 1e9 + 7; long long int dp[MAXN][MAXN]; void c() { for (int i = 0; i < MAXN; i++) { for (int j = 0; j < MAXN; j++) { if (i == j) dp[i][j] = 1; else if (j == 0) dp[i][j] = 1; ... |
#include <bits/stdc++.h> using std::sort; struct Edge { int v, w, next; } e[200002]; int ecnt, h[100002]; inline void add_edge(int u, int v, int w) { e[++ecnt] = {v, w, h[u]}; h[u] = ecnt; e[++ecnt] = {u, w, h[v]}; h[v] = ecnt; } int size[100002], dis1[100002], dis2[100002], dp[100002]... |
#include <bits/stdc++.h> using namespace std; const int N = 100100; bool isPrime[N]; vector<int> primes; vector<int> adj[N]; void init() { memset(isPrime, true, sizeof(isPrime)); for (int i = 2; i * i <= N; i++) if (isPrime[i]) { for (int j = i * i; j < N; j += i) isPrime[j] = false; ... |
#include <bits/stdc++.h> using namespace std; char a[1001][1001]; int main() { long long n, m, i, j, s = 0; cin >> n >> m; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) cin >> a[i][j]; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) { if (a[i][j] == f && a[i + 1][j] == ... |
#include <bits/stdc++.h> using namespace std; int main() { unordered_map<char, int> check; int n, count = 0; cin >> n; string temp; cin >> temp; for (int i = 0; i < temp.size() - 1; i += 2) { check[temp[i]]++; char ch = temp[i + 1]; ch = tolower(ch); if (check.find(ch... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; int ans, K, n; vector<int> s[101010]; int fa[101010], f[101010][222][3], g[222][3], sz[101010], jc[222], S[222][222]; void dfs(int x) { int c, i, y, j, k; sz[x] = 1; f[x][0][0] = 1; c = s[x].size(); for (i = 0; i <... |
#include <bits/stdc++.h> using namespace std; const int N = 212345, LG = 21, mod = 1000000007; const double eps = 1e-3, pi = acos(-1.0); char s[5], t[5], a[3]; int main() { long long n, k; scanf( %lld , &n), scanf( %lld , &k); if (n / 2 > k) { printf( %lld n , k * (2 * k - 1) + (n - 2 * k) *... |
#include <bits/stdc++.h> using namespace std; int main(void) { map<string, string> m; int q; cin >> q; int i; string s1, s2; while (q--) { cin >> s1 >> s2; if (m.count(s1) == 0) m[s2] = s1; else { m[s2] = m[s1]; m.erase(s1); } } cout <<... |
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x > y ? y : x; } const int INF = 2139062143; template <typename T> void read(T &x) { x = 0; bool f = 1; char ch; ... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long INF = 1e18; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, r1, r2, r3, d; cin >> n >> r1 >> r2 >> r3 >> d; vector<long long> a(n... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, c, l = 0, t, ans = 0; cin >> n >> c; for (int i = 0; i < n; i++) { cin >> t; if (l) { long long x = min(t, c - l); ... |
#include <bits/stdc++.h> using namespace std; char ch[1000100]; int l; void dfs(int k) { if (k >= l) return; if (ch[k] == l ) { dfs(k + 1); printf( %d n , k + 1); } else { printf( %d n , k + 1); dfs(k + 1); } } int main() { scanf( %s , ch); l = strlen(ch); ... |
#include <bits/stdc++.h> using namespace std; const int OO = (int)1e9; int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; long long n, x, y; bool ok; map<long long, long long> cnt; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; for (int ... |
#include <bits/stdc++.h> using namespace std; const int N = 12 + 1, M = 1 << N | 5; bool dp1[M][N + N], dp2[M][N + N]; int n, k, mx[M], c[N + N]; int main() { cin >> n; dp1[0][1] = true; for (int i = 0; i < n; i++) { cin >> c[i]; if (c[i] < 2) n--, k++, i--; } if (n > k) return... |
#include <bits/stdc++.h> int a[3005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); int cnt = 0; for (int i = 1; i < n; ++i) for (int j = 0; j < i; ++j) if (a[i] < a[j]) ++cnt; if (cnt & 1) printf( %d , cnt * 2 - 1); else p... |
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; int n; int dp[1000010]; int main() { while (~scanf( %d , &n)) { int a = 0; for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); if (x == 1) a++; } dp[0] = dp[1] = 1; for (int i =... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int MAXN = 3e5 + 5; const double PI = acos(-1); long long a[MAXN][2]; long long dp[MAXN][2][2]; int main(void) { int n, x; scanf( %d%d , &n, &x); for (int i = 1; i <= n; i++) { scan... |
#include <bits/stdc++.h> using namespace std; struct P { int x, y, z; bool operator<(const P &a) const { return y > a.y; }; }; int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[10] = {0, 1, 0, -1, 1, -1, 1, -1}; long long o[500101]; int l[500111... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { ll a, b, n; cin >> a >> b >> n; ll cnt = 0; if (a > b) swap(a, b); while (max(a, b) <= n) { a +... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; inline int read() { int 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 << 3) + (x << 1) + ch - 0 ; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> ... |
#include <bits/stdc++.h> using namespace std; const long double INF = 1e18 + 7; long long N = 1e6 * 5; long double EPS = 1 / 1e18; long long a[1005]; map<long long, long long> cnt; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; for (lo... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int cas = 0; cas < t; cas++) { int n; cin >> n; vector<int> numbers(n); int sum = 0; int zer = 0; int ans; for (int i = 0; i < n; i++) { cin >> numbers[i]; sum = sum... |
#include <bits/stdc++.h> using namespace std; char c[55][55]; int n, i, j, m1, m2, m3, m4; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %s , c[i] + 1); m1 = m3 = n + 1; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) if (c[i][j] == 4 ) { m1 = min(m1, i... |
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; int main() { int T; cin >> T; while (T--) { char c; int x1 = -1, y1 = -1, x2 = -1, y2 = -1; for (... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; char s[maxn]; int fa[maxn], siz[maxn]; int l[maxn][2]; int n, k; int findset(int x) { if (fa[x] == x) return x; return fa[x] = findset(fa[x]); } void Union(int x, int y) { int rx = findset(x), ry = findset(y); if (... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using PP = pair<ll, P>; using VB = vector<bool>; using VI = vector<ll>; using VS = vector<string>; using VC = vector<char>; using VP = vector<P>; using VPP = vector<PP>; using VD = vector<double>; using V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.