func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 1003; const int mod = 1e9 + 7; int a[N][N]; int c[N]; int n; int sum; int main() { int i, j; scanf( %d , &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf( %d , &a[i][j]); for (i = 0; i < n; i++) sum += a[i][i] * ... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << ( << p.first << , << p.second << ) ; } template <typename C> ostream& operator<<(ostream& os, const vector<C>& v) { for (__typeof((v).begin()) __... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct que { int l, r, id; long long ans; } q[N]; int block, s[N], tong[N * 20], k; bool cmp1(que i, que j) { if (i.l / block != j.l / block) return i.l / block < j.l / block; return i.r < j.r; } bool cmp2(que i, que j)... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int oo = ~0u >> 2, mo = (int)1e9 + 7; const int mn = 110000, mm = 110000 * 2, ml = 18; struct Edge { int y, l; } E[mm]; int g[mn], d[mn], s[mn], blg[mn]; int fa[mn][ml], f[mn]; bool o[mn]; int n, m, tt(1); void add(i... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, a; cin >> n >> a; double angd = 180 * 1.0 / n; cout << 2 1 ; int x = floor(a / angd); if (x == 0) cout << 3 << endl; else if (a - x * angd < (1 + x) * angd - a) cout << min(x ... |
#include <bits/stdc++.h> using namespace std; template <typename T> using V = vector<T>; int gcdex(int a, int b, int &x, int &y) { if (a == 0) { x = 0; y = 1; return b; } int x1, y1; int g = gcdex(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; } inl... |
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, a[N][N]; deque<int> p[N]; int ptr[N], mat[N]; bool vis[N][N]; void upd(int x) { while (!p[x].empty() && vis[x][p[x].front()]) p[x].pop_front(); while (!p[x].empty() && vis[x][p[x].back()]) p[x].pop_back(); if (p[x].empty(... |
#include <bits/stdc++.h> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << ( << a.first << , << a.second << ) ; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, flag = 0; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < (n - 1); i++) { if (a[i] > a[i + 1]) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { long long int ml = 0, mr = 0, j; j = i; while (j < n - 1 && s[j] != R ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; pair<long long, long long> a[n]; for (long long i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i + 1; } sort(a, a + n); long long mx = 0, mx_start = 0, mx_end = 0; long long j; lo... |
#include <bits/stdc++.h> char abc[1000001]; int main() { char ab[1000001]; scanf( %s , ab); int abcc = strlen(ab); int i, x = 0, y = 0; for (i = 0; i < abcc; i++) { x += ab[i] == x ? 1 : 0; y += ab[i] == y ? 1 : 0; } if (x > y) for (i = 0; i < x - y; i++) abc[i] = ... |
#include <bits/stdc++.h> using namespace std; void solve(int test) { int x; cin >> x; int no = x % 10; int cnt = 0; while (x) { cnt++; x /= 10; } int ans = (no - 1) * 10; while (cnt) { ans += cnt; cnt--; } cout << ans << n ; } int main() { io... |
#include <bits/stdc++.h> using namespace std; int a[19][19]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { a[i][1] = 1; a[1][i] = 1; } for (int i = 2; i <= n; i++) { for (int j = 2; j <= n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } } cou... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q, i = 1, j, k, temp = 0, flag = 0; string s; cin >> n >> p >> q; cin >> s; if (n % p == 0 && n != p + q || n % q == 0 && n != p + q) { if (n % p == 0) { cout << n / p << endl; for (i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; for (int i = 0; i <= (c / b); i++) { int tmp = c - (i * b); if (tmp % a == 0) { cout << Yes << endl; return 0; } } cout << No << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[105], nr = 0, poz = 0; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] <= k) nr++; else { poz = i; break; } } if (poz || nr == 0) ... |
#include <bits/stdc++.h> using namespace std; int p[2010]; int main(void) { int N, ans = 0, i, j; cin >> N; for ((i) = 0; (i) < (int)(N); (i)++) cin >> p[i]; for ((i) = 0; (i) < (int)(N); (i)++) if (p[i] < 0) p[i] = -p[i]; for ((i) = 0; (i) < (int)(N); (i)++) { int a = 0, b = 0; ... |
#include <bits/stdc++.h> using namespace std; const int Max_L = 100000 + 100, inf = ~0U >> 2; pair<int, int> Ret[1000]; int main() { int L, b, f; cin >> L >> f >> b; int n; cin >> n; set<pair<int, int> > S; S.insert(pair<int, int>(-inf, -inf)); S.insert(pair<int, int>(inf, inf)); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; string s; cin >> s; string ans; for (long long i = 0; i < k; i++) { ans.push_back(s[i]); } for (long long i = k... |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> seq; int n; long e; cin >> n; int first = 0; long long s = 0; int f = 0; for (int i = 0; i < n; i++) { cin >> e; if (e != 1) { s += e; f++; } else { first++; } ... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > points, hull; bool comp(pair<long long int, long long int> a, pair<long long int, long long int> b) { if (a.first != b.first) return a.first < b.first; return a.second < b.second; } int cross(pair<lon... |
#include <bits/stdc++.h> using namespace std; long long n, x, sum = 0, sumtotal; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { cin >> x; sum += x; } sumtotal = n * (n + 1) / 2; cout << sumtotal - sum << endl; } |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:167177216 ) int main() { double y1, y2, yw, xa, ya, r; cin >> y1 >> y2 >> yw >> xa >> ya >> r; double ll = 0, rr = xa; yw -= r; double yt = y1 + r + 1e-9; for (int i = 0; i < 300; ++i) { double xm = (ll + r... |
#include <bits/stdc++.h> using namespace std; int main() { int n, d[100000]; string ch; long long res = 0; bool b = 0; cin >> n >> ch; for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < n; i++) { if (ch[res] == < ) res -= d[res]; else res += d[res];... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000; int centroid[maxn]; int parent[maxn]; int subtree[maxn]; int heaviest[maxn]; vector<int> graph[maxn]; void dfs(int u, int p = 0) { parent[u] = p; subtree[u] = 1; heaviest[u] = 0; int vert = 0; for (auto v : graph... |
#include <bits/stdc++.h> using namespace std; int n, k, r1, r2; string ans; bool pytaj(int x, int y) { cout << 1 << << x << << y << n ; fflush(stdout); cin >> ans; return ans[0] == T ; } int znajdz(int l, int r) { if (r < l) return -1; while (l < r) { int d = (r - l ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; int c[N][26], fa[N], l[N], sz[N], np = 1, cnt = 1; int a[N], b[N]; int q, len, vi[N]; char s[N]; void expend(int x) { int p = np; np = ++cnt; l[np] = l[p] + 1; sz[np] = 1; for (; p && !c[p][x]; p = fa[p]) c[p][x] = np... |
#include <bits/stdc++.h> using namespace std; int k; bool primes[200000][100]; int okay[5000000]; int okayN; int nLeft[1000]; bool isPrime[1000]; bool used[5000000]; vector<int> ans; bool compare(int a, int b) { if (nLeft[a] > nLeft[b]) return 1; if (nLeft[a] < nLeft[b]) return 0; return... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 0x7fffffff / 2; int n, m; int fa[maxn]; int vis[maxn]; struct edge { int u; int v; int w; } e[maxn]; struct ex { int mi; int mx; int sum; } ex[maxn]; int father(int x) { if (x != fa[... |
#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> namespace FastIO { bool IOerror = 0; inline char nc() { static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; if (p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, 100000, stdin); if (pend == p1) { IOerror = 1; return -1; } ... |
#include <bits/stdc++.h> using namespace std; typedef struct cell { long long mx, pref, suf, total; } cell; int tam[55], vet[300000]; long long sum[55], preffix[55], suffix[55], best[55], v[300000]; long long getMax(int n) { long long ret = -1000000000000000000LL, aux = 0LL; for (int i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); inline int sgn(double x) { if (x < -eps) return -1; else if (x > eps) return 1; else return 0; } struct Point { double x, y; Point(double _x = 0.0, double _y = 0.0) : x(_x... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long inf = 10000000; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(long long year) { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } inline void normal(l... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long MOD = 1e9 + 7; const long long mod = 998244353; const long long mxN = 1e6; void fileio() {} vector<long long> v[mxN]; vector<long long> vis(mxN); long long nd; void dfs(long long x, long long p) { vis[x] = ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long dx[4] = {-1, 1, 0, 0}; const long long dy[4] = {0, 0, -1, 1}; const long long MAX = 5e3 + 5; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long n, m, ans, k, Q; string sec... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int count = 0; int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i =... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5, mod = 998244353; inline int mod1(int x) { return x < mod ? x : x - mod; } inline int mod2(int x) { return x < 0 ? x + mod : x; } inline void add(int &x, int y) { x = mod1(x + y); } inline void sub(int &x, int y) { x = mod2(x - y); } inlin... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, A[12][N], q; struct node { int ans, lrt[12], rrt[12]; void trans(int u, int v) { ans--; for (int i = 1; i <= n; i++) { if (lrt[i] == u) lrt[i] = v; if (rrt[i] == u) rrt[i] = v; } } } t[N... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, l[N], r[N], cnt[4 * N], one[4 * N]; vector<int> g; map<int, int> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> l[i] >> r[i]; g.push_back(l[i] - 1);... |
#include <bits/stdc++.h> using namespace std; template <class temp> inline void Rd(temp &p) { p = 0; char c; while (c = getchar(), c < 48) ; do p = p * 10 + (c & 15); while (c = getchar(), c > 47); } int pow(int n, int m) { int ans = 1; while (m) { if (m & 1) ans = 1ll ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6; const long long LINF = 1e18; long long int n, cnt = 0, ans = 0, a, b, c, d, cmp[ohara], cmpp, m, h, w, x, y, sum[ohara], pos; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; string alph( a... |
# include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); int t; cin>>t; while(t--){ int n,m; cin>>n>>m; int ans=0; int a[101]={0}; for(int i=0; i<n;i++){ int x; cin>>x; a[x]=1; } for(int i=0;i<m;i++){ int x; cin... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, ans, last, d, x, y, a, b; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void exgcd(long long a, long long b, long long& d, long long& x, long long& y) { if (!b) { x = 1, y = 0, d = a; } else { exgcd(... |
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll nax = 1e5 + 69; int n; vector<ll>possible; void fun(ll *a,int l,int r,ll *pref){ if(l>r || l<0 || r>n) return; possible.push_back(pref[r+1]-pref[l]); if(a[r]==a[l]) return; int mid = (a[l] + a[r])/2; int ind =... |
#include <bits/stdc++.h> using namespace std; const int maxn = 101010 * 2; vector<int> vec[maxn]; vector<int> mp[maxn]; bool vis[maxn]; int arr[maxn]; int dfs(int x) { vis[x] = true; int ans = vec[x].size(); int siz = mp[x].size(); for (int i = 0; i < siz; i++) { int y = mp[x][i]; ... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int n) { if (n == 1) { return (a); } if (n == 0) { return 1; } long long int c = power(a, n / 2); if (n % 2 == 0) { return (c * c); } else { return c * c * a; } } ... |
#include <bits/stdc++.h> int main() { int n, m, p, q, a, b; scanf( %d %d %d %d , &n, &m, &p, &q); scanf( %d %d , &a, &b); int u = q - m, v = p - n; if (u < 0) u = -u; if (v < 0) v = -v; if ((u) % b == 0 && (v) % a == 0) { int c = u / b - v / a; if (c < 0) c = -c; if (c % ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = int(1e9); const int MAX = 100007; int dp[MAX][3], n; string s; int main() { ios_base::sync_with_stdio(false); cin >> n >> s; dp[0][1] = dp[0][0] = dp[0][2] = 1; for (int i = 1; i < s.size(); i++) { ... |
#include <bits/stdc++.h> int cal(int x) { int sum = 0; for (int i = 1; i < x; i++) { sum = sum + i; } return sum; }; char x[101][101]; using namespace std; int main() { int n, c1 = 0, c2 = 0, total1 = 0, total2 = 0; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0... |
#include <bits/stdc++.h> using namespace std; void action() { string s; cin >> s; reverse(s.begin(), s.end()); long long c = 0, f = 0, j; for (long long i = 0; i < s.length(); i++) { if (s[i] == 1 ) { f++; } if (i % 2 == 0) c++; } if (f > 1) cout << c; ... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int n, k; std::cin >> n >> k; int s[n + 1]; for (int i = 1; i < n + 1; ++i) { std::cin >> s[i]; } if (k >= n) std::cout << s[n]; else { int max = s[n]; for (int i = 1; i <= (n - k); ++... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long inf = 1e18; const long long N = 2e2 + 5; long long n; long long a[N]; void solve(long long id) { cin >> n; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long odd = 0, even = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int tt = 0; tt < int(t); tt++) { int n; cin >> n; map<int, int> c; for (int i = 0; i < int(n); i++) { int pi; cin >> pi; c[-pi]++; } vector<int> pp; for (aut... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; for (int i = 0; i < n / 4; i++) { cout << bbaa ; } if (n % 4 == 1) { cout << b ; } if (n % 4 == 2) { cout << bb ; } if (n % 4 == 3) { cout << bba ; } } |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, kol = 0, sum = 0, a; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a; if (sum + a > m) { kol++; sum = a; } else sum += a; } cout << kol + 1; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; vector<int> v[maxn]; pair<long long, long long> a[maxn]; long long q[maxn], siz[maxn]; bool c[maxn]; long long n, m, k; set<pair<long long, long long> > s; map<pair<long long, long long>, bool> mark; int main() { ios_base:... |
#include <bits/stdc++.h> using namespace std; int dep[100005], present[100005]; int main() { int n, p; scanf( %d , &n); for (int i = 2; i <= n; ++i) { scanf( %d , &p); present[dep[i] = dep[p] + 1] ^= 1; } printf( %d n , accumulate(present, present + n + 1, 1)); } |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int cnt[maxn]; int check(int k) { if (k == 0) return 1; long long d = 1, ans = maxn; while (d < maxn) d <<= 1; while (d >>= 1) if (ans - d >= 0) if ((ans - d) * (ans - d - 1) >= 2 * k) ans -= d; if (ans * ... |
#include bits/stdc++.h using namespace std; #define int long long #define yes YES n #define no NO n const int M = 1000000007; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int T; cin >> T; //T = 1; while(T--){ int n, k; cin >> n >... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; int arr[n]; for (int i = (int)(0); i <= (int)(n - 1); i++) { cin >> arr[i]; } int hash1[100005] = {0}; for (int i = (int)(0); i <= (int)(n... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int MaxN = 3e5 + 5; map<int, int> mp; struct node { int x, y; } arr[MaxN], brr[MaxN]; struct qnode { int x, y; bool operator>(const qnode &p) const { return p.y > y; } } st; bool cmp(node b, node c) { if (b... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline int readChar(); template <class T = int> inline T readInt()... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long n; int main() { cin >> n; if (n == 1) { cout << 0; return 0; } cout << n / 2 - 1 + (n % 2 != 0); return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 1; const int MOD = 1e9 + 7; struct node { int n4, n7, n47, n74; }; bool tab[MAX], lazy[4 * MAX]; int n, q; node seg[4 * MAX]; void build(int v = 1, int l = 0, int r = n - 1) { if (l == r) { seg[v].n7 = tab[l]; seg[... |
#include <bits/stdc++.h> using namespace std; int dirx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int diry[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string str1, str2; int main() { int n, m; cin >> n >> m; cin >> str1 >> str2; if (str1[0] == > && str2[0] == v || str1[0] == < && str2[0] == ^ ) cout... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; int arr[n], brr[m]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { cin >> brr[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ... |
#include <bits/stdc++.h> using namespace std; void i1d(vector<long long> &v) { for (auto &i : v) cin >> i; } void p1d(vector<long long> &v) { for (auto i : v) cout << i << ; cout << endl; } long long t; void solve() { cin >> t; while (t--) { long long n; cin >> n; ... |
#include <bits/stdc++.h> using namespace std; const int N = 500000; mt19937 Rand(time(0)); int mod[3]; struct hasher { int a[3]; hasher(int x = 0) { a[0] = a[1] = a[2] = x; } friend hasher operator+(const hasher &a, const hasher &b) { hasher res; for (int i = 0; i < 3; ++i) { r... |
#include <bits/stdc++.h> using namespace std; using nagai = long long; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int c = 0; int t = 1; while (t <= n) { n -= t, ++c, t *= 2; } if (n) ++c; cout << c << n ; retur... |
#include <bits/stdc++.h> using namespace std; const int NMAX = 200000 + 5; const int MMAX = 2000 + 5; const int INF = 1000000000; const int BS = 1000000000 + 7; const long long INFLL = 1000000000ll * 1000000000ll; const long double eps = 1e-6; int a[NMAX]; bool is_inverted[4 * NMAX]; bool shouldSetT... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long n, f1, f2, f3, c, ans, t1[3], t2[5], aa1[3][3], aa2[5][5], a1[3][3] = {{0, 0, 1}, {1, 0, 1}, {0, 1, 1}}, a2[5][5] = {{0, 0, 1, 0, 0}, {1, 0, 1, 0, 0}, {0, 1, 1, 0, 0}, ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0, x, y, z, cnt = 0; string s; set<long long> zero, one; se... |
#include <bits/stdc++.h> using namespace std; int n; string s; long long int a[101]; long long int dp[101][101][101]; long long int f(int start, int end, int l) { if (start > end) { return 0; } if (start == end) { return a[l]; } if (dp[start][end][l] != 0) { return dp[s... |
#include <bits/stdc++.h> using namespace std; const int maxn = 103, maxm = 1003; int m, n, ar[maxn]; double dp[maxn * maxm], pre[maxn * maxm]; int main() { scanf( %d%d , &n, &m); if (m == 1) { printf( 1 ); return 0; } int sum = 0; for (int i = 1; i <= n; i++) scanf( %d , &ar[i]... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n, 0); vector<long long> pos(32, 0); for (long long i = 0; i < n... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, t, piles = 1; bool flag = true; cin >> n; vector<int> s1, s2; vector<int>::iterator it; for (i = 0; i < n; i++) { cin >> t; s1.push_back(t); } sort(s1.begin(), s1.end()); while (flag) { flag = ... |
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int M = 1 << 16; bitset<N> mp[M]; int a[N], sum, rk[N], k, n; priority_queue<pair<int, int> > que; void dfs(int s, int t) { if (s == 0) return; int r = 0; for (; t * k < N && mp[s][t * k]; r++, t *= k) { } for (int... |
#include <bits/stdc++.h> using namespace std; struct edge { int u; int v; int c; }; bool compare(edge e, edge u) { return e.c < u.c; } int findparent(int parent[], int u) { int p = parent[u]; if (p == u) { return p; } int fp = findparent(parent, p); if (p == fp) { r... |
#include <bits/stdc++.h> using namespace std; long double f[400][3100], p[400][3100], ans; int n, m, up[400]; void dp(int i) { int j; long double pre, nw; pre = f[i][0]; f[i][0] = 0; for (j = 1; j <= n; j++) { nw = f[i][j]; f[i][j] = pre * p[i][j] + f[i][j - 1] * (1 - p[i][j]); ... |
#include <bits/stdc++.h> using namespace std; int a[1010], seq[1010], id; int qtes, u[1000010], v[1000010]; inline void add(int x, int y) { a[y] -= a[x], a[x] *= 2, u[++qtes] = x, v[qtes] = y; } inline void Solve(int x, int y, int z) { int q[3] = {x, y, z}; register int i, j; for (i = 0; i <... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MAXN = 1e5 + 10; const int MAXK = 5 + 1; long long sumv[MAXK][MAXN << 2], setv[MAXN << 2]; long long prefix[MAXK][MAXN], C[MAXK][MAXK]; void Pushdown(int o, int lft, int rht) { if (setv[o] != -1) { setv[(o << 1)] = ... |
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &item) { out << ( << item.fi... |
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, dst, cur; int main() { cin >> m >> n >> k; dst = n + m + 34; for (int i = 0; i < k; i++) { cin >> x >> y; cur = min(min(x - 1, y - 1), min(m - x, n - y)); dst = min(dst, cur); } if (dst < 5) cout << YES n... |
#include <bits/stdc++.h> using namespace std; long long ceil(long long a, long long b) { if (a % b == 0) return a / b; return a / b + 1; } int main() { long long n; int q; scanf( %lld %d , &n, &q); for (int j = 0; (j) < int(q); (j)++) { int x, y; scanf( %d %d , &y, &x); ... |
#include <bits/stdc++.h> using namespace std; const long long N = 100005, xian = (long long)1500000 * 1500000; long long q[N], ans[N], n; pair<long long, long long> a[N]; inline long long cal(pair<long long, long long> x) { return x.first * x.first + x.second * x.second; } pair<long long, long long> s... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void gg(T &res) { res = 0; T fh = 1; char ch = getchar(); while ((ch > 9 || ch < 0 ) && ch != - ) ch = getchar(); if (ch == - ) fh = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 0 ,... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long INF = 1e12; vector<long long> ans[200010]; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const int INF = 0x7ffffff; const int MOD = 1e9 + 7; int a[MAXN + 17], b[MAXN + 17], id[MAXN + 17]; bool cmp(int c, int d) { return a[c - 1] > a[d - 1]; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]... |
#include <bits/stdc++.h> using ll = long long; const int N = 5e5 + 5; using namespace std; int n, m, k; vector<int> build_kmp(string s, string t, bool check = false) { vector<int> t_match(((int)t.size()) + 1, 0); for (int i = (2); i <= (((int)t.size())); ++i) { int c = t_match[i - 1]; whil... |
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; long long int INF = 1e18; long long int power(long long int base, long long int exp) { long long int res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base); base = (base * base); exp /= 2; } ret... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(m); int cnt = 0, ma = 0; for (int i = 0; i < m; ++i) { cin >> a[i]; cnt += a[i]; ma = max(ma, a[i]); } if (cnt < n || 2 * (cnt - ma) < n || (n % 2) && m <= 2) { cout ... |
#include <bits/stdc++.h> using namespace std; long long n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC; cin >> TC; while (TC--) { map<char, int> mp; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (mp[s[i]] <= 1)... |
#include <bits/stdc++.h> using namespace std; int main() { setlocale(LC_ALL, RUS ); double r; cin >> r; for (double x = 1; x <= 9; x++) { double y = ((r - 1) / (2 * x)) - ((x + 1) / 2); if (y == (long long)y && y > 0) { cout << x << << fixed << setprecision(0) << y; ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const long long MAXN = 600010; const long long INF ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int indexp = INT_MAX, indexr = INT_MAX; int arr[n], brr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; i... |
#include <bits/stdc++.h> long long num_div(long long x, long long limit) { long long ans(0); for (long long i = 1; i <= sqrt(x); ++i) { if (!(x % i)) { if (i > limit && i * i == x) ans++; else { if (i > limit) ans++; if (x / i > limit) ans++; } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int N; vector<pair<int, int> > ans; vector<int> E[maxn]; void go(int i, int t) { ans.push_back({i, t}); } void dfs(int i, int p, int t) { go(i, t); int d = (t < E[i].size()); if (!d) t -= E[i].size(), go(i, t); for (aut... |
#include <bits/stdc++.h> using namespace std; long long a[200000 + 5], b[200000 + 5], vis[200000 + 5]; int main() { long long i, j, k; long long n, m; long long o = 0, minx = 10005, s = 0; scanf( %I64d , &n); for (i = 0; i < n; i++) { scanf( %I64d , &m); if (m % 2 == 0) s +... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.