solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 9 * 840; long long dp[9][11234], cnt[9], w; int main() { scanf("%lld", &w); for (int(i) = (1); (i) <= (8); (i)++) scanf("%lld", cnt + i); memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int(i) = (0); (i) <= ((8) - 1); (i)++) for (int(j) = (0); ...
15
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; int M, N; int dp[51][1 << 12]; int main() { cin >> N >> M; if (N > M) swap(N, M); memset(dp, oo, sizeof(dp)); dp[0][0] = 0; for (int i = (0); i < (M); i++) { for (int j = (0); j < (1 << (2 * N)); j++) { ...
13
#include <bits/stdc++.h> using namespace std; // #define int long long typedef pair<int, int> pii; #define ll long long #define ar array const int mxN=4e5; const int mod=1e9+7; const ll INF=1e18; #define what_is(x) cerr << #x << " is " << x << endl; vector<int> adj[2*mxN]; int parent[2*mxN]; vector<ar<int,2>>edges; ...
9
#include <bits/stdc++.h> using namespace std; int eps, k, n; int x[128], y[128]; double P[128], dp[128][128]; bool can(double R) { for (register int i = (1); i < (int)(n + 1); ++i) { double D = sqrt((x[0] - x[i]) * (x[0] - x[i]) + (y[0] - y[i]) * (y[0] - y[i])); if (D <= R) P[i] = 1; else ...
13
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { while (b) { a = a % b; swap(a, b); } return a; } string process(string &item) { stack<char> chars; for (int i = 0; i < (int)item.size(); i++) { if (chars.size() == 0) { chars.push(item[i]); } else {...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 33; vector<int> a[MAXN]; bool visited[MAXN]; bool ans = true; int n, m; void dfs(int i, int prev) { visited[i] = true; for (int k = 0; k < a[i].size(); k++) { int t = a[i][k]; if (t != prev && visited[t]) ans = false; else if (!v...
5
#include <bits/stdc++.h> using namespace std; const int NMax = 100003; int n, x, y, c, sum_edges; int mx[NMax], viz[NMax]; vector<pair<int, int> > G[NMax]; void dfs(int node) { viz[node] = 1; mx[node] = 0; for (int i = 0; i < (int)G[node].size(); ++i) { if (!viz[G[node][i].first]) { dfs(G[node][i].first...
10
#include <bits/stdc++.h> using namespace std; const long long inf = -1e18; const long long INF = 1e18; const long long mod = 998244353; const long long N = 200005; long long n, k, m; long long a[N]; long long fac[500005], inv[500005]; long long qpow(long long a, long long b) { if (b == 0) return 1; if (b & 1) { ...
16
#include <bits/stdc++.h> const int MOD = (int)1e9 + 7; const int INF = 99999999; using namespace std; struct Node { int x, y; int cost; int s; Node() {} Node(int x_, int y_, int cost_, int s_) : x(x_), y(y_), cost(cost_), s(s_) {} }; int n, m, k; int dp[105][105][1 << 7]; int vis[105][105][1 << 7]; int cost[1...
17
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx") using namespace std; const long long md = 1e9 + 7; const long long N = 1100000; const long long inf = 1e18; vector<long long> t; long long n; long long sum(long long i) { long long r = 0; for (; i >= 0; i = (i ...
15
#include <bits/stdc++.h> using namespace std; long long cal(long long n) { long long result = 0; for (long long i = 2; i * i * i <= n; i++) { result += n / (i * i * i); } return result; } int main() { long long st = 1, ed = 5e15, md, input, tmp = 0; scanf("%I64d", &input); while (st < ed) { md = (...
9
#include <bits/stdc++.h> using namespace std; inline int read() { char c; int x = 0; int b = 1; do { c = getchar(); if (c == 45) b = -1; } while (c > 57 || c < 48); do x = x * 10 + c - 48, c = getchar(); while (c <= 57 && c >= 48); x *= b; return x; } const int maxn = 2010, mod = 1e9 + 7; int ...
25
#include <bits/stdc++.h> using namespace std; long long a[10][4]; long long b[10]; bool vis[5]; long long dis(int i, int j) { long long x = a[i][0] - a[j][0], y = a[i][1] - a[j][1], z = a[i][2] - a[j][2]; return x * x + y * y + z * z; } bool check() { for (int u = 0; u < 8; u++) { for (int v = 0; v < 8; v++) ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, m, ans; vector<pair<long long, long long> > amel[maxn], dara[maxn * 10], yal; vector<int> tmp, h[2], v[maxn]; int cn[maxn][maxn], s[maxn], mark[maxn], hast[maxn]; bool dfs(int i) { if (mark[i]) return 0; mark[i] = 1; for (auto A : v[i]) { ...
13
#include <bits/stdc++.h> using namespace std; const long long inf = 1ll << 60, INF = 1ll << 40; const int N = 2005, M = 120005, mod = 1e9 + 7; template <class T> inline void gmin(T &x, const T &y) { if (x > y) x = y; } template <class T> inline void gmax(T &x, const T &y) { if (x < y) x = y; } inline void ch(int &x...
18
#include <bits/stdc++.h> using namespace std; pair<int, int> l[200010], r[200010]; int a[200010], c[200010]; void work(int n) { if (a[1] > 1) { printf("-1\n"); return; } l[1] = r[1] = make_pair(1, 1); for (int i = 2; i <= n; i++) { l[i] = l[i - 1].second >= 2 ? make_pair(l[i - 1].firs...
17
#include <bits/stdc++.h> using namespace std; int arr[2005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, i, j, a, ct, c = 0; vector<int> v; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a; v.push_back(a); if (1 <= a && a <= m) { arr[a]++; } else { ar...
8
#include <bits/stdc++.h> using namespace std; vector<int> a[100005]; long long ans, tmp; pair<int, int> A[100005], B[100005]; int Pow[100005], Rev[100005], son[100005], val[100005], vis[100005], ma[100005], OUT[100005], IN[100005]; int sum, P, n, i, x, y, M, tot, X; inline int Q_pow(int a, int b) { int res = 1; ...
22
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &a) { T ret(0), f(1); char ch(getchar()); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ret = ret * 10 + (ch ^ 48); ch = getchar(); } a = ret * ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 3100; const int oo = MAXN * MAXN; int n, m, x, y; vector<int> G[MAXN]; int d[MAXN][MAXN]; bool mk[MAXN]; void bfs(int root) { queue<int> q; q.push(root); d[root][root] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (auto x : G...
12
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long mod = 1e9 + 7; const long long N = 1e6 + 10; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; long long ans = 0; int z = y / x; for (int i = 0; i <...
2
#include <bits/stdc++.h> using namespace std; int inf = std::numeric_limits<int>().max(); long long teto(long long a, long long b) { return a / b + (a % b != 0); } long long ftot(long long n, long long k) { if (k == 0) return 0; long long t = 0; while (n > 0) { if (n >= k) { t += k; n = n - k; ...
7
#include <bits/stdc++.h> using namespace std; int h[222222] = {}; bool vis[222222] = {}; struct ff { int x, y; } f[222222] = {}; int weizhi[222222] = {}, shuliang[222222] = {}; int e[444474] = {}; int size[222222] = {}; int tou, wei, q[222222] = {}; int rudu[222222] = {}; int gen[222222] = {}; int temp[222222] = {}; ...
11
#include <bits/stdc++.h> using namespace std; int main() { set<int> v; v.clear(); int n, i, j, s; scanf("%d", &n); int f[100001]; memset(f, 0, sizeof(f)); for (i = 1; i <= n; i++) { scanf("%d", &f[i]); v.insert(f[i]); } for (i = 2; i <= n; i++) { s = 0; for (j = i - 1; j > 0; j--) { ...
8
#include <bits/stdc++.h> using namespace std; constexpr long long INF = 1e9; struct Edge { int dest, back; long long f, c; }; struct PushRelabel { vector<vector<Edge>> g; vector<long long> ec; vector<Edge*> cur; vector<vector<int>> hs; vector<int> H; PushRelabel(int n) : g(n), ec(n), cur(n), hs(2 * n), ...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1000000005; vector<int> odd, even; int cnt[2000005]; int su[2000005]; bool judge[2000005]; int num; void prepare() { memset(judge, true, sizeof(judge)); num = 0; int N = 2000005; for (int i = 2; i <= N; i++) { if (judge[i]) su[num++] = i; for...
10
#include<iostream> #include<map> #include<cstring> using namespace std; typedef long long ll; map<int,int>mp; int an[210210]; int ans[210200]; int main(){ int T; cin>>T; for(int i=1;i<=600;i++)an[i]=i; while(T--){ memset(ans,0,sizeof ans); mp.clear(); int n,a,b,s; cin>>n>>a>>b>>s; int num=b-a+1; int min...
8
#include <bits/stdc++.h> using namespace std; typedef vector<pair<int, string> > vpis; const int inf = numeric_limits<int>::max(); const long long int linf = numeric_limits<long long int>::max(); int main() { int n, m; vector<int> newtoys; map<int, int> make_pair; cin >> n >> m; for (int i = 0; i < (n); ++i) ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; string ar; int dp[n]; for (int i = 0; i < n; i++) dp[i] = INT_MAX; cin >> ar; ar[0] = '1'; dp[0] = 0; for (int i = 1; i < n; i++) { if (ar[i] == '1') for (int j = i - 1, count = 1; count <= d && j >= 0; j--, ...
0
#include <bits/stdc++.h> using namespace std; const int C = 800001; int sget(char tab[]) { for (int z = 0;; z++) { tab[z] = getchar(); if (tab[z] <= 32) return z; } } vector<vector<int> > F(C), F2(C); int trie[C][26], iss[C], is2[C], par[C], dep[C], lst = 1, ij[C], ij2[C], ...
15
#include <bits/stdc++.h> using namespace std; const int N = 100 + 5; int n; long long m; int a[N], b[N]; inline bool judge(int x) { int invalid = a[0] - x + b[0]; for (int i = 1; i < 60; i++) { if (a[i] <= x) { invalid -= min(invalid, x - a[i]); x = a[i]; } else invalid += a[i] - x; in...
14
#include <bits/stdc++.h> using namespace std; const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void YES(bool t = 1) { cout << YESNO[t] << endl; } void Yes(bool t = 1) { cout << YesNo[t] << endl; } void yes(bool t = 1) { cout << yesno[t] << endl; } cons...
2
#include <bits/stdc++.h> using namespace std; bool equiv(string a, string b) { if (a == b) return true; int L = a.length(); if (L % 2 != 0) return false; string a1 = a.substr(0, L / 2); string a2 = a.substr(L / 2, L / 2); string b1 = b.substr(0, L / 2); string b2 = b.substr(L / 2, L / 2); bool check = e...
9
#include <bits/stdc++.h> using namespace std; int a[1000]; int main() { string s1, s2; int i, j; cin >> s1 >> s2; if (s1.length() != s2.length()) { cout << "NO" << endl; return 0; } for (i = 0, j = s2.length() - 1; i < s1.length(); i++, j--) { if (s1[i] != s2[j]) { cout << "NO" << endl; ...
0
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point(long long x = 0, long long y = 0) : x(x), y(y) {} Point operator+(Point a) { return Point(x + a.x, y + a.y); } Point operator-(Point a) { return Point(x - a.x, y - a.y); } } a[100111]; int main() { ios ::sync_with_stdio(false);...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1, 0); for (int i = 0; i < n - 1; i++) { int temp1, temp2; cin >> temp1 >> temp2; a[temp1]++; a[temp2]++; } int result = 0; for (int i = 1; i < a.size(); i++) { if (a[i] == 1) result++; } ...
2
#include <bits/stdc++.h> using namespace std; void ETA() { long long int n, x; cin >> n; vector<long long int> vec; for (long long int i = 0; i < n; i++) { cin >> x; if (i != 0 and x == 1 and vec.back() == 1) continue; vec.push_back(x); } long long int m = vec.size(); long long int i = 0, j = ...
0
#include <bits/stdc++.h> const double pi = 3.14159; using namespace std; void fast() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int arr[26]; int main() { fast(); string s; cin >> s; if (s[0] >= 'a' && s[0] <= 'z') s[0] = (s[0] - 32); cout << s << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b; cin >> n >> a >> b; char A[n]; for (long long i = 0; i < n; i++) cin >> A[i]; if (A[a - 1] != A[b - 1]) cout << 1; else cout << 0; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; template <typename T> inline T read(T& x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x = f ? -x :...
17
#include <bits/stdc++.h> using namespace std; int v[1005]; int g[1005]; char a[1005][1005]; int main() { int n, m; int coun = 0; int temp = 0; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; if (a[i][j] == '*') { v[j]++; g[i]++; ...
6
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) cout << i << " "; cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) solve(); }
0
#include <bits/stdc++.h> const int N = 2e5 + 10; const int MOD = 1e9 + 7; const int INF = 2e9; const long long INFLL = 1e18; const double PI = acos((double)-1); inline int mult(int a, int b, int p = MOD) { return (1ll * a * b) % p; } inline int add(int a, int b, int p = MOD) { return (1ll * a + b) % p; } inline int fpo...
14
#include <bits/stdc++.h> using namespace std; int s[101], t[101]; int main() { int a, b, c, n; cin >> n >> a >> b; for (int i = 0; i < a; i++) { cin >> c; s[c] = 1; } for (int i = 0; i < b; i++) { cin >> c; t[c] = 1; } for (int i = 1; i <= n; i++) { if (s[i] != 0) cout << 1 << " ...
0
#include <bits/stdc++.h> using namespace std; int n, r; int p = -1, best = -1; char op[3] = "TB"; void work(int v) { int cnt = 0, tims = 0; int b = r, c = v; while (c) { cnt++; tims += b / c; b %= c; swap(b, c); } if (b == 1 && tims == n && cnt > best) { best = cnt; p = v; } } int ma...
13
#include <bits/stdc++.h> using namespace std; const int MaxN = 1505; struct point { int x, y, idx; }; vector<int> edges[MaxN]; point points[MaxN]; int sol[MaxN], c[MaxN]; bool mark[MaxN]; int dfs(int u) { mark[u] = true; c[u] = 1; for (__typeof((edges[u]).begin()) p = (edges[u]).begin(); p != (edges[u])....
14
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> st[200000]; vector<int> G[200000]; int col[200000], suc = 1; void dfs(int u) { for (int i = 0; i < G[u].size(); i++) if (col[G[u][i]] == -1) col[G[u][i]] = col[u] ^ 1, dfs(G[u][i]); else if (col[G[u][i]] != (col[u] ^ 1)) suc = ...
8
#include <bits/stdc++.h> using namespace std; int main() { char a[5005]; cin >> a; int len = strlen(a); int aa = 0, bb = 0, cc = 0; for (int i = 0; i < len; i++) { if (a[i] == 'a') { if (bb || cc) { printf("NO"); return 0; } aa++; } else if (a[i] == 'b') { if (c...
4
#include <bits/stdc++.h> using namespace std; int a, b, d, i; int main() { cin >> a >> b; if (a == 1 && b == 0) { cout << 1; return 0; } d = a - b; if (d == 0) { cout << "infinity"; return 0; } else if (d < 0 || b > a / 2 || !a) { cout << 0; return 0; } int nr = 0; for (i = 2; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; if (t == 10 && n == 1) { cout << -1 << endl; } else if (t == 10 && n > 1) { for (int i = 1; i <= n - 1; i++) { cout << 1; } cout << 0 << endl; } else if (t < 10) { for (int i = 1; i <= n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); int n, d; cin >> n >> d; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; vector<vector<double>> dp(n + 1, vector<double>(10, -1)); vector<vector<pair...
13
#include <bits/stdc++.h> using namespace std; template <typename T> void printv(vector<T> v) { for (auto e : v) { cout << e << " "; } cout << "\n"; } template <typename T> void printvv(vector<T> vv) { for (long long i = 0; i < vv.size(); i++) { cout << i << ": "; for (auto e : vv[i]) { cout <<...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native") using namespace std; namespace output { void __(short x) { cout << x; } void __(unsigned x) { cout << x; } voi...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n - k - 1; i++) cout << i + 1 << " "; for (int i = n - k - 1, j = 0; i < n; i++, j++) cout << n - j << " "; cout << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; signed main() { long long n, m; cin >> n >> m; vector<long long> v(n); map<long long, long long> mp; for (long long i = 0; i < n; i++) { cin >> v[i]; mp[v[i]]++; } set<pair<long long, long long>> s; for (long long i = 0; i < n; i++) { if (mp[v[i]...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long MN = 2e6 + 10; char cad[MN]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int T; cin >> T; while (T--) { int N; cin >> N; cin >> cad; int l = 0, r = N - 1; while (l < N && cad[l] == '0') ...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long A[n]; for (long long i = 0; i < n; i++) { cin >> A[i]; A[i] %= 2; } stack<long long> st; for (long long i = 0; i < n; i++) { if (!st.empty...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<vector<int>> input(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> input[i][j]; } } unordered_set<int> x, y;...
20
#include <bits/stdc++.h> using namespace std; const int maxN = 100224; const int inf = 1 << 30; int n, a[maxN]; int l[maxN]; struct SegmentTree { int data[maxN * 4]; void update(int node, int l, int r, int idx, int val) { if (l > r || idx < l || idx > r) return; if (l == r && l == idx) { data[node] = ...
11
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int flag = 0; long long i = 0; while (i < s.length()) { if (s[i] == s[i + 1]) { s.erase(i, 2); if (i != 0) i -= 1; else i = 0; if (flag == 0) flag = 1; else if (flag == 1) ...
4
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator+(const Point& other) const { return {x + other.x, y + other.y}; } Point operator-(const Point& other) const { return {x - other.x, y - other.y}; } Point o...
24
#include <bits/stdc++.h> using namespace std; int m[1100][1100]; int n; void outn() { cout << "YES"; for (int i = 1; i <= n; i++) { cout << endl; for (int j = 1; j <= n; j++) cout << m[i][j]; } } int main() { int a, b; cin >> n >> a >> b; if (a > 1 && b > 1) { cout << "NO"; return 0; } i...
9
#include <bits/stdc++.h> long long c[1000]; int main() { long long x, i, m, t; int s; scanf("%I64d", &x); t = x; s = 0; while (x % 2 == 0) { x /= 2; c[s++] = 2; } m = (long long)(sqrt(x) + 1); for (i = 3; i <= m; i += 2) { while (x % i == 0) { x /= i; c[s++] = i; } } if...
6
#include <bits/stdc++.h> #pragma GCC optimize(3, "Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") using namespace std; inline char gc() { static char buf[1 << 16], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) +...
19
#include <bits/stdc++.h> using namespace std; int n, k; int l[200005], r[200005], good[200005]; char m[200005], nxt[200005]; string s, t; string res; vector<int> v; void dfs1(int u) { if (!u) return; dfs1(l[u]); t += s[u]; v.push_back(u); dfs1(r[u]); } bool dfs(int u, int h, bool goodSub) { if (!u) return f...
17
#include <bits/stdc++.h> using namespace std; void add(int k, char s[], char s2[], int l) { int d, i; for (i = 0; i < l; i++) { d = (k + (s[i] - '0')) % 10; s2[i] = d + '0'; } return; } void mk(int l, char a[], char b[]) { int i, h, j, z; char c[1001]; for (i = 0; i < l; i++) b[i] = a[i]; for (i...
7
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T& a, T b) { retu...
20
#include <bits/stdc++.h> using namespace std; int modul(int n); int mac(int n) { n += 9; if (modul(n) != 10) { n = mac(n); } return n; } int main() { int k; cin >> k; int a[k]; a[0] = 19; for (int i = 1; i < k; i++) { a[i] = mac(a[i - 1]); } cout << a[k - 1]; } int modul(int n) { int j =...
3
#include <bits/stdc++.h> using namespace std; int n, m, status[2001][2001], g[4000001][5], kol[4000001], h; char a[3000][3000]; bool f; void dfs(int x, int y) { status[x][y] = 1; if (a[x][y] == '^') { if (status[x - 1][y] == 1) f = true; else if (status[x - 1][y] == 0) dfs(x - 1, y); } if (a...
14
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 1; bool f = false; map<string, int> mp, mp_2; set<long long> st; string s, p, q; int main() { ios::sync_with_stdio(false); cin.tie(0); long long tt, a, b, d = 0, sum = 0, sum_2; vector<long long> v, v_2; cin >> tt >> b; while (tt--) { ...
4
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int MAX_VAL = 1e6 + 2; const int INF = 0x3f3f3f3f; using namespace std; void file() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int q; cin >> q; vector<pair<string, string> > v; for (int i = 0; i < q; ++i) { bool fo...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; long long 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; } const long long MA...
25
#include <bits/stdc++.h> using namespace std; bool possible(long long mid, long long k, long long n) { long long t = k, cnt = 0; k = 1; while ((mid / k) >= 1) { cnt += (mid / k); k *= t; } if (cnt >= n) return true; else return false; } int main() { long long n, k; cin >> n >> k; long ...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 10; int n, m; vector<int> adj[MAXN]; int q[MAXN], d[MAXN], sec[MAXN]; priority_queue<pair<int, int>> pq; vector<pair<int, int>> vec[MAXN]; bool cmp(int u, int v) { return d[u] < d[v]; } int get(int v, int nd, int tot) { int ret = n + 3; { mems...
13
#include <bits/stdc++.h> using namespace std; int answer(int h, int w, int u1, int d1, int u2, int d2) { int ans = w; while (h > 0) { if (h == d1) { ans += d1; ans -= u1; if (ans < 0) ans = 0; } else if (h == d2) { ans += d2; ans -= u2; if (ans < 0) ans = 0; } else ...
0
#include <bits/stdc++.h> using namespace std; bool islucky(int n) { while (n) { if ((n % 10 != 4) && (n % 10 != 7)) return false; n /= 10; } return true; } pair<int, int> lucky; vector<pair<int, int> > v, vs, res; map<pair<int, int>, int> whereIt; int main() { int n, lp = -1; cin >> n; for (int i = ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); long long int n, j, coding = 0, math = 0, pe = 0; cin >> n; long long int a[n], b[n], i, team; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); for (i...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x; vector<int> v; scanf(" %d %d", &n, &k); for (int i = 0; i < n; i++) { scanf(" %d", &x); v.push_back(x); } sort(v.rbegin(), v.rend()); int total = 0; for (int i = 0; i < n; i += k) { total += (v[i] - 1) * 2; } printf(...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; bool f[26]; int r = 0, n; for (int i = 0; i < 26; i++) f[i] = false; cin >> n; cin >> s; if (n > 26) { cout << -1; return 0; } for (int i = 0; i < n; i++) { if (f[(int)s[i] - 97]) r++; else f[(int)s[i] - 9...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, i = 0; cin >> n; string s; cin >> s; for (i = 0; i < n; i++) { if (s[i] == '0') { break; } } if (i == s.size()) { cout << s.size(); } else { cout << i + 1;...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (c >= 0) { if ((b + c) % a == 0) { cout << a; return 0; } else { cout << (b + c) % a; return 0; } } else if (c < 0) { if (b + c == 0) { cout << a; return 0; } el...
2
#include <bits/stdc++.h> using namespace std; struct H { int w, a, c; bool operator<(const H &cmp) const { return (long long)cmp.a * w > (long long)a * cmp.w; } } hh[500001]; long long ans1; double ans2; void qs(int l, int r, int W) { if (l > r) return; if (l == r) { ans1 += ((long long)hh[l].a * W) /...
20
#include <bits/stdc++.h> using namespace std; int arr[100][100]; int DP[100][2]; bool zero[100]; int n, m, k; int ans; bool same(int i) { if (i == 0) { return true; } else { return zero[i] == zero[i - 1]; } } void solve() { for (int i = 0; i < n; i++) { for (int fst = 0; fst <= 1; fst++) { int...
14
#include <bits/stdc++.h> using namespace std; int n, ans; int p[200010]; char s[200010]; int main() { int T; long long now; scanf("%d", &T); while (T--) { scanf("%s", s); ans = 0; n = strlen(s); for (int i = 0; i < n; i++) { if (s[i] == '1') p[i] = 0; else { if (!i) ...
9
#include <bits/stdc++.h> using namespace std; long long int n, m, ans, co, fr; vector<long long int> v; int main() { cin >> n >> m; for (long long int i = 0; i < n; i++) { long long int a, b; cin >> a >> b; co += a; v.push_back(a - b); } sort((v).begin(), (v).end(), greater<long long int>()); ...
3
#include <bits/stdc++.h> using namespace std; int n, A[10010], S[111][11111]; int main() { scanf("%d", &n); int tot = 0; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); A[x]++; tot += x; } int ans = 1; S[0][0] = 1; for (int i = 1; i <= 100; i++) if (A[i]) for (int j = 100;...
13
#include <bits/stdc++.h> using namespace std; bool dot = true, ff = 0, ss = 0; int f = 0, s = 0, first = 0, second = 0; int main() { char a[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; a[i][j] == 'X' ? f++ : 0; a[i][j] == '.' ? dot = 0 : 0; a[i][j] =...
10
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, mod = 1e9 + 7, i; cin >> n >> k; long long a[50]; a[0] = 1; for (i = 1; i <= 45; i++) { a[i] = a[i - 1] * n; a[i] %= mod; } vector<long long> bt; while (k) { bt.push_back(k % 2); k /= 2; } long long ans = 0;...
3
#include <bits/stdc++.h> using namespace std; void out() { cout << -1; exit(0); } int main() { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; for (int s1 = 1; s1 < 220; s1++) { for (int s2 = 1; s2 < s1; s2++) { for (int s3 = 1; s3 < s2; s3++) { if (v1 <= s1 and v1 * 2 >= s1) if (...
5
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)2e9; const long long md = 1000000007; long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; long long power(long long a, long long p, long long md) { long long ans = 1; while (p) { if (p & 1) ans *= a; p /= 2; a *= a; ans...
13
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long n, a, b, c, d; cin >> n >> a >> b >> c >> d; long long res = 0; int ab = a + b; int ac = a + c; int bd = b + d; int cd = c + d; long long maxnum = max(ab, max(ac, max(bd, cd))); long long minnum = min(ab, ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; long double m, a, b; long double ans = 1e9; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a >> b; ans = min(ans, m * a / b); } cout << fixed << setprecision(10); cout << an...
0
#include <bits/stdc++.h> using namespace std; int a[55], b[55], d[105], f[55], c[55], inv[55]; const int p = 998244353; long long qp(long long a, int b, int p) { long long r = 1; while (b) { if (b & 1) r = r * a % p; a = a * a % p, b >>= 1; } return r; } int main() { int n, i, j, k, l, t, m = 0; sca...
19
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int a[N]; int n, k, p; vector<int> odd, even; int main() { cin >> n >> k >> p; for (int i = 1; i <= int(n); i++) { scanf("%d", &a[i]); if (a[i] & 1) odd.push_back(a[i]); else even.push_back(a[i]); } int cnte = ((int)(...
9
#include <bits/stdc++.h> using namespace std; int Scan() { int res = 0, ch, flag = 0; if ((ch = getchar()) == '-') flag = 1; else if (ch >= '0' && ch <= '9') res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0'; return flag ? -res : res; } void Out(int a) { if (a > ...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 5010; int n, m, v1[N], v2[N], ...
10
#include <bits/stdc++.h> using namespace std; const int M = 500; int a[200200], b[200200], c[200200]; int id[200200], nn; long long ans; struct Array { vector<int> vec; vector<vector<int> > cnt; vector<int> lazy; int ans, sum, tot, n; Array() {} void pre() { n = vec.size(); for (int i = 1; i < n; i+...
25
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, n, m = 0, c = 0; cin >> n; map<int, int> mp; for (int i = 1; i <= n; i++) { cin >> a; mp[a]++; if (m < mp[a]) m = mp[a]; } for (auto it = mp.begin(); it != mp.end(); it++) { ...
9
#include <bits/stdc++.h> int main() { long long int a1, b1, a2, b2, a3, b3; scanf("%lld %lld", &a1, &b1); scanf("%lld %lld", &a2, &b2); scanf("%lld %lld", &a3, &b3); if (a2 + b3 <= b1) { if (a3 <= a1 && b2 <= a1) { printf("YES\n"); return 0; } } if (a2 + b3 <= a1) { if (a3 <= b1 &&...
4
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(const bool& b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) ...
7