func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int MAX = 2e6 + 5; const int MAXN = 7e6 + 5; const long long INF = 0x3f3f3f3f3f3f3f3f; int n, q, s, first[MAX], nextt[MAXN], u[MAXN], v[MAXN], cnt; long long w[MAXN]; void add(int a, int b, long long c) { u[cnt] = a, v[cnt] = b, w[cnt] = c; nextt... |
#include <bits/stdc++.h> using namespace std; long long q, n; string h; int main() { ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); cin >> q; while (q--) { cin >> n; if (n == 1) { cout << a n ; continue; } for (long long i = 1; i <= n / 2; i++) ... |
#include <bits/stdc++.h> using namespace std; long double mem[50 + 5][50 + 5][50 + 5]; long double fact[55]; vector<int> num; int n, p, L; long double dp(int sum, int idx, int cnt, int last) { if (sum > p || cnt > L) { return 0; } if (idx == n) { return (sum + num[last] > p && cnt + ... |
#include <bits/stdc++.h> using namespace std; int main() { int arr[4]; cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; sort(arr, arr + 4); if ((arr[0] + arr[3]) == (arr[1] + arr[2]) || (arr[0] + arr[1] + arr[2]) == arr[3]) { cout << YES << n ; } else { cout << NO << n ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int a[21], n; cin >> a[0] >> a[1] >> n; for (int i = 2; i <= n; i++) a[i] = a[i - 1] + a[i - 2]; cout << a[n]; return 0; } |
#include <bits/stdc++.h> using namespace std; bool check(string& a, string& b) { if (a.size() != b.size()) return false; int ind1 = -1, ind2 = -1; bool check = false; bool buck[26] = {0}; int count = 0; for (int i = 0; i < a.size(); i++) { if (a[i] != b[i]) { count++; i... |
#include <bits/stdc++.h> int ct, n, m, tct, cnt[540010], mp[540010], t[540010], a[50010][4], lmax = 27 * 27 * 27 * 27, B, pool[200010], *pt(pool), *v[540010], ans[70010][402]; char s[50010], x[10], y[10]; int nd(const char* st, const char* ed) { int res = 0; while (st != ed) res = res * 27 + (... |
#include <bits/stdc++.h> using namespace std; int main() { long long t = 1; while (t--) { string s; cin >> s; sort(s.begin(), s.end()); long long n = s.size(), ans = 0; long long l = 0, r = n - 1; while (l <= r) { long long m = l + (r - l) / 2; if (s[m] ==... |
#include <bits/stdc++.h> const int maxn = 1011; const int mod = 256; char str[maxn]; int main() { gets(str); int len = strlen(str); int sad = 0; for (int i = 0; i < len; i++) { int a[11] = {0}, j = 0, temp = 0; int c = str[i]; while (c) { a[j++] = c % 2; c /= 2;... |
#include <bits/stdc++.h> using namespace std; inline long long read() { register long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 0 ; ch = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; int dp[101][3] = {}; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1, a; i <= n; ++i) { cin >> a; dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])); if (a & 1) dp[i][1] = max(dp[i - 1]... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int a[maxn], m, n, ans, dp[maxn]; inline bool check(int x) { memset(dp, 0, sizeof(dp)); for (int sta = 0; sta <= 1 && sta < n; sta++) { dp[sta] = sta ? max(a[0] + x, a[1]) : a[0]; for (int i = sta + 1; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i]; } int u = 0, v = 1; vector<vector<double>> d[2]; d[u].assign(n + 1, vector<double>(n + 1)); for (int i = 1; i <= n; ++i) {... |
#include <bits/stdc++.h> using namespace std; int f(int, int); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; int a[m + 1]; int c[m]; int b = 0; for (int i = 0; i < m; i++) { c[i] = 0; } for (int i = 0; i <... |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& s, vector<T> t) { for (int i = 0; i < (int)(t.size()); i++) s << (i ? : ) << t[i]; return s; } template <typename T> istream& operator>>(istream& s, vector<T>& t) { for (int i = 0; i < (int)(t.... |
#include <bits/stdc++.h> using namespace std; const int off = 1 << 18; const int MOD = 1e9 + 7; int q, n = 1; int st[off << 1] = {}, sp[off], st2[off << 1]; vector<int> g[200001]; int qt[200000], qv[200000], qval[200000], ch[200001] = {}; int tin[200001], tout[200001], timer = -1, par[200001]; void df... |
#include <bits/stdc++.h> using namespace std; void _print(long long int x) { cerr << x << ; } void _print(float x) { cerr << x << ; } void _print(double x) { cerr << x << ; } void _print(char x) { cerr << x << ; } void _print(string x) { cerr << x << ; } void _print(bool x) { cerr << x << ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; char s[maxn]; int vis[maxn]; pair<char, int> sta[maxn]; int main() { scanf( %s , s); int o = -1; for (int i = 0; s[i]; i++) { if (s[i] == 0 && o >= 0 && sta[o].first == 1 ) { vis[sta[o].second] = 1; ... |
#include <bits/stdc++.h> using namespace std; vector<long long int> prime; unordered_set<long long int> stprime; void sieve(long long int n) { bool p[n + 1]; memset(p, true, sizeof(p)); for (long long int i = 2; i * i <= n; i++) { if (p[i]) { for (int j = i * i; j <= n; j += i) { ... |
#include <bits/stdc++.h> using namespace std; int frd[2110][2110], rev[2110][2110]; vector<int> v; int main() { int a, b, c, d, e, i, j, p, q, mx, mx1, len; string x, y; cin >> x >> y; a = x.length(); b = y.length(); x = % + x; y = * + y; for (i = b; i >= 1; i--) { for ... |
#include <bits/stdc++.h> using namespace std; int arr[1000000]; int main() { int n, x, counter = 0; cin >> n >> x; for (int i = 0; i < n; i++) scanf( %d , &arr[i]); sort(arr, arr + n); while (arr[((n + 1) / 2 - 1)] != x) { arr[n++] = x; sort(arr, arr + n); counter++; } ... |
#include <bits/stdc++.h> using namespace std; const int MX = 305; vector<int> adj[MX]; vector<int> l, ans; int dfs(int u, int v, vector<int>& p, int par = 0) { int sum = 0; for (int w : adj[u]) { if (w != par) { p.push_back(w); sum = max(sum, dfs(w, v, p, u)); p.pop_back(... |
#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; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long ln, lk, lm; const int MN = 10000; int mod; char s[505][505]; pair<int, int> id[2][MN], rid[505][505]; int sz[2]; vector<int> mp[MN], mpc[MN]; long long A[505][50... |
#include <bits/stdc++.h> using namespace std; int a, b, x, y; int main() { cin >> a >> b; if (a > b) { x = b; y = (a - b) / 2; } else { x = a; y = (b - a) / 2; } cout << x << << y; } |
#include <bits/stdc++.h> int main() { int n, m; scanf( %d %d , &n, &m); char a[1005][1005]; for (int k = 0; k < n; k++) { scanf( %s , a[k]); } char b[1005][1005] = {0}; for (int x = 1; x < n - 1; x++) { for (int y = 1; y < m - 1; y++) { if (a[x - 1][y] == # && a[x - 1... |
#include <bits/stdc++.h> using namespace std; int t[110], w[110]; int main() { int n, cnt = 0; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &w[i]); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { if (t[i] == w[j]) { ... |
#include <bits/stdc++.h> using namespace std; template <class T> void rd(T& ret) { ret = 0; bool ok = 0, u = 0; for (;;) { int c = getchar(); if (c >= 0 && c <= 9 ) ret = (ret << 3) + (ret << 1) + c - 0 , ok = 1; else if (c == - ) u = 1; else if (ok) { ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long MAX = 100005; const long double PI = 3.14159265359; const long double G = 9.807; const long long INF = 1e18; const long double EPS = 1e-6; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int maxn = 3e5 + 10, lg = 20; vector<pair<long long, long long> > v[maxn]; long long n, w[maxn], rmq[lg + 2][... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:100000000 ) int mod = 1000000007; int mas[1010]; int pow2(int b) { if (b == -1) return 0; int res = 1; for (int i = 1; i <= b; i++) { res <<= 1; res %= mod; } return res; } int GCD(int a, int b) {... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a[1000]{}; for (int i = 0; i < t; i++) { int n, s, k; cin >> n >> s >> k; set<int> b; for (int j = 0; j < k; j++) { cin >> a[j]; b.insert(a[j]); } int ans = n; fo... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const double PI = acos(-1.0); const long long MOD = 1000000007LL; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmi... |
#include <bits/stdc++.h> using namespace std; int t, n; int hmz, hmbz, bsz = -100000, sum; int main() { cin >> t; for (; t; t--) { cin >> n; hmz = 0; hmbz = 0; bsz = -100000; sum = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 0) ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int times[maxn][maxn], Time, cost[maxn][maxn], n, m; string k[maxn]; int dfs(int x, int y) { if (!min(x, y) or x > n or y > m) return 0; times[x][y] = ++Time; int now = k[x][y - 1]; int nextx, nexty; if (now == R ) ... |
#include <bits/stdc++.h> using namespace std; vector<int> graf[1000001]; vector<int> chains[1000001]; vector<int> chainsbit[1000001]; int chainwhere[1000001], chainposition[1000001]; void update(int chainidx, int x, int val) { while (x <= chainsbit[chainidx].size() - 1) { chainsbit[chainidx][x] +=... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<int> f(n, 0); unordered_map<int, vector<int>> mp; for (int i = 0; i < n; i++) mp[... |
#include <bits/stdc++.h> using namespace std; char str[405][405]; int pre[405][405], now[405]; int main() { int t, n, m, i, j, k, p, ans, mn; scanf( %d , &t); while (t--) { scanf( %d%d , &n, &m); ans = n * m; for (i = 1; i <= (n); i++) { scanf( %s , str[i] + 1); for... |
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c &... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 1e2 + 5, M = 1e5 + 5; int lim = (1 << 10) - 1; bool vis[M]; vector<int> primes; int idx[M]; void pre() { for (int i = 2; primes.size() < 110; ++i) { if (vis[i]) continue; primes.emplace_back(i); ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b; cin >> a >> b; if (a == 0 || b == 0) { cout << 0 << endl; return; } cout << min((a + b) / 3, min(a, b)) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tc = 1; cin >>... |
#include <bits/stdc++.h> using namespace std; bool isvowel(char c) { c = tolower(c); return (c == a || c == e || c == i || c == o || c == u ); } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b; while (cin >> n >> m >> a >> b) { a--; b--; int oa, pa, ob, pb; oa = a / m; pa = a % m; ob = b / m; pb = b % m; if (b == n - 1) { pb = m - 1; } if (oa == ob) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; int arr[n][m]; int row[n]; int col[m]; for (int i = 0; i < n; i++) { row[i] = i; for (int j = 0; j < m; j++) { col[j] = j; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long SIZE = 100000; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const long double PI = acos(-1); const long long MAXN = numeric_limits<long long>::max(); template <class T> T maxT(T ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; char c[2] = { w , b }; cin >> n; if (n % 2 == 1) cout << -1 ; else { for (int i = 1; i <= n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if ((j / 2) % 2 == 0) ... |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (auto i : v) os << i << ; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for (auto i : v) os << i << ; return os; } ... |
#include <bits/stdc++.h> using namespace std; int n; int lazy[600005]; bool haslazy[600005]; int tree[600005]; int arr[200005]; int lft(int x) { return 2 * x + 1; } int ryt(int x) { return 2 * x + 2; } struct lol { int x; int y; int z; }; void updt(int x, int l, int r, int value) { ... |
#include <bits/stdc++.h> using namespace std; int i; double a, b, c, d, base, top, mid, x11, x22, y11, y22, minim1, minim2, maxim1, maxim2; int main() { scanf( %lf%lf%lf%lf , &a, &b, &c, &d); base = 0.0; top = 1000000000.0; for (i = 1; i <= 100; i++) { mid = (base + top) / 2.0; ... |
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> point[int(2e5 + 10)]; map<int, int> mark_x, mark_y; long long res; void sol() { cin >> n; for (int i = 0; i < n; i++) { cin >> point[i].first >> point[i].second; mark_x[point[i].first]++; mark_y[point[i].second]++;... |
#include <bits/stdc++.h> using namespace std; template <class T> bool isPrime(T x) { if (x <= 1) return false; T i; for (i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } template <class T> class Prime { public: vector<T> z; Prime() { z.resize(1e5 + ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 3 * n - 1 << << 2 << endl; cout << 1 3 << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; bool ispalindrom(string s) { string rs; reverse(s.begin(), s.end()); rs = s; reverse(s.begin(), s.end()); if (rs == s) return true; else return false; } int main() { string s; int k; cin >> s >> k; int n = s.length... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300001; int f[maxn], a[maxn]; inline void add(int x, int val) { for (int i = x + 1; i < maxn; i += i & (-i)) f[i] += val; } inline int get(int x) { int ans = 0; for (int i = x; i > 0; i -= i & (-i)) ans += f[i]; return ans; } ... |
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; int n, s; int frq[1002]; int t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> s; for (int i = 1; i <= n; ++i) { int a, b; cin >> a >> b; frq[a] = max(frq... |
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXTREE = 50; const int MOD = 998244353; const int INV6 = 166374059; const int MINCOORD = -1000000000; const int MAXCOORD = +1000000000; ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& a) { char c = getchar(); int f = 1; a = 0; for (; c > 9 || c < 0 ; c = getchar()) if (c == - ) f = -1; for (; c <= 9 && c >= 0 ; c = getchar()) a = a * 10 + c - 48; a *= f; } const int o =... |
#include <bits/stdc++.h> using namespace std; vector<int> dif; map<int, int> g; int a[120000]; int main() { int n, flag; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (int i = 2; i <= n; i++) { if (g[a[i] - a[i - 1]] == 0) dif.push_back(a[i] - a[i - ... |
#include <bits/stdc++.h> using namespace std; void init_code() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } set<pair<int, int>> es; map<int, list<int>> m; void add(int a, int b) { m[a].push_back(b); m[b].push_back(a); } int v[1001]; void dfs(int node) { v[node] = 1; ... |
#include <bits/stdc++.h> using namespace std; const int N = 4040, inF = 1e9; int n, a, b, c, dp[N]; int main() { cin >> n >> a >> b >> c; dp[0] = 0; for (int i = 1; i <= n; i++) { dp[i] = -inF; if (i >= a) dp[i] = max(dp[i], dp[i - a] + 1); if (i >= b) dp[i] = max(dp[i], dp[i - b] ... |
#include <bits/stdc++.h> using namespace std; const long long K = 10001; signed main() { long long n, l, r, ans = 0; cin >> n >> l >> r; vector<long long> a(n), b(n); for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n; i++) cin >> b[i]; vector<long long> bad, good; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mnx = 1e5 + 9; long long q, n; long long a[mnx], k; map<int, int> m; int main() { cin >> q; while (q--) { cin >> n; for (int j = 1; j * j <= n; j++) { int jk = n / j; if (j == n / jk) { ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int main() { string s; cin >> s; int index = s.size() - 1; vector<char> din3(s.size(), 0); vector<char> din2(s.size(), 0); if (index - 2 >= 5) din3[index - 2] = 1; if (index - 1 >= 5) din2[index - 1] = 1; ind... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, l, tmp; long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 50; long long mod = 998244353; int n, m, u, v; vector<int> adj[N]; long long toAdd[N + N]; vector<pair<int, int> > q[N]; long long ans[N]; void dfs(int src, int par, int dep, long long sum) { for (auto i : q[src]) { toAdd[dep]... |
#include <bits/stdc++.h> using namespace std; int n; long long a[200010] = {}; vector<int> e[200010]; long long t[200010] = {}; long long q[200010] = {}; int s, b; long long ans = -222147483600ll; bool cmp(long long x, long long y) { return x > y; } void dfs(int x, int y) { vector<long long> w; ... |
#include <bits/stdc++.h> const int N = 1e5 + 5; struct ooo { int v, id; } p[N << 1]; bool operator<(const ooo& a, const ooo& b) { return a.v < b.v; } int n, ans, id, h, m, k, x; int main() { scanf( %d%d%d%d , &n, &h, &m, &k); m /= 2; for (int i = 1; i <= n; i++) scanf( %d%d , &x, &p[i]... |
#include <bits/stdc++.h> using namespace std; using int64 = long long; struct Primal_Dual { const int INF = 1 << 30; struct edge { int to, cap, cost, rev; }; vector<vector<edge> > graph; vector<int> potential, min_cost, prevv, preve; Primal_Dual(int V) : graph(V) {} void add_edge... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == W && s[i + 1] == U && s[i + 2] == B ) { i += 2; cout << ; } else { cou... |
#include <bits/stdc++.h> using namespace std; void fastIO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); } int main() { fastIO(); int n; int m; int total; int day = 0; cin >> n >> m; while (n != 0) { day++; n = n - 1; if (day % m =... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum = 0; cin >> n; vector<long long int> v; for (long long int i = 0; i < n; i++) { long long int el; cin >> el, sum += el; v.push_back(el); } sum = sum / n; long long int res = 0, curr = 0; ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; string s; cin >> s; if (k == 0) { cout << s; return; } if (n == 1) cout << 0 ; else { if (s[0] > 1 ) { s[0] = 1 ; k--; } for (long lo... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s; cin >> s; int ans = 0; int count = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == ) ) { ans--; if (ans < 0) { count++; ans = 0; } } else {... |
#include <bits/stdc++.h> using namespace std; const long long INF = 4e18; const long long MAX = 2e5 + 5; const long long MOD = 1e9 + 7; int n, m; void exgcd(int a, int b, long long &c, long long &d) { if (a == 0) { c = 0; d = 1; return; } exgcd(b % a, a, d, c); c -= b / a *... |
#include <bits/stdc++.h> using namespace std; struct node { int l, r; } line[1000005]; int a[5000005], ls[5000005], b[5000005]; vector<node> ans; bool cmp(node a, node b) { return a.l < b.l; } int main() { int n, k; while (~scanf( %d %d , &n, &k)) { memset(a, 0, sizeof(a)); memset(... |
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, m, a, s, c, b, n, x, y, ar[1001]; cin >> n; while (n--) { cin >> s >> a >> b >> c; x = s / c; y = x / a * b; cout << x + y << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; const int mxn = 2e5; int n; string ar[mxn]; void solve() { cin >> n; for (int i = 0; i < n; ++i) cin >> ar[i]; set<string> second; for (int i = n - 1; i >= 0; --i) { ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int x; cin >> x; while (x--) { int n, m, ans = 0; 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];... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 4e5; int n, m, q; int head[Maxn], tot, father[Maxn], cnt[Maxn]; int vis[Maxn]; struct Edge { int to, next; } edge[Maxn * 10]; void init() { memset(head, -1, sizeof(head)); tot = 0; for (int i = 0; i < Maxn; i++) father[i] = i... |
#include <bits/stdc++.h> using namespace std; string pad(string x, int lngth) { reverse(x.begin(), x.end()); for (int i = 0; i < lngth; i++) x += 0 ; reverse(x.begin(), x.end()); return x; } string add(string x, string y) { string res = ; int mx = max(x.length(), y.length()); x = ... |
#include <bits/stdc++.h> using namespace std; const double PI = 4 * atan(1); template <int p> struct FF { long long val; FF(long long x = 0) { val = (x % p + p) % p; } bool operator==(const FF<p> other) { return val == other.val; } bool operator!=(const FF<p> other) { return val != other.val; } ... |
#include <bits/stdc++.h> using namespace std; int n, m, k, dx, dy, x, y; char c[5]; bool f; long long ans; struct blk { int x, y; blk(int xx = 0, int yy = 0) { x = xx; y = yy; } bool operator<(const blk& b) const { return x < b.x || (x == b.x && y < b.y); } }; vecto... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e18; const long double eps = 1e-8; const double pi = acos(-1); const long long hashh = 247; char s[203040]; long long p[203040], cnt[203040], hs[203040][2]; long long get(long long l, long long r) { ... |
#include <bits/stdc++.h> using namespace std; int m, n, cnt = 0; vector<vector<int> > g; vector<int> outgroup; int main() { cin >> n >> m; vector<int> emptyg; g.push_back(emptyg); for (int i = 1; i <= n; i++) { vector<int> subg; g.push_back(subg); } for (int i = 0; i < m; i... |
#include <bits/stdc++.h> using namespace std; int n, q, a[210000], b[210000]; int tree[210000]; char Getchar() { static char now[1 << 20], *S, *T; if (T == S) { T = (S = now) + fread(now, 1, 1 << 20, stdin); if (T == S) return EOF; } return *S++; } int read() { int x = 0, f =... |
#include <bits/stdc++.h> using namespace std; long long int x, y, a[3000], n, m, sum; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { cin >> x >> y; sum += min(a[--x], a[--y]); } cout << sum; return 0; } |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; void init_ios() { ios_base::sync_with_stdio(0); cin.tie(0); } const int N = (1 << 19); int n, m, jump[N][20]; pair<int, int> a[N], drz[2 * N]; void add(int v, int val, int ind) { v += N; if (val < drz[v].first) retu... |
#include <bits/stdc++.h> using namespace std; int n, a[2001][2001], s1[2001], s2[2001], res = 0, d[2001]; string s; int main() { scanf( %d n , &n); for (int i = 0; i < n; ++i) { cin >> s; for (int j = 0; j < n; ++j) if (s[j] == 0 ) a[i][j] = 0; else a[i][... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int ans = -1; for (int i = 0; i < n - 1; i++) { if (s[i + 1] < s[i]) { ans = i; break; } } if (ans == -1) cout << NO ; else { cout << YES << endl; ... |
#include <bits/stdc++.h> using namespace std; int main() { int x, i; int a[100]; while (cin >> x && x) { if (x == 1) { cout << x << endl; } else { cout << x << ; for (i = 1; i < x; i++) cout << i << ; cout << endl; } } return 0; } |
#include <bits/stdc++.h> using namespace std; void solve(int cnum) { int di[] = {-1, 0, 0, 1}; int dj[] = {0, -1, 1, 0}; int n, m; cin >> n >> m; vector<vector<int>> arr(n, vector<int>(m)); vector<vector<int>> ans(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < ... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, k; pair<int, int> a[N]; long long b, s; int main() { cin >> n >> k; cin >> b; for (int i = 1; i <= n; i++) { scanf( %d , &a[i].first); a[i].second = i; } sort(a + 1, a + n, greater<pair<int, int> >());... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n % 2 == 0) { cout << n / 2 << n ; } else { cout << int(n / 2) + 1 << n ; } } } |
#include <bits/stdc++.h> using namespace std; const int maxm = 200000 + 5; const int maxn = 200000 + 5; struct Edge { int from, to, w, id; }; vector<Edge> edges; vector<int> G[maxn]; int ans[maxm]; int n, m; int win[maxn], wall[maxn]; inline void solve() { memset(ans, -1, sizeof ans); ... |
#include <bits/stdc++.h> using namespace std; queue<int> Q; vector<int> edges[11000]; int num[11000]; int ans; int n; int bfs(int s) { int cnt = 0; for (int i = 0; i < edges[s].size(); i++) { cnt += edges[edges[s][i]].size() - 1; } return cnt; } int main(void) { int i; sc... |
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; if (a == b) { cout << infinity ; return 0; } if (a < b) { cout << 0; return 0; } long long int x, i, k, j; x = a - b; long long int sq; sq = sqrt((a - b) * 1... |
#include <bits/stdc++.h> using namespace std; int ans[120000], fa[120000], i, j, k, l, n, m, n2; int get(int x) { return fa[x] == x ? x : (fa[x] = get(fa[x])); } int main() { scanf( %d , &n); if (n & 1) return puts( -1 ), 0; for (i = 0; i < n; ++i) fa[i] = i; n2 = n / 2; for (i = 0; i < n2; ... |
#include <bits/stdc++.h> using namespace std; int k; int main() { cin >> k; for (int i = 1; i < k; i++) { cout << i; for (int j = 2; j < k; j++) { if (i * j < k) cout << << i * j % k; else cout << setw(2) << i * j / k << i * j % k; } cout <<... |
#include <bits/stdc++.h> using namespace std; int main(void) { int t; cin >> t; while (t--) { long long n, x, sum = 0, ans = 0, cur; cin >> n >> x; priority_queue<long long> nums; for (int i = 0; i < n; ++i) { cin >> cur; nums.push(cur - x); } for (int... |
#include <bits/stdc++.h> using namespace std; long long n, v[500005], lastLeft[500005], lastRight[500005], solLeft[500005], solRight[500005], sol[500005]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; } for (int i = 1; i <= n; ++i) { lastLeft[i] = 0; } ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.