func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 998244353; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vec... |
#include <bits/stdc++.h> using namespace std; bool checkbitt(long long int num, int pos); long long int setbitt(long long int num, long long int pos); long long int resetbitt(long long int num, int pos); const long long int mod = 1e9 + 7; const long long int N = 1e6 + 10; long long int count(long long int... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; const int N = 2e5 + 5; const double pi = acos(-1); int t; int main() { cin >> t; while (t--) { int n, m; cin >> n >> m; if (n % m == 0) cout << YES << n ; else cout << NO << n ; ... |
#include <bits/stdc++.h> using namespace std; int n, ans = 1e9; vector<vector<int> > cnt(65); vector<set<int> > ed; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; ed.resize(n + 1); bool tw = false; for (int i = 0; i < n; i++) { long long a; cin >> a; int ... |
#include <bits/stdc++.h> using namespace std; const long long INF64 = 1e18 + 1337; const int INF32 = 1e9 + 228; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, s; cin >> n >> s; vector<long long> a(n); long long sum = 0; ... |
#include <bits/stdc++.h> using namespace std; int n; pair<long long, long long> P, d[100000]; double rm, rM; int main() { scanf( %d%I64d%I64d , &n, &P.first, &P.second); for (int i = 0; i < n; i++) { pair<long long, long long> Q; scanf( %I64d%I64d , &Q.first, &Q.second); double t = (... |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << ( << p.first << , << p.second << ) ; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int i, j, k, n, m, vis[maxn], cnt, Q[maxn], top; void dfs(int now) { vis[now]++; if (!vis[now * 2 % n]) dfs(now * 2 % n); if (!vis[(now * 2 + 1) % n]) dfs((now * 2 + 1) % n); Q[++top] = now; } int main() { cin >> n; ... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > getfac(long long int n) { vector<pair<long long int, long long int> > ret; for (long long int i = 1; i < sqrt(n) + 1; i++) { if (n % i == 0) { ret.push_back({min({i, n / i}), max({i, n / i})}); } ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = (2e5 + 42); const int MAXLOG = 20; const int64_t inf = (int64_t)1e18; int n, m, S; vector<pair<int, int> > G[MAXN]; void read() { cin >> n >> m >> S; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; G[u]... |
#include <bits/stdc++.h> int main() { int n, ce = 0, co = 0, A[100], i, o = 0, e = 0; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &A[i]); for (i = 0; i < n; i++) { if (A[i] % 2 == 0) ce++; if (A[i] % 2 != 0) co++; } if (co == 1) { for (i = 0; i < n; i++) { if... |
#include <bits/stdc++.h> using namespace std; long long c[(1 << 20)]; struct SuffixTree { int s[(1 << 20)]; map<int, int> to[(1 << 20)]; int len[(1 << 20)] = {(1 << 30)}, fpos[(1 << 20)], link[(1 << 20)], id[(1 << 20)]; int node, pos, sz = 1, n = 0; int make_node(int p, int l... |
#include <bits/stdc++.h> using namespace std; int n; long long a[100000], b[100000]; vector<pair<int, long long>> connections[100000]; pair<long long, long long> needed(int node) { long long temp = a[node] - b[node]; long long temp2 = temp / 1000000007; temp %= 1000000007; for (const pair<int,... |
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0}; int dy[] = {0, 0, 1, -1, 0, 0, 0, 0}; const int inf = 1000000000; const double eps = 0.000000009; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; multiset<long long> s; long long now = 0; for (int i = 1; i <= n; i++) { long long a; cin >> a; a -= i; s.insert(a); s.insert(a); now -= a;... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; int n, m; int u[N], v[N]; vector<int> G[N]; bool check(int m) { for (int i = 1; i <= n; ++i) G[i].clear(); vector<int> in(n + 1, 0); fo... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 1e9; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; int a[n][m], b[n][m]; vector<int> col[n + m], col2[n + m]; in... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; int p[N]; pair<int, int> v[N]; void solve(int nx, int nnx) { int curr = 1; for (int i = 1; i <= n; i++) p[i] = 0; p[curr] = nx; p[nx] = nnx; curr = nx; bool okay = true; for (int i = 2; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int tmp = 3; int x = 1, y = 2; int n; cin >> n; bool flag = true; for (int i = 1; i <= n; i++) { int q; cin >> q; if (q == tmp) { flag = false; } if (q == x) swap(tmp, y); else ... |
#include <bits/stdc++.h> using namespace std; template <typename...> static inline int getchar_unlocked(void) { return getchar(); } template <typename...> static inline void putchar_unlocked(int c) { putchar(c); } void reader(int& x) { int k, m = 0; x = 0; for (;;) { (k) = getc... |
#include <bits/stdc++.h> using namespace std; int p[1000005]; int fnd(int x) { return p[x] = p[x] == x ? x : fnd(p[x]); } void unn(int x, int y) { p[fnd(y)] = fnd(x); } int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; } int pq[5144]; vector<in... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 305; const long long mode = 1e9 + 7; const long long maxm = 1e5 + 10; long long n, q, t, w[maxn], fa[maxn], nw[maxn], dp[maxm], son[maxn], z[maxn], cur, ww[maxn]; long long u, v; signed main() { cin >> n >> q >> t; for (lon... |
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T modMul(T a, T b, T m) { T x = 0, y = a % m; while (b > 0) { if (b % 2 == 1) x = (x + y) % m; y = (y * 2) % m; b /= 2; } ret... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; int N, M, S; vector<pair<int, int> > b; vector<pair<pair<int, int>, int> > s; vector<pair<int, int> > b2; vector<pair<pair<int, int>, int> > s2; int ans[MAX_N + 1]; priority_queue<pair<int, int>, vector<pair<int, int> >, ... |
#include <bits/stdc++.h> using namespace std; bool yes; int t, n, m, len, l, sender[105]; map<string, int> msi; map<int, string> mis; string str, user[105], text[105]; set<int> mention[105]; int ans[105]; int dp[105][105]; char c; bool solve(int pos, int idx) { if (pos == m) return 1; if (... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), b(n); for (auto &it : a) cin >> it; for (auto &it : b) cin >> it; int mna = *min_element(a.begin(), a.end()); int mnb = *min_element(b.be... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1050; int s[maxn][maxn]; int main(int argc, char const *argv[]) { int n, a, b; cin >> n >> a >> b; if (a != 1 && b != 1) { printf( NO n ); return 0; } if (n == 1) { printf( YES n0 n ); return 0; } ... |
#include <bits/stdc++.h> template <typename T> T power(T x, T y, T mod) { T res = 1; while (y > 0) { if (y & 1) res = (res * x) % mod; y /= 2; x = (x * x) % mod; } return res; } using namespace std; long long int a[2005][2005]; long long int d1[4005]; long long int d2[400... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; if (tmp % 2) cout << tmp << ; else cout << tmp - 1 << ; } cin.get(); cin.get(); } |
#include <bits/stdc++.h> using namespace std; int n, a[1005], b[1005]; int main() { bool same = 1; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d%d , a + i, b + i); same &= a[i] == b[i]; } if (!same) { puts( rated ); return 0; } for (int i = 2; i <= n... |
#include <bits/stdc++.h> using namespace std; long long fpow(long long x, long long y, long long m) { long long temp; if (y == 0 || x == 1) return 1; temp = fpow(x, y / 2, m); if (y % 2 == 0) return ((temp) * (temp)) % m; else return (((x) % m) * ((temp * temp) % m)) % m; } long ... |
#include <bits/stdc++.h> int main() { char c, str[100]; int i; scanf( %c , &c); getchar(); gets(str); if (c == L ) { for (i = 0; i < strlen(str); i++) { if (str[i] == q ) { str[i] = w ; } else if (str[i] == w ) { str[i] = e ; } else if (st... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ... |
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long m = 1000000007) { a %= m; long long res = 1; while (b) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } long long bpow(long long a, long long b) { l... |
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <class T1, class T2> void sortPair(vector<T1> &v1, vector<T2>... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { char c; bool nega = 0; while ((!isdigit(c = getchar())) && (c != - )) ; if (c == - ) { nega = 1; c = getchar(); } x = c - 48; while (isdigit(c = getchar())) x = x * 10 + c -... |
#include <bits/stdc++.h> using namespace std; int mark[111111]; int a[111111]; int b[111111]; int n; int noEle, cnt; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n + 1); for (int i = 1; i <= n; i++) { if (b[i] != a[i]) ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, t = 2; cin >> n; string s; cin >> s; for (int i = 0; i < n;) { cout << s.at(i); i += t; t++; } cout << endl; } |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; struct Point { int x, y; Point(int x_ = 0, int y_ = 0) : x(x_), y(y_) {} Point(std::istream &in) { in >> x >> y; x *= 2; y *= 2; } }; bool operator<(const Point &a, const Point &b) { return (a.x < b... |
#include <bits/stdc++.h> using namespace std; int main() { int i, j, w, h; char a[101][101]; cin >> w >> h; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { char x; cin >> x; a[j][i] = x; } } for (j = 0; j < w; j++) { for (int k = 0; k < 2; k++) {... |
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) const int N = 1e6 + 10, mod = 998244353; const double eps = 1e-7; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int mul(int a, int b) { return (l... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 0.00000001; void pr() { cout << endl; } template <typename T1, typename... T2> void pr(const T1& arg, const T2&... args) { cout << arg << ; pr(args...); } const int N = 5e5 + 10; vector<int> v[N], m... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; map<int, set<pair<int, string>, greater<pair<int, string> > > > mp; for (int i = 0; i < n; i++) { string s; int a, b; cin >> s ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3fffffff; const long long oo = 3000000000000000000LL; int tes, n; long long ans[3], mn[4], mx[4], ll[4], rr[4], lt[4], rt[4], ret[3]; bool get(long long s, long long x, long long y, long long z) { if (s <= x) { ret[0] = s; ret[1... |
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, c; cin >> n; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == s[i + 1] && i != s.size() - 1) { c += 1; } } cout << c; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, i, j, arr[1005] = {0}; cin >> n >> m; for (i = 1; i <= m; i++) { cin >> a >> b; arr[a] = 1; arr[b] = 1; } for (i = 1; i <= n; i++) { if (arr[i] == 0) break; } cout << n - 1 << endl; for... |
#include <bits/stdc++.h> using namespace std; struct block { string str; int pos; }; static bool compare(block b1, block b2) { int n = b1.str.length(); for (int i = 0; i < n; i++) { if (b1.str[i] != b2.str[i]) { if ((i + 1) % 2) { return (b1.str[i] < b2.str[i]); }... |
#include <bits/stdc++.h> using namespace std; double ans[3], temp[3]; int a[200200]; int n; bool f(double d) { double x = 0; int cnt = 0; for (int i = 0; i < n; i++) { if (x < a[i]) { if (cnt == 3) return false; x = a[i] + 2 * d; temp[cnt++] = a[i] + d; } } ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 3e6; const double eps = 0.00000001; long long ksm(long long a, long long n) { long long ans = 1; while (n) { if (n & 1) ans = ans * a % mod; a = a * a % mod; n >>= 1; } return ans; } i... |
#include <bits/stdc++.h> /*#include <iostream> #include <algorithm> #include <math.h> #include <iomanip> #include <string> #include <vector> #include <set> #include <sstream>*/ #define ll long long #define fop(i,m,n) for(int i=m; i<n; i++) #define fastIO ios::sync_with_stdio(0), cin.tie(0), cou... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline void add(int& x, int y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } inline int mul(int x, int y) { return ((long long)x * y) % mod; } int gcd(int a, int b) { if (b) return gcd(b, a % b); return ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 10; const ll inf_ll = 1e18 + 10; template <ll M> struct modint { static ll reduce(ll n) { constexpr static ll b = -1ull / M; ll r = n - (ll)(__uint128_t(b) * n >> 64) * M; return r >= M ? r - M : ... |
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> P(N); for (long long i = 0; i < N; i++) { cin >> P[i]; } sort(P.begin(), P.end()); long long min = P[0], vid = 0; for (long long i = 1; i < P.size(); i++) { if ((P[... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long long INFLL = (long long)1e16; const int MOD = (int)1e9 + 7; template <typename T> void out(T x) { cout << x << endl; exit(0); } bool bysec(const pair<int, int> &a, const pair<int, int> &b) { return a.second < ... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); string s; cin >> s; long long i = 0; while (i + 1 < s.size() && s[i] == s[i + 1]) { if (s[i] == 0 ) { cout << 3 << << 1 << n ; cout << 1 << << 1 <... |
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if (x > y) { int t = x; x = y; y = t; } cout << x << << (y - x) / 2 << endl; } |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; string s; int main() { cin >> s; int i = 0, cnt = 0; int len = s.size(); while ((i = s.find( VK )) != -1) { s[i] = s[i + 1] = . ; cnt++; } if (s.find( VV ) != -1 || s.find( KK ) != -1) cnt++; printf( %d... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double PI = acos(-1.0); int a[100005], s[100005], dp1[100005], dp2[100005], b[100005], ans[100005]; int main() { int n, i, maxlen, k; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]), b[n - i + 1] = -a[i]; ... |
#include <bits/stdc++.h> using namespace std; int n, m, q, tot, rec[100010], cnt[100010][360], num[360], Limit, W, tmp[100010]; long long delta[360], sum[360], a[100010]; struct Set { int k, l, r; } s[100010]; long long AskBig(int now) { int pos = tmp[now]; long long ans = sum[pos]; fo... |
#include <bits/stdc++.h> using namespace std; int n, x; string case1[3] = { >.v , >.. , ^.< }, case2[5] = { >>>.v , >>.vv , .>..v , ^^.<. , ^.<<< }; int main() { cin >> n >> x; if (n == 5 && x == 5) { for (int i = 0; i < 5; i++) cout << case2[i] << endl; cout << 1 << << 1;... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 5; long long n, a[maxn], dp[maxn][2], f[maxn][2], d[maxn]; long long head[maxn], ecnt; struct edge { long long to, next; } e[maxn << 1]; void adde(long long u, long long v) { e[++ecnt].to = v; e[ecnt].next = head[u]; ... |
#include<bits/stdc++.h> #define FOR(i,a,b) for( int i=(a); i<(b); ++i) #define REP(i,a,b) for( int i=(a); i<=(b); ++i) #define SHOW(x) for(auto i:(x)){ cout << i << ;} cout << endl; #define MAXN 25 using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef vector<int> VI; void... |
#include <bits/stdc++.h> using namespace std; const int N = 2000000 + 77, Mod = 1000000007, L = 30; int n, m, k, dp[N], T[L], P[N], Ps[N], SS[L]; char S[N]; int main() { scanf( %d %d , &n, &k); scanf( %s , S + 1); m = strlen(S + 1); dp[0] = Ps[0] = 1; for (int i = 1; i <= m; ++i) { P... |
#include <bits/stdc++.h> using namespace std; unordered_map<string, int> mp; char ans[2][1005]; bool x[5005]; int oprd[2][5005]; char orig[5005][1005]; char op[5005][20]; char input[4][1005]; char line[4 * 1005]; int main() { int n, m; while (scanf( %d%d , &n, &m) != EOF) { mp.clear()... |
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const int maxn = 500050; const int mod = 1e9 + 7; using namespace std; int main() { ios::sync_with_stdio(0); int n, a, b; cin >> n >> a >> b; int c = 0, ans = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == ... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 2; string s; long long n; long long func(vector<long long> a) { stack<long long> st; long long max_ = 0; for (long long i = 0; i < n; i++) { while (!st.empty() && a[i] > st.top()) { long long cur = st.top(); ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 1; i <= 400; i++) s += to_string(i); int n; cin >> n; cout << s[n - 1]; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, b, g, ans = 0; cin >> b >> g >> n; if (n < b && n < g) ans = n + 1; else if (n < b && n > g) ans = g + 1; else if (n < g && n > b) ans = b + 1; else { ans = min(b, g) + 1 - (n - max(b, g)); } co... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkMin(T &a, T b) { if (b < a) a = b; } template <typename T> inline void checkMax(T &a, T b) { if (a < b) a = b; } const int P = 1e7 + 19; const int Q = 1e9 + 7; const int MAX_N = 5005 + 30000; int n, k, w[M... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < 0 || _tc > 9 ) && _tc != - ) _tc = getchar(); if (_tc == - ) _tc = getchar(), _tmp = -1; while (_tc >= 0 && _tc <= 9 ) _x... |
#include <bits/stdc++.h> using namespace std; long long dp[10000006]; int main() { long long n, x, y; scanf( %lld%lld%lld , &n, &x, &y); for (int i = 0; i <= n; ++i) dp[i] = 1e18 + 100; dp[1] = x; for (int i = 2; i <= n; ++i) { if (i % 2 == 1) dp[i] = min(dp[i - 1] + x, min(dp[i ... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n, t = 0, a[6], d1, d2, d3, d4, s1, s2; cin >> m >> n; char s[m][n]; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) { cin >> s[i][j]; if (s[i][j] == * ) { a[t] = i; a[t + 1] = j; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long tot = n * (n + 1) / 2, zr = n - m, gr = m + 1; long long k = zr / gr, ans = 0; if... |
#include <bits/stdc++.h> using namespace std; long long fp(long long n, long long p) { if (p == 0) return 1; if (p == 1) return n; long long res = fp(n, p / 2) % (long long)(1e9 + 7); res = ((res) * (res)) % (long long)(1e9 + 7); if (p % 2) res = (res * n) % (long long)(1e9 + 7); return res;... |
#include<bits/stdc++.h> using namespace std; #define int long long int #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pii pair<int,int> #define F first #define S second #define pb push_back const int mod1=998244353,mod2=(int) 1e9+7; int power(int n,int k,int mod){int... |
#include <bits/stdc++.h> using namespace std; struct qnode { int id; long long val; bool operator<(qnode b) const { return val > b.val; } }; queue<int> qu[200100]; int w[200100], vis[200100], add[200100]; int n, m, Q, opt, x, y, z; long long dis[200100]; priority_queue<qnode> q; vector<pai... |
#include <bits/stdc++.h> using namespace std; const int N = 2019, mod = 998244353; int n, m, ans, f[N << 1][N], g[N << 1][N]; int qpow(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod, b >>= 1; } return ret; } int main() { s... |
#include <bits/stdc++.h> using namespace std; const int N = 4040; int dp[N][N]; int n, m; int main() { while (scanf( %d%d , &n, &m) != EOF) { int i, j; memset(dp, 63, sizeof(dp)); memset(dp[0], 0, sizeof(dp[0])); int ret = 0; for (i = 1; i <= n; i++) { int x, y; ... |
#include <bits/stdc++.h> using namespace std; const long long LINF = 0x3f3f3f3f3f3f3f3f; const long long NLINF = 0xf7f7f7f7f7f7f7f7; const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7; const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9; const int N = 2e5 + 10; int n, freq[30], mark[30]; vector<char> odd, ch; char s[... |
#include <bits/stdc++.h> #pragma GCC target( pclmul ) using ul = std::uint32_t; using ull = std::uint64_t; using li = std::int32_t; using ll = std::int64_t; using llf = long double; using uss = std::uint8_t; const ul tau = 15; const ul fib[] = { 1, 1, 2, 3, 5, 8, ... |
#include <bits/stdc++.h> const int N = 1e5 + 1; const int INF = 1e9 + 9; int n; int d[N]; std::vector<int> a[N]; int dfs(int v) { for (int u : a[v]) { d[v] += dfs(u); } if (d[v] == 0) return d[v] = 1; return d[v]; } int main() { scanf( %d , &n); for (int i = 1; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; int n, m, n1, m1; double dp[1002][1002], ans, c[1003][1003]; int main() { scanf( %d %d , &n, &m); scanf( %d%d , &n1, &m1); if (n == n1) ans = 0.000000; else if (m == 1) dp[n1][m1] = 2 * (n - n1); else { for (int i = n - 1; i >= ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (x > y) swap(x, y); if (x <= 0) return y; if (y % x == 0) return x; return gcd(y % x, x); } int main() { vector<long long> a; long long b[400000]; bool c[400000]; for (long long i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; struct outgoing { long long wt = INF, to = -1; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; vector<long long> stations; vector<pair<long long, long long>> connections; ... |
#include <bits/stdc++.h> using namespace std; vector<char> v; vector<char> vv; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char s[3][3], ss[3][3]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) cin >> s[i][j]; for (int i = 0; i < 2; i++) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n / 2; i++) { cin >> a[i]; } sort(a, a + n / 2); int bb = 0, cc = 0; for (int i = 0; i < n / 2; i++) { bb += abs(a[i] - (i * 2 + 1)); cc += abs(a[i] - (i * 2 + ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; const long long mod = 1e9 + 7; const long long INF = 1e18 + 10; int main() { long long n, m, i; string s; cin >> n; while (n--) { cin >> m >> s; if (s.size() < 11) cout << NO n ; else { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, mod = 1000000007, INF = 1e9 + 7; const int block = 316; int n, k, type[N], a[N], m, cnt[N * 3], l[N][5]; long long ans, res[N], p[N][5]; set<long long> s; map<long long, int> conv; struct query { int l, r, id, num; query(){}; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; const int MAXQ = 3e5 + 5; const int inf = 0x3f3f3f3f; struct Query { int id, l, r; Query(void) {} Query(int _id, int _l, int _r) : id(_id), l(_l), r(_r) {} }; long long res[MAXQ]; struct Solver { vector<int> a, b; ... |
#include <bits/stdc++.h> using namespace std; long long A[300010], B[300010]; int n, m; struct node { int negpos, negpos_pref, negpos_suf, neg, neg_pref, neg_suf, pos, pos_pref, pos_suf, len; node() { negpos = negpos_pref = negpos_suf = neg = neg_pref = neg_suf = pos = pos_pref =... |
#include <bits/stdc++.h> using namespace std; int a[110], b[110], cnt, n; map<int, int> mp; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { int num; scanf( %d , &num); if (!mp[num]) { mp[num]++; b[cnt++] = num; } } sort(b, b + cnt); if (cn... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int ans = 15; for (int i = 0; i < n; i++) { if (s[i] == 0 ) ans &= 8; if (s[i] == 1 || s[i] == 2 || s[i] == 3 ) ans &= 7; if (s[i] == 1 || s[i] == 4 || s[i] == 7 ) ans &= 13; ... |
#include <bits/stdc++.h> using namespace std; set<string> normal; set<string> grumpy; void build_normal() { normal.insert( great! ); normal.insert( don t think so ); normal.insert( don t touch me ); normal.insert( not bad ); normal.insert( cool ); } void build_grumpy() { grumpy.inser... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 100010; int dp[550][550], A[550], B[550], path[550][550], n, m; bool print(int x) { if (!x) return false; if (print(path[n][x])) printf( %d , B[x]); else printf( %d , B[x]); return true; }... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; void solve() { long long n; cin >> n; vector<long long> a(n); for (long long &i : a) cin >> i; unordered_map<long long, bool> m; for (int i = 0; i < n; i++) { long long sum = a[i]; for (int j = i ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, maxi = 0; cin >> n; std::stack<int> stk; for (int i = 0; i < n; ++i) { cin >> a; a %= 2; maxi = max(maxi, a); if (!stk.empty()) { if (stk.top() == a) stk.pop(); else stk.p... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b; long long c, nr = 0; for (a = 1; a <= n; ++a) { for (b = a; b <= n; ++b) { c = sqrt(a * a + b * b); if (c * c == a * a + b * b && c >= b && c <= n) ++nr; } } cout << nr; ... |
#include <bits/stdc++.h> using namespace std; void fastIO() { ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); cout.tie(nullptr); cin.tie(nullptr); } template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N, P - 1); } template <class T> ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T alex(T x) { return (x > 0) ? x : -x; } template <class T> void read(T& x) { x = 0; T f = 1; char ch = getchar(); while ((ch < 48 || c... |
#include <bits/stdc++.h> using namespace std; string s, ss; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> s; ss = s; reverse(ss.begin(), ss.end()); cout << s + ss; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.