func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> #define mset(arr, val) memset(arr, val, sizeof(arr)) #define all(v) v.begin(), v.end() #define F first #define S second #define endl n using namespace std; // const double PI = acos(-1.0); // const double E = exp(1.0); // const double EPS = 1e-9; const int MOD = (int)1e9 ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; vector<int> mp[maxn]; vector<int> R[maxn]; vector<int> L[maxn]; int ans = 0; bool vis[maxn]; int n, m; struct node { int last_L; int last_R; } last[maxn]; void dfs(int now, int l, int r) { if (now == n) { ans... |
#include <bits/stdc++.h> using namespace std; struct Data { int Value, Number; }; bool operator<(Data A, Data B) { return A.Value < B.Value; } int Get() { char c; while (c = getchar(), c < 0 || c > 9 ) ; int X = 0; while (c >= 0 && c <= 9 ) { X = X * 10 + c - 48; c ... |
#include <bits/stdc++.h> int64_t a[400005], b[200005]; int64_t len; int n; bool check(int64_t value) { std::vector<std::pair<int64_t, int64_t>> v; for (int i = 0; i < n; ++i) { auto rg = std::make_pair(b[i] - value, b[i] + value); if (rg.first < 0) { rg.first += len; rg.secon... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline int add(int a, int b) { if ((a += b) >= mod) a -= mod; return a; } inline int mult(int a, int b) { long long t = 1ll * a * b; if (t >= mod) t %= mod; return t; } inline int dec(int a, int b) { if ((a -... |
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); bool b = false; for (int i = 2; i < n; i++) { if (a[i - 2] + a[i - 1] > a[i] && a[i] + a[i - 1] > a[i - 2] && a[i - 2] + a[i] > a[i... |
#include <bits/stdc++.h> using namespace std; int main() { int nCase; scanf( %d , &nCase); while (nCase--) { int a, b; scanf( %d%d , &a, &b); if (a == 0) { if (b == 0) printf( 1 n ); else printf( 0.5 n ); continue; } if (b == 0) {... |
#include <bits/stdc++.h> using namespace std; void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int MAXN = 2e5 + 1; const long long INF = 1e18; const long long MOD = 1e9 + 7; const long double PI = acos(-1); long long n, a[MAXN], dp[MAXN], d[MAXN], cnt[... |
#include <bits/stdc++.h> using namespace std; int powmod(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y /= 2; x = (x * x) % p; } return res; } string dectobin(int x) { string s = ; wh... |
#include <bits/stdc++.h> using namespace std; long long a[5]; char x[4]; long long res = 1e14; inline long long calc(long long x, long long y, char xx) { if (xx == * ) return x * y; return x + y; } int main() { register int i, j; for (i = 1; i <= 4; i++) cin >> a[i]; for (i = 1; i <= ... |
#include <bits/stdc++.h> using namespace std; void solve() { int i; string b, a; cin >> b; int size = b.size(); for (i = 0; i <= size - 1; i++) { a += b[i]; i++; } a += b[size - 1]; cout << a << n ; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0);... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 7; int main() { long long n; cin >> n; for (long long a = 0; a < n / 1234567 + 1; a++) for (long long b = 0; b < n / 123456 + 1; b++) { long long c = n - a * 1234567 - b * 123456; if (c >= 0 && c % 1234 == 0) { ... |
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k, x, y; cin >> n >> k; for (int i = 0; i < n - 1; ++i) { cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } int kol... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, mod = 1e9 + 7; inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; } int n, cnt[maxn], vec[maxn], tot; int main() { scanf( %d , &n); cnt[0] = 1; for (int i = 1, x; i <= n; ++i) { scanf( %d , &x), tot = 0;... |
#include <bits/stdc++.h> int main() { int i = 1, n, m; scanf( %d%d , &n, &m); while (1) { if (m < i) break; m -= i; i = i % n + 1; } printf( %d n , m); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, x; cin >> n >> x; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int j = 1, teams = 0; for (int i = n - 1; ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; const long long LIMIT = 2e18 + 1; int n; long long k; long long arr[N]; long long cnt[N]; bool isUnsafe(long long a, long long b) { return a > LIMIT / b || b > LIMIT / a; } int solve(int i) { int res = 0; long long s, p... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long double pi = acos(-1.0); const long double eps = 1e-9; const int MAX_SIZE = 50; const int dX[] = {-1, 1, 0, 0, -1, 1, -1, 1}; const int dY[] = {0, 0, -1, 1, 1, -1, -1, 1}; template <class S, class T> ostream& operat... |
#include <bits/stdc++.h> using namespace std; const int N = 260; const int MOD = 1000000000 + 7; int n, m, t; int mid; int v[N], mod[N]; bool g[10][N]; long long ans, f[10]; inline void Dfs(int k, int d) { ans += f[d]; if (ans > MOD) ans -= MOD; if (d > 5) return; for (int i = k; i <= ... |
#include <bits/stdc++.h> using namespace std; int n, h, l, r; int a[2000 + 5], dp[2000 + 5][2000 + 5]; int solve(int curr, int idx) { if (idx == n) { if (l <= curr && curr <= r) return 1; else return 0; } if (dp[curr][idx] != -1) return dp[curr][idx]; int p1 = 0, p2 =... |
#include <bits/stdc++.h> const int maxn = 1e6 + 10; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int n, m; int cas, tol, T; struct Sam { ... |
#include <bits/stdc++.h> using namespace std; template <class T> string tostring(T x) { ostringstream out; out << x; return out.str(); } long long toint(string s) { istringstream in(s); long long x; in >> x; return x; } int main() { int n, x, tmp; cin >> n >> x; int... |
#include <bits/stdc++.h> using namespace std; void past_code(); vector<int> v[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int x, y, j, k; cin >> x; for (int i = 1; i <= 2 * x; i++) { cin >> y; v[y].push_back(i); } long long s... |
#include <bits/stdc++.h> using namespace std; int n = 0, s = 0, d = 0; map<int, vector<int> > graph; map<int, bool> vis; bool stop = false; void Dfs(int m) { if (m == d || stop) { cout << m; stop = true; return; } cout << m << ; for (int i = 0; i < (int)graph[m].size(); ... |
#include <bits/stdc++.h> using namespace std; mt19937 rnd(51); const long long INF = 1e18; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; vector<vector<long long>> a(n, vector<long long>(m)), ... |
#include <bits/stdc++.h> using namespace std; const int M = 1e6 + 7; inline long long stoll(char* s, const long long& p, bool f = 0) { long long a = 0; bool fl = 0; for (; *s; ++s) a = a * 10 + *s - 48, fl |= (f && a >= p), a %= p; return a + fl * p; } long long b, n, p, phi; char B[M], N[M]... |
#include <bits/stdc++.h> using namespace std; int main() { int n, d; pair<int, int> friendlist[100001]; scanf( %d%d , &n, &d); for (int i = 0; i < n; i++) scanf( %d%d , &((friendlist + i)->first), &((friendlist + i)->second)); sort(friendlist, friendlist + n); int it_left = 0; int ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 7, MAX_LOG = 20; int n, m; vector<int> adj[MAXN]; bool isPassed[MAXN]; int par[MAXN][MAX_LOG], cycleCnt[MAXN], h[MAXN]; void pre(int root) { isPassed[root] = true; for (auto nei : adj[root]) { if (!isPassed[nei]) { ... |
#include <bits/stdc++.h> int a[200003], b[200003], f[200003]; int main() { int n, m, q; scanf( %d%d%d , &n, &m, &q); int i, l, h; for (i = 0; i < n; i++) { scanf( %d%d , &l, &h); a[l]++; a[h + 1]--; } int sum = 0, co = 0; for (i = 0; i <= 200000; i++) { if (a[i] !... |
#include <bits/stdc++.h> using namespace std; inline bool isPrime(uint64_t n) { if (n == 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (uint64_t div = 3; div * div <= n; div += 2) if (n % div == 0) return false; return true; } inline std::vector<uint64_t> ... |
#include <bits/stdc++.h> using namespace std; const int M = 1000000007, BIG = 0x3f3f3f3f; long long p, k; inline long long Mod(long long x, long long m) { x %= m; if (x < 0) x += m; return x; } vector<long long> Process() { vector<long long> ans; while (p) { const long long m = Mod... |
#include <bits/stdc++.h> using namespace std; long long pow1(long long b, long long expo, long long md) { if (!expo) return 1; long long tmp = pow1(b, expo / 2, md); tmp = (tmp * tmp) % md; if (expo % 2) tmp = (tmp * b) % md; return tmp; } long long w[1000005] = {}; long long apow[1000005]... |
#include <bits/stdc++.h> using namespace std; map<int, long long> x, y; map<pair<int, int>, long long> xy; int main() { int n; cin >> n; while (n--) { int xx, yy; cin >> xx >> yy; x[xx]++; y[yy]++; xy[make_pair(xx, yy)]++; } long long ans = 0; for (auto i : ... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, ans; int main() { cin >> a >> b >> c; long long pom = min(a, b); a -= pom; b -= pom; ans = c + pom; ans <<= 1; if (a or b) ans++; cout << ans; } |
#include <bits/stdc++.h> using namespace std; const int order[10][10] = { {99, 98, 97, 96, 95, 94, 93, 92, 91, 90}, {80, 81, 82, 83, 84, 85, 86, 87, 88, 89}, {79, 78, 77, 76, 75, 74, 73, 72, 71, 70}, {60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, {59, 58, 57, 56, 55, 54, 53, 52, 51, 50}, ... |
#include <bits/stdc++.h> using namespace std; long long n, k; vector<long long> v; int main() { if (fopen( a.txt , r )) { freopen( a.txt , r , stdin); } else ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; if (k >= 1e6) { cout << -1; exit(0); }; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int t = 1; if (m == 10) { if (n == 1) { cout << -1 ; return 0; } else { cout << 1 ; for (int i = 1; i < n; i++) { cout << 0 ; } } } else { ... |
#include <bits/stdc++.h> using namespace std; int n, m; long long k; int main() { unsigned long long n, m, k; cin >> n >> m >> k; if (k < n) { cout << k + 1 << << 1 << endl; return 0; } k -= n; long long row = k / (m - 1); cout << n - row << ; if (row % 2) ... |
#include <bits/stdc++.h> using namespace std; int n, m, u, v, s, to[5010], ne[5010], pre[5010], cnt, dfn[5010], low[5010], len, f[5010], ss, q[5010], w[5010], d[5010], dis[5010]; bool us[5010]; void add(int u, int v) { to[++s] = v; ne[s] = pre[u]; pre[u] = s; } void dfs(int k) { dfn[k]... |
#include <bits/stdc++.h> using namespace std; int L = 2e5; vector<vector<int>> g(L); vector<int> dp(L), d(L, 0), par(L, -1); vector<bool> used(L); int dist; int ask1(int u) { cout << d << u + 1 << endl; int t; cin >> t; if (t == -1) { while (true) { } } return t; }... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long LINF = 1e18; const int MOD = 1e9 + 7; void test() {} const int MAX = 1 << 19; int tree[2 * MAX], prefMax[2 * MAX]; int killed = 0, m, n; vector<pair<int, int> > play; int query(int x, int y) { int res = -1; fo... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 6e6; const long long inf = 1e18; const long long maxv = 2e8 + 100; const int miniinf = 1e9; const long double eps = 1e-6; const long long flowconst = 1e9; void init() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; const int M = 26; const long long mod = 1e9 + 7; const long long MOD = 998244353; const int P = 1336; const long double eps = 0.000000001; const long long inf = 1e18 + 7; mt19937 gen(time(0)); vector<int> g[N]; int sz[N], a[N];... |
#include <bits/stdc++.h> using namespace std; bool changed[222222]; pair<int, int> edges[222222]; set<pair<int, int> > adj[111111]; bool visited[111111]; deque<pair<int, int> > to_connect; vector<int> Harry; char outbuf[12000000]; char* out = outbuf; int moves = 0; void flush_harry() { out += ... |
/* * * Author: Hsueh- * Date: 2021-03-05 21:34:52 * * */ #include <bits/stdc++.h> using namespace std; #define dbg(x...) do { cout << #x << ... |
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)2e18 + 5; const long long MOD = (long long)1e9 + 7; const int MAXN = 55; long long mul(long long x, long long y) { if (x == 0) return 0; if (y > INF / x) return INF; return x * y; } long long add(long long x, long l... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1025; long long p[MAX_N]; int main() { long long s, n, sum = 0; scanf( %lld%lld , &n, &s); for (int i = 1; i <= n; ++i) scanf( %lld , &p[i]), sum += p[i]; sort(p + 1, p + 1 + n); if (sum < s) { printf( -1 n ); return... |
#include <bits/stdc++.h> using namespace std; const int d1 = 7; const int d2 = 29; const int mod = 19260817; char str[200005]; bool h1[mod + 5], h2[mod + 5]; int r1[200005], r2[200005]; int kf[4][200005]; int check[200005][2]; int fff[200005]; bool ban[200005]; int main() { int t, n; sca... |
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const long long inf = 1e18; const long long mod = 1e9 + 7; void solve() { long long n; cin >> n; vector<long long> a(n); vector<vector<long long> > cnt(100001); long long me = 0; for (long... |
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 5; const long long mod = 1e9 + 7; void solve() { long long n; cin >> n; if (n == 1) { cout << -1 << endl; return; } cout << n << << n + 1 << << n * (n + 1) << endl; } int32_t main() { ios_base... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int t; cin >> t; while (t--) { int n, c0, c1, h; cin >> n >> c0 >> c1 >> h; string binary; cin >> binary; int count0 = 0, count1 = 0; int an... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000000 + 7; long long int n, k, summ, tr, a[1000000], minn, maxx; string s, s1; map<int, int> been; int compare(const void* a, const void* b) { return ((*(long long int*)a) - (*(long long int*)b)); }; int gcd(int a, int b) {... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long t; cin >> t; while (t--) { int a; set<int> pr; cin >> a; int ar[a]; for (int i = 0; i < a; i++) { cin >> ar[i]; pr.insert(ar[i]); } cout <<... |
#include <bits/stdc++.h> using namespace std; const int maxl = 100000; map<int, int> SG, num; int n, x, tmp, ans = 0, prime[maxl], tot = 0; bool notprime[maxl + 1]; inline void init() { notprime[1] = 1; for (int i = 2; i <= maxl; i++) { if (!notprime[i]) prime[++tot] = i; for (int j = 1;... |
#include <bits/stdc++.h> using namespace std; long long pi = 1, sum = 0, n, k, a[200100], pos[200100]; const long long inf = (long long)1e19; int main() { scanf( %I64d %I64d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %I64d , &a[i]); pos[i] = (a[i - 1] != 1 ? i - 1 : pos[i - 1]); } ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int n; unordered_map<int, int> bit[MAX]; unordered_map<int, int> idx; int inf = 1000000001; void update(int pos, int t, int val) { for (; t < inf; t += (t & -t)) { bit[pos][t] += val; } } int get(int pos, int t) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; vector<int> graph[MAXN]; int values[MAXN]; long long dp[MAXN]; int leftValue[MAXN]; priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > pq; void dfs(int u, int p... |
#include <bits/stdc++.h> using namespace std; const long long logn = 63; const long long inf = 1e18; void upd(long long& a, const long long& b) { a = min(a, b); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> a(n), b(n); for (int i = 0; i < n;... |
#include <bits/stdc++.h> struct Edge { Edge(int _from, int _to) : from(_from), to(_to) {} int from, to; }; enum GraphNodeColor { NODE_WHITE, NODE_GREY, NODE_BLACK }; class Graph { public: Graph(int nodes, std::vector<Edge> edges) : neighb(nodes, std::vector<int>()) { node_count = no... |
//EK ONKAR #include <bits/stdc++.h> using namespace std; /******************************MACROS******************************/ #define int long long #define ld long double #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define yes cout<< Yes n #define no cout<<... |
#include <bits/stdc++.h> using namespace std; const int limit = 453; int n, m, q, i, x, y, col; vector<pair<int, int> > edges[100011]; pair<int, int> Q[100011]; vector<int> cols[100011]; int sz[100011]; int id_big[100011], cnt_big; int dad[100011]; vector<int> who[100011]; int big[limit + 11][1000... |
#include <bits/stdc++.h> using namespace std; int main() { int n, d, m, i, a, b; cin >> n >> d >> m; for (i = 0; i < m; i++) { cin >> a >> b; if ((a - b + d) * (a - b - d) <= 0 && (a + b - d) * (a + b + d - 2 * n) <= 0) cout << YES << endl; else cout << NO ... |
#include <bits/stdc++.h> using namespace std; int main() { long long s; scanf( %I64d , &s); long long d = s; int n = 0; while (s > 0) { d /= 10; d *= 10; int a = s - d; if (a == 4 || a == 7) { n++; } s /= 10; d = s; } if (n == 0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, k; cin >> n >> a >> b >> k; long long int skips_left = k; long long int win = 0; long long int h[n]; long long int skips_req[n]; for (long long int m = 0; m < n; m++) { skips_req[m] = 0; } for... |
#include <bits/stdc++.h> using namespace std; const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; inline long long gcd(long lon... |
#include <bits/stdc++.h> using namespace std; const int MaxN = 400007; const int mod = (int)1e9 + 7; int a, b, k, t, N; int ans, f[MaxN], s[MaxN]; int main() { int i, j; scanf( %d%d%d%d , &a, &b, &k, &t); f[2 * k * t + 1] = 1; N = 4 * k * t + 1; for (i = 1; i <= t + t; i++) { for (... |
#include <bits/stdc++.h> using namespace std; bool DEB = 0; void __start__() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } mt19937_64 rnd(time(0)); using ll = long long; using vi = vector<int>; using ld = long double; using pii = pair<int, int>; void test_case() { ll n, k, tw... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> c(n); for (int i = 0; i < n; ++i) { scanf( %d , &c[i]); } vector<int> ans(n + 1, 0); for (int i = 0; i < n; ++i) { vector<int> mx(n + 1, 0); int p = 0; for (int k = i; k < n; +... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long res = 1; long long mdl = 1000000000 + 7; long long s1 = s.size(); vector<long long> fibo(s1 + 1); fibo[0] = 1; fibo[1] = 1; for (long long i = 0; i < s1; i++) { if (s[i] == m || s[i] ... |
#include <bits/stdc++.h> using namespace std; char a[5005], b[5005]; int la, lb; int memo[5005][5005]; int dp(int x, int y) { if (x == la || y == lb) return 0; else if (memo[x][y] != -1) { return memo[x][y]; } else { int ans1 = dp(x, y + 1) % 1000000007; int ans2 = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, s = 0, q = 0; cin >> a >> b >> n; for (int i = 1;; i++) { if (n != 0) { if (i % 2 == 1) { if (a >= n) { for (int j = n; j >= 1; j--) { if (a % j == 0 && n % j == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const int MAXN = 2005; int n, m; char maze[MAXN][MAXN]; void Dfs(int x, int y) { if (x >= n - 1 || y >= m - 1 || x < 0 || y < 0) return; int xx, yy, s = 0; for (int i = 0; i < 2; ++i) for (... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[200005]; int visited[200005]; int dfs(int u) { visited[u] = 1; int iscycle = ((adj[u].size() == 2) ? (1) : (0)); for (int i = 0; i < adj[u].size(); ++i) { if (visited[adj[u][i]] == 0 and dfs(adj[u][i]) == 0) iscycle = 0; } r... |
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MOD1 = 1e9 + 123; long long MOD2 = 1e9 + 321; vector<int> fun(string &s) { int i; vector<int> v; for (i = 0; i + 1 < s.length(); i++) if (s[i] != s[i + 1]) v.push_back(i + 1); if (s[s.length() - 1] == 1 ) v... |
#include <bits/stdc++.h> using namespace std; void solve() {} int main() { long long a, b, c, d; cin >> a >> b >> c >> d; long long ans = 0; long long l = max(c, a + b); long long r = c + d + 1; for (long long i = l; i < r; i++) { long long che = min(i - c, d - c + 1); long lon... |
#include <bits/stdc++.h> using namespace std; int a[1000006]; int n, k; int max_a; int has[20000007]; bool judge(int num) { if (num == 1) return true; int cnt = 0; for (int i = 0; i < num * 2; i++) { has[i] = i / num; } for (int i = num * 2; i <= max_a; i++) { has[i] = has[i ... |
#include <bits/stdc++.h> using namespace std; int n, cnt; char x[55]; int main() { scanf( %s , x); n = strlen(x); for (int i = 0; i < n; i++) cnt += x[i] == a ; printf( %d n , min(n, cnt * 2 - 1)); } |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> arr; long long int num; for (int i = 0; i < n; i++) { cin >> num; arr.push_back(num); } sort(arr.begin(), a... |
#include <bits/stdc++.h> using namespace std; int num[150000]; void Sum(int i, int op, int n, int &sum) { if (i != op && i > 0 && i <= n && op > 0 && op <= n) { swap(num[i], num[op]); if ((i & 1) && (op & 1)) { if ((i > 1 && num[i] < num[i - 1] || i == 1) && (i < n && num[i] < ... |
#include <bits/stdc++.h> using namespace std; const inline int __GET_INT() { int ret; scanf( %d , &ret); return ret; } int main() { long long A = __GET_INT(), B = __GET_INT(), n = __GET_INT(); for (int i = 0; i < n; ++i) { long long l = __GET_INT(), t = __GET_INT(), m = __GET_INT(); ... |
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005]; char c[1005][1005]; int main() { int n, m; cin >> n >> m; int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; if (c[i][j] == * ) { a[i]++; b[j]++;... |
#include <bits/stdc++.h> using namespace std; long long n, A, B, C = 1; const long long E = 1e9 + 7; int main() { cin >> n; if (n <= 1) { cout << 0 << endl; return 0; } for (long long i = 2; i < n; i++) { A = B; B = C; C = 2 * B + 3 * A; C %= E; } long... |
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int main() { long long int i, t, a = 0, k, b = 0, j = 0, l = 0, n, m, r = 0, c = 0, ct = 0, pos = 0, neg = 0, flag = 0, x, y, space, maxi, ans = 999999, ans2 = -100, avg, sum = 0; double d;... |
#include <bits/stdc++.h> using namespace std; set<int> s[300000]; int ans[300000]; bool vis[300000]; int nr[500000]; int main() { int n, m; scanf( %d %d , &n, &m); priority_queue<pair<int, int> > pq; for (int i = 0; i <= 2 * m; i++) nr[i] = -1; for (int i = 0; i < n; i++) { int k, ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m == 3 && n >= 5) cout << -1 << endl; else { if (m == 3 && n == 4) puts( -1 0 n1 0 n0 2 n0 1 ); else { for (int i = 1; i <= m; i++) cout << i << << i * i + 343231 << endl; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int s[n]; int f[10] = {0}; for (int i = 0; i < n; i++) { cin >> s[i]; } int tmp; for (int j = 0; j < m; j++) { cin >> tmp; f[tmp] = 1; } int emp = 1; for (int i = 0; i < ... |
#include <bits/stdc++.h> const int maxn = 3e5 + 3; int n, a[maxn], b[maxn], m, l[maxn], r[maxn]; void solve() { scanf( %d , &n); m = 0; for (int i = 0; i < n; ++i) { scanf( %d , a + i); b[m++] = a[i]; } std::sort(b, b + m); m = std::unique(b, b + m) - b; for (int i = 0; i <... |
#include <bits/stdc++.h> using namespace std; int main() { int Q = 9, R = 5, B = 3, N = 3, P = 1, q = 9, r = 5, b = 3, n = 3, p = 1; int sum2 = 0, Sum2 = 0; char c[64]; for (int i = 0; i < 64; i++) { cin >> c[i]; } for (int i = 0; i < 64; i++) { switch (c[i]) { case q : ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 10; const long long MN = 5e2 + 10; long long n, m, a[MN], b[MN]; vector<pair<long long, char> > ans; long long lz = 0; bool fl = false; void fail() { cout << NO n ; exit(0); } long long get(long long l, long long r) {... |
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } long long int fexp(long long int a, long long int b) { long long... |
#include <bits/stdc++.h> using namespace std; const int N = 2005; vector<pair<int, int> > v[N * N]; bool flag[N * N], a[N][N], vis[N][N]; pair<int, int> dis[N * N]; int id[N][N], q[N * N], ID, n, m, r, c, sx, sy, ans; char s[N]; void bfs(int r, int c) { int L = 0, R = 0; q[R++] = id[r][c]; f... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const long long MOD = 1000000007; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; void solve() { int n; cin >> n; vector<ll> a(n); ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } int idx[200001] = {0}; vector<int> g[160]; int dp[160][100001] = {0}; int len[160][200001] = {0}; int nless(vector<int>& v, int val) { if (!(int)v.size()) return ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 1000 + 5; const long long INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000; int n, k, dp[maxn], a[maxn]; bool check(long long x) { for (int i = 1; i <= n; i++) { dp[i] = i - 1; for (int j = 1; j < i; j++) { if (abs(a[i] ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int i = 0; int cnt[101] = {0}; for (int i = 0; i < n; i++) { cin >> arr[i]; cnt[arr[i]]++; } int a = -1, b = -1; for (int i = 0; i <= 100; i++) { if (cnt[i] == n / 2) { ... |
#include <bits/stdc++.h> const int MAXN = 2020; int n, m; int mp[MAXN][MAXN], realx[MAXN], realy[MAXN], cntx, cnty; char dir[MAXN]; int len[MAXN]; void unique(int *real, int &cnt) { std::sort(real, real + cnt); int t2 = 1; for (int t1 = 1; t1 < cnt; t1++) if (real[t1] ^ real[t1 - 1]) real[... |
#include <bits/stdc++.h> using namespace std; char func(char c) { if (c >= A && c <= Z ) c = tolower(c); if (c == o ) c = 0 ; else if (c == l || c == i ) c = 1 ; return c; } int main() { string s; int n; cin >> s >> n; for (int i = 0; i < n; i++) { stri... |
#include <bits/stdc++.h> using namespace std; const long long P = (long long)1e9 + 7; int n, k; int a[2]; long long c[60][60]; long long cnt[60][60]; int dp[60][60]; struct rmdr { int i, j; bool operator<(const rmdr& a) const { if (50 * i + 100 * j != 50 * a.i + 100 * a.j) return 5... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e5 + 5; const long long inf = -1; const long long m = 1e6; vector<long long> prime; bool sieve[m + 2]; void primeSieve() { memset(sieve, true, sizeof(sieve)); sieve[0] = sieve[1] = false; prime.push_back(2); for (long lon... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; using ld = long double; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pi>; using si = set<int>; using sl = set<ll>; using qi = qu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.