func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; char a[502][502]; int n, m; int ds[502][502][251]; int dfs(int i, int j, int x, int y, int st) { if (i > x || j > y) { return 0; } if (a[i][j] == * || a[x][y] == * || a[i][j] != a[x][y]) { return 0; } if (ds[i][x][st] != -1) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string vowel = AEIOUYaeiouy ; string in; char s; bool x = false; getline(cin, in); int h = in.size(); for (int k = (h - 1); k >= 0; k--) { if (isalpha(in[k])) { s = in[k]; break; } } for (int ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const long double eps = 1e-7; const long long inf = numeric_limits<long long>::max() / 2 - 1; const long long mod = 1000000007; const long long maxn = 800007; struct plan { long long l1, r1; long long l2, r2;... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-5; const int MOD = int(1e9) + 7, MX = int(5e4) + 1; long long memo[100][3001][2]; int n, l; pair<int, int> A[101]; long long dp(int i, int len, int f) { if (len == l) return 1; if (i == n || len > l) return 0; long long &ret =... |
#include <bits/stdc++.h> using namespace std; const int nmax = 110; char s[nmax]; bool pal(int n) { int i; for (i = 0; i <= (n - 1) / 2; i++) if (abs(s[i] - s[n - i - 1]) > 2 || abs(s[i] - s[n - i - 1]) == 1) return 0; return 1; } int main() { int t, n, i; cin >> t; for (i = 1;... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; int n; vector<bool> b; vector<int> v; stack<int> st; bool fi; vector<bool> dins; void dfs(int u) { if (fi) return; if (b[u]) { if (dins[u]) { fi = true; v.push_back(u); while (!st.empty() and st... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int* degree = new int[100005]; for (int i = 1; i <= n; i++) { degree[i] = 0; } while (m--) { int a, b; cin >> a >> b; degree[a]++; degree[b]++; } int deg1 = 0, deg2 = 0, ... |
#include <bits/stdc++.h> using namespace std; long long N, M, x, y, K, ml, T, ans; long long f[1000000], s[1000000]; const long long md = 1e9 + 7; const long long MAXN = 1e5 + 2; string in; int main() { cin >> N >> K; f[0] = 1; for (int i = 1; i <= MAXN; i++) { f[i] = f[i - 1]; if ... |
#include <bits/stdc++.h> using namespace std; vector<int> vec[201], v[201]; int afis[201], scor[201], n, test[201]; bool viz[201]; void elim(int val) { for (int i = 0; i < v[val].size(); i++) scor[v[val][i]]--; } bool incearca(int start) { int i, j; for (i = 1; i <= n; i++) { scor[i] = v... |
#include <bits/stdc++.h> using namespace std; const int maxN = 1e6 + 5; int n, x, y, ile[4 * maxN]; long long pref[4 * maxN], mini = 1e18; bool czy = 0; long long spr(long long x, long long y) { long long t; if (__builtin_smulll_overflow(x, y, &t)) czy = 1; return x * y; } int main() { i... |
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; while (y--) { res *= x; } return res; } void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } bool sortbysec(const pair<long long, long lo... |
#include <bits/stdc++.h> using namespace std; const int LIMIT = 20; int n, dep[300001]; vector<int> adj[300001]; int dp[300001][LIMIT], dp2[300001][LIMIT]; void dfs(int x, int pre) { vector<int> child; for (auto y : adj[x]) { if (y != pre) { dfs(y, x); child.push_back(y); ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, a; cin >> n; long long A[n]; for (long long i = 0; i < n; i++) { cin >> a; A[i] = a; } long long sum = 0, odd = 0, small = 1000000009; for (long long i = 0; i < n; i++) { if (A[i] % 2 != 0) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 2005500; struct state { int len, link; map<char, int> next; }; state st[N]; int sz, last; void sa_init() { last = st[0].len = 0; sz = 1; st[0].link = -1; } void sa_extend(char c) { int k = sz++, p; st[k].len = st[l... |
#include <bits/stdc++.h> using namespace std; using ll = long long int; using vi = vector<ll>; using ii = pair<ll, ll>; int main() { ios::sync_with_stdio(false); int n; cin >> n; int mini = (int)1e9; vi v; for (int i = 0; i < n; i++) { int aux; cin >> aux; v.push_back... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const long long inf = 10000005; int nsize, root, n, tot, nedge, hed[maxn], father[maxn], maxson[maxn], sz[maxn], vis[maxn]; long long M, pw[maxn]; map<int, int> up[maxn], cst[maxn]; vector<int> dist[maxn], down[maxn]; struct Ed... |
#include <bits/stdc++.h> using namespace std; int main() { int h, n; cin >> n >> h; for (int i = 1; i <= n; i++) { if (i % 2 == 1) { for (int j = 1; j <= h; j++) { cout << # ; } } else { if ((i / 2) % 2 == 1) { for (int j = 1; j <= h - 1; j++) { ... |
#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; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } struct Dinic { struct edge { long long to, cap, rev; edge(long l... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-loops ) #pragma GCC target( avx2 ) using namespace std; const int maxn = 1e6 + 5; int n; bool used[maxn]; vector<int> v[maxn]; vector<int> g[maxn]; int ans[maxn]; int pr[maxn]; int t[4 * maxn]; void init() { used[0] = true; used... |
#include <bits/stdc++.h> using namespace std; int n, i, j, k, x, y, w, m, Q, used[100500], start; int a[100500], b[100500], c[100500]; vector<pair<int, int> > g[100500]; vector<int> f[1000500]; long long d[100500]; long long hea[200500]; int new_w[100500], new_d[100500]; int hea2[200500]; int st[100... |
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << = << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != , ) cerr << *sdbg++; cerr << = << h << , ; _dbg(sdb... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int test = 0; test < q; test++) { int a, b, c, d, k; cin >> a >> b >> c >> d >> k; int pen = (a - 1) / c + 1, pencil = (b - 1) / d + 1; if (pen + pencil > k) { cout << -1 << n ; } els... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 2; int t, n, m, U, V, sum, ans1, ans2; bool kt[maxn], ch[maxn]; struct T { int c, id; }; vector<T> a[maxn]; vector<int> s[maxn]; void Enter() { cin >> m >> n; for (int i = 1; i <= m; i++) { a[i].clear(); s[i].... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000; const long long INFLL = INF * INF; long long pot2[100]; vector<long long> czek_all(long long l, long long r, long long k) { vector<long long> wynik; long long x = r - l + 1; long long res = INFLL; for (int i = (1);... |
#include <bits/stdc++.h> #pragma GCC optimize( O2,unroll-loops ) using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int MAXN = 100010, LOG = 20; long long n, m, K, u, v, X, Y, t, a, b, ans, shit; long long A[MAXN], f[MAXN], g[M... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n, *p; cin >> m >> n; p = new int[m]; for (int i = 0; i < m; i++) cin >> p[i]; sort(p, p + m); cout << p[m - n] << endl; } |
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1ll; while (b > 0) { if (b % 2 != 0) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b /= 2; } return res % 1000000007; } long long ncr(long long n, long long k) { ... |
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long x; cin >> x; for (long long i = 1; i <= x; i++) { for (long long j = i; j <= x; j++) { if (j % i == 0 && i * j > x && j / i < x) { cout << j << << i << end... |
#include <bits/stdc++.h> using namespace std; const int N = 110000; long long init[N], tab[N * 2], ope[N][3], ch[N], h[N], num[N * 8], sum[N * 8], ans[N * 8], nn, ss, aa; bool ini[N * 2]; int sz = 0; inline void Update(int x, int l, int r) { if (l == r) return; int lc = (x << 1), rc = lc + 1; ... |
#include <bits/stdc++.h> using namespace std; int n; int tree[1000005 << 2]; int mn[1000005 << 2]; int mx[1000005 << 2]; int pos; char s[1000005]; void pushup(int rt) { tree[rt] = tree[(2 * rt)] + tree[(2 * rt + 1)]; mn[rt] = min(mn[(2 * rt)], tree[(2 * rt)] + mn[(2 * rt + 1)]); mx[rt] = max... |
#include <bits/stdc++.h> using namespace std; int f(long long x) { long long i, j, cnt = 0; for (i = 1; i <= x; i *= 2) { for (j = i; j <= x; j *= 3) cnt++; } return cnt; } int main() { int l, r; cin >> l >> r; cout << f(r) - f(l - 1); } |
#include <bits/stdc++.h> using namespace std; int prime[1000100]; void get_prime() { for (int i = 2; i < 1000100; i++) { if (!prime[i]) { for (int j = i * 2; j < 1000100; j += i) { prime[j] = i; } } } for (int i = 2; i < 1000100; i++) { if (!prime[i]) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, x; cin >> t; while (t--) { cin >> x; if (x % 2 == 0) { cout << x / 2 << << x / 2 << endl; } else { cout << 1 << << x - 1 << endl; } } } |
#include <bits/stdc++.h> using namespace std; string FILE_NAME = testcase.A ; string NAME; string itos(int n) { stringstream ss; ss << n; return ss.str(); } const int dx[] = {0, 1, 0, -1}; const int dy[] = {-1, 0, 1, 0}; bool is_right(vector<pair<int, int> > p) { vector<int> len2(3, 0);... |
#include <bits/stdc++.h> using namespace std; double const e = 0.000001; int main() { int n, a, d; cin >> n >> a >> d; int prevv = 10000000; double prevt = 0; for (int i = 0; i < n; i++) { int t, v; cin >> t >> v; double t1 = (double)v / a; double s1 = a * t1 * t1 / 2; ... |
#include <bits/stdc++.h> using namespace std; int n, d[333][333], k; int main() { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> d[i][j]; } } cin >> k; while (k--) { int a = 0, b = 0, c = 0; cin >> a >> b >> c; d[a][b] = min... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n; long long m; long long k; cin >> n >> m >> k; vector<long long> p(m); for (long long i = 0; i < m; ++i) { cin >> p[i]; } long long i = 0; long long r = ((p[0] + k - 1) ... |
#include <bits/stdc++.h> using namespace std; double f(double x, double A, double B, double L) { double y = sqrt(L * L - x * x); return (A * x + B * y - x * y) / L; } int main(void) { double A, B, L; scanf( %lf%lf%lf , &A, &B, &L); if (L <= B) { printf( %.8f n , min(A, L)); retur... |
#include <bits/stdc++.h> using namespace std; int main() { double d, l, v1, v2; scanf( %lf %lf %lf %lf , &d, &l, &v1, &v2); l -= d; v1 += v2; l /= v1; printf( %f , l); } |
#include <bits/stdc++.h> using namespace std; void run_case() { int n, k; cin >> n >> k; vector<int> A(n); for (int &a : A) { cin >> a; } vector<int> ans; for (int i = 1; i < n; i++) { ans.push_back(A[i - 1] - A[i]); } sort(ans.begin(), ans.end()); ; int res =... |
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; string final; long long int id = -1, count = 0, r = 0, l = 0; for (long long int i = 0; i < (long long int)s.length(); i++) { if (s[i] == # ) { id = i; count++; } if (s[i] == ( ) ... |
#include <bits/stdc++.h> using namespace std; vector<int> cost[4]; vector<vector<int> > G; void solve() { long long n, p, w, d; cin >> n >> p >> w >> d; for (long long y = 0; y < w; y++) { if (p < y * d) continue; long long wx = p - y * d; if (wx % w) continue; long long x = ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; const long long inf = 1e18; long long n; long long arr[20]; bool flag = false; void rec(long long i, long long s) { if (i == n + 1 && s % 360 == 0) flag = true; if (i > n) return; rec(i + 1, s + arr[i]); rec(i + 1,... |
#include <bits/stdc++.h> using namespace std; long long a[1000006], s[1000006]; int main() { ios_base::sync_with_stdio(false); long long n, i, j, k; string st; cin >> st; long long ln = st.size(); stack<long long> stk; for (i = 0; i < ln; i++) { if (st[i] == ( ) { stk.pu... |
#include <bits/stdc++.h> using namespace std; long long n, m, a[110][110], dp[110][110]; bool vis[110][110]; long long dfs(long long x, long long y, long long num) { if (a[x][y] < num) return (long long)3000000000000000000; if (x == n - 1 && y == m - 1) return a[x][y] - num; if (dp[x][y] != -1) retu... |
#include <bits/stdc++.h> using namespace std; long long aa; bool bb; char ch; long long scan() { while (ch = getchar(), (ch < 0 || ch > 9 ) && ch != - ) ; ch == - ? (bb = 1, aa = 0) : (bb = 0, aa = ch - 48); while (ch = getchar(), (ch >= 0 && ch <= 9 )) aa = aa * 10 + ch - 48; r... |
#include <bits/stdc++.h> int n, k, pos[1000005]; char s[1000005]; struct ac_automaton { int ch[1000005][26], fail[1000005], arr[1000005], cnt[1000005], totc; int fir[1000005], nxt[1000005], to[1000005], tot, in[1000005], out[1000005], block; void line(int x, int y) { nxt[++tot] = fir[x];... |
#include <bits/stdc++.h> using namespace std; const int maxn = (4000000) + 7; const int inf = (1e9) + 7; const long long LLinf = (1e18) + 7; const long long mod = 1e9 + 7; int main() { int n; scanf( %d , &n); n++; n /= 2; n--; printf( %d , n); return 0; } |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 5; const int mod = 1e9 + 7; const int N = 3 * 1e5 + 5; int n, c[N], maxOf[N]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> c[i]; maxOf[c[i]] = i; } int ... |
#include <bits/stdc++.h> using namespace std; const long long int M = 998244353; void solve() { long long int a; cin >> a; cout << ((a / 2) + 1) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; cin >> t; while (t--) solve(); } |
#include <bits/stdc++.h> const int MaxN = 300000; using namespace std; long long arr[MaxN + 5], a[MaxN + 5], n; struct Segment { int l, r, lx, mx, rx; int Sign(long long x) { return x > 0 ? 1 : -1; } void Update(Segment A, Segment B) { lx = A.lx, rx = B.rx; mx = max(A.mx, B.mx); if... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2.5e5 + 10; template <typename T> inline T read() { T ans = 0, flag = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) flag = -1; c = getchar(); } while (isdigit(c)) { ans = ans * 10 + (c - 48); ... |
#include <bits/stdc++.h> namespace XX { template <template <typename> class Compare, typename T> inline T& UP(T& x, const T& y) { if (Compare<T>()(y, x)) x = y; return x; } template <typename Compare, typename T> inline T& UP(T& x, const T& y, Compare comp) { if (comp(y, x)) x = y; return x;... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int aa[2010]; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , &aa[i]); sort(aa, aa + n); int p = n - 1; int ans = 0; while (p >= 0) { int temp = aa[p]; ans += (temp - 1) * 2; p -= k;... |
#include <bits/stdc++.h> int d[1000]; void Qsort(int, int); bool Checked(int, int); int main(int argc, char** argv) { char a[10000]; std ::cin >> a; int id = 0; int k = 0; while (a[k] != 0 ) { int num = 0; while ((a[k] != 0 ) && (a[k] != , )) { num = (num * 10) + (a[... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, vis[N]; int Log2[N], a[N], st[N][20], lim[N]; void pre() { Log2[1] = 0, st[1][0] = a[1]; for (int i = 2; i <= n; ++i) { Log2[i] = Log2[i - 1]; if (i == 1 << Log2[i - 1] + 1) Log2[i]++; st[i][0] = a[i]; }... |
#include <bits/stdc++.h> using namespace std; const int MAX_SIZE = 1e6 + 10, INF = 2 * 1e9, MAX_N = 7e3 + 5, MAX_K = 3e4 + 5; const long long SuperINF = 1e18; const double eps = 0.5, PI = 20 / 7; void files() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } int tests; in... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k, d1, d2; cin >> n >> k >> d1 >> d2; if (n % 3 != 0) { cout << no << endl; continue; } long long w1, w2, w3; bool flag = true; if (k - 2 * d... |
#include <bits/stdc++.h> using namespace std; int q; bool read() { if (scanf( %d , &q) < 1) { return 0; } return 1; } int get_dig(char c) { if ( 0 <= c && c <= 9 ) { return c - 0 ; } if ( a <= c && c <= f ) { return c - a + 10; } return -1; } unsign... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, sum = 0; scanf( %d , &n); int a[n]; for (i = 0; i < n; i++) { scanf( %d , &a[i]); } sort(a, a + n); for (i = 0; i < n; i++) { sum += a[i]; } printf( %d n , a[n - 1] * n - sum); return 0; } |
#include <bits/stdc++.h> using namespace std; template <class T> int len(const T &c) { return (int)c.size(); } template <class T> void cmin(T &a, T b) { if (b < a) a = b; } template <class T> void cmax(T &a, T b) { if (b > a) a = b; } vector<pair<int, int> > v; int main() { int n... |
#include <bits/stdc++.h> using namespace std; const int step[2] = {-1, 1}, mn = 101000; int n, m, xs, ys, kx, ky, x, y, fx, fy, cnt; long long ans; string st; set<int> T[mn]; void fix(int x, int y, int& fx, int& fy) { if (x == 1) fx = 1; else if (x == n) fx = 0; if (y == 1) f... |
#include <bits/stdc++.h> using namespace std; const int N = 10005; bool dp[N][2]; char s[N]; set<string> ans; inline bool ck(int x, int y) { bool same = true; for (int i = 0; x + i < y; ++i) { same &= s[x + i] == s[y + i]; } return !same; } int main() { scanf( %s , s); int ... |
#include <bits/stdc++.h> using namespace std; bitset<300000005> pr; int uke[20000005]; int anti_uke(int l, int r) { int ans = 0; for (register int i = 5; i <= r; i += 4) { if (i >= l && pr[i] == 0) ++ans; } if (l <= 2 && r >= 2) ++ans; return ans; } int main() { int l, r; s... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; char str[MAXN]; int main() { scanf( %s , str); int n = strlen(str); printf( 3 nL 2 nR 2 nR %d , 2 * n - 1); return 0; } |
#include <bits/stdc++.h> using namespace std; int prim[100000]; int main() { int a, b; cin >> a >> b; bool ok = false; int x = 0; for (int i = 3; i <= a; i++) { for (int j = 2; j < i / 2; j++) { if (i % j == 0) { ok = true; break; } } if (o... |
#include <bits/stdc++.h> using namespace std; const int MAX = 5e5 + 10, mod = 1e9 + 9, base = 41, INF = 1e9 + 10, sq = 502; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); long long n, b; cin >> n >> b; long long a[n]; for (long long i = 0; i < (n); ++i) cin >> a[i]; long lon... |
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const long long infLL = 9000000000000000000; template <typename first, typename second> ostream& operator<<(ostream& os, const pair<first, second>& p) { return os << ( << p.first << , << p.second << ) ; } template <typenam... |
#include <bits/stdc++.h> using namespace std; const int mm = 1111; struct point { double x, y; point() {} point(double _x, double _y) : x(_x), y(_y) {} } g[mm]; point MakeVector(point &P, point &Q) { return point(Q.x - P.x, Q.y - P.y); } double CrossProduct(point P, point Q) { return P.x * Q.y -... |
#include <bits/stdc++.h> using namespace std; int n; int a[200000 + 5]; int d[200000 + 5]; set<pair<int, int> > s; set<pair<int, int> >::iterator it; void djikstra() { int u, v; fill(d, d + n + 2, (int)100000000); d[1] = 0; s.insert(make_pair(d[1], 1)); while (!s.empty()) { it = ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; void sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; vector<int> v; vector<double> ... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const int N = 1e6 + 7; int tr[N][26], id[N], idx; char s[100007][1003], str[10007]; bool flag; int n, m, len[N]; int res[N], cnt; int trans(char c) { if (c >= A && c <= Z ... |
#include <bits/stdc++.h> int main() { int x, y; scanf( %d , &x); if ((x % 4 == 0) || (x % 7 == 0) || (x % 47 == 0) || (x % 74 == 0) || (x % 447 == 0) || (x % 474 == 0) || (x % 477 == 0) || (x % 744 == 0) || (x % 774 == 0) || (x % 747 == 0)) { printf( YES ); } else { printf(... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:200000000 ) using namespace std; const int cs = 0x186A1; const int up = 1001; int n, ans; int u[1005]; vector<int> p, s; int main() { for (int i = 2; i < up; i++) if (!u[i]) for (int j = i * i; j < up; j += i) u[j] = 1; for (... |
#include <bits/stdc++.h> using namespace std; signed main() { long long n, x, y; cin >> n >> x >> y; long long arr[n]; for (long long i = 0; i < n; i++) { cin >> arr[i]; } long long an = -1; for (long long i = 0; i < n; i++) { bool ans = true; for (long long j = i - 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int p = 0; char ch = 0 , var; pair<int, char> sam[4]; string str[4]; for (int i = 0; i < 4; i++) { cin >> str[i]; sam[i].first = str[i].size() - 2; sam[i].second = (char)65 + i; } sort(sam, sam + 4); if (sa... |
#include <bits/stdc++.h> using namespace std; int a[100], b[100], path[11]; int res; bool check(int pos, int l1, int l2) { if (pos == 0) { return 1; } if (!l1 && !l2) return 1; int l = l1 ? a[pos] : 0; int r = l2 ? b[pos] : 9; for (int i = l; i <= r; i++) { if (path[i]) { ... |
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> pri[3005]; long long ans; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { int par, mon; cin >> par >> mon; pri[par].push_back(mon); } for (int i = 1; i <= m; i++) sort(pri[i].begin(), pri[i].end());... |
#include <bits/stdc++.h> using namespace std; bool p(string s) { int n = s.length(); for (int i = 0; i < n / 2; i++) { if (s[i] != s[n - i - 1]) return 0; } return 1; } int main() { std::ios::sync_with_stdio(false); string s; cin >> s; int n = s.length(); for (char c = ... |
#include <bits/stdc++.h> using namespace std; int main() { void solution(); solution(); return 0; } struct item { int v; int i; }; bool operator<(item a, item b) { return a.v < b.v; } const int maxn = 200000; item a[maxn]; int c[maxn]; void solution() { int n; scanf( %i ,... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c, d, e; cin >> a >> b >> c >> d >> e; int f[5] = {a, b, c, d, e}, mn = a + b + c + d + e, ans = a + b + c + d + e; sort(f, f + 5); map<int, int> mp; fo... |
#include <bits/stdc++.h> using namespace std; long long int fast_exp(long long int base, long long int exp1) { long long int res = 1; while (exp1 > 0) { if (exp1 & 1) res = (res * base) % 1000000007; base = (base * base) % 1000000007; exp1 /= 2; } return res % 1000000007; } lon... |
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-12; const int N = 2067; int n, t; long double f[N][N], ft[N][N]; struct Node { int ss, sl, ts, tl; long double p; } node[N]; bool comp(Node c1, Node c2) { return c1.tl * (1 - c1.p) * c2.p < c2.tl * (1 - c2.p) * c1.p; ... |
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; using ll = long long; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1; char getc() { return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), ... |
#include <bits/stdc++.h> using namespace std; bool win(long long s, long long e) { if (e % 2 == 1) { return s % 2 == 0; } if (s > e / 2) { return s % 2 == 1; } if (s > e / 4) return true; return win(s, e / 4); } bool lose(long long s, long long e) { if (s >= e / 2 + 1) { ... |
#include <bits/stdc++.h> using namespace std; long long q1 = 1000000007, q2 = 100003; long long p1 = 1299827, p2 = 41; bool v[100009]; long long sp[100009]; void sieve() { for (long long i = 2; i < 100009; i += 2) sp[i] = 2; for (long long i = 3; i < 100009; i += 2) { if (!v[i]) { sp[i... |
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e9; long long max(long long a, long long b, long long c) { return max(a, max(b, c)); } long long n; long long house[200011]; long long mn[200011][2][2]; long long mx[200011][2][2]; long long f(long long i, long long j,... |
#include <bits/stdc++.h> using namespace std; int G[23][23], n, m; bool check() { for (int i = 1; i <= n; ++i) { int cnt = 0; for (int j = 1; j <= m; ++j) cnt += G[i][j] != j; if (cnt > 2) return false; } return true; } int main(int argc, char const *argv[]) { cin >> n >> m; ... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[100005]; map<int, int> mp; map<int, int> mp1; vector<int> rt; int c[100005]; bool vis[100005]; bool bfs(int nd) { int col = c[nd]; int fg = 0; queue<int> q; vis[nd] = true; q.push(nd); while (!q.empty()) { int no... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10, tsz = 5 * maxn, offset = 1e5; vector<int> graph[maxn]; int sz[maxn]; bool big[maxn]; int a[maxn], b[maxn]; long long dp[maxn]; struct Line { int m; long long c; } tree[tsz]; int Left[tsz], Right[tsz], idn = 1, tra... |
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; inline void solve() {} int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int lucky = 0; for (auto const &c : s) lucky += c == 4 || c == 7 ; bool is_lucky = lucky > 0; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-6; const int N = 1 << 17; char S[N], T[N]; int AS[N], AT[N], BS[N], BT[N]; int main() { cin >> (S + 1) >> (T + 1); int n = strlen(S + 1), m = strlen(T + 1); for (int i = 1... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, P, M, T; cin >> N >> P >> M >> T; deque<int> dq(N, 1); for (int x = 0; x < T; x++) { int typ, pos; cin >> typ >> pos; if (typ) { dq.push_back(1); ... |
#include <bits/stdc++.h> using namespace std; const int N = 100100; int segTree[N * 4], n, x, y, z, l, r, val; map<int, int> TMp, NMp; vector<pair<int, int>> vv; vector<int> v, numm[N]; struct Query { int type, tim, num, ind; }; Query q[N]; void update(int i, int j, int pos) { if (i > r || j... |
#include <bits/stdc++.h> using namespace std; const int maxn = 10001; vector<int> g[maxn]; int res; int color[maxn]; int vis[maxn]; void solve(int root, int c) { vis[root] = 1; if (color[root] != c) res++; for (int i = 0; i < g[root].size(); i++) { int to = g[root][i]; if (vis[to])... |
#include <bits/stdc++.h> using namespace std; struct node { node *arr[27]; int ind; node() { memset(arr, 0, sizeof arr); ind = 0; } }; const int N = 1e5 + 5; int dp[N][2]; node *root; int nodes = 0; void insert(string &s) { node *cur = root; for (int i = 0; i < s.size... |
#include <bits/stdc++.h> using namespace std; int px, py; int tx, ty; int decide(int x, int y, int x2, int y2) { px = tx; py = ty; px -= x; py -= y; x2 -= x; y2 -= y; int dis = x2 * py - y2 * px; return dis >= 0; } int main() { int n, d; cin >> n >> d; int ele; ... |
#include <bits/stdc++.h> using namespace std; const int cstMax = 1e6 + 100; const int cstAlphaSize = 26; char a[cstMax], b[cstMax]; int c[cstMax][cstAlphaSize]; long long getGcd(long long a, long long b) { long long r; while (b != 0) r = a % b, a = b, b = r; return a; } int main() { long... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; std::vector<long long> x0, x1, y0, y1; long long a[n][4]; for (long long int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2] >>... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.