func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> const int inf = 1e7 + 7; long long mod = 1e9 + 7; const double eps = 1e-9; using namespace std; int num[1000005]; char s[1000005]; int main() { cin >> s; int len = strlen(s); num[len] = 0; for (int i = len - 1; i >= 0; i--) { if (s[i] == 0 ) num[i] =... |
#include <bits/stdc++.h> using namespace std; int n, a, b, x, r; int main() { for (cin >> n >> a >> b, r = n; x * a <= n; x++) r = min(r, (n - x * a) % (5 * b)); cout << r; } |
#include <bits/stdc++.h> using namespace std; typedef long double ld; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; long long mod = 1e9 + 7; const long long inf = 1e18; const long long maxn = 3e5 + 5; void solve() { long long n, k; cin >> n >> k; ... |
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const int N = 1005; int a[N][N]; int dp[N][N][2]; int d[] = {2, 5}; void print(int x, int y, int z) { if (x == 0 && y == 0) return; if (x == 0 || y && dp[x - 1][y][z] > dp[x][y - 1][z]) { print(x, y - 1, z); cout <... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { if (i == a[a[a[i]]]) { return cout << YES , 0; } } cout << NO ; } |
#include <bits/stdc++.h> using namespace std; int T, N, P, ap[109][109]; int main() { scanf( %d , &T); while (T--) { scanf( %d %d , &N, &P), P += 2 * N; for (int df = 1; df < N && P; df++) for (int i = 0; i < N && P; i++) ap[i][(i + df) % N] = 1, P--; for (int i = 0; i < N; i++) ... |
#include <bits/stdc++.h> using namespace std; int n; int main() { int s = 0, i; cin >> n; while (n != 0) { s = 0; for (i = 0;; ++i) { s += (1 << i); if (s >= n) break; } if (s == n) { cout << i + 1 << ; n -= (1 << i); } else { co... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a1, a2; cin >> a1 >> a2; int res = 0; while (a1 && a2 && (a1 > 1 || a2 > 1)) { if (a1 > a2) swap(a1, a2); ++a1; a2 -= 2; ++res; } cout << res << n... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long fact[1100000]; void find_fact() { fact[0] = fact[1] = 1; for (int i = 2; i <= 1e6; i++) fact[i] = (i * fact[i - 1]) % mod; } bool isvalid(long long num, int num1, int num2) { while (num > 0) { int cval = (num ... |
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } const int ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b; int ans = 0; cin >> a >> b; ans += a; while (a >= b) { ans += (a / b); a = (a / b) + (a % b); } cout << ans; } |
#include <bits/stdc++.h> using namespace std; long long mx, my, w; map<double, int> a, b; int rev(long long x) { long long ret = 0; while (x) { ret *= 10; ret += x % 10; x /= 10; } return ret; } long long get(long long x, long long y) { a.clear(); for (long long i =... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int a, b, c; cin >> a >> b >> c; string s; cin >> s; vector<int> brr[26]; int p1 = R - A ; int p2 = P - A ; int p3 = S - A ; for (int i = 0; i < s.size(); ++i) { brr[s[i] - A ].e... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[30]; bool mark[N]; bool dp[30][1000]; int n; void update() { dp[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j < 1000; j++) { dp[i][j] = dp[i - 1][j]; if (j >= a[i] && !mark[i]) dp[i][j] |= ... |
#include <bits/stdc++.h> using namespace std; long long a[2][2010]; long long b[2010]; int dp[2010][2010][2]; int way[2010][2010][2]; int sz[2]; int r(int p1, int p2, int w) { if ((p1 == sz[0]) && (p2 == sz[1])) return 0; if (dp[p1][p2][w] != -1) return dp[p1][p2][w]; if ((p1 == 0) && (p2 == 0... |
#include <bits/stdc++.h> const int MAXN = 100 * 1000; int a[MAXN + 10]; int dp[MAXN + 10]; int mx = 0; using namespace std; int main() { long long n, m, k, s = 0; cin >> k >> n >> m; long long shif = (k - (n % k)) % k; n = n + shif; if (m < n) cout << 0 << endl; else cout... |
#include <bits/stdc++.h> using namespace std; int a[(1 << 17) + 1]; int tree[4 * (1 << 17)]; void build(int nd, int s, int e, bool ex) { if (s == e) { tree[nd] = a[s]; return; } int mid = (s + e) / 2; int left = 2 * nd; int right = 2 * nd + 1; build(left, s, mid, !ex); bu... |
#include <bits/stdc++.h> using namespace std; int n; string s; queue<int> q[2]; int main() { ios_base::sync_with_stdio(); cin.tie(); cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == D ) { q[0].push(i); } if (s[i] == R ) { q[1].push(i); } } ... |
#include <bits/stdc++.h> using namespace std; int n, m, q; pair<int, int> t[300100]; pair<int, int> up[300100]; pair<int, int> down[300100]; pair<int, int> inter(pair<int, int> a, pair<int, int> b) { int f = max(a.first, b.first); int s = min(a.second, b.second); pair<int, int> res = {f, s}; ... |
#include <bits/stdc++.h> using namespace std; int min(int x, int y) { return x < y ? x : y; } int max(int x, int y) { return x > y ? x : y; } void swap(int &x, int &y) { int t; t = x, x = y, y = t; } char s[200000]; int main() { int x, y, i, j, n, k, t; while (~scanf( %d%d , &n, &k)) { ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = INT_MAX - 1; bool check(ll r, ll g, ll b, ll w, ll total) { if (r < 0 || g < 0 || b < 0 || w < 0) { return false; } ll numberIsOne = 0; if (r & 1) { numberIsOne++; } if (g & 1) { numberIs... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const long long INFF = 1e18; const int INF = 1e9; const int mod = 1e9 + 7; const int MAX = 2e7 + 7; vector<long long> st1, st2; int main(void) { long long a, b; scanf( %lld %lld , &a, &b); ; long long c = a + b; f... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string second; cin >> second; int mi = 0, gr = 0, le = 0, ans = 0; for (int i = 0; i < second.length(); i++) { if (second[i] == - ) mi++; ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 7; const int MOD = 1e9 + 7; int a[MAX], h[MAX], c[MAX] = {0}; int main() { int n, m, i, j, k, q; scanf( %d %d %d , &n, &k, &m); for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = 0; i < n; i++) { h[i] = a[i] % m; ... |
#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; const long int maxi = 1000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, h1, i, j; cin >> n >... |
#include <bits/stdc++.h> using namespace std; inline int solve(int w, int h, int S) { if (S == (2 * w + 1) * (2 * h + 1)) return 2 * (w + 1) * (h + 1) - 1; if (S > (2 * w + 1) * (2 * h + 1)) return 0; S = (2 * w + 1) * (2 * h + 1) - S; if (S & 3) return 0; S /= 4; int res = 0; for (int w... |
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int main() { int T[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; string s, t, Ans = , M; int d = 0, m = 0, y = 0, x = 0; cin >> s; for (int i = 0; i <= s.length() - 10; i++) { t = s.substr(i + 6, 4); ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int max1 = 0, max2 = 0, min1 = (1000000000 + 9), min2 = (1000000000 + 9); for (int i = 0; i < n; i++) { long long int x, y; cin >> x >> y; if (y < min1) { min1 ... |
#include <bits/stdc++.h> using namespace std; bool debug = true; const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1, 0}; template <typename X> inline X square(const X& a) { return a * a; } int scan_d() { bool minus = false; int result = 0; char c... |
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, /STACK:20000007 ) #pragma GCC optimize( unroll-loops ) const int N = (int)1e6 + 100; const int maxn = (int)1e3 + 100; const int base = (int)1e9; const int mod = (int)1e9 + 7; const int inf = INT_MAX;... |
#include <bits/stdc++.h> using namespace std; long long int det(long long int a, long long int b, int bit) { if (!bit) { if (a & 1) return a; if (b & 1) return b; return a; } if (a & (1ll << bit)) return det(a, b, bit - 1); if (!(b & (1ll << bit))) return det(a, b, bit - 1); if... |
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, m, b[N][N], a[N][N]; void solve() { if (n % 2) { printf( %d n , n); return; } bool ok = 1; while (n > 1 && ok && n % 2 == 0) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ... |
#include <bits/stdc++.h> using namespace std; int day[4][48] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30,... |
#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); int n, t; int a[100100], cur = 0, all; int binpow(int a, int k) { if (k == 0) return 1; int ans = binpow(a, k / 2); ans = 1ll * ans * ans % ... |
#include <bits/stdc++.h> using namespace std; long long ceilVal(long long a, long long b) { long long sum = a / b; if (a % b) return ++sum; return sum; } int main() { long long a, n, m; scanf( %lld%lld%lld , &n, &m, &a); long long sum = 0; sum = ceilVal(n, a) * ceilVal(m, a); pri... |
#include <bits/stdc++.h> using namespace std; void p(vector<int> a) { int x = 0; for (int y : a) { if (x) printf( ); printf( %d , y); x = 1; } puts( ); } int main() { int n; cin >> n; if (n % 2 == 0) return !printf( -1 n ); vector<int> a, b, c; for (int i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, sum = 0; cin >> n >> x >> y; sum = (n * y) / 100; if ((n * y) % 100 != 0) { sum += 1; } if (sum <= x) cout << 0; else cout << abs(sum - x); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; if (n & 1) cout << n / 2 << n ; else { long long int p = 1; for (long long int i = 1; 2 * p <= n; i++) p = 1 << i; ... |
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { while (b > 0) { a %= b; swap(a, b); } return a; } template <class _T> inline _T sqr(const _T& first) { return first * first; } template <class _T> inline string tostr(const _T& a) { os... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c =... |
#include <bits/stdc++.h> using namespace std; const int N = 2007; const int mod = 998244353; template <class I> inline void read(I &x) { int f = 1; char c; for (c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; for (x = 0; c >= 0 && c <= 9 ; x = (x << 3)... |
#include <bits/stdc++.h> long long expow(long long a, long long b, long long p) { long long v = 1; for (; b; b >>= 1, a = a * a % p) if (b & 1) v = v * a % p; return v; } long long inv(long long a, long long p) { return expow(a, p - 2, p); } using namespace std; const int N = 1000 + 11; co... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int Inf = 0x3f3f3f3f; struct Edge { int id; int u, v, w; Edge(int x = 0, int y = 0, int z = 0) : v(x), w(y), id(z) {} } e[N]; vector<Edge> edges; vector<int> G[N]; int ans[N], fa[N][20], dep[N], st[N][20], used[N], f... |
#include <bits/stdc++.h> const int N = 1e5 + 10, M = 26; template <typename T = int> inline T read() { T x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= ch == - , ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f ? -x : x; } char s[N]; int ... |
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long n) { long long ans = 1; for (int i = 1; i <= n; i++) ans *= x; return ans; } long long gcd(long long x, long long y) { return (x % y == 0) ? y : gcd(y, x % y); } long long n, l, r; int main() { cin >> ... |
#include <bits/stdc++.h> using namespace std; const int M = 200000 + 10; int a[M]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); double R_L = 0; double R_R = 0.5 * a[n - 1] - 0.5 * a[0]; int num = 0; double C1, C2, C3; C2... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; using ll = long long; using pii = pair<int, int>; int pa[maxn]; int sz[maxn]; int d[maxn]; int f[maxn]; vector<ll> pre[maxn]; vector<int> g[maxn], dis[maxn]; map<pii, ll> ans; int find(int p) { return p == pa[p] ? pa[p] ... |
#include <bits/stdc++.h> using namespace std; inline void ad(int& x, long long y) { x = (x + y) % 1000000007; } int n, f[40][40][2], t[40], c; int main() { scanf( %d , &n); f[30][0][1] = 1; for (int i = 30; i; --i) for (int j = 0; j <= 30; ++j) { ad(f[i - 1][j][0], f[i][j][0] * (1ll <<... |
#include<bits/stdc++.h> using namespace std; long long ans; int d[100005]; int main(){ int t; cin>>t; while(t--){ int n; scanf( %d ,&n); for(int i=1;i<=n;++i)scanf( %d ,&d[i]); sort(d+1,d+1+n); ans=d[n]; for(int i=1;i<=n;++i)ans+=d[i]*(n+1ll-i-i); printf( %lld n ,ans); } } |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void solve() { int a, b, n; cin >> a >> b >> n; bool aturn = true; while (n > 0) { int x; if (aturn) { x = gcd(a, n); aturn = false; } els... |
#include <bits/stdc++.h> using namespace std; int read() { int res = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1, c = getchar(); while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); return res * f; } const int m... |
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; while (cin >> a >> b) { long long divi = a - b, cnt = 0; if (a == b) cout << infinity << endl; else { for (long long i = 1; i * i <= divi; i++) { if (divi % i == 0) { long lon... |
#include <bits/stdc++.h> const long long MAX = 300000; const double PI = 3.14159265358979323846; long long T[MAX * 2]; long long ceil_log2(long long n) { long long v = 1; long long log = 0; while (v < n) { v <<= 1; log++; } return log; } std::bitset<64> reverse(std::bitset<64... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int add_MOD(int a, int b) { a += b; if (a >= MOD) { return a - MOD; } if (a < 0) { return a + MOD; } return a; } int mul_MOD(int a, int b) { return a * (long long)b % MOD; } const int N = (int)2e5 + ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) #pragma GCC target( avx,tune=native ) using namespace std; const long long mod = 1e9 + 7; long long w[11]; vector<vector<long long> > mul(vector<vector<long long> >& a, ... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int dx[] = {0, 0, 1, -1}; long long int dy[] = {1, -1, 0, 0}; long long int m = 0, n, res = 0, k; string s2, ch = , s, t, s1 = ; vector<pair<string, long long int> > vm; vector<pair<pair<long long int, long long int... |
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 20); class Disjoint_Set { public: int sz[MX], P[MX]; int find_(int x) { if (x != P[x]) P[x] = find_(P[x]); return P[x]; } int comp; void init(int N) { for (int j = 1; j <= N; j++) sz[j] = 1, P[j] = j; ... |
#include <bits/stdc++.h> using namespace std; const int N = 200007; int n, m, q, p[N], a[N], apre[N], lst[N], ppre[N], fa[N], dep[N], w[N], b[N]; vector<int> G[N]; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } int read() { int x; scanf( %d , &x); ... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6; long long a[MAXN], mod = 1e9 + 7, ans; long long power(long long x, long long y) { if (y == 0) return 1; long long mid = power(x, y / 2); if (y % 2 == 1) return mid * mid % mod * x % mod; else return mid * mid ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j = 0, c1 = 0, c0 = 0; string a, b; vector<long long int> v0, v1; cin >> n; cin >> a; cin >> b; for (i = 0; i < n; i++) { if (b[i] == 0 ) { if (a[i] == 1 ) v1.push_back(i); el... |
#include <bits/stdc++.h> using namespace std; bool check(long long n, long long s) { long long sum = 0; while (n) { sum += n % 10; n /= 10; } return sum == s; } int main() { long long n, s, rt, ans = -1; cin >> n; for (s = 1; s < 100; s++) { rt = sqrt(s * s + 4 * n)... |
#include <bits/stdc++.h> using namespace std; vector<int> e; double best = -1; int main() { int n, u; cin >> n >> u; for (int i = 0; i < n; i++) { int k = 0; cin >> k; e.push_back(k); } int k = 2; for (int j = 1; j < n; j++) { int ej = e[j]; int ei = e[j - 1... |
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ui = unsigned int; using pii = pair<int, int>; using pll = pair<int, int>; struct fast_ios { fast_ios() { ios::sync_with_stdio(false); cin.tie(NULL); } } fast_ios_; ll u, v, a; int solve() { cin >> u ... |
#include <bits/stdc++.h> using namespace std; long long t, n, m, u, v, q, k; const int N = 3e5 + 500; const int LN = 20; const int SN = 331; const long long mod = 1e9 + 7; const long long INF = 1LL << 57; long long arr[N], brr[N]; string str, ss; vector<int> adj[N]; vector<int> idx[N]; int d[N];... |
#include <bits/stdc++.h> using namespace std; const int N = 2000200; bool Ch(int Ans); int n, k; int a[N]; int c[N]; int p[N]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) scanf( %d , a + i), c[a[i]]++; for (int i = 1; i < N; i++) p[i] = c[i] + p[i - 1]; sort(a + 1, a + n + 1... |
#include <bits/stdc++.h> using namespace std; vector<int> v; int n, m; int f() { int ans = 0; for (int i = 0; i < n; i++) { int a = 10; for (int j = i; j < n; j++) { for (int k = i; k <= j; k++) a = min(a, v[k]); ans += a; } } return ans; } int main() { ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long powmod(long long a, long long b, long long p) { if (b == 0) return 1; if (b == 1) return a; long long temp = powmod(a, b / 2, p); temp *= temp; ... |
#include <bits/stdc++.h> using namespace std; long long pw(long long x, long long p) { if (p == 0) return 1; long long t = pw(x, p / 2); if (p % 2 == 0) return (t * t) % 1000000007; else return (((t * t) % 1000000007) * x) % 1000000007; } const long long NN = 500007; long long pare... |
#include <bits/stdc++.h> using namespace std; int main() { long f, n; long double a, b, ans; while (cin >> a >> b >> n) { long flag = 0, i, j; for (i = -1000; i <= 1000; i++) { ans = 1; f = 0; for (j = 0; j < n; j++) { ans *= i; if (abs(ans) > 1000... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) cin >> x[i]; vector<int> ans(n + 1); for (int i = 0; i < n; i++) { int dominant = 0; vector<int> m(n + 1); for (int j = i; j < n; j++) { m[x[j... |
#include <bits/stdc++.h> using namespace std; const long long nax = 105; long long a[nax]; signed main() { long long n, cnt0 = 0, cnt1 = 0; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 0) cnt0++; else cnt1++; } if (cnt0 == n) { ... |
#include <bits/stdc++.h> using namespace std; int n; int y[50010] = {}; int t[50010] = {}; unordered_map<int, int> ha; bool cmp(int x, int y) { return x > y; } bool ff(int x) { ha.clear(); for (int i = 1; i <= n; i++) y[i] = t[i]; for (int i = 1; i <= n; i++) { if (y[i] <= x && ha[y[i]] ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; int m; cin >> n >> m; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } map<i... |
#include <bits/stdc++.h> using namespace std; void maloosh_lazma() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { maloosh_lazma(); int n, k; cin >> n >> k; string s; cin >> s; int l, ll; char q, qq; for (int i = 0; i < k; i++) { cin >> l >> ll >> ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ; int beauty[n]; for (int asdf = 0; asdf < n; asdf++) { cin >> beauty[asdf]; }; map<int, long long int> occ; long long int most = 0; for (int... |
#include <bits/stdc++.h> using namespace std; int n, m, i, ii, c; long long xa, xb, xc, xd, mask, a[100100], b[100100]; int main() { scanf( %d%d , &n, &m); for (i = 0; i < n; i++) { scanf( %I64d.%I64d.%I64d.%I64d , &xa, &xb, &xc, &xd); a[i] = (xa << 24) + (xb << 16) + (xc << 8) + xd; } ... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.1415926535897932384626433832795; unsigned long long mod = 1000 * 1000 * 1000 + 7; int INF = 1000 * 1000 * 1000; vector<int> v; class node { public: node() { left = right = NULL; addVal = 0; } ... |
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; while (t--) { long long n, a, b; cin >> n >> a >> b; string s; cin >> s; for (long long i = 1; i < s.length() - 1; i++) { if (s[i] =... |
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> P; vector<int> vis; vector<vector<int> > C; vector<int> lab, sz; void getCycle() { vis = vector<int>(N, 0); lab = vector<int>(N, 0); for (int i = 0; i < N; i++) { if (vis[i]) continue; C.push_back(vector<int>()); ... |
#include <bits/stdc++.h> using namespace std; int main() { string p; cin >> p; bool yon; for (int i = 0; i < p.length(); i++) { if (p[i] == H || p[i] == Q || p[i] == 9 ) { yon = true; break; } else yon = false; } if (yon) cout << YES << endl; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int mod = 1e6 + 3; string mm(char c) { if (c == > ) return 1000 ; if (c == < ) return 1001 ; if (c == + ) return 1010 ; if (c == - ) return 1011 ; if (c == . ) return 1100 ; if (c == , ) return 1101 ; ... |
#include <bits/stdc++.h> using namespace std; template <typename T> class Sieve { public: vector<T> primes; vector<bool> is_prime; Sieve(int MAX = 1000000) { is_prime.resize(MAX + 1, true); is_prime[0] = is_prime[1] = false; for (long long int i = 2; i * i <= MAX; i++) if ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using pll = pair<ll, ll>; using vll = vector<pll>; using MAP = map<ll, ll>; using sl = set<ll>; using sll = set<pll>; using MAPs = map<ll, sl>; using MAPv = map<ll, vl>; const ll in... |
#include <bits/stdc++.h> using namespace std; int n, d[128][128][8]; string s; int main() { ios::sync_with_stdio(0); cin >> n >> s; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 0; k <= 4; k++) { if (s[i - 1] == . ) continue; if (!k) { ... |
#include <bits/stdc++.h> using namespace std; int a[100100]; int d[100100]; 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++) { d[i] = 100100; } d[0] = 0; for (int i = 0; i < n; i++) { int l = 0... |
#include <bits/stdc++.h> int main() { int a[10000], b = 1, i, n; for (i = 1; i < 1000; i++) { a[b] = i; if (a[b] >= 100) { a[b + 2] = a[b] % 10; a[b + 1] = a[b] / 10 - a[b] / 100 * 10; a[b] = a[b] / 100; b += 3; } else if (a[b] >= 10) { a[b + 1] = a[b]... |
#include <bits/stdc++.h> using ll=long long; #define MOD 1000000007 using namespace std; void calc(double c, double m, double p, double v, double *exp, double prob, int n, int x){ if(x==1){ prob *= p; *exp += prob*n; return; } else if(x>1){ doub... |
#include <bits/stdc++.h> using namespace std; long long n, m; long long sum = 0; int main() { scanf( %lld%lld , &n, &m); long long max_add = (n - 1) * n / 2; long long min_add; if (n % 2) min_add = (n / 2 + 1) * (n / 2); if (n % 2 == 0) { long long a1 = (n / 2 + 1) * (n / 2) / 2; ... |
#include <bits/stdc++.h> using namespace std; const int N = 4010; long long O_O[N][N]; const long long mod = 1e9 + 7; int main() { int o_o; memset(O_O, 0, sizeof(O_O)); O_O[0][0] = 1; for (int i = 1; i <= 4000; ++i) { if (i < 4000) o_o = i; else o_o = 4000; fo... |
#include <bits/stdc++.h> using namespace std; const int N = 17; int n, m, x, y, z, inf; int bin[N], d[N][N], du[N], f[1 << N], q[N]; int main() { for (register int i = 1; i <= 16; ++i) bin[i] = 1 << (i - 1); int sum = 0; scanf( %d , &n); scanf( %d , &m); memset(d, 60, sizeof(d)); inf =... |
#include <bits/stdc++.h> long long mod = 1000000007; using namespace std; int n, m; long long b; struct node { int money, monitors, pre; vector<int> G; } a[202]; bool cmp(node x, node y) { return x.monitors > y.monitors; } long long dp[2][1 << 20]; int setbit(int x, int pos) { return x | (1 <<... |
#include <bits/stdc++.h> using namespace std; struct Number { array<int, 4> x = {{0, 0, 0, 0}}; Number() {} Number(int a) { if (a != -1) x[a]++; } long double log_value() const { if (x[0] > 0) return -INFINITY; return x[2] * log(2L) + x[3] * log(3L); } int mod() const {... |
#include <bits/stdc++.h> using namespace std; void solve(); signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t = 1; cin >> t; while (t--) solve(); } void solve() { long long n; cin >> n; string a, b; cin >> a >> b; str... |
#include <bits/stdc++.h> using namespace std; const int N = 305; int c[N], a[N], d[N]; bool cmp(int first, int second) { if (a[first] != a[second]) return a[first] < a[second]; return first > second; } inline int lowbit(int first) { return first & -first; } int query(int first) { int res = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; vector<vector<pair<int, int>>> pos(n, vector<pair<int, int>>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { pos[i][j] = {i, j}; } ... |
#include <bits/stdc++.h> using namespace std; int N, K; int gru0[] = {0, 1, 2}; int gru1[] = {0, 1, 0, 1, 2}; int grundy(int x) { if (K) { if (x < 5) { return gru1[x]; } else if (x & 1) { return 0; } else { return grundy(x / 2) == 1 ? 2 : 1; } } else { ... |
#include <bits/stdc++.h> using namespace std; int main() { int h, m, n; cin >> h >> m >> n; int* id = new int[n]; int* hash = new int[n]; int* hsh = new int[h]; int nc = 0; int res = 0; char z; int i, j, k, l; for (i = 0; i < h; i++) { hsh[i] = 0; } for (i = 0; ... |
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7, INF = 0x3f3f3f3f; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; ret... |
#include <bits/stdc++.h> using namespace std; long long dp[int(1e5 + 2)][2]; int a[int(1e5 + 2)]; vector<int> v[2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int mod = 998244353; int t; cin >> t; while (t--) { v[0].clear(); v[1].clear(); for (int i... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int q, ans = 0; cin >> q; if (q % 2) q -= 9, ans++; if (q < 0) ans = -1; else ans += q / 4; if (q == 2) ans = -1; cout << ans << endl; } return 0; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.