solution
stringlengths
52
181k
difficulty
int64
0
6
#include<iostream> #include<algorithm> #define INF (1<<24) using namespace std; int t[8],x,y,z; int ans,mini; int s[]={4,1,4,1,2,1,2,1}; void change(){ int tmp; tmp=s[0]; for(int i=0;i<7;i++)s[i]=s[i+1]; s[7]=tmp; } int compute(){ int res=0; for(int i=0;i<8;i++){ res+=max(0,t[i]-s[i]); } return re...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; for (int qq = 0; qq < q; qq++) { int n, m; cin >> n >> m; bool cs[n]; for (int i = 0; i < n; i++) { cs[i] = 0; } vector<int> arr(n); for (int i...
2
#include <bits/stdc++.h> using namespace std; const long long INFll = 0x3f3f3f3f3f3f3f3fLL; const int INF = 0x7ffffff; const int mod = 1000000007; double dp[210][210][2 * 201 + 10]; int a[210], p[210]; int n, l, k; void solve() { memset(dp, 0, sizeof(dp)); dp[0][0][201 + k] = 1; for (int i = 1; i <= n; ++i) f...
2
#include <bits/stdc++.h> using namespace std; long long dp[4 * 100005], dp2[4 * 100005]; vector<pair<int, int> > g[4 * 100005]; int st[4 * 100005], par[4 * 100005]; int child[4 * 100005][2]; vector<int> node; void build(int n, int s, int e, int p) { par[n] = p; if (s == e) return; int mid = (s + e) / 2; child[n...
4
#include <bits/stdc++.h> using namespace std; long long a[201010]; int main() { long long n, m, k; while (~scanf("%lld%lld%lld", &n, &m, &k)) { memset(a, 0, sizeof(a)); long long i, j, ans = 0, sum = k; for (i = 1; i <= n; i++) scanf("%lld", &a[i]); for (i = n; i >= 1; i--) { if (a[i] > k) con...
4
#include <bits/stdc++.h> using namespace std; bool check(int step, int m, vector<int> v) { if (v[0] + step >= m) v[0] = 0; for (int i = 1; i < v.size(); i++) { if (v[i] < v[i - 1]) { if (v[i] + step >= v[i - 1]) v[i] = v[i - 1]; } else { if (v[i] + step >= m && (v[i] + step) % m >= v[i - 1]) v[i...
1
#include <bits/stdc++.h> using namespace std; int t, n, inf = 1e9 + 3; int main() { cin >> t; while (t--) { long long int x; cin >> x; if (x > 14 && x % 14 <= 6 && x % 14 >= 1) cout << "YES" << endl; else cout << "NO" << endl; } }
2
#include <bits/stdc++.h> using namespace std; typedef struct { int u, v, cu, cv; } Edge; const int N = 500010, M = 1000010; int fa[M]; Edge e[M]; int cnt; int sz[M]; int co[N]; int st[N]; pair<int, int> stk[M]; int top; int n, m, k; void init() { for (int i = 1; i <= n + n; i++) { fa[i] = i; sz[i] = 1; } ...
3
#include <bits/stdc++.h> using namespace std; long long i, n, p1, p2, v1, v2, k, a, b, d, pmin, pmax, vmin, vmax, pl, pu, vl, vu; vector<long long> l; int main() { cin >> p1 >> p2 >> v1 >> v2 >> k; a = min(p1, v1); b = max(p2, v2); l.push_back(0); i = 0; while (l[l.size() - 1] <= b) { l.push_back(l[...
4
#include<bits/stdc++.h> using namespace std; int n; vector<int>graph[100005]; int dp[100005]; int f(int curr){ int&ret = dp[curr]; if(~ret) return ret; ret = 0; for(int i=0; i<graph[curr].size(); i++){ int nexter = graph[curr][i]; ret = max(ret,f(nexter)+1); } return ret; } int main(){ memset(dp,-1,sizeof(dp...
0
#include <bits/stdc++.h> using namespace std; long long sum[100001], axis[100000]; int s[100001]; long long calc(int n, long long limit) { for (int i = 0; i < n; i++) axis[i] = sum[i] + limit; sort(axis, axis + n); int tot = unique(axis, axis + n) - axis; memset(s, 0, sizeof(s)); long long res = 0; for (int...
5
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; ; lb: while (t--) { string s; cin >> s; long long n = s.length(); if (n == 1) { cout << "...
3
#include <iostream> using namespace std; int N,M,Q; int L,R,p[100000],q[100000]; int x[501][501],sum[501][501]; int main(){ cin>>N>>M>>Q; for(int i=0;i<M;i++)cin>>L>>R,x[L][R]++; for(int i=0;i<Q;i++)cin>>p[i]>>q[i],p[i]--; for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) sum[i][j]=x[i][...
0
#include <bits/stdc++.h> using namespace std; const int N = 5005; const int inf = 1e9; inline int read() { int x = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { ch = getchar(); if (ch == '-') w = -1; } while (ch <= '9' && ch >= '0') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar();...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c, t; cin >> n >> m; int a[n + 1]; a[0] = 0; for (int i = 1; i <= n; i++) { cin >> c >> t; a[i] = a[i - 1] + c * t; } int pos = 1; for (int i = 0; i < m; i++) { cin >> t; while (pos <= n && t > a[pos]) pos++; cout <...
2
#include <iostream> #include<algorithm> #define ll long long using namespace std; bool comp(ll a, ll b) { return (a < b); } int main() { int t; cin>>t; while(t--) { ll p,a,b,c,d,e,f; cin>>p>>a>>b>>c; d=p%a; e=p%b; f=p%c; if(e==0||d==0||f==0) ...
1
#include <bits/stdc++.h> using namespace std; int n, k, res, tmp, m; int a[1000012]; string s; string dx(string s, int l, int r) { string ss = ""; for (int i = r; i >= l; i--) ss = ss + s[i]; s.erase(l, r - l + 1); s.insert(l, ss); return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
2
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; const ld eps=1e-9; //// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Downloa...
0
#include <bits/stdc++.h> using namespace std; int a[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; int b[2] = {365, 366}; bool legal(int y) { if ((y % 400 == 0) || ((y % 100 != 0) && (y % 4 == 0))) return true; return false; } int...
2
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; int main() { int h,w; cin>>h>>w; vector<vector<char>> a(h,vector<char>(w)); rep(i,h)rep(j,w)cin>>a[i][j]; vector<bool> t(h),y(w); rep(i,h){ rep(j,w){ if(a[i][j]=='#')t[i]=y[j]=true; } } rep(i,h)...
0
#include <iostream> using namespace std; int n; string d[2][555555]; int h[2][555555]; int r[555555]; int main() { cin >> n; cin >> d[0][0]; int k = 1; for (int i = 1; i <= n; i++) { int a = i%2; int b = 1-a; for (int x = 0; x < 3; x++) { for (int y = 0; y < k; y++) { int z = x*k+y; int u = x; ...
0
#include <bits/stdc++.h> using namespace std; vector<int> edge[100005]; int col[100005]; bool used[100005]; int finalnode[100005]; int par[100005]; int dfs(int u, int p) { used[u] = true; par[u] = p; int result = 0; for (int i = 0; i < edge[u].size(); i++) { int v = edge[u][i]; if (used[v]) continue; ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 6; const long long mod = 777777777; int n, m; int w[4][4]; struct node { long long cnt[4][4]; node() { memset(cnt, 0, sizeof(cnt)); } }; node tree[4 * MAXN]; node merge(node n1, node n2) { node ret; for (int i1 = 1; i1 <= 3; i1++) { for (i...
5
#include<bits/stdc++.h> using namespace std; #define RI register int int read() { int q=0;char ch=' '; while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar(); return q; } typedef long long LL; const int N=100005; int n,tot,h[N],ne[N<<1],to[N<<1],du[N]; LL a[N],f[N]; void add(int x,in...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; struct edge { int u, v, w; edge() {} edge(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {} }; int n, a, b, c, d; vector<edge> e, ans; vector<int> G[maxn]; void dfs(int u, int f, int t) { if (G[u].size() == 1) { if (!t) { if (!a) a = ...
1
#include <bits/stdc++.h> using namespace std; void Input(); void solve(); void test_cases(); int test_case = 1; signed main() { test_case = 1; test_cases(); while (test_case--) { Input(); solve(); } } const int M = 2e5; int n, k, a, m, b, c, d, x, A, B, C; vector<int> ar, br, v, left, right; multiset<in...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; string second; int dp[5][N], n; set<string> ans; string get(int l, int r) { string ans = ""; if (r < n) ans = second.substr(l, r - l + 1); return ans; } bool calc(int x, int p) { if (p >= n) return 1; return dp[x][p]...
3
#include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int INF=1000000007; int f[101010],s[101010],a[101010],g[101010]; int ksm(int w,int x) { int ans=1; while(x) { if(x&1) ans=(long long)ans*w%INF; x/=2; w=(long long)w*w%INF; } return ans; }...
0
#include<iostream> #define rep(i,n) for(int i=0;i<n;i++) #define ck(a,b) (0<=a&&a<b) #define INF 1<<30 using namespace std; int dx0[]={0,1,0,-1,-1,-1},dx1[]={1,1,1,0,-1,0},dy[]={-1,0,1,1,0,-1}; int md[100][100],td[100][100],s,t,sx[10],sy[10],tx[10],ty[10],m,n,tc,mc; void rec(int x,int y,int a){ td[x][y]=a; rep(d,6){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, q; cin >> n >> q; long long int p = 0, m = 0; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) p++; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string a; cin >> a; if (n & 1) { cout << ":("; return 0; } int cnt1 = 1; int cnt2 = 1; if (a[0] == ')') { cout << ":("; return 0; } a[0] = '('; ...
3
#include<iostream> using namespace std; bool check(int X,int n,int m){ return (n*2020 + m*2021 == X); } //n*2020 + m*2021 = X void sol(int X){ for (int m = 0; m <= X/2021; m++) { int n; n=(X-2021*m)/2020; if(check(X,n,m)){ cout << "YES" << endl; return ; ...
2
#include <bits/stdc++.h> using namespace std; int dp[2][31][31][31][31], n, H; inline void updata(int h, int i, int j, int p, int q, int c, int key, int num) { int w[4] = {i, j, p, q}; for (int t = 0; t < num; t++) { if (t == c) w[t] = w[t] == H ? H : 0; if (t != c) w[t] = min(w[t] + 1, H); } sort(w, w ...
4
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; #define MP make_pair #define PB push_back #define X first #define Y second #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i) #define ITER(...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e2 + 9; int n; char a[N]; void home() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void enter() { cin >> n; } bool check(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } void solve() { bool ok = false; int...
2
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int N; cin >> N; vector<int> arr(2 * N); for (auto& x : arr) { cin >> x; } sort(arr.begin(), arr.end(), greater<int>()); if (arr[N - 1] > arr[N]) cout << "YES"; else cout << "NO"; cout << endl; return ...
1
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int res = 1; a = a % 1000000007; while (b > 0) { if (b & 1) { res = (res * a) % 1000000007; b--; } a = (a * a) % 1000000007; b >>= 1; } return res; } long long int gcd(lo...
5
#include <bits/stdc++.h> using namespace std; //typedef long long int ll; //#define M (int)(1e9+7) #define int long long const int mxN=1e5; //ll n,m,a[mxN],b[mxN]; bool comp(pair<int,int> a,pair<int,int> b){ if(a.first==b.first) return a.second>b.second; else return a.first<b.first; } bool isPrime(int...
1
#include <bits/stdc++.h> using namespace std; int arr[17]; int n; int check(int l, int r) { int cnt = 1; for (int i = l + 1; i <= r; i++) { if (arr[i] >= arr[i - 1]) { cnt += 1; } else { return 1; } } return cnt; } int divide(int l, int r) { if (l < r) { int m = l + (r - l) / 2; ...
1
#include<iostream> #include<cstdio> int n,m; struct edge{int to,nxt;}E[200050]; int H[100050],tot=1; void add_edge(int a,int b){ E[++tot]=(edge){b,H[a]},H[a]=tot; E[++tot]=(edge){a,H[b]},H[b]=tot; } int D[100050],cnt6,cnt4,way,P,Q; void dfs(int now,int S,int T,int fae){ if (fae&&now==S) return; if (now==T){way+...
0
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define pb push_back #define mp make_pair #define f first #define s second int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, sum = 0; cin >> b; for (a = 1; a <= sqrt(b); a++) { if (b % a == 0) { if (b / a == a) sum += 1; else sum += 2; } } cout << sum; }
2
#include <bits/stdc++.h> using namespace std; int n; int m; vector<int> v[102]; int deg[102]; bool vis[102]; queue<int> q; int dp[102][102]; long long int unused[102][102]; int mx[102]; long long int C[102][102]; long long int r[2][102]; inline void dfs(int b, int pr = -1) { if (pr != -1) { memset(dp[b], 0, sizeo...
4
#include <bits/stdc++.h> using namespace std; int n, m, t, a[310][310]; int tp, tu, td; int r[301][301], d[301][301], l[301][301], u[301][301]; void init() { memset(d, 0, sizeof(d)); memset(r, 0, sizeof(r)); memset(l, 0, sizeof(l)); memset(u, 0, sizeof(u)); for (int i = 0; i < n; i++) for (int j = 0; j < ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; int l = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { if (a[i + 1] <= a[i]) { int n = 0; n = (a[i] - a[i + 1]) / k + 1; l = l + n; a[i + 1] = a[...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], t = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) { t++; } } if (n == 1 && t == 0) { cout << "YES"; } else { if (t == 1 && n > 1) { cout << "YES"; } else { cout << "N...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int count = 0; int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i = 0; i < n - 1; i++) { if...
2
#include <bits/stdc++.h> using namespace std; const int N = 111111; pair<long long, int> a[N]; long long ans[N]; long long levelPrice[N]; long long n, A, cf, cm, m; int main() { ios::sync_with_stdio(false); cout.precision(10); cin >> n >> A >> cf >> cm >> m; for (int i = 1; i <= n; i++) { cin >> a[i].first;...
4
#include <bits/stdc++.h> using namespace std; int X[] = {0, 0, 1, 0, 0, -1}; int Y[] = {0, 1, 0, 0, -1, 0}; int Z[] = {1, 0, 0, -1, 0, 0}; struct node { int x, y; node() {} node(int x, int y) : x(x), y(y) {} }; int sum, mx; vector<int> v[200004]; map<int, int> mp; int a[200005]; bool vis[200005]; void dfs(int u) ...
3
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream &operator<<(ostream &s, const pair<A, B> &p) { return s << "(" << p.first << "," << p.second << ")"; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) { s << "[ "; for (auto it : c) s << it << " "; ...
3
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { while (n % i == 0) n = n / i; if (n == 1) cout << i; else cout << 1; return; } } cout << n; } int main() { long long t = ...
1
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; #define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++) int main() { ll a,b,x; cin>>a>>b; string s; cin>>s; if(count(s.begin(),s.end(),'-')==1 && s[a]=='-') cout<<"Yes"; else cout<<"No"; }
0
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) { return x; } return gcd(y, x % y); } void solve() { int n; cin >> n; vector<int> v(n); for (auto& x : v) { cin >> x; } int g = 0; for (int i = 0; i < 30; ++i) { int k = (1 << i); int c = 0; for (au...
1
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0 || b == 0) return 0; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } int main() { int n, m, z; cin >> n >> m >> z; int lcm = n * m / gcd(n, m); cout << z / lcm; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long a, s, d[200003][6], d1[200003][6], f[6], f1[6], g, h, j, k, l, i, n, m; vector<int> v[200003]; void dfs(int idx, int par) { for (auto it : v[idx]) { if (it == par) continue; dfs(it, idx); d[idx][0]++; d1[idx][0]++; for (int i = 1; i < m; ...
4
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) using namespace std; typedef pair<int,int> ii; const int IINF = INT_MAX; struct Point3d { int x,y,z; bool operator < ( const Point3d &p ) const { if( z != p.z ) return z < p.z; if( y != p.y ) return y > p.y; ...
0
#include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<(int)(n);i++) #define si(c) ((int)(c).size()) #define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++) #define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--) #define all(c) (c).begin(), (c).end() #define D(a) cerr << #a << "=" <...
0
#include <bits/stdc++.h> using namespace std; long long C[1005][1005]; long long pow1[1005]; const long long mod = 1e9 + 7; int n, m; int light[1005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; C[0][0] = 1; pow1[0] = 1; pow1[1] = 1; for (int i = 1; i <= n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; long long v[200002], w[200002], u[400010]; int main() { long long n, m, i, j, k = 0; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> v[i]; if (v[i] == m) j = i; } for (i = j - 1; i >= 1; i--) { if (v[i] < m) w[i] = w[i + 1] - 1; else w...
5
#include <cstdio> int main(){int n,s;while(scanf("%d",&n)+1){for(s=1;n;s*=2){n&s&&printf("%d%c",s,n-s?32:10);n-=n&s;}}}
0
#include<stdio.h> int main(void) { int N,A,B; scanf("%d%d",&N,&A); B=N*N-A; printf("%d\n",B); return 0; }
0
#include <bits/stdc++.h> using namespace std; string impossible; mt19937 mt_rand( chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 5e2 + 5; const int M = 1e4 + 5; const int L = 41; int MOD = 1e9 + 7; long long n, m, k, i, j, d; bool f0, f1, f2; const int MAXN = 2e3; int main() { ios...
2
#include <bits/stdc++.h> using namespace std; void fillString(unsigned long long int n, string &st) { while (n > 0) { int num = n % 10; n /= 10; if ((num & 1) == 0) { st = "0" + st; } else { st = "1" + st; } } int left = 18 - st.length(); for (int i = 0; i < left; i++) { st =...
1
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define rep(i, n) REP(i, 0, n) #define REP(i, a, n) for(int i=(a); i<n; i++) pair<pii, pii> cut(pii& p, int s) { int w = p.first, d = p.second; s %= 2*w + 2*d; pii a, b; if(s < w) { a = {s, d}; b = {w-s, d}; ...
0
#include <bits/stdc++.h> using namespace std; #define ll long long template <typename T> bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;} const ll MOD = 1e9+7; long long Comb(int n, int i){long long ans = 1; if(i == 0 || i...
0
#include <bits/stdc++.h> using namespace std; int x, y, q; void exgcd(int a, int b) { int temp; if (b == 0) { x = 1; y = 0; q = a; } else { exgcd(b, a % b); temp = x; x = y; y = temp - a / b * y; } } int c3, c4, c5; int k3, k4, k5; int f, x0, Why_Cant_I_Use_y0_In_Eclipse; int up, dow...
5
#include <bits/stdc++.h> using namespace std; using ll = int64_t; const int Mod = 1e9 + 7; const int Inf = (1LL << 31) - 1; const int Maxx = 2e5; void _case() { int n; cin >> n; int one = 0, zero = 0, x; ll ans = 1; while (n--) { cin >> x; if (x) { one++; if (one == 2) { ans *= zer...
2
#include<iostream> #define LEFT 0x01 #define RIGHT 0x02 #define BOTH 0x03 using namespace std; typedef unsigned long long int ull; int main() { while(true){ int n; int ans=0; cin>>n;if(n==0)break; ull cls[n][n],hand[n][n],shrow[n],hgcol[n]; fill(shrow,shrow+n,~(0ULL));fill(hgcol,hgcol+n,0); fo...
0
#include <bits/stdc++.h> using namespace std; const int oo = 1000000000; const int MAXN = 810; const int MAXE = 1000000; struct Edge { int s, e, nx, c; double co; } E[MAXE]; int head[MAXN], cnt; void add(int s, int e, int c, double co) { E[cnt].s = s; E[cnt].e = e; E[cnt].c = c; E[cnt].co = co; E[cnt].nx ...
5
#include <iostream> #include <string> int main() { int n, a, b; std::cin >> n >> a >> b; std::string s; std::cin >> s; for (int i = 0; i < s.size(); i++) { if (s.at(i) == 'a' && a+b > 0) { std::cout << "Yes" << std::endl; if (a > 0) { a--; } else { b--; } } else if (s.at(i) == 'b' && b > 0) { s...
0
#include<iostream> using namespace std; int main(){ int a; cin >> a; int b = a / 200; cout << 10 - b << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x[101] = {0}, y[101] = {0}; char c; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c; if (c == '*') { x[i]++; y[j]++; } } } for (int i = 1; i <= n; i++) { i...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2") using namespace std; using ll = long long; int a[101001]; int b[101010]; int dp[101010]; int p1[101010]; int p2[101010]; ll ans = 0; int n, k; void add(int* __restrict a, int* __restrict dp, int n) { for (int i = 0; i < n; ++i) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> fs(20, 1); for (int i = int(1); i < int(20); i++) fs[i] = fs[i - 1] * i; vector<long long> ls; for (int i = 1; i <= 10; i++) { for (int j = int(0); j < int(1 << i); j++) { long long n = 0; for (int k = int(0); k < int(i...
3
#include <bits/stdc++.h> using namespace std; long long n, len, x, ans, s; int main() { cin >> x; x = abs(x); while (x > s) { ans++; s += ans; } while ((s - x) % 2 == 1) { ans++; s += ans; } cout << ans; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const long long z = 127, MOD = 1e9 + 7; long long Z[MAXN + 1]; void fillZ() { Z[0] = 1; for (int n = 1; n <= MAXN; ++n) Z[n] = z * Z[n - 1] % MOD; } struct RollingHashing { vector<long long> H; RollingHashing(string &S) { int N = S.length()...
4
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C& a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); } template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second ...
5
#include<bits/stdc++.h> using namespace std; const int N=3003,mod=1e9+7,inv2=5e8+4; int n,m,Q,a[N],f[N][N]; void add(int &x,int y){x=(x+y)%mod;} int main() { scanf("%d%d",&n,&Q); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[i][j]=a[i]<a[j]?1:0; for(int T=1;T<=Q;T++) { int x...
0
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; typedef long long i64; typedef long double ld; typedef pair<i64,i64> P; #define rep(i,s,e) for(int i = (s);i <= (e);i++) int n; int m; vec...
0
#include <bits/stdc++.h> using namespace std; const int md = 1e9; const int xn = 1e5 + 10; const int xm = 1e6 + 10; const int SQ = 450; const int sq = 1e3 + 10; const int inf = 1e9 + 10; long long power(long long a, long long b) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md ...
2
#include <bits/stdc++.h> using namespace std; #define mod 998244353 long long pw[5000005],fact[5000005],inv[5000005]; long long pow_log(long long x,int y) { if (!y) return 1; long long ret=pow_log(x,y/2); ret=(ret*ret)%mod; if (y%2) ret=(ret*x)%mod; return ret; } int ncr(int n,int r) { return ((fact[n]*inv[r])%...
0
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int sum[n]; bool won[n]; for (int i = 0; i < n; i++) { int x; cin >> x; if (i) sum[i] = sum[i - 1] + x - 1; else sum[i] = x - 1; won[i] = x - 1; } vector<pair<int...
2
#include <climits> #include <cstdlib> #include <iostream> #include <queue> #include <vector> using namespace std; struct edge { int to, dist, num; edge(int t, int d, int n):to(t), dist(d), num(n){} }; struct state { int pos, num, money; state(int p, int n, int m):pos(p), num(n), money(m){} bool operator>(const s...
0
#include <iostream> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << x*y/2 << endl; }
0
#include <bits/stdc++.h> using namespace std; struct E { int v, w, next; } e[200010]; int head[200010], cnt; int dis[200010], vis[200010]; int tmp[200010]; map<int, int> Map[200010]; void add(int u, int v, int w) { e[cnt].v = v; e[cnt].w = w; e[cnt].next = head[u]; head[u] = cnt++; } queue<int> q; void spfa(i...
4
#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<int> x(N); rep(i, N) cin >> x[i]; int ans = 1e9; rep(i, N - K + 1) { int l = x[i], r = x[i + K - 1]; ans = min({ans, abs(l) + r...
0
#include <iostream> #include <cstdio> using namespace std; void solve(int s, int g){ if(s <= 5){ if(s < g){ for(int i = s; i < g; i++){ printf("%d ", i); } printf("%d\n", g); }else{ for(int i = s; i > g; i--){ printf("%d ", i); } printf("%d\n", g); } }else{ if(s < g){ for(int i =...
0
#include<bits/stdc++.h> using namespace std; int main() { int n,m,a,s=0; cin>>n>>m; while(m--) { cin>>a; s=s+a; } if(s>n) cout<<"-1"; else cout<<(n-s); return 0; }
0
#include <bits/stdc++.h> using namespace std; string A[100000 + 5], s; int val[10], fact[10]; int n; int main() { cin >> s >> n; for (int i = 0; i < n; ++i) { cin >> A[i]; } for (int i = 0; i < 10; ++i) { val[i] = i, fact[i] = 10; } for (int i = n - 1; i >= 0; i--) { int d = A[i][0] - '0'; i...
3
#include <bits/stdc++.h> using namespace std; void solve(); int n, m, k, ki; vector<int> a[200]; int visited[200]; int counter = 0; void dfs(int v) { if (visited[v]) { return; } visited[v] = 1; for (int i = 0; i < a[v].size(); i++) { dfs(a[v][i]); } } int main() { cin >> n >> m; int all_zeros = 1;...
3
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int T, x, a, up, low, mid; cin >> T >> x; for (int i = 0; i < T; i++) { cin >> a; v.push_back(a); } sort(v.begin(), v.end()); mid = (T + 1) / 2; if (v[mid - 1] == x) { cout << "0" << endl; return 0; } up = upper_...
3
#include <bits/stdc++.h> using namespace std; int n, a, b, c, d; int check(int no) { if (no > n || no < 1) return 0; return 2; } int main() { int i, j, t; scanf("%d %d %d %d %d", &n, &a, &b, &c, &d); int p_r = c - b; int p_s = d - a; int p_t = c + d - a - b; long long int ans = 0; for (i = 1; i <= n; ...
2
#include <iostream> using namespace std; int main() { while(true){ int M, T, P, R; cin >> M >> T >> P >> R; if(M==0 && T==0 && P==0 && R==0) break; int CP[50], TT[50], PT[50][10]; // 正解数,時間計,ペナルティ for(int i=0; i<T; i++){ CP[i] = TT[i] = 0; for(int j=0; j<P; j++) PT[i][j] = 0; } for(int ...
0
#include<stdio.h> #include<iostream> using namespace std; int main(){ int n; while(1){ scanf("%d",&n);if(n==0)break; int s=0;int t=0; for(int i=1;i*i<=n;i++) {t=n/i; if(n%i==0){s+=i+t; if(n==t||t==i)s-=t; } //cout<<t<<endl; } if(n==1)s=0; //cout<<s<<endl; if(s>n)printf("abundant number\n"); if(s==n)printf("perf...
0
#include <bits/stdc++.h> using namespace std; int main() { int i, j, count = 0, t, n, k, taps[200], res[200], f[200], m; cin >> t; for (i = 1; i <= t; i++) { count = 0; cin >> n >> k; for (j = 1; j <= k; j++) { cin >> taps[j]; } for (j = 1; j <= n; j++) f[j] = 0; while (1) { fo...
1
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 7; const int MAXN = 4e4 + 10; int n, k; int a[MAXN]; int s[70][MAXN << 2], lazy[70][MAXN << 2]; void pushDown(int b, int rt) { if (s[b][rt] > 0) { s[b][rt << 1] += lazy[b][rt]; s[b][rt << 1 | 1] += lazy[b][rt]; lazy[b][rt << 1] += lazy[b]...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; long long int k = n * m; long long int arr[k + 1]; arr[0] = -1; map<long long int, long long int> mp1; long long int t = 0, sum = 0; for (long long int i = 1; i <= k; i++) { cin >> arr[i]; if (arr[i] ==...
2
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(double t) { cerr << t; } template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> void _...
2
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" ...
0