solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int nm = 22; const double eps = 1E-6; const int mm = 1048577; const double pi = 3.1415926535897932384626433832795; int n; double l, r, x[nm], y[nm], a[nm]; double f[mm]; void nhap() { scanf("%d%lf%lf", &n, &l, &r); int i; for (i = 1; i <= n; ++i) { scanf("%l...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int N = 3e5 + 50; int t; int n; int st[N]; int ans = 0; int main() { cin >> t; while (t--) { cin >> n; memset(st, 0, sizeof st); ans = 0; string belt; cin >> belt; int flag1 = 0; int flag2 = 0; for (int i = 0; i...
2
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; multiset<long long> order; for (int i = 0; i < n; ++i) { long long a; cin >> a; order.insert(a); } long long add = 0, ans = -1e18; while (order.size() > 1) { long long cur = *order.begin() + add; ans = max(an...
3
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<iostream> using namespace std; /* * mode0なら最小値、mode1なら最大値を返す。 */ int getval(int mode, int* rep, int begin, int end) { int result; result = rep[begin]; for (int i = begin + 1; i < end; i++) { if (mode == 0 && result > rep[i]) { result = rep[i...
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define rrep(i,n) for(int i=n-1;i>0;--i) #define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define Vi vector<int> #define Vl vector<long long> #define pb(a) push_back(a) using namespace std; typedef long long ll; const int inf=100000000...
0
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; vector<string> start, End; vector<vector<int> > dead, dist, graph, Rgraph, people, lab; int n, T, V, s, t; const int inf = 100000; vector<int> parent; bool BFS() { bool visited[V]; for (int i = 0; i < V; ++i) visited...
5
#include <iostream> using namespace std; int main(){ int a,b; cin>>a>>b; for(int i=0;i<1002;++i){ if(i*8/100==a && i/10==b){ cout<<i; break; } else if(i==1001){ cout<<"-1"; } } }
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10; long long read() { long long x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 3) + (x << 1) + c - 48; c = getchar(); } return x * f; }...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using db = double; using vi = vector<int>; const int inf = 0x3f3f3f3f; const db eps = 1e-8; const int mod = 1e9 + 7; ll qpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100; int head[N], nxt[N], w[N], to[N]; int cnt = 0; void add_edge(int u, int v, int dis) { to[cnt] = v; w[cnt] = dis; nxt[cnt] = head[v]; head[u] = cnt++; } int depth[100]; bool bfs() { queue<int> q; while (!q.empty()) { q.pop(); } memset(d...
5
#include <sstream> #include <fstream> #include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <string> #include <stack> #include <queue> #include <cmath> #include <ctime> #include <utility> #include <cassert> #include <bitset> #define rep(i,x,n) for(int i=x;i<n;i++) #define ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long l, r; cin >> l >> r; long long q = (r - l + 1) / 2; vector<long long> v; long long a = l; cout << "YES\n"; for (int i = 0; i < q; i++) { cout << a << " " << a + 1 << endl; a +=...
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int n, a, b, c, t[200015]; int main() { scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; ++i) scanf("%d", &t[i]); int ans = 0; for (int i = 1; i <= n; ++i) { if (t[i] == 1) { if (a) --a; else if (b) -...
1
#include <bits/stdc++.h> using namespace std; const int SIZE = 202; int n, m; int from[SIZE * SIZE], to[SIZE * SIZE], cst[SIZE * SIZE], mat[SIZE][SIZE]; void floyd() { for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) mat[i][j] = mat[j][i] = min(mat[i][j], mat[i][k]...
4
#include<bits/stdc++.h> using namespace std; typedef long long ll; int N; ll A[200010],X[200010]; ll mem[200010]; ll MAX[200010]; ll aa[200010],bb[200010]; ll ans = 0; int main() { scanf("%d",&N); for(int i = 1; i <= N; i++) { scanf("%lld%lld",X + i,A + i); A[i] += A[i - 1]; } for...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); i++) os << v[i] << " "; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for (type...
4
#include<iostream> using namespace std; int main() { int n; cin>>n; int a[5][4][11]={0}; int b,f,r,v; for(int i=0;i<n;i++) { cin>>b>>f>>r>>v; a[b][f][r]+=v; } for(int i=1;i<=4;i++) { for(int j=1;j<=3;j++) { for(int k=1;k<=10;k++) { cout<<" "<<a[i][j][k]; } cout<<endl; } if(i!=4)cout<<"####################"<<endl; } ret...
0
#include<bits/stdc++.h> using namespace std; const int N=1000005; int n,a[N],cnt[3],b[3],c[3],pre[N],nxt[N];char s[N];vector<int>V; inline bool cmp(int x,int y){return cnt[x]<cnt[y];} inline void del(int x){pre[nxt[x]]=pre[x];nxt[pre[x]]=nxt[x];cnt[a[x]]--;} int main() { scanf("%s",s+1);n=strlen(s+1);a[0]=a[n+1]=-1; ...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; vector<long long> fact, ifact, invs; long long combmod(int n, int k, long long MOD, int M = 1e5) { if (!fact.size()) { fact.resize(M + 1); ifact.resize(M + 1); invs.resize(M + 1); fact[0] = ifact[0] = invs[0] = fact[1] = if...
5
#include <bits/stdc++.h> using namespace std; long long int res[1000005], p[1000005]; void solve() { long long int n, t; cin >> n; set<long long int> s; for (long long int i = 1; i <= n; i++) cin >> p[i]; cin >> t; for (long long int i = 0; i < t; i++) { long long int x; cin >> x; s.insert(x); ...
5
#include<iostream> #include <algorithm> using namespace std; int main(){ while(true){ int n; int m=10000000; cin>>n; if(n==0)break; int s[n]; for(int i=0;i<n;i++){ cin>>s[i]; } sort(s,s+n); for(int i=0;i<n-1;i++){ if(s[i+1]-s[i]<m){ m=s[i+1]-s[i]; } } cout<<m<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 10, LG = 20; int par[N][LG], h[N]; int lca(int v, int u) { if (h[v] < h[u]) swap(v, u); for (int i = 0; i < LG; i++) if ((1 << i) & (h[v] - h[u])) v = par[v][i]; if (v == u) return v; for (int i = LG - 1; i >= 0; i--) if (par[v][i...
6
#include <bits/stdc++.h> const long long int mrx = 1e6 + 5, M = 1e9 + 7; long long int mx = INT_MIN, mn = INT_MAX; using namespace std; long long int x1, x2, s, t1, t2, p, d; long long int poezd, igor; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cin >> s >> x1 >> x2; cin >> t1 >> t2; cin >> p...
3
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; } template <class T> void amin(T &a, T v) { if (a > v) a = v; } template <class T> void amax(T &a, T v) { if (a < v) a = v; } int ROUND(double x) { return (int)(x...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 1; int n, m, x, y, c, canw, w[MAXN], b[MAXN], dp[MAXN][MAXN]; bool vis[MAXN]; vector<int> G[MAXN]; vector<int> comps[MAXN]; void dfs(int cur, int c) { comps[c].push_back(cur); vis[cur] = true; for (int i = 0; i < G[cur].size(); i++) if (!vis...
4
#include <bits/stdc++.h> using namespace std; long long n, k, p; long long dp[30][300000]; long long f[300000], finv[300000]; inline long long qpow(long long a, long long b, long long p) { long long k = 1; while (b) { if (b & 1) k = k * a % p; a = a * a % p; b >>= 1; } return k; } long long num, is[...
3
#include <bits/stdc++.h> using namespace std; const int N = 1099; long long n, t, k1, k2, mark[N], x, v, ans, mark2[N], y; vector<int> g[N]; int dfs(int x, int par) { if (mark[x] == 1) { ans = x; return 0; } for (long long i = 0; i < g[x].size(); i++) { if (g[x][i] != par) dfs(g[x][i], x); } } int m...
2
#include <bits/stdc++.h> int a[1000010]; int main() { int i, j, k, n; for (scanf("%d", &n), k = 0, i = 0; i < n; scanf("%d", &j), k += j == 2, i++) ; if (n == 1) { printf("1\n"); return 0; } if (k > n - 2) k = n - 2; for (a[1] = 1, a[2] = 2, i = 3; i <= n; i++) a[i] = (a[i - 1] + (long long)...
4
#include <bits/stdc++.h> using namespace std; using namespace std; template <class T1, class T2> using p = pair<T1, T2>; template <class T1, class T2> using m = vector<pair<T1, T2>>; template <class T> using vv = vector<vector<T>>; template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; ...
2
#include <iostream> using namespace std; int a,b,c,tot,ans; int main(void){ cin>>a>>b; for(int i=0;i<a;i++){ cin>>c; tot+=c; if(tot<=b)ans+=1; } cout<<ans+1<<endl; }
0
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; const int mod = 1000000007; long long modpow(long long n, int k) { long long r = 1; while (k > 0) { if (k & 1) r = (r * n) % mod; n = (n * n) % mod; k >>= 1; } return r; } int main() { int N, K; cin >> N >> K; ve...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e5; void solve() { int n; string s, ss; cin >> n >> ss; s = ss; vector<int> h; for (int i = 0; i < n; i++) { if (ss[i] == 'H') h.push_back(i); } int ans = inf; for (int start = 0; start < n; start++) { int ed = (start + (int)h.size...
3
#include <bits/stdc++.h> using namespace std; int a[5005], b[5005], c[5005]; double m[102][102]; int main() { int n, e, deg = 0; scanf("%d%d", &n, &e); for (int i = 0; i < e; ++i) { scanf("%d%d%d", &a[i], &b[i], &c[i]); --a[i]; --b[i]; } for (int i = 1; i < n - 1; ++i) { for (int j = 0; j < e;...
3
#include <bits/stdc++.h> using namespace std; int ABS(int a) { if (a < 0) a = -a; return a; } int nod(int a, int b) { if (0 == a) return b; if (0 == b) return a; if (a == b) return a; return nod(a % b, b % a); } int main() { int n; static int x[100010]; int i, j; int a, b; int *p; scanf("%d", &n...
5
#include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; if(a+b==15)cout<<"+"<<endl; else if(a*b==15)cout<<"*"<<endl; else cout<<"x"<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m; char temple[110][110]; vector<pair<int, int> > res; int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> temple[i][j]; } } for (int i = 1; i <= n; ++i) { bool found = false; for (int j = 1; j <= ...
1
#include <bits/stdc++.h> using namespace std; struct node { long long m, s; }; const int maxn = 100000 + 10; node p[maxn]; long long sum[maxn]; int n; long long d; bool cmp(const node &a, const node &b) { return a.m < b.m; } int main() { cin >> n >> d; for (int i = 1; i <= n; i++) cin >> p[i].m >> p[i].s; sort(...
2
#include<bits/stdc++.h> using namespace std; int n,m,k; char grid[1000][1000]; int steps[1000][1000]; queue<pair<int,int> > q; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; bool ok(int i,int j){ return i>=0&&i<n&&j>=0&&j<m; } void BFS(int x,int y){ memset(steps,0x3f,sizeof(steps)); q.push(make_pair(x,y)); steps[x][y]...
0
#include <bits/stdc++.h> using namespace ::std; const long double PI = acos(-1); const int MOD = 1000000000 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int add(long long a, long long b) { return (a % MOD + b % MOD + 2 * MOD) % MOD; } int mul(long long a, long long b) { return...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int i, ans; int num[2005]; while (scanf("%d%d", &n, &k) != EOF) { ans = 0; for (i = 0; i < n; i++) scanf("%d", &num[i]); sort(num, num + n); for (i = n - 1; i >= 0; i = i - k) ans += (num[i] - 1) * 2; printf("%d\n", ans); ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2003; const int mod = 1e9 + 7; int tag[N << 2], mn[N << 2], mx[N << 2], sum[N << 2]; vector<int> vx, vy; void solve(int pos, int l, int r, int v) { tag[pos] = mx[pos] = mn[pos] = v; sum[pos] = 1ll * (vx.back() - vx[v]) * (vx[r] - vx[l]) % mod; } void pushu...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long k, sum = 0; cin >> k; string s; cin >> s; int len = s.length(); for (int i = 0; i < len; i++) { sum += s[i] - '0'; } if (sum >= k) cout << "0\n"; else { sor...
2
#include <bits/stdc++.h> using namespace std; int n, num[200010], ins = -1, des = 123456789, res[200010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); for (int i = 1; i <= n; i++) { if (num[i] > ins && (num[i] >= des || num[i] < num[i + 1])) ins = num[i], res[i] = 0; ...
3
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define For(i,j,k) for(int i=j;i<=k;i++) #define Dow(i,j,k) for(int i=j;i>=k;i--) #define LL long long using namespace std; inline int read() { int x = 0,f = 1; char ch = getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f = -1; ch = getchar(); } w...
0
//https://onlinejudge.u-aizu.ac.jp/beta/room.html#KUPC2020Spring/problems/B #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); in...
0
#include<bits/stdc++.h> using namespace std; int main(void){ int A, B; cin >> A >> B; cout << max(max(A+B,A-B),A*B) << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; cout << m + n - 1 << '\n'; for (int i = 1; i <= n; ++i) { cout << 1 << ' ' << i << '\n'; } for (int i = 2; i <= m; ++i) { cout << i << ' ' << 1 << '\n'; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n; long long k; int main() { cin >> n >> k; long long b; long long c = 0, a; cin >> b; for (int i = 2; i <= n; i++) { cin >> a; if (b > a) c++; else { b = a, c = 1; } if (c == k) { cout << b; return 0; } } co...
2
#include <bits/stdc++.h> using namespace std; const int N = 2222; int n, h; double dp[N][N][2][2]; int a[N]; int lf[N], rg[N]; double p; double get(int i, int j, int t1, int t2) { return (i > j ? 0.0 : dp[i][j][t1][t2]); } int main() { ios::sync_with_stdio(false); scanf("%d%d%lf", &n, &h, &p); for (int i = 1; i...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const double PI = 3.14159265358979323846; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a, b; cin >> a >> b; if (a == 1 && b == 1) cout << 1; else { long long c = 0; while (a ...
3
#include <bits/stdc++.h> using namespace std; struct node { int x, y, z; int id; } zt[100005]; bool cmp(node a, node b) { if (a.x == b.x) { if (a.y == b.y) return a.z > b.z; return a.y > b.y; } return a.x > b.x; } int main() { int n, Max = 0, Min; int key1 = 0, key2 = -1; int a[3]; cin >> n; ...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; #define INF 2000000000000000000 ll n,m,a[20],z[1<<20]; D p[20],ans; ll gcd(ll x,ll y){ if(x%y==0)return y; return gcd(y,x%y); } ll lcm(ll x,ll y){ x/=gcd(max(x,y),min(x,y)); if(x>INF/y)return INF; return x*y; } int main(void){ ...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; char a[n][m]; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) { cin >> a[i][j]; } } long long counter = 0; for (int i = n - 1; i < n; ++i) { for (int j = 0; j < m; ++j) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, flag = 0, i, j; char a[5][5]; cin >> n; map<int, int> mp; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { cin >> a[i][j]; if (a[i][j] == '.') continue; else mp[a[i][j] - '0']++; } } for (auto it...
1
#include <bits/stdc++.h> using namespace std; const int M = 2020; const double pi = acos(-1), eps = 1e-7; int n; long long ans; struct Point { int x, y; double sl; void in() { scanf("%d%d", &x, &y); } Point() {} Point(int a, int b) : x(a), y(b) {} double Get(int a, int b) { return atan2(y - b, x - a); } d...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pr = pair<int, int>; using prll = pair<long, long>; using V = vector<int>; using Vll = vector<long long>; template <typename T, typename TT> pr operator+(pair<T, TT> a, pair<T, TT> b) { return {a.first + b.first, a.secon...
1
#include <bits/stdc++.h> using namespace std; long long n, m, a[100100], b[100100], pa[100100], pb[100100]; long long ans = 10e17; void go(long long x) { long long t = 0; int i = lower_bound(a, a + n, x) - a; t += x * i - pa[i]; i = lower_bound(b, b + m, x) - b; t += pb[m] - pb[i] - x * (m - i); ans = min(a...
4
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << '(' << p.first << ", " << p.second << ')'; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { long long l = v.size(); for (long...
2
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long ...
0
#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; if (!(n & 1)) { cout << (n >> 1) << "\n"; while (n != 0) { cout << 2 << " "; n -= 2; } } else { vector<long long> v; while (n > 3) { ...
1
#include <bits/stdc++.h> using namespace std; bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } double gcd(double a, double b) { if (b == 0) return a; return gcd(b, double(int(a) % int(b))); } long long int MOD = 1000000007; long long int power(long long int b, long ...
3
#include <bits/stdc++.h> using namespace std; long long int a[200200], b[200200]; int main() { int n, i, j, k, x, y, curr, temp, m; long long int ans, rose = 0; long long int ta, tb; scanf("%d %d %lld %lld %d", &n, &m, &ta, &tb, &k); for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); a[i] += ta; } f...
2
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, f, x, i, j, m; scanf("%lld", &n); long long a[n]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); scanf("%lld%lld", &x, &f); long long ans = 0; for (i = 0; i < n; i++) { if (a[i] > x) { long long temp = a[i] / (x + f); ...
6
#include <bits/stdc++.h> const int N = 1e6 + 7; long long a[N], f[N], yks[N]; int n, q; template <class T> void G(T &num) { static char a; static bool fl; for (a = getchar(), fl = false; a > '9' || a < '0'; a = getchar()) if (a == '-') fl = true; for (num = 0; a >= '0' && a <= '9'; a = getchar()) num = ...
5
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> inline void gmax(T1& a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1& a, T2 b) { if (b < a) a = b; } const long long inf = 0x3f3f3f3f; const long long maxn = 1e2 + 5; void solve() { long long n, k; while...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; if (n < 6) cout << "-1" << endl; else { cout << "1 2\n2 3\n3 4\n3 5\n2 6" << endl; for (i = 7; i <= n; i++) cout << "2 " << i << endl; } for (i = 2; i <= n; i++) cout << "1 " << i << endl; }
3
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<vector<int>> graph; namespace lca { vector<int> dfsArr; vector<int> height; vector<int> first; void dfs(int cur, int par = -1, int curHeight = 0) { dfsArr.push_back(cur); height[cur] = curHeight; first[cur] = dfsArr.size() - 1; for (auto...
3
#include <iostream> using namespace std; int N; long long a,b; int main(){ cin >> N; long long sum = 0,mi = 1e18; bool judge = false; for(int i=0;i<N;i++){ cin >> a >> b; if(a!=b) judge = true; sum += a; if(a>b) mi = min(mi,b); } if(!judge) cout << 0 << endl; else cout << sum-mi << endl; }
0
#include <bits/stdc++.h> using namespace std; int n, m, tot, cnt1, cnt2, f[10000]; struct nd { int x, y; long long v; } e[2000010], a[10000], ret1[10000], ret2[10000]; int find(int x) { if (f[x] != x) f[x] = find(f[x]); return f[x]; } bool cmp(nd x, nd y) { return x.v < y.v; } int main() { cin >> n; for (in...
4
#include <bits/stdc++.h> using namespace std; int round(int n, int m) { float t = (100.00 * m) / n; int p = (int)(t + 0.5000); return p; } const int size = 1e5 + 7; int arr[size]; int proc[size]; int vis[size]; int ind[1000]; int main() { int n, k; memset(arr, 0, sizeof(arr)); cin >> n >> k; for (int x = ...
3
#include <bits/stdc++.h> using namespace std; char num[10000 + 10]; char changed[11][10000 + 10]; int n, k; int _count[11]; struct Fabs { int aabs; int location; char num; int aim; }; Fabs old[10000 + 10]; bool cmp(Fabs a, Fabs b); void change(int a); int cmps(int a, int b); int main() { cin >> n >> k; cin ...
3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > A; int n, x, y; void no() { cout << "NO\n"; exit(0); } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; cin >> n; if (n & 1) no(); for (int i = 0; i <= n; i++) { if (i != n) cin >> x >> y; els...
2
#include<iostream> #include<cstdio> using namespace std; int main() { int n; scanf("%d",&n); puts(n%10==9||n/10==9?"Yes":"No"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; long long K; int head[100010], v[100010 << 1], nxt[100010 << 1], tot = 0; inline void add_edge(int s, int e) { tot++; v[tot] = e; nxt[tot] = head[s]; head[s] = tot; tot++; v[tot] = s; nxt[tot] = head[e]; head[e] = tot; } int siz[100010], mx[100010], r...
5
#include<cstdio> #include<cstring> #include<algorithm> #define N 100010 #define ll long long using namespace std; int n, map[N][4], b[4], w1[N], w2[N], flag1[N], flag2[N], x, pos[N], s[N]; ll sum1, sum2; inline char gc(){ static char now[1<<16], *S, *T; if(S==T){T=(S=now)+fread(now, 1, 1<<16, stdin); if(S==T)return E...
0
#include <bits/stdc++.h> using namespace std; int a[11000], b[11000]; int main() { string s, t; cin >> s >> t; int ls = s.length(); int lt = t.length(); if (ls != lt) { cout << "No" << endl; return 0; } else { for (int i = 0; i < ls; i++) { if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || ...
1
#include <bits/stdc++.h> using namespace std; long long n, suma, minim, maxim, pos1, pos2; long long v[300001]; char c; long long nrok(long long v[300001]) { int ans = 0; suma = 0; minim = 600001; for (int j = 1; j <= n; j++) { suma += v[j]; if (suma < minim) minim = suma; } if (minim >= 0) ans++; ...
4
#include<iostream> using namespace std; int J[1000][1000]={0}; int O[1000][1000]={0}; int I[1000][1000]={0}; char maps[1000][1000]; int main(){ int m,n,k; int a,b,c,d; cin>>m>>n>>k; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ cin>>maps[i][j]; J[i][j]=J[i][j-1]; O[i][j]=O[i][j-1]; I...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; ll md = 1000000007; ll exp(ll a, ll b) { ll r = 1ll; while (b > 0) { if (b & 1) { r = r * (a % md); r = (r + md) % md; } b >>= 1; a = (a % md) * (a % md); a = (a + md) % md; } return (r + md) % md; } ll gcd(ll a,...
3
#include <bits/stdc++.h> using namespace std; int n, k, tmp, z, j, i, last; int usg(int a, int b) { if (a == 0 || b == 0) return a + b; if (a > b) return usg(b, a % b); else return usg(a, b % a); } int main() { cin >> n >> k; if (n / 2 > k) { cout << "-1" << endl; return 0; }; if (n == 1 &...
1
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long long int INF = (long long int)1e15; void solve() { long long int N; cin >> N; long long int d = 0; long long int p = 2; while (N > p - 1) { p *= 2; d++; } cout << d << endl; long long int n = 1; long...
4
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N], par[N], h[N]; bool mark[N]; vector<int> adj[N]; void dfs(int root) { mark[root] = true; par[root] = -1; for (auto v: adj[root]) { if (!mark[v]) dfs(v); if (h[v] + 1 > h[root]) { h[root] =...
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 2010; long long n, k; char mp[maxn][maxn]; long long dp[maxn][maxn]; bool visited[maxn][maxn]; queue<pair<long long, long long> > que[2]; char min_char[2]; void push_in(long long idx, long long i, long long j) { if (i < n && j < n && !visited[i][j])...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; long long n, x, y, c; long long progr(long long first, long long last, long long cnt) { long long ans = first + last; if (ans % 2 == 0) ans /= 2; else { assert(cnt % 2 == 0); cnt /= 2; } return ans * cnt; } l...
2
#include <iostream> using namespace std; const int INF = 999999999; const int rot[] = {4, 1, 4, 1, 2, 1, 2, 1}; int main () { int n[8]; while (cin >> n[0]) { for (int i = 1; i < 8; i++) cin >> n[i]; int min_c = INF, min_n = INF; int res = 0; for (int i = 0; i < 8; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> occ(26); for (int i = 0; i < 26; i++) occ[i] = 0; for (int i = 0; i < n; i++) { char x; cin >> x; occ[x - 'A']++; } sort(occ.rbegin(), occ.rend()); long long ans = 0; for (auto el : occ) { l...
2
#include <bits/stdc++.h> using namespace std; long long int ipow(long long int base, long long int exp) { long long int result = 1; while (exp) { if (exp & 1) { result *= base; result %= 1000000007; } exp >>= 1; base *= base; base %= 1000000007; } return result; } long long int a...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=55; const int maxm=2466; const ll inf=0x3f3f3f3f3f3f3f3f;//long long最大值,8个3f #define tp tuple<ll,ll,ll> vector<tp> G[maxn];//存每个点所能到达的点 ll c[maxn],d[maxn];//此点换钱的钱数和花费时间 ll dp[maxn][maxm]; int main(){ int n,m,s; scanf("%d%d%d",&n,&m,&...
0
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 1) return a - 1; if (b == 0) return 10000000; return a / b + gcd(b, a % b); } int main() { int n, answ = 10000000; cin >> n; for (int i = 0; i < n; i++) answ = min(answ, gcd(n, i)); if (n == 1) answ = 0; cout << answ << endl;...
2
#include <bits/stdc++.h> using namespace std; const int N = 100000; int n; int a, b; int t[N]; int p[N]; bool lls(int c1, int c2) { if (a > b) { if (t[c1] < t[c2]) return true; return (t[c1] == t[c2] && c1 < c2); } else { if (t[c1] > t[c2]) return true; return (t[c1] == t[c2] && c1 < c2); } } int ...
3
#include <bits/stdc++.h> using namespace std; int n, l, v; int a[205]; double ans; double p[205]; double dp[205][205][405]; int main() { cin >> n >> l >> v; for (int i = 1; i <= n; i++) { cin >> p[i]; p[i] /= 100; } for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0][0][v + 200] = 1; for (int ...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, temp, ans; while (cin >> a) { cin >> b >> c; cout << (b * c) + (a - 1) * (b + c - 1); } return 0; }
1
#include <bits/stdc++.h> #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") const int MAXN = 1e5 + 10, inf = 1e9 + 10, MAX = 1e4 + 10; using namespace std; int w, l; int a[MAXN]; int main() { scanf("%d%d", &w, &l); for (int i = 1; i < w; i++) { scanf("%d", &a[i]); a[i] += a[i - 1]; } ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const double pi = 3.14159265358979323846; int n, m, k; vector<int> a; vector<int> b; bool read() { if (!(cin >> n >> m >> k)) return false; a.resize(n); b.resize(m); for (int i = 0; i < int(n); ++i) cin >> a[i]; for (int i = 0; i < int(m); ++i...
2
#include <bits/stdc++.h> using namespace std; int N; long long C[1001][1001]; long long dp[1001]; long long color[1001]; long long combination(int n, int p) { if (n == p || p == 0) { return C[n][p] = 1; } if (C[n][p] != -1) { return C[n][p]; } else { long long ans = combination(n - 1, p) % 100000000...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c<'0' | c> '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } stru...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void smn(T &a, const T &b) { if (b < a) a = b; } template <class T> inline void smx(T &a, const T &b) { if (b > a) a = b; } template <class T> inline T rev(const T &a) { T _ = a; reverse(_.begin(), _.end()); return _; } const double eps =...
5
#include <iostream> using namespace std; int main() { int l, m, n, s, r, i; while (cin >> l && l) { s = 0; r = 0; for (i = 0; i < 12; i++) { cin >> m >> n; s += m-n; if (!r && s >= l) r = i+1; } if (r == 0) cout << "NA" << endl; else cout << r << endl; } }
0
#include <bits/stdc++.h> using namespace std; long long ans, a, b, c; int main() { cin >> a >> b >> c; if (a > b) swap(a, b); if (a > c) swap(a, c); if (b > c) swap(b, c); ans = ((b + a - 1) * (c + a - 1)) - ((a - 1) * a); cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int const N = 2e5 + 20; int n, m, a[N], p[N], ans; int32_t main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int k = 1; k * n <= m; k++) { p[n - 1] = min(a[n - 1], m * k - (k - 1...
5