solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { bool a = false, b = false, c = false, d = false; char str[110]; scanf("%s", &str); int len = strlen(str); a = (len >= 5); for (int i = 0; i < len; i++) { b = b || (str[i] >= 'A' && str[i] <= 'Z'); c = c || (str[i] >= 'a' && str[i] <= 'z'); ...
1
#include <bits/stdc++.h> using namespace std; long long int ans(long long int n) { long long int a = 0; for (long long int i = 2; (long long int)(i * i * i) <= n; i++) { a += n / ((long long int)(i * i * i)); } return a; } int main() { std::ios::sync_with_stdio(false); long long int n; cin >> n; lon...
3
#include <bits/stdc++.h> const int Mod = (int)1e9 + 7; const int MX = 1073741822; const long long MXLL = 9223372036854775807; const int Sz = 1110111; using namespace std; inline void Read_rap() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline void randomizer3000() { unsigned int seed; asm("r...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline void gn(T &x) { char c, sg = 0; while (c = getchar(), (c > '9' || c < '0') && c != '-') ; for ((c == '-' ? sg = 1, c = getchar() : 0), x = 0; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0'; if (sg) x =...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); long t; cin >> t; while (t--) { long a, b, c, d; cin >> a >> b >> c >> d; long x, y, x1, y1, x2, y2; cin >> x >> y >> x1 >> y1 >> x2 >> y2; x -= a - b, y -= c - d; if ((...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int x[N], y[N]; int main() { int n; scanf("%d", &n); long long sumx = 0, sqx = 0, sumy = 0, sqy = 0; for (int i = 0; i < n; ++i) { scanf("%d%d", x + i, y + i); sumx += x[i]; sqx += 1LL * x[i] * x[i]; sumy += y[i]; sqy += 1...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 200004; long long power(long long a, long long n) { if (n == 0) return 1; long long ans = 1; long long val = a; while (n) { if (n % 2) { ans *= val; ans %= 1000000007; } val *= val; val %= 1000000007; n /= 2; } re...
6
#include <bits/stdc++.h> using namespace std; int main() { string st; cin >> st; int f = 0, s = 0; for (int i = 0; i < st.size(); i++) { if (st[i] == '7') s++; else if (st[i] == '4') f++; } if (s == 0 && f == 0) { cout << "-1"; return 0; ; } else if (f >= s) cout << "4"...
2
#include <bits/stdc++.h> const long long mod = 1000000007; const long long Inf = 2 * 1e9; using namespace std; int toint(string s) { long long ans = 0; for (int(i) = 0; (i) < s.length(); (i)++) ans = ans * 10 + (s[i] - '0'); return ans; } vector<int> a; vector<pair<int, int>> pr; int main() { ios::sync_with_std...
3
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int mod = 1000000007; const int N = 200005; int n; int a[N]; int solve(int cur) { int tmp = cur; int mx = 0; while (tmp <= a[n - 1]) { tmp += cur; int ind = lower_bound(a, a + n, tmp) - a; --ind; if (ind >= 0) { ...
4
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; int p = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') p = -p; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar(); x = x * p; } const int ma...
3
#include <bits/stdc++.h> using namespace std; vector<long long> arr; long long n, k, a, b; long long reccc(long long l, long long r) { long long c = lower_bound(arr.begin(), arr.end(), r) - lower_bound(arr.begin(), arr.end(), l); if (c == 0) { return a; } if (r == l + 1) { return b * c; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; long long a[N], b[N], r[N], sum[N], mx; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } for (int i = 0; i < n; ++i) { cin >> b[i]; ...
3
#include <bits/stdc++.h> using namespace std; int main(){ char a; cin>>a; if(a<=90){cout<<"A"<<endl;} else{cout<<"a"<<endl;} }
0
#include <bits/stdc++.h> inline int gi() { int 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; } int a[101][101], num[101][101], cnt, o[101][101], S, T; int fir[6000], dis[1000...
5
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << end...
0
#include <iostream> #include <cmath> using namespace std; int main(){ double x, q; while(cin >> q, q != -1.0){ x = q / 2.0; while(abs(x*x*x-q) >= 0.00001*q){ x = x-(x*x*x-q)/(3*x*x); } printf("%.6f\n", x); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, a, j, b, c, d, x, y; cin >> n; for (i = 0; i < n; i++) { cin >> a >> b >> x >> y; c = max((x * b), ((a - 1 - x) * b)); d = max((a * y), (a * (b - 1 - y))); cout << (max(c, d)) << endl; } }
1
#include<bits/stdc++.h> using namespace std; string s; int ans=0; int main(){ cin>>s; char now=s[0]; for (int i=1;i<s.size();i++) if (s[i]==now) ans++,now=s[i]=='0'?'1':'0'; else now=s[i]; printf("%d",ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; int a[702], g[702][702]; int f[702][702][2]; int gcd(int x, int y) { if (!y) return x; else return gcd(y, x % y); } bool dfs(int l, int r, int x) { int t; if (l > r) return 1; if (x == 0) t = l - 1; else t = r + 1; if (t < 1 || t > n) re...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, m, d[100][100], f[20][100], pos[100], ans; vector<int> p[2]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &d[i][j]); int T = 8000; ans = INF; while (T--) { p[0]...
4
#include <iostream> #include <cmath> using namespace std; int main() { int d[4]; int e, f; int sum = 0; int MIN = 1000; for (int i = 0; i < 4; i++) { cin >> d[i]; sum += d[i]; MIN = min(MIN, d[i]); } cin >> e >> f; sum += max(e, f); cout << sum-MIN << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct node { int x, id; }; bool cmp(const node &a, const node &b) { return a.x < b.x; } node a[100010]; int from[100010]; int main() { int n, m; while (scanf("%d%d", &n, &m) == 2) { for (int i = 0; i < n; i++) { scanf("%d", &a[i].x); a[i].id = i; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; set<pair<int, int>> bridges; int asdadsa, low[N], dis[N], dsuParent[N], dfsParent[N]; int n, m, a, b; vector<int> g[N]; vector<pair<int, int>> edges; set<pair<int, int>> directed_edges; bool comp(const int &a, const int &b) { return dsuParent[a] < ds...
6
#include <bits/stdc++.h> using namespace std; vector<long long> erat; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long nd(long long a) { map<long long, long long> m; while (a != 1) { ++m[erat[a]]; a /= erat[a]; } long long count = 1; for (auto e : m...
4
#include <bits/stdc++.h> using namespace std; int n, m, d, tot, now, last, p[1000039], pl[1000039]; long long q[1000039], k, x, y, z, ans, pus; struct yyy { int to; long long w; int z; }; struct ljb { int head, h[1000039]; yyy f[2000039]; inline void add(int x, int y, long long z) { f[++head] = (yyy){y,...
6
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long n=2,m=1; for(int i=0;i<N;i++){ m=n+m; n=m-n; } cout << n << endl; }
0
#include <bits/stdc++.h> using namespace std; int dp[1 << 26]; int main() { int bit = 0; string S; fill_n(dp, 1 << 26, 1 << 27); dp[0] = 0; cin >> S; for(int i = 0; i < S.size(); i++) { bit ^= (1 << (S[i] - 'a')); for(int j = 0; j < 26; j++) { dp[bit] = min(dp[bi...
0
#include <bits/stdc++.h> using namespace std; int Q; bool vis[41]; int C; map<string, int> msi; int n, Max; long long v[41], deg[41]; void update_maximum(long long R) { int Size = 0; while (R) { if (R & 1) Size++; R >>= 1; } Max = max(Size, Max); } int pickPivot(long long P) { int pivot = -1, Max = -1...
5
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { if (b == 0) return a; else return gcd(b, a % b); } template <class T> T power(T a, T b) { T result = 1; while (b > 0) { if (b & 1) result = result * a; a = a * a; b >>= 1; } return result; } template <clas...
2
#include <bits/stdc++.h> int main() { int a, b, x1, y1, x2, y2; scanf("%d%d%d%d%d%d", &a, &b, &x1, &y1, &x2, &y2); a *= 2; b *= 2; int i, j, s1, s2, r1, r2; s1 = x1 + y1; s2 = x2 + y2; r1 = 0; r2 = 0; if (s1 < 0) r1 = 1; if (s2 < 0) r2 = 1; i = fabs(s1 / a - r1 - s2 / a + r2); s1 = x1 - y1; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b, t, r = 0; cin >> t; while (t--) { cin >> a >> b; r = pow(min(max((a + a), b), max((b + b), a)), 2); cout << r << endl; } return 0; }
1
#include <bits/stdc++.h> const double pi = 4.0 * atan(1.0); const double e = exp(1.0); const int maxn = 3e5 + 8; const long long mod = 1024 * 1024 * 1024; const unsigned long long base = 1e7 + 7; using namespace std; vector<int> g[maxn]; int a[maxn], r[maxn], b[maxn]; int ans = 0; int h = 0, l = 0; void dfs(int u, int ...
6
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N, cnt=0; cin >> N; vector<int> A(N); rep(i, N) cin >> A.at(i); rep(i, N) if(A.at(A.at(i)-1)==i+1) cnt++; cout << cnt/2 << endl; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second typedef pair<int,int> P; struct data{ int y,x; int bit; int s; data(){ } data(int y...
0
#include <iostream> #include <string> #include <sstream> #include <algorithm> #include <vector> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<bool> vb; typedef vector<vb> vvb; #define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init)) typedef vector<string> vs; typede...
0
#include <bits/stdc++.h> using namespace std; typedef long long mx[2][2]; mx a, b, c; long long d, l, r, k; void mul(mx x, mx y) { memset(c, 0, sizeof(c)); for (int i = 0; i < (2); ++i) for (int j = 0; j < (2); ++j) for (int k = 0; k < (2); ++k) (c[i][j] += x[i][k] * y[k][j] % d) %= d; memcpy(x, c, size...
3
#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 k; cin >> k; if (k <= 30) cout << "NO" << endl; else { cout << "YES" << endl; if (k - 30 == 6) cout << 6 <<...
1
#include <bits/stdc++.h> int Min(int a, int b) { return a < b ? a : b; } int main() { int n, x1, x2, t1, t2, p, d; int t3, t4, ans; while (scanf("%d %d %d", &n, &x1, &x2) == 3) { scanf("%d %d %d %d", &t1, &t2, &p, &d); if (x2 > x1) { t3 = (x2 - x1) * t2; if (d == 1) { if (p > x1) ...
3
#include<bits/stdc++.h> #define mk make_pair #define r(i,n) for(int i=0;i<n;i++) using namespace std; string s[500]; int h,w,sum=0; vector<int>x,y; void del(int t1,int t2){ vector<pair<char,pair<int,int> > >p; for(int i=t1;i<h;i++)if(s[i][t2]!='.'){ p.push_back(mk(s[i][t2],mk(i,t2))); break; } for(int i...
0
#include <bits/stdc++.h> using namespace std; int MOD = 1e9 + 7; int k; long long now[2][2], tod[2][2], tmp[2][2], res[2][2]; void init() { tod[0][0] = 2; tod[0][1] = 2; tod[1][0] = 0; tod[1][1] = -1; } int flag = 0; void mult(long long x) { if (flag == 1) { x--; res[0][0] = 1; res[0][1] = 1; ...
5
#include<iostream> using namespace std; int main(int argc, char const *argv[]) { int a; cin>>a; cout<<1110-a; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 61; const int M = 1e6 + 500; const long long int ths = 1LL << 40; const int NN = 5e3 + 6; void solve() { long long int n; cin >> n; long long int a[n...
2
#include <bits/stdc++.h> using namespace std; void solve() { int64_t a, b, c; cin >> a >> b >> c; int64_t ans = abs(a - b) + abs(b - c) + abs(c - a); for (int da = -1; da <= 1; da++) { for (int db = -1; db <= 1; db++) { for (int dc = -1; dc <= 1; dc++) { int64_t val = abs(a + da - (b + db)) + ...
1
#include <bits/stdc++.h> using namespace std; void test(); int main() { int t = 1; for (int i = 1; i <= t; i++) { test(); cout << endl; } return 0; } void test() { map<string, int> mp, mp1; int ans = INT_MIN; string name; int n; cin >> n; string s[n]; int m[n]; for (int i = 0; i < n; i++...
1
#include <bits/stdc++.h> using namespace std; int mp[2000003 * 6], tot, nxt[2000003], point[2000003], v[2000003], c[2000003], val[2000003], siz[2000003], son[2000003]; int deep[2000003], ans[2000003], mx, mark[2000003], n; void add(int x, int y, int z) { tot++; nxt[tot] = point[x]; point[x] = tot; v[tot] = ...
4
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) using namespace std; const int ALP='z'-'a'+1,MAX_N=2e5,INF=1e8; string S; int N,opt[MAX_N+1],dp[1<<ALP],cnt[ALP]; int main(){ cin>>S; N=(int)S.size(); opt[0]=0; fill(dp,dp+(1<<ALP),INF); dp[0]=0...
0
#include <bits/stdc++.h> using namespace std; int a[52]; int b[52]; const int k5 = 5000; int n; long long dp[52][52][k5 + 5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } vector<p...
6
#include <bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(x);i<(y);++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif const int inf=1e9; const int64_t inf64=1e18; c...
0
#include<bits/stdc++.h> using namespace std; const int N=205; int n,i,j,k,s[N][N],f[N][N],col[N],ans; char c[N]; bool dfs(int u){ for(int i=1;i<=n;++i)if(s[u][i]){if(col[i]==-1 && s[u][i]){ col[i]=col[u]^1; if(!dfs(i))return 0; }else if(col[i]==col[u])return 0;} return 1; } int main(){ scanf("%d",&n); memset(c...
0
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e4 + 14; const int MOD = 1e9 + 7; const long long INF = 1e9 * 1ll * 1e9; int n, l, r; bool can[MaxN][MaxN]; bool used[MaxN]; pair<int, int> a[MaxN]; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) return a.second > b.second; if...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int j = 0; j < n - 1; j++) { string t; cin >> t; for (int i = 0; i < t.length(); i++) if (t[i] != '?' && t[i] != s[i]) if (s[i] == '?') s[i] = t[i]; else s...
3
#include <bits/stdc++.h> using namespace std; long long n; long long primes[] = {2, 3, 5, 7, 11}; int cnts[] = {0, 0, 0, 0, 0}; int limit = 2; vector<long long> ans; void dfs(long long cur, int id) { if (id == limit) { ans.push_back(cur); } else { while (cur < n * n * 2) { dfs(cur, id + 1); cur ...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 23; int n, a[maxN], cnt[maxN], dp[maxN], bis[maxN], f[maxN]; bool bad[maxN]; int bs(int l, int r, int x) { while (l < r) { int mid = (r + l) / 2; if (bis[mid] >= x) r = mid; else l = mid + 1; } return l; } int main() { ...
5
#include <bits/stdc++.h> using namespace std; int n, m, k; bool debug = false; int W; struct company { long long w, a, c; bool operator<(const company b) const { return c * b.w < b.c * w; } } coms[500005]; int main() { scanf("%d%d%d", &n, &m, &W); for (int i = 0; i < m; i++) scanf("%I64d", &coms[i].w); for (i...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, i = 0, j; cin >> n; j = n - 1; int arr[n], dup[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; dup[i] = arr[i]; } sort(dup, dup + n); if (n == 1) cout << dup[0]...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int pre = 0; for (int i = 0; i < k; i++) { pre += a[i]; } int minval = pre; int index = 0; for (in...
2
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <bitset> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <queue> #define mp make_pair #define pb push_back typedef long long ll; typedef long doubl...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m, k, u, v, c[200005] = {}, d[200005] = {}, z = 0; vector<int> g[200005] = {}; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 0; i < m; i++) cin >> u >> v, g[u].push_back(v), g[v].p...
3
#include<bits/stdc++.h> using namespace std; const int INF = 1e8; int main(){ int n,m; while(cin >> n >> m, n){ vector<int> c(m); for(int i=0;i<m;i++)cin >> c[i]; vector<int> x(n); for(int i=0;i<n;i++)cin >> x[i]; vector<int> cur(256,INF), nxt(256); cur[128] = 0; for(int i=0;i<n;i++)...
0
#include<bits/stdc++.h> using namespace std; #define MN 1000000 #define mod 1000000007 inline int read() { int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } int f[MN+5],p[MN+5],inv[MN+5],Inv[MN+5],n,ans; inline ...
0
#include <bits/stdc++.h> using namespace std; mt19937 rnd(239); vector<vector<long long>> g; vector<long long> color; const long long MOD = 998244353; long long n; long long m; bool ok = true; long long l = 0; long long r = 0; void dfs(long long v, long long c) { color[v] = c; if (c == 0) l++; else r++; ...
4
#include <bits/stdc++.h> using namespace std; int n, m; int arr[100005]; int pf[32][100005]; int st[4 * 100005]; void init() { memset(arr, 0, sizeof(arr)); memset(pf, 0, sizeof(pf)); return; } void build(int l = 0, int r = n - 1, int idx = 0) { if (l == r) { st[idx] = arr[l]; return; } int mid = l +...
2
#include <bits/stdc++.h> struct IO { template <typename T> inline friend IO operator>>(IO in, T &x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch ^ 48); ...
3
#include<iostream> using namespace std; int main(){ char s; cin >> s; if(s=='A')cout << "T"; if(s=='T')cout << "A"; if(s=='G')cout << "C"; if(s=='C')cout << "G"; }
0
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define sc second typedef pair<int,int> P; int N,K; int C[5003],R[5003]; int A,B; vector<int>G[5003];int s1[5003]; vector<P>G2[5003]; int main() { scanf("%d%d",&N,&K); for(int i=0;i<N;i++){ scanf("%d%d",&C[i],&R[i]); } for(int i=0;...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; const double pi = acos(-1); long long power(long long a, long long b, long long m = MOD) { long long ans = 1; while (b > 0) { if (b & 1) ans = ((ans % m) * (a % m)) % m; a = ((a % m) * (a % m)) % m; b...
2
#include <bits/stdc++.h> #pragma warning(disable : 4996) const int kMaxn = 5555; int n, a[kMaxn], ok[kMaxn], cnt[55]; char str[kMaxn << 1], s[kMaxn][kMaxn]; bool cmp(int x, int y) { return strcmp(s[x], s[y]) < 0; } int main() { static int i, j, k, last; static int ans, now, best; memset(str, 0, sizeof(str)); me...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n >> a; if (a % 2 == 0) a = n - a + 1; cout << (a - 1) / 2 + 1; }
1
#include <bits/stdc++.h> template <typename T> inline void read(T &t) { int f = 0, c = getchar(); t = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) t = t * 10 + c - 48, c = getchar(); if (f) t = -t; } template <typename T> void write(T x) { if (x < 0) putchar('-'), x = -x; if (x ...
5
#include <bits/stdc++.h> using namespace std; set<int> edges[1000000]; set<int> rem; int component[1000000]; set<int> comp_id; void go(int id) { queue<int> bfs; bfs.push(id); component[id] = id; while (!bfs.empty()) { int u = bfs.front(); bfs.pop(); stack<int> st; for (auto v : rem) { if (...
5
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; char match(char c) { return c == ']' ? '[' : '('; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); string line; while (cin >> line) { int n = line.size(); vector<int> closing(n, -1); stack<int> st; pair<int, string> an...
1
#include <bits/stdc++.h> using namespace std; const char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}; const int dy[] = {1, 0, -...
2
#include <bits/stdc++.h> using namespace std; int n; bool row(vector<vector<int> > &table) { for (int i = 0; i < n; ++i) { bool flag = true; for (int j = 0; j < n; ++j) { if (!table[i][j]) flag = false; } if (flag) return true; } return false; } bool col(vector<vector<int> > &table) { for ...
1
#include <bits/stdc++.h> using namespace std; const int N = 30000; const int INF = 1000000000; map<string, int> lzs; char str[50]; string s, sub[N]; int num[N], score[N]; int getsum(string sb) { int r = 0, i; for (i = sb.size() - 1; i >= 0; i--) r += (sb[i] - 'a' + 1); return r; } int _max(string sb) { int r = ...
6
#include <bits/stdc++.h> using namespace std; void solve() { long long w, h, n, a, i, z = 0; cin >> w >> h >> n; set<long long> sh, sv; map<long long, long long, greater<long long> > m1, m2; map<long long, long long, greater<long long> >::iterator itx, ity; sh.insert(z); sh.insert(h); sv.insert(z); sv...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, t; cin >> n >> a; t = 0; for (int i = 1; i <= n; i++) { if (a % i != 0) { continue; } if (i > a) { break; } for (int j = 1; j <= n; j++) { if (j > a) { break; } if (i * j == a...
1
#include <bits/stdc++.h> using namespace std; char s[10]; int n; int notzero[12], cnt[12], ten[10], ans; int main() { ten[0] = 1; for (int i = 1; i < 8; ++i) ten[i] = 10 * ten[i - 1]; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%s", s); int len = strlen(s); notzero[s[0] - 'a'] = 1; fo...
3
#include"bits/stdc++.h" #define int long long #define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i) using namespace std; const int MAX_N=2999; int N; vector<double> p; double dp[MAX_N+1][MAX_N+1]; signed main(){ cin>>N; p.resize(N); REP(i,N) cin>>p[i]; REP(i,(N+1)/2) dp[N-i][i]=1; for(int i=N-1;i>=0;--i){ for(...
0
#include <iostream> using namespace std; int main() { int a,b; cin>>a>>b; int an=-1; for(int i=0;i<=10000&&an==-1;i++) { if (i*8/100==a && i/10==b) an=i; } cout<<an<<endl; }
0
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int main(void){ int cards[5]; char dummy; while (cin>>cards[0]>>dummy>>cards[1]>>dummy>>cards[2]>>dummy>>cards[3]>>dummy>>cards[4]) { int count=0,ans=0; sort(cards,cards+5); for (int i=0; i<4; i++) ...
0
#include<stdio.h> #include<string.h> typedef long long ll; int pre[10005]; void init(){ int s=1; for(int i=1;i<=10000;i++){ pre[i]=pre[i-1]+s; s++; } } int main(){ int t; scanf("%d",&t); init(); while(t--){ int x; scanf("%d",&x); int ans,a; for(int i=1;i<=x;i++){ if(pre[i]>=x){ a=pre[i]; a...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; vector<int> G[N]; int n, m; void Direct() { vector<int> dis(n + 1, 1e9), par(n + 1, -1); queue<int> que; que.push(1); dis[1] = 0; int mx = 0; while (que.size() > 0) { int u = que.front(); que.pop(); for (int v : G[u]) { ...
4
#include <bits/stdc++.h> using namespace std; void print(vector<int> v) { for (long long int i = 0; i < v.size(); i++) { cout << v[i]; } } int main() { long long int n, k; cin >> n >> k; string s; cin >> s; vector<int> v; for (long long int i = 0; i < s.length(); i++) { if (s[i] == '1') { ...
2
#include <bits/stdc++.h> using namespace std; vector<int> v[26]; int A[26], m; void solve() { string s; cin >> s; for (int i = 0; i < s.length(); i++) v[s[i] - 'a'].push_back(i); for (int i = 0; i < 26; i++) { if (s.find(i + 'a') != string::npos) { m = v[i][0] + 1; for (int j = 1; j < (int)v[i]....
3
#include <iostream> #include <set> using namespace std; long long n, a, s, l, r, b[200005]; set<int> st; int main() { int i; scanf("%d", &n); for(i=1; i<=n; i++) scanf("%d", &a), b[a] = i;; st.insert(0); st.insert(n+1); for(i=1; i<=n; i++) { l = *(--st.lower_bound(b[i])); r = *st.lower_bound(b[i]); s += i *...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n, a[MAXN], b[MAXN], x, y, sec[MAXN]; long long pt[2][MAXN]; bool cmp(int u, int v) { return a[u] - b[u] > a[v] - b[v]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> x >> y; y = min(y, n); for (int i = 0; i < n;...
5
#include <bits/stdc++.h> using namespace std; set<long long> G[2000]; vector<long long> path; long long cnt; long long mat[2001][2001]; long long low[2009], pre[2009]; struct Edge { long long F, S, cost; }; vector<Edge> edges; vector<long long> mb; long long N, M, s, t; long long vs[2009]; bool DFS(long long u, long ...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long double eps = 1e-9; const long long maxn = 1e5 + 1; const long long inf = 5e18; const long long minf = -inf; bool solve() { long long n, ans_cnt = 0, ans_use = 0; cin >> n; vector<long long> cnt(n + 1, 0), use(n + 1, 0); for ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { int n, k; cin >> n >> k; vector<int> a(n, 0); vector<bool> is_peak(n, false); for (int i = 0; i < n; ++i) { cin >> a[i]; } int border = 1, max_size = 0; for (int i = 1; i < k - 1; ++...
2
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, p; cin >> n >> p; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long l = max(a[0], a[n - 1] - n + 1); long long r = a[n - 1]; ve...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; void print_case() { static int cnt = 0; printf("Case #%d: ", ++cnt); } int l, r; void solve() { scanf("%d%d", &l, &r); if (r < 2 * l) { printf("YES\n"); } else { printf("NO\n"); } } int main() { int casen = 1; scanf("%d", &...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, ans = 0, it = 0; cin >> n; vector<int> v1(n), v2(n); for (int i = 0; i < n; i++) { cin >> v1[i]; v2[i] = v1[i]; } sort(v2.begin(), v2.end()); while (v1 != v2) { it++; ...
1
#include <bits/stdc++.h> using namespace std; char mapp[12][12]; bool vis[12][12][4]; int dis[4][2] = {0, 1, 1, 1, 1, 0, 1, -1}; bool dfs(int i, int j, int k) { int cnt = 4; while (cnt--) { vis[i][j][k] = 1; i += dis[k][0]; j += dis[k][1]; if (i < 1 || j < 1 || i > 10 || j > 10 || mapp[i][j] != 'X')...
2
#include <bits/stdc++.h> template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) { return b < a ? (a = b, true) : false; } template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) { return a < b ? (a = b, true) : false; } const int N = 1e5 + 5; int n, last[26], l[N], r[N], pre[N][27], nex[N][27...
6
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n; vector <int> a; ll solve(int l, ll cl, int r, ll cr){ if(l + 1 == r) return 0; ll ret = 1e18; for(int k = l + 1 ; k < r ; k++){ ret = min(ret, solve(l, cl, k, cl + cr) + solve(k,...
0
#include<bits/stdc++.h> using namespace std; int main(void){ int n; cin>>n; vector<int> a(n),b(n); for(int i=0;i<n;i++){ cin>>a[i]; b[i]=a[i]; } sort(b.begin(),b.end()); for(int i=0;i<n;i++){ if(a[i]!=b[n-1]){ cout<<b[n-1]<<endl; }else{ cout<<b[n-2]<<endl; } } return 0;...
0
#include<bits/stdc++.h> #define ll long long #define fi first #define se second using namespace std; const ll MOD=10000; string a,b; int m; ll dp[502][2][500][11][3][2]; inline ll solve(string s){ int n=(int)s.length(); for(int i=0;i<n+1;i++) for(int j=0;j<2;j++) for(int k=0;k<m;k++) for(int l=0...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; const int lazy = int('a' - 'A'); const long long N = 1e7 + 1; string alphabet = "abcdefghijklmnopqrstuvwxyz"; long long sum = 0, final = 0, result =...
1
#include <cmath> #include <cstdio> #include <iostream> using namespace std; typedef struct{ double x; double y; }point; void Printp(point a){ printf("%lf %lf\n", a.x, a.y); } void koch(int d, point p, point q){ if(d==0) return; point s, u, t; //calculation s.x=(2*p.x+q.x)/3.0; s.y=(2*p.y+q.y)/3.0; t.x=(p....
0