func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int getint() { int s = 0, o = 1; char c; for (c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) o = -1; for (; c >= 0 && c <= 9 ; c = getchar()) s *= 10, s += c - 0 ; return s * o; } const int maxn = 30005; int gem[maxn]... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T f = 0, x = 0; char c = getchar(); while (!isdigit(c)) f = c == - , c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); return f ? -x : x; } namespace run { inline char getc() { ... |
#include <bits/stdc++.h> using namespace std; int ans1 = 0, ans2 = 0, ans3 = 0, a[100]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i % 3 == 1) ans1 += a[i]; if (i % 3 == 2) ans2 += a[i]; if (i % 3 == 0) ans3 += a[i]; } if (ans1 >= ans2... |
#include <bits/stdc++.h> using namespace std; inline const int getint() { int r = 0, k = 1; char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) k = -1; for (; c >= 0 && c <= 9 ; c = getchar()) r = r * 10 + c - 0 ; return k * r; } const int N = 1e5 + 10; ch... |
#include<bits/stdc++.h> #define inf 0x3f3f3f using namespace std; typedef long long ll; const int maxn = 3e5+5; const int mod = 1e9+7; int a[maxn],b[maxn]; int main() { int T; cin>>T; while(T--){ int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int j=1;j<=n;j++) cin>>b[j]; ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, n, m, z, ck = 0; cin >> n >> m >> z; for (i = 1; i <= z; i++) { if (n * i > z) break; else if ((n * i) % m == 0) { ck++; } } cout << ck << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 1700; int n, m, tim, res[N * N], num[N * N], a[N][N], s[N][N], id[N][N]; bool ray[N][N]; bool check(int x, int y) { return s[x + 3][y + 3] - s[x - 4][y + 3] - s[x + 3][y - 4] + s[x - 4][y - 4] <= 15; } void dfs1(int ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void join(vector<T>& arr, string sep) { bool first = true; for (auto t : arr) { if (first) { first = false; cout << t; } else { cout << sep << t; } } cout << n ; } struct Euler { ... |
#include <bits/stdc++.h> using namespace std; int n, k, a[111000], s, ans[111000]; int main() { cin >> n >> k; for (register int i = 1; i <= n; i++) { cin >> a[i]; s += a[i]; } if (s % k != 0) { cout << No ; return 0; } int t = s / k; int cnt = 0; for (regi... |
#include <bits/stdc++.h> using namespace std; int w[100001]; int main() { map<string, int> mp; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> w[i]; } sort(w, w + n); string s; for (int i = 0; i < m; i++) { cin >> s; mp[s]++; } int a[101], k ... |
#include <bits/stdc++.h> using namespace std; const int Max = 2e6 + 10; const int Mod = 1e9 + 7; const int MAX = 2e18; int main() { long long int x, j = 0, mx = 0, mx2 = 0, cnt = 0; bool f = 0, f2 = 0, f3 = 0; string s; cin >> x >> s; long long int ar[x + 5]; memset(ar, 0, sizeof(ar));... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; if (n <= 30) cout << NO n ; else { cout << YES n ; long long d = n - 30; long long a = 6, b = 10, c = 14; if (d == 6 || d == 10 || d == 14) cout << 6 10 15 << d - 1 << endl;... |
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1000000007; const ll M = 1000000000000000000ll; inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); } inline ll mult(ll a, ll b) { retu... |
#include <bits/stdc++.h> using namespace std; int main() { int x1, x2, x3, n1, n2, n3; scanf( %d %d %d , &x1, &x2, &x3); n3 = (x1 - x2 + x3) / 2; n2 = x3 - n3; n1 = x1 - n3; if (n1 < 0 || n2 < 0 || n3 < 0 || 2 * (n1 + n2 + n3) != x1 + x2 + x3) printf( Impossible n ); else pri... |
#include <bits/stdc++.h> using namespace std; struct pp { long long int len, v; }; bool cmp(pp& a, pp& b) { if (a.v == b.v) return a.len > b.len; return a.v > b.v; } int main() { long long int n, k; cin >> n; cout << (n - 1) * n * (2 * n - 1) / 6 - 1 - 1 + n * (n - 1) / 2 << endl; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<db, db>; using vi = vector<int>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<string>; using vii = vector<pii>; using v... |
#include<bits/stdc++.h> using namespace std; #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define PB(x, v) x.push_back(v); #define M_P(a, b) make_pair(a, b) #define pll pair<ll, ll> #define ll long long int #define mll map<ll, ll> #define vl vector<ll> #define fa(x, v) fo... |
#include <bits/stdc++.h> using namespace std; void read(long long a = 0) { freopen( in , r , stdin); if (a) freopen( out , w , stdout); } int main() { long long n, m, k; cin >> n >> m >> k; long long done = 0; while (k--) { long long x, y; cin >> x >> y; long long mi ... |
#include <bits/stdc++.h> const int inf = 1 << 30; const long long INF = 1ll << 61; using namespace std; int n, m; int c[1000000 + 55]; int nnum[1000000 + 55]; int aa[1000000 + 55]; int sum[1000000 + 55]; int len; void init() { memset(c, 0, sizeof(c)); memset(aa, -1, sizeof(aa)); } bool i... |
#include <bits/stdc++.h> using namespace std; long long int e, d, c, x, aux, aux2; priority_queue<pair<long long int, long long int> > q; void res(long long int n) { long long int k = n; e = 0; d = 1; while (k > 0) { d = d * 10 + 1; e++; k = k / 10; } c = (d - 1) / 10; ... |
#include <bits/stdc++.h> using namespace std; int n; int a[111111], b[111111], ra[111111]; set<pair<int, int> > s; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0, _n = (int)(n); i < _n; i++) cin >> a[i], a[i]--, ra[a[i]] = i; for (int i = 0, _n = (int)(n); i < _n; i++) cin ... |
#include <bits/stdc++.h> int x[100010]; int main() { int a, b, c, i; scanf( %d%d%d , &a, &b, &c); for (i = 1; i <= a; i++) scanf( %d , &x[i]); int s = 0, t = 1; long long int count = 0; while (1) { if (t > a && s == 0) { printf( %I64d , count); return 0; } w... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, t; cin >> n >> t; string s; cin >> s; for (long long int i = 0; i < t; i++) { for (long long int j = 0; j < n - 1; j++) { if (s[j] == B && s[j + 1] == G ) { s[j] = G ; s[j + 1] = B ... |
#include <bits/stdc++.h> const int inf = 0xfffffff; const long long INF = 1ll << 61; using namespace std; int n, s, k; int aa[100 + 55][100 + 55]; int ans; void init() { memset(aa, 0, sizeof(aa)); } bool input() { while (scanf( %d %d %d , &n, &s, &k) == 3) { for (int i = 0; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; int main() { int number; cin >> number; long long ans = number; while (1) { int x = 100000000; for (int i = 2; i <= sqrt(number); i++) { if (number % i == 0) { x = min(x, i); } } if (x == 100000000) break... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum; cin >> n; long long int arr[n]; sum = 0; for (long long int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } sort(arr, arr + n); long long int curr = 0; long long int cnt = 0; lon... |
#include <bits/stdc++.h> using namespace std; int T, n, x; int main() { scanf( %d , &T); while (T--) { scanf( %d%d , &n, &x); printf( %d n , 2 * x); } return 0; } |
#include <bits/stdc++.h> using namespace std; int n, s[1000005], t[1000005]; int bef[1000005][2]; long long ss, st, cs, ct; bool sw; int main() { memset(bef, -1, sizeof(bef)); bef[0][0] = bef[0][1] = 0; scanf( %d , &n); for (int i = (1); i <= (n); i++) scanf( %d , &s[i]), ss += s[i]; for... |
#include <bits/stdc++.h> using namespace std; const int M = 998244353; int main() { long long n; cin >> n; map<long long, long long> mp; long long a[200005]; for (long long i = 0; i < n; i++) { cin >> a[i]; mp[a[i]] = i; } long long ans = 1, w = mp[a[0]]; for (int i = 0... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int ans = 0; while (n % 3 == 0 || n % 6 == 0) { if (n % 6 == 0) { n /= 6; ans++; } else if (n % 3 == 0) { n /= 3; ans += 2; } } if (n != 1) { cout << -1 << en... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 9, inf = 1e18, mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int a, b, c, d, k; cin >> a >> b >> c >> d >> k; int x = (a + c -... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string str; int j = 0; cin >> str; int len = str.length(); for (int i = 0; i < len - 1; i = i + 2) { cout << str[i]; } cout << str[len - 1]; cout << endl; ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long mod = 1000000007; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long p, ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, n, moves = 0, flag = 1, gears; cin >> n; cin >> gears; moves = n - gears; for (i = 1; i < n; i++) { cin >> gears; if (i % 2 == 1) gears = (gears + (n - moves)) % n; else gears = (gears + moves) % ... |
#include <bits/stdc++.h> using namespace std; int dp[3000]; bool apare[1010]; int n, k, c; int main() { ios_base ::sync_with_stdio(0); cin >> n >> k; while (k--) { cin >> c; apare[c] = 1; } queue<int> q; vector<int> lungimi; for (int i(0); i < 1010; i++) { if (!ap... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; using namespace std; const int maxn = 404; int n, m, k; int s[103], t[103]; int c[103][103], d[103][103], e[103][103], f[103][103]; struct Edge { int u, v, c, w, next; Edge(int u, int v, int c, int w, int next) : u(u), v(... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; vector<int> way(s.size()); way[0] = 0; for (int i = 1; i < (int)s.size(); i++) { if (s[i] == 0 ) way[i] = i; else way[i] = way[i - 1]; } int l = 0,... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s = ; for (int i = 0; i < k; i++) s += char(i + 97); for (int i = 0; i < n - k; i++) { s += char(i % k + 97); } cout << s << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int i = 0; vector<int> ans; ans.push_back(v[0]); ans.push_back(v[n - 1]); while (i < n - 3) { int k = v[i + 1]; int l = v[i + 2]; ... |
#include <bits/stdc++.h> using namespace std; long long n, m; struct pt { long long x, y; pt() {} pt(long long x, long long y) : x(x), y(y) {} }; vector<vector<long long>> used; vector<vector<long long>> g; void parasha(pt q, pt p, long long weight, deque<pt>& bfs, vector<vector... |
#include <bits/stdc++.h> using namespace std; using lint = long long; using pi = pair<lint, lint>; const int MAXN = 100005; int n, m, sum; int cnt[MAXN]; set<int> s[MAXN]; int p[MAXN]; vector<tuple<int, int, int>> dap; void MOVE(int dst, int src, int v) { vector<int> mutation; for (auto &i :... |
#include <bits/stdc++.h> using namespace std; long long n, p, su; long long a[100005], b[100005]; long double ex[100005]; bool check(long double mid) { long double need = 0; for (int i = 0; i < n; i++) { long double ne = max(0.0L, a[i] * (mid - ex[i])); need += ne; } return (mid * ... |
#include <bits/stdc++.h> using namespace std; int W, H, N, num; char ch; multiset<int> maxHorSize, maxVertSize; set<int> horiz, vert; long long max_area; long long find_max(set<int> &setCut, char cut) { auto med = setCut.find(num); auto big = med; auto sml = med; ++big; --sml; if (... |
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > S; set<pair<long long, long long> >::iterator it; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t, n; for (cin >> t; t--;) { cin >> n; S.clear(); long long a = 1, b = 0, ans ... |
#include <bits/stdc++.h> using namespace std; int main() { int A[26] = {0}, count = 0; string s; getline(cin, s); for (int i = 1; i < s.size(); i += 3) { A[int(s[i]) - 97] = 1; } for (int i = 0; i < 26; i++) { if (A[i] == 1) { count++; } } cout << count; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops,fast-math ) using namespace std; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } const in... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mx = 1e5 + 5; long long middle(long long a, long long b, long long c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b; else if ((b <= a && a <= c) || (c <= a && a <= b)) return a; else ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000009; const int N = 100005; const double PI = 4 * atan(1); const long long MAX = 9223372036854775807; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b ==... |
#pragma GCC optimize( Ofast ) #include bits/stdc++.h typedef long long ll; using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > stru... |
#include <bits/stdc++.h> using namespace std; int main() { string table; string hand; getline(cin, table, n ); transform(table.begin(), table.end(), table.begin(), ::tolower); getline(cin, hand, n ); transform(hand.begin(), hand.end(), hand.begin(), ::tolower); if (hand.find(table[0]... |
#include <bits/stdc++.h> using namespace std; const int N = 820; typedef struct node { int l, r, x; } node; node a[N * N]; bool cmp(node x, node y) { return x.x > y.x; } int n, m, k, t, tot = 0; int v[N], p[N], ans[N]; int main() { cin >> n; n = n * 2; for (int i = 1; i <= n; i++) ... |
#include <bits/stdc++.h> const long long N = 1e6 + 10; const long long mod = 1e9 + 7; long long dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; using namespace std; struct node { long long x, y, id; node() {} node(long long x, long long y, long long i) : x(x), y(y), id(i) {} }; long long ans[N]; sta... |
#include <bits/stdc++.h> using namespace std; const long long NR = 5e5 + 100; const long long oo = 2e9 + 100; const long long MOD = 998244353; long long n; string s; long long a[NR]; long long dp[5]; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long i; cin >> n; cin >>... |
#include <bits/stdc++.h> using namespace std; long long A[100010]; long long B[100010]; priority_queue<long long> pq; set<int> S; int P[100010]; long long ans[100010]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &A[i]); B[0] = 0LL; for (int i = 1;... |
#include <bits/stdc++.h> using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template <class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + ep... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; vector<long long> pref(n + 1); for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + a[i]; long long ans = lower_bound(pref.begin... |
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string s; std::cin >> s; std::string_view view = s; size_t n = 0; while (!view.empty()) { const size_t id = view.find( > ) + 1; const auto tag = view.substr(0, id); view.re... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; if (n > m) { swap(n, m); } if (n > 3) { cout << ((n * m / 2) * 2); } else { if (n == 3) { cout << m * n / 2 * 2; return 0; } else { if (n == 2) { ... |
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %1d , &a[i]); b[i] = b[i - 1] + a[i]; } for (int i = 1; i + k - 1 <= n; i++) { int sum = b[i - 1] + b[n] - b[i + k - 1];... |
#include <bits/stdc++.h> using namespace std; int n, m, j, s; int k[100000], a[100000], b[100000]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> k[i]; for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y; if (x == 1) { cin >> z; k[y - 1] = z; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char s[N]; int a[N], sta[N], tp; int main() { scanf( %s , s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; ++i) if (s[i] == 0 ) { if (tp) a[sta[tp--]] = 1; } else sta[++tp] = i; for (int i ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, n1, n2; cin >> n >> n1 >> n2; int A[n], i; for (i = 0; i < n; ++i) cin >> A[i]; sort(A, A + n, std::greater<int>()); int a, b; if (n1 < n2) { a = n1; b = n2; } else { a = n2; b = n1; } d... |
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; long long step[101]; step[0] = 1; for (int i = 1; i < 101; i++) step[i] = (step[i - 1] * 2) % ((int)1e9 + 7); long long ans = 0; for (int i = 0; i < x.size(); i++) if (x[i] == 1 ) ans = (ans + step[x.si... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:1024000000,1024000000 ) const int INF = 0x3f3f3f; const long long mod = 1e9 + 7; const int MAXN = 1055; const double eps = 1e-6; const double pi = acos(-1.0); using namespace std; int main() { long long n, t; cin >> ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math ) #pragma GCC optimize( O3 ) using namespace std; using namespace std::chrono; long long mod_exp(long long x, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = (res * x) % 1000000007; x = (x... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; map<int, int> uchs; for (int i = 0; i < n; i++) { int x; cin >> x; if (uchs.find(x) != uchs.end()) { (uchs.at(x))++; } else uchs.insert(pair<int, int>(x, 1)); } cin >> m; ... |
#include <bits/stdc++.h> using namespace std; int T, n, head[300005], cnt, in[300005], ans, rt; struct edge { int to, nxt; } e[300005 << 1]; void add(int u, int v) { e[++cnt] = (edge){v, head[u]}; head[u] = cnt; } void dfs(int u, int fa, int tot) { if (tot > ans) ans = tot, rt = u; for... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long sum = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { sum = (sum << 1) + (sum << 3) + (c ^ 48); c = getchar(); } return sum; } long long const maxn = 1e5 + 5; lo... |
#include <bits/stdc++.h> using namespace std; const int MX = 1e5 + 10; int n, a[MX], out[MX], mn[MX]; int bs(int L, int R, int val) { if (R - L == 1) return L; int mid = (R + L) / 2; if (val <= mn[mid]) return bs(L, mid, val); else return bs(mid, R, val); } int main() { cin >... |
#include <bits/stdc++.h> int main() { int i, j, l, n, k, good; static int a[6][1001], dp0[1001], dp1[1001], pp[6][1001]; scanf( %d%d , &n, &k); for (i = 1; i <= k; i++) for (j = 1; j <= n; j++) { scanf( %d , &a[i][j]); if (i == 1) pp[1][a[i][j]] = j; else { ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; vector<pair<long long, long long> > v(m); ... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 3; const long long INFF = (long long)1e18; int cnt[N]; bool ck[N]; int main() { for (int i = 2; i < N; i++) { if (ck[i]) continue; for (int j = i; j < N; j += i) ck[j] = true; cnt[i]++; if (i <= 1000) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string b; cin >> b; if (b.length() < 4) { cout << b << n ; continue; } cout << b[0]; for (int i = 1; i < b.length(); i += 2) { cout << b[i]; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { string s; int n, s2 = 0, ans = 0, s1 = 0; cin >> s; n = s.size() - 1; for (int i = n; i >= 0; i--) if (s[i] == 1 ) { s2 = i; break; } for (in... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long infinity = 1000000000000000000; const int inf = 1e9 + 5; bool do_debug = false; const int maxn = 3e5 + 5, maxjump = 19; int n_nodes, n_edges, nq; vector<int> adj[maxn]; int depth[maxn] = {0}; long long in... |
#include <bits/stdc++.h> using namespace std; queue<int> que; vector<bool> init, goal; vector<bool> visited; vector<vector<int>> nodes; void calculate(int root, bool flip1, bool flip2) { const vector<int> &children = nodes[root]; visited[root] = true; if (init[root] ^ flip1 != goal[root]) { ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } int n, m; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> m; vector<vector<int> > board(n, vector<int>(m)); for (auto... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n; cin >> n >> k; if (n == 2) return cout << 2 << << 1 << << 2 << endl, 0; int ans1, ans2; int l = 1, r = n; while (l < r) { int mid = (l + r) / 2; cout << 1 << ... |
#include <bits/stdc++.h> using namespace std; int const sz = 2 * 1e5; int const oo = 1e9; bool comp(int i, int j) { return i < j; } long long num[1000000], kk[101]; void fill(int n, int m) { long long arr[4] = {0, 1, 2, 3}; int l = 0; num[0] = 1; num[1] = 2; num[2] = 3; for (int i = ... |
#include <bits/stdc++.h> using namespace std; int f[100005], s[100005]; int main() { int n, k, inp; scanf( %d %d , &n, &k); for (int i = 1; i < k + 1; i++) { scanf( %d , &inp); s[inp] = i; if (!f[inp]) f[inp] = i; } int ans = 0; for (int i = 1; i < n + 1; i++) { if ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n, m, k; cin >> n >> m >> k; long long cnt = n / k; if (m <= cnt) cout << m << n ; else ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; const int N = 1001002; int a, b, c, d, i, j, n, m, k, tot, now, last; int nx[N][26], sib[N], pr[N], fir[N]; int cnt[N], en[N]; char str[502]; int num[2][N]; int dp[2][2002][2002]; vector<int> lev[503]; int dfs... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string n; int k; cin >> n >> k; int ans = 0; int p = 0; for (auto it = n.rbegin(); p < k && it != n.rend();) { if (*it != 0 ) { ++ans; n.erase((++it).... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) using namespace std; using ll = int64_t; const size_t kBuben = 10; const int kNone = -1; struct Pair { int value, count; }; struct ByValue { inline bool operator()(const Pair& a, c... |
#include <bits/stdc++.h> using namespace std; namespace flyinthesky { const int MAXN = 500000 + 5; struct edge { int u, v, w; bool operator<(const edge &b) const { return w < b.w; } } ed[MAXN], ed2[MAXN]; struct whw { int id, fr, t; }; struct ask { int id; bool operator<(const ask &b... |
#include <bits/stdc++.h> using namespace std; bool cmp(long long int a, long long int b) { return b < a; } int main() { long long int n; cin >> n; long long int a[n + 1]; for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); } sort(a + 1, a + n + 1, cmp); long long int ans = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, b, d; int a[100000 + 10]; cin >> n >> b >> d; for (int i = 0; i < n; i++) cin >> a[i]; int p = 0, emp = 0; int temp = 0; for (int i = 0; i < n; i++) { if (a[i] > b) continue; temp += a[i]; if (temp > d) {... |
#include <bits/stdc++.h> const int N = 100000 + 10; int n; std::vector<int> adj[N]; bool flag[N]; void dfs(int a, int fa = -1) { if (adj[a].size() > 2) return; flag[a] = true; for (int i = 0; i < adj[a].size(); ++i) { int b = adj[a][i]; if (b != fa) dfs(b, a); } } int main() { ... |
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const long long M = 1e9; map<long long, set<long long>> ms; long long a[200100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, m, x, t = 0, s = 0, p, r; ... |
#include <bits/stdc++.h> using namespace std; const int N = 300009; vector<long long> visited[N]; map<pair<int, int>, int> mp; set<int> s; int n, m; void dfs(int j) { set<int> q; for (auto i : s) { if (mp[{j, i}] != 1) { q.insert(i); } } for (auto p : q) { s.erase... |
#include <bits/stdc++.h> using namespace std; int n, a[300300], q, p, x, y, l[300300], b[300300]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> q; for (int i = 1; i <= q; i++) { cin >> p; if (p == 1) { cin >> x >> y; a[x] = y; l[x] = i;... |
#include <bits/stdc++.h> using namespace std; int N; char buf[20]; set<int> B, S, Q; const int INF = 1e9; inline int get_b() { return ((int)(B).size()) ? *B.rbegin() : -INF; } inline int get_s() { return ((int)(S).size()) ? *S.begin() : INF; } int main() { scanf( %d , &N); long long ans = 1; ... |
#include <bits/stdc++.h> using std::pair; using std::string; using std::vector; template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; string procStatus() { s... |
//#define _USE_MATH_DEFINES #include<bits/stdc++.h> //#pragma GCC optimize ( O3 ) //#pragma GCC target ( sse4 ) using namespace std; #define ll long long #define endl n #define f first #define s second #define ar array #define pb push_back #define eb emplace_back #define mp make_pair #de... |
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m, len[maxn << 2]; bool first[maxn << 2]; long long mm[maxn], rr[maxn], ss[maxn], last[maxn << 2]; vector<long long> summ[maxn << 2], sumr[maxn << 2]; vector<int> tree[maxn << 2]; bool cmp(int a, int b) { return mm[a] * rr[b] ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6; const long long INF = 1e18; const long long mod = 1e9 + 7; long long y; long long n, m; vector<long long> v; void rec(long long x) { if (x > m) { return; } if (x == m) { cout << YES << endl; y = 1; ... |
#include <bits/stdc++.h> using namespace std; vector<int> a; vector<pair<pair<int, int>, int> > b; vector<int> k; vector<int> ans; signed main() { ios_base::sync_with_stdio(0); int n, m; cin >> n; a.resize(n); b.resize(n); ans.resize(n); for (int i = 0; i < n; i++) { cin >>... |
#include <bits/stdc++.h> using namespace std; int n, a[100010], cnt[100010]; int main() { int max1 = 0, max2 = 0; cin >> n; ; for (int i = 1; i <= n; i++) { cin >> a[i]; ; } for (int i = 1; i <= n; i++) { if (a[i] > max1) { max2 = max1; max1 = a[i]; ... |
#include <bits/stdc++.h> using namespace std; class Solution { public: Solution(int _n) : N(_n) {} void guess(long long n, int k) { long long l = 1; long long r = n; int M = min(4LL * k, n); mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); string ans; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.