func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n, x, ans = 0, i; cin >> n; for (i = 0; i < n; i++) { cin >> x; ans += (i + 1) * x; } ans -= (((n - 1) * (n)) / 2); cout << ans << n ; } |
#include <bits/stdc++.h> using namespace std; int a, b, c; int main() { scanf( %d %d %d n , &a, &b, &c); if (a == b && c == 0) printf( YES n ); else if ((a != b && c == 0) || (a > b && c > 0) || (a < b && c < 0)) printf( NO n ); else { if ((b - a) % c == 0) printf( YES n ... |
#include <bits/stdc++.h> using namespace std; const int MAX_L = 3000; int T[MAX_L][MAX_L]; int last[MAX_L], z[MAX_L]; ; char s[MAX_L], p[MAX_L]; int main() { int Ls, Lp, is, ip, k, i, j, r; scanf( %s%s , &s, &p); Ls = strlen(s); Lp = strlen(p); for (i = 0; s[i]; i++) { is = i; ... |
#include <bits/stdc++.h> using namespace std; int main() { int v0, v1, v2, vm, a0, a1, a2; bool err = true; scanf( %d%d%d%d , &v2, &v1, &v0, &vm); for (int i = v0; i <= v0 * 2; i++) { for (int j = v1; j <= v1 * 2; j++) { for (int k = v2; k <= v2 * 2; k++) { if (vm <= i && vm ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int main() { int n; cin >> n; string s; cin >> s; queue<int> D, R; for (int i = 0; i < n; i++) { if (s[i] == D ) D.push(i); if (s[i] == R ) R.push(i); } while (D.size() && R.size()) { if (D.... |
#include <bits/stdc++.h> const double eps = 1e-19; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const int MAXN = 300005; using namespace std; int n, m; int ans[MAXN]; vector<int> g[MAXN]; bool used[MAXN]; void dfs(int v) { int kol = 0; for (int j = 0; j < (int)g[v].s... |
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> ostream& operator<<(ostream& o, const pair<T, U>& p) { o << ( << p.first << , << p.second << ) ; return o; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << [ ; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1510, INF = 1e9 + 9; int n, s, m, k, last[N], a[N], dp[N][N]; bool check(int x) { memset(dp, 0, sizeof dp); for (int i = 0; i < n; i++) { int val = 0; for (int j = last[i]; j <= i; j++) val += a[j] <= x; for (int j = 1; j <= m... |
#include <bits/stdc++.h> using namespace std; struct Node { pair<int, int> A; int x, y; Node() {} Node(pair<int, int> A, int x, int y) { this->A = A; this->x = x; this->y = y; } }; char s[1001][1001]; int sp[10], cur, ans[10]; Node heap[1000001]; void swap(Node& a, No... |
#include <bits/stdc++.h> using namespace std; int len(int n) { if (n < 10) return 0; return 1 + len(n / 10); } int main() { int n, l; long long sum = 0, z = 1; cin >> n; l = len(n); for (int x = 0; x < l; x++) z *= 10; while (n > 0) { sum += (n - z + 1) * (l + 1); n =... |
#include <bits/stdc++.h> using namespace std; const int N = 100005, mod = 1000000007; int n, m, T, q, f[6]; int main() { cin >> n; for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); for (int j = 1; j <= 4; j++) { if ((j & 1) == (x & 1)) f[j]++; } for (int j = 2;... |
#include <bits/stdc++.h> using namespace std; int a[200005]; long double b[200005]; int n; long double dp1[200005], dp2[200005]; long double check(long double val) { int i; for (i = 0; i < n; i++) b[i + 1] = a[i] - val; dp1[1] = b[1]; long double ans = b[1]; for (i = 2; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1}; int n, m; int xw, yw, xb, yb; int xtw, ytw, xtb, ytb; deque<pair<int, int>> ww, wb, bw, bb; int dist[1000][1000], parx[1000][1000], pary[1000][1000]; int crap; ... |
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } int N, M; bitset<1013> grid[1013]; int dn[1013][1013], rt[1013][1013]; int upd[1013][1013]; int x ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int sz = 10; map<int, int> mp[11]; int n, k; unsigned long long a[maxn], ans; unsigned long long fac[13]; int main() { fac[0] = 1; for (int i = 1; i <= 10; i++) fac[i] = 10LL * fac[i - 1]; scanf( %d%d , &n, &k); ... |
#include <bits/stdc++.h> using namespace std; const int mx = 1123; int limit[26]; const long long mod = 1e9 + 7; int n; string s; struct Node { int maxstr, minpart; long long ways; Node(int maxstr, int minpart, long long ways) : maxstr(maxstr), minpart(minpart), ways(ways){}; Node(... |
#include <bits/stdc++.h> using namespace std; bool is_prime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } vector<int> gen_primes(int l, int r) { vector<int> primes; for (int i = l; i <= r; i++)... |
#include <bits/stdc++.h> using namespace std; void FLASH() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void SETF() { cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed); } void UNSETF() { cout.ios_base::unsetf(ios_base::fixed); cerr... |
#include <bits/stdc++.h> using namespace std; int x[6]; int m[6]; int w[6]; int h, uh; int main() { x[0] = 500; for (int i = 0; i < 5; i++) { cin >> m[i]; if (i) x[i] = x[i - 1] + 500; } for (int i = 0; i < 5; i++) cin >> w[i]; cin >> h >> uh; int score = 0; for (int ... |
#include <bits/stdc++.h> using namespace std; const int MM = 1005; const long long MOD = 1000000007; int vis[MM][MM] = {0}; int n, m, k; bool judge(int x, int y) { if (x - 1 >= 0 && y - 1 >= 0) { if (vis[x - 1][y - 1] && vis[x - 1][y] && vis[x][y - 1]) return true; } if (x - 1 >= 0 && y + ... |
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, a, b; int main() { cin >> n >> m >> x >> y >> a >> b; long long W = min(n, (m * a) / b); long long divA = a, divB = b; for (long long i = 2; i * i <= divB; i++) { while (divB % i == 0) { if (divA % i == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1e4; int a[maxn], mod; int b[maxn]; int n; int pow(int a, int b) { if (b == 1) return a; int t = pow(a, b >> 1); t = 1LL * t * t % mod; if (b & 1) t = 1LL * t * a % mod; return t; } int ny(int a) { return pow(a, mod... |
#include <bits/stdc++.h> using namespace std; int n, rsp, ans, taram; char first; int main() { cin >> n; cin >> first; if (first == U ) { taram = 2; rsp++; } else taram = 1; for (int i = 2; i <= n; i++) { cin >> first; if (rsp * 2 == i - 1) { ans += (fi... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, x, y; cin >> n >> x >> y; vector<int> arr(n, 0); for (int i = 0; i < n; ++i) { cin >> arr[i]; } sort(arr.begin(), arr.end()); if (x > y) { cout << n << n ; } else { int i... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; long long int x; x = a % b; if (x == 0) cout << x << endl; else { long long int r = a / b; long long int res ... |
#include <bits/stdc++.h> using namespace std; int gcd(int u, int v) { int tmp; while (v) { tmp = v; v = u % v; u = tmp; } return u; } int main() { int a, b, t; cin >> a >> b; if (a > b) { swap(a, b); } if ((t = gcd(a, b)) == 1) { cout << NO << ... |
#include <bits/stdc++.h> #define ll long long #define ld long double #define vec vector #define pii pair<int, int> using namespace std; const long long MAXVAL = (long long) 1e18 + 1; const long long MOD = 1000000007ll; //const long long MOD = 998244353ll; const int INF = 1000000001; long long... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string str1, str2; cin >> str1 >> str2; int diffcount = 0; for (int i = 0; i < str1.length(); i++) { if (str1[i] != str2[i]) diffcount++; } if (diffcount % 2 == 1) { ... |
#include<iostream> #include<algorithm> using namespace std; class node{ public: int a; int b; }; bool com(node a,node b){ return a.a<b.a; } int main(){ int times=0; cin>>times; while(times--){ int t=0; cin>>t; node *arr=new no... |
#include <bits/stdc++.h> using namespace std; int n; long double l, v1, v2; long double a[100000]; long double p[100001]; vector<pair<long double, int> > events; int main() { cout << fixed << setprecision(12); cin >> n >> l >> v1 >> v2; long double dist = l * v2 / (v1 + v2); events.push_ba... |
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define f(i,x,y) for(int i=x;i<=y;i++) #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //priority_queue<int>Q; //unordered_map<string,int> Q; const int MAX=3e5+10; ll a[MAX]; void solve()... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const ll llinf = (1ll << 61) - 1; const double eps = 1e-6, ldeps = 1e-9; struct Dbg { static constexpr auto &os = cout; template <class C> static auto dud(C *x) -> declty... |
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n >> s; int sol = n; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1] and s[i - 1] != D ) { sol--; s[i] = D ; } } cout << sol << endl; } |
#include <bits/stdc++.h> using namespace std; void FastIO() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cout.precision(15); } string fun(string str) { int i, l = str.length(); for (i = 0; i < l; i++) { if (str[i] == + ) str[i] = * ; else s... |
#include <bits/stdc++.h> using namespace std; char s[410][42]; char a[42], t[42]; int main() { int n; while (~scanf( %d , &n)) { int ans = n, g = 0; for (int k = 0; k < n; k++) { scanf( %s , t); while (true) { int k = 0; for (int i = 0; t[i] != 0 ;) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> arr(n), lefts(n), rights(n); for (int &x : arr) cin >> x; stack<int> positions; for (int i = 0; i < n; ++i) { while (!positions.empt... |
#include <bits/stdc++.h> using namespace std; const int MX = 400000; long long l[500000], r[500000], k[500000], b[500000], a[500000], pref1[500000], pref2[500000], s = MX; long long f(long long b1, long long a1, long long b2, long long a2) { return (b1 - b2) / (a1 - a2); } void add(long long kx, l... |
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int x, int1, int2, int3, tempsum, lastsum = -1; string s, s1, s2, s3; cin >> s; x = s.size(); for (int d1 = 1; d1 < x - 1 && d1 < 8; d1++) { for (int d2 = 1; d2 < x - d1 && d2 < 8; d2++) { s1 = s.substr(0, d1); ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) const long double pi = 2 * acos(0.0); using namespace std; int power(int a, int n) { if (n == 0) { return 1; } int p = power(a, n / 2) % 1000000007; p = (p... |
#include <bits/stdc++.h> using namespace std; template <class T, class T2> T2 fac(T n) { return n < 2 ? 1 : fac<T, T2>(n - 1) * n; } template <class T> T nb_combinaisons(T k, T n) { if (n < k) return nb_combinaisons<T>(n, k); return fac<T, long long int>(n) / (fac<T, long long int>(n ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int N, M, U = 110, D = 0, L = 110, R = 0, cnt; char s[maxn][maxn]; inline int gi() { char ch; int ret = 0, f = 1; do ch = getchar(); while (!(ch >= 0 && ch <= 9 ) && ch != - ); if (ch == - ) f = -1, ch = getchar(); ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int pre[N]; void solve() { string s; int n, k, ans = 0; cin >> n >> k >> s; for (int i = 0; i < n; i++) { if (s[i] == 1 ) { if (i == 0) pre[i] = 1; else pre[i] = pre[i - 1] + 1; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const int N = 1e5 + 10; const int mod = 100; int main() { string str; int n, ans; cin >> n >> str; ans = n; for (int i = 0; i < n - 1; i++) { if (str[i] == U && str[i + 1] == ... |
#include <bits/stdc++.h> using namespace std; const int N = 850; int capacity[N][N], p[N], visit[N], n, source, sink, max_flow; pair<int, int> a[N]; vector<int> adj[N]; double f[N], cost[N][N], res; double dis(pair<int, int> a, pair<int, int> b) { return sqrt((a.first - b.first) * (a.first - b.first) ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; string ans = ; int f; if (a > b) { ans += 0 ; a--; f = 0; } else { ans += 1 ; f = 1; b--; } for (int i = 1; i < c; i++) { if (f) { ans += ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200200; int n; int a[maxn], b[maxn], c[3][maxn]; int sum[maxn]; int lowbit(int x) { return x & (-x); } void add(int p, int v = 1) { for (int i = p; i <= n; i += lowbit(i)) sum[i] += v; } int get(int p) { int ret = 0; for (int i... |
#include <bits/stdc++.h> using namespace std; bool vis[205][205]; int cnt; vector<int> ans; void dfs(int x, int y) { if (x % 2 == 0 && y % 2 == 0) cnt++; vis[x][y] = 1; if (!vis[x + 1][y]) dfs(x + 1, y); if (!vis[x][y + 1]) dfs(x, y + 1); if (!vis[x - 1][y] && (x - 1 >= 0)) dfs(x - 1, y); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; bool remove = true; int ans = 0; while (remove) { remove = false; int idx; char c = 0 ; if (s.size() > 1) { for (int i = 0; i < s.size(); i++) { if ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 50; long long g[maxn]; int ans, n; inline int ctz(long long s) { return s ? __builtin_ctzll(s) : 8 * sizeof(long long); } void BronKerbosch(long long clique, long long allow, long long forbid) { if (!allow && !forbid) { ans = max... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int m, k, n, s, tot, del, a[N], b[N], c[N], d[N]; int main() { scanf( %d%d%d%d , &m, &k, &n, &s); del = m - k * n; for (int i = 1; i <= m; i++) scanf( %d , &a[i]); for (int i = 1, x; i <= s; i++) { scanf( %d , &x); ... |
#include <bits/stdc++.h> using namespace std; const int N = (int)3e5 + 7; int n, k; int x[N], y[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> x[i]; } for (int i = 1; i <= n; i++) { cin >> y[i]; } long long... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > a; bool g[100][100]; bool used[100]; int n; void dfs(int v) { used[v] = true; for (int i = 0; i < n; i++) if (g[v][i] && !used[i]) dfs(i); } int main() { int m; cin >> n >> m; bool now = false; for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int M = 512; const int T = 101; int n, m; long long a[M][M]; long long b[M][M]; int t; int x[T], y[T]; void solve(int xl, int xr, int yl, int yr) { if (xl == xr && yl == yr) { b[xl][yl] = a[xl][yl]; } else if (xl != xr) { int tm =... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 2; int pos[MAX], a[MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, c = 0, k; cin >> n; for (int i = 1; i < n + 1; i++) cin >> k, a[k] = i, pos[i] = k; for (int i = 1; i < n + 1; i++) { if... |
#include <bits/stdc++.h> using namespace std; int a[1000000], psum[1000000]; map<long long, long long> mp, pp; vector<long long> v; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { int n, k; cin >> n >> ... |
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using vll = vector<ll>; using vpi = vector<pair<int, int>>; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int speedlim = 301; bool overtake = true; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; if (n <= m && n <= k) { cout << YES ; } else cout << NO ; return 0; } |
#include <bits/stdc++.h> using namespace std; map<pair<string, string>, pair<int, int> > mp; set<pair<string, string> > st; int main() { int n, d; cin >> n >> d; for (int i = 0; i < n; ++i) { string s, q; int x; cin >> s >> q; scanf( %d , &x); if (mp.count({q, s})) { ... |
#include <bits/stdc++.h> using namespace std; int n, m; int len[500020]; vector<int> s[500020]; vector<int> g[500020]; int col[500020]; set<int> FK; int c; int rt; void dfs(int u, int p) { if (p) { vector<int> t; int k = c; for (auto v : s[u]) { if (!col[v]) continue; ... |
#include <bits/stdc++.h> using namespace std; long long rate[2000002]; int n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> rate[i]; long long p = 0, c; int del = 0; vector<int> vec; for (int i = 1; i <= n; i++) { if (i - del > 1) c = (-rate[i - 1] * ((n... |
#include <bits/stdc++.h> using namespace std; struct wektor { int roz; int *tab; int roztab; wektor() { tab = new int[1]; roz = 0; roztab = 1; } ~wektor() { delete[] tab; } int size() { return roz; } bool empty() { return roz == 0; } void pop_back() { roz--; } ... |
#include <bits/stdc++.h> using namespace std; const double kEps(1e-8); #pragma gcc optimize(2) int gcd(int x, int y) { while (y ^= x ^= y ^= x %= y) ; return x; } void write(int x) { if (x < 0) putchar( - ), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + 0 ); } int qpow(in... |
#include <bits/stdc++.h> using namespace std; const int SIZE = 100005; const int MSIZE = 10000; const int INF = 1 << 30; set<int>::iterator it; int main() { int n, a, b; int p[SIZE]; set<int> fi, se; map<int, int> mp; bool flag[SIZE]; while (cin >> n >> a >> b) { fi.clear(), se... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n, a, d; cin >> n >> a >> d; int t, v; double T, P = 0, D; while (n--) { cin >> t >> v; T = 1.0 * v / a; if (T * v <= 2 * d) { D = (1.0 * d - T * v * 0.5) / v; T = T + D; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long fac[2000001]; long long PowMod(long long a, long long b, long long mod) { long long ret = 1LL; while (b) { if (b & 1) ret = (ret * a) % mod; a = (a * a) % mod; b >>= 1; } return ret; } void ... |
#include <bits/stdc++.h> using namespace std; int a[1002][102]; int main() { int n, m, k, x; cin >> n >> m >> k; cout << m * (m - 1) / 2 << endl; for (int i = 0; i < m; i++) { for (int j = i + 1; j < m; j++) { if (!k) cout << i + 1 << << j + 1 << endl; else ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); int n; cin >> n; int m; cin >> m; std::vector<std::vector<long long> > re(n, std::vector<long long>(m, 0)); long long ta = 0; for (int i = 0; i < n; ++i)... |
#include <bits/stdc++.h> using namespace std; template <class htpe, class cmp> using heap = priority_queue<htpe, vector<htpe>, cmp>; template <class htpe> using min_heap = heap<htpe, greater<htpe> >; template <class htpe> using max_heap = heap<htpe, less<htpe> >; const int INF = 1791791791; const long... |
#include <bits/stdc++.h> using namespace std; string to_string(const string& s) { return + s + ; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } string to_string(vector<bool> v) { bool first = true; string res = { ;... |
#include <bits/stdc++.h> using namespace std; const long long inf = 13e9; const long long dd = 1e6 + 7; int main() { int n, s, r = -1; cin >> n >> s; s *= 100; for (int i = 0; i < (long long)n; i++) { int x, y; cin >> x >> y; x = x * 100 + y; if (x <= s) r = max((100 - y)... |
#include <bits/stdc++.h> using namespace std; long double PI = acosl(-1); bool compare_int(int a, int b) { return (a > b); } bool compare_string(string a, string b) { return a.size() < b.size(); } bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return ... |
#include <bits/stdc++.h> using namespace std; set<int> st[2]; map<int, int> mp; int ar[110]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> ar[i]; mp[ar[i]]++; } int idx = 0; map<int, int>::iterator it1; for (it1 = mp.begin(); it1 != mp.end(); it1++)... |
#include <bits/stdc++.h> using namespace std; string s; int len; set<string> v; bool check[111111][5]; void fuck(string father, int now) { if (now - 2 > 4) { string now1 = s.substr(now - 2, 2); if (now1 != father) { v.insert(now1); if (check[now - 2][2] == true) che... |
#include <bits/stdc++.h> using namespace std; inline char nc() { return getchar(); static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void read(T &x) { x = 0; ... |
#include <bits/stdc++.h> using namespace std; const int mn = 1e6 + 10; int a[mn * 3]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) a[i] = i; for (int i = 2; i <= n; i++) { int v = a[i - 1]; for (int j = i - 1; j < n + i - 1; j += i) { swap(v, a[min(j + i,... |
#include <bits/stdc++.h> using namespace std; const int N = 106, INF = 0x3f3f3f3f; 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 * 10 + ch - 0 ; ch = ge... |
#include <bits/stdc++.h> using namespace std; long long fact[1000001]; long long pow(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } long long modinv(long long k) { return pow(k, ... |
#include <bits/stdc++.h> using namespace std; int n, a[100010], cewa, now; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); now = 0; for (int i = 0; i < n; i++) { if (now > a[i]) { cewa++; now -= a[i]; } now += a[i]... |
#include <bits/stdc++.h> using namespace std; int destroy(list<int> row) { int totalDestroyed = 0, lastDestroyed = -1; int combo = 1; while (lastDestroyed != 0) { lastDestroyed = 0; combo = 1; list<int>::iterator it = row.begin(); list<int>::iterator prev = it++; for (; it ... |
#include <bits/stdc++.h> using namespace std; const int N = 112; const long long mod = 1e9 + 7; int R; long long p1, p2, p3, p4, s; int lim[N]; long long F[N][N]; long long ksm(long long a, long long b = mod - 2) { long long ret = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ret = ret... |
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> ostream& operator<<(ostream& o, const pair<T, U>& p) { o << ( << p.first << , << p.second << ) ; return o; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << [ ; ... |
#include <bits/stdc++.h> using namespace std; int a[1000001]; int main() { int n, k; cin >> n >> k; if (k == 1) return puts( 3 ), 0; for (int i = 1; i <= n; i++) a[i] = i; for (int i = 2; i <= n; i++) if (a[i] == i) { for (int j = i; j <= n; j += i) a[j] = (a[j] / i) * (i - 1); ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:134217728 ) using namespace std; const long long MOD = 1000000000 + 7; const long long MAGIC = 123123123; const double PI = 4 * atan(1.); const double EPS = 1E-7; void time_elapsed() { cout << nTIME ELAPSED: << (double)clock() / CLOCKS_PER_S... |
#include <bits/stdc++.h> const int MOD = (int)1e9 + 7; using namespace std; stack<long long> st; int main() { long long n, num; cin >> n; long long sum = 0; int over = 0; st.push(1); for (int i = 1; i <= n; i++) { string s; cin >> s; if (over == 1) continue; if (s... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n; cin >> k >> n; int ans = 0; unordered_set<int> pref_sums; int curr_sum = 0; while (k--) { int x; cin >> x; curr_sum += x; pref_sums.insert(curr_sum); ... |
#include <bits/stdc++.h> using namespace std; const int maxn(2e5 + 5); int n, m, s, a[maxn], bl[maxn], br[maxn], b[maxn], o[maxn], len, id[maxn], blk; int mn[505][505], st[505][505], tag[505], w[maxn], pmn[maxn], smn[maxn]; int curmn[505], curst[505], curtag[505]; inline void Modify(int l, int r, int id) { ... |
#include <bits/stdc++.h> using namespace std; long long n, fact[200001], a[200005]; long long power(long long a, long long b) { if (b == 0) return 1; long long p = power(a, b / 2); p = ((p % 1000000007) * (p % 1000000007)) % 1000000007; if (b & 1) { return (a * p) % 1000000007; } ret... |
#include <bits/stdc++.h> using namespace std; long long T; void Read(long long &x) { char c; while (c = getchar(), c != EOF) if (c >= 0 && c <= 9 ) { x = c - 0 ; while (c = getchar(), c >= 0 && c <= 9 ) x = x * 10 + c - 0 ; ungetc(c, stdin); return; } ... |
#include <bits/stdc++.h> using namespace std; long long dp[1 << 18][100], d, f[20]; int main() { int m, l, n, i, j, k, c[10]; char a[20]; memset(c, 0, sizeof(c)); for (f[0] = 1, i = 1; i < 20; i++) f[i] = f[i - 1] * i; scanf( %s%d , a, &m); l = strlen(a), n = 1 << l; for (i = 0; i < l;... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; int a[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> a[i][j]; } } long long l = 0, r = 1e9 + 1; i... |
#include <bits/stdc++.h> using namespace std; int N; int x, y, root = -1; vector<int> g[200100]; int len[200100], viz[3][200100]; int dmax = 0, ind; int stacky[200100], l = 0; void dfs(int x) { viz[0][x] = 1; if (g[x].size() == 1) { len[x] = 1; } else { int okk = 1; int kid... |
#include <bits/stdc++.h> using namespace std; int n; vector<int> a; bool check(vector<int> &b) { if (b.size() <= 1) return !b.empty(); int d = a[b[1]] - a[b[0]]; for (int i = 1; i < b.size(); ++i) { if (d != a[b[i]] - a[b[i - 1]]) return false; } return true; } bool solve(int o, in... |
#include <bits/stdc++.h> using namespace std; template <class T> void in(T &x) { x = 0; bool flag = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) flag = 1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = ge... |
#include <bits/stdc++.h> using namespace std; int A; int gcd(int a, int b) { if (a < b) swap(a, b); if (a % b == 0) return b; return gcd(b, a % b); } pair<int, int> find(vector<pair<int, int> > &sets, int a) { if (sets[a].first != a) sets[a].first = find(sets, sets[a].first).first; return ... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const int N = 200005; int len, fa[26], sz[N]; char s1[N], s2[N]; int Find(int x) { return (fa[x] == x) ? x : fa[x] = Find(fa[x]); } void Unite(int x, int y) { int fax = Find(x), fay = Find(y); if (f... |
#include <bits/stdc++.h> using namespace std; struct node { int x, y; node(int x1 = 0, int y1 = 0) : x(x1), y(y1){}; bool operator=(const node &b) const { return (x == b.x) && (y == b.y); } }; const int dx[5] = {0, 0, 0, 1, -1}; const int dy[5] = {0, 1, -1, 0, 0}; int N, M, Q; char maze[1007][... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e6 + 1; void solve() { long long n, m; cin >> n >> m; if (m == 0) { cout << 0; return; } long long total[n + 1]; memset(total, 0, sizeof(total)); long long ai, bi, ci; for (long long i = 0; i < m; i++)... |
#include <bits/stdc++.h> using namespace std; const int N = 300010, K = 18; char s[N]; bool sm[K * K][N], b[N], vis[N]; int n, p, tot, ans, ss, w[K][K], mp[K][K], a[N], cnt[K], q[N]; int cal(int S) { int res = 0; for (int i = (1); i <= (p); i++) if (S & (1 << (i - 1))) res += cnt[i]; retur... |
#include <bits/stdc++.h> using namespace std; inline namespace Infinity { inline namespace Constant { constexpr const int eof = EOF; constexpr const int maxint = INT_MAX; constexpr const long long maxll = LLONG_MAX; } // namespace Constant inline namespace TypeDefine { using uint = unsigned int; us... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.