Dataset Viewer
Auto-converted to Parquet Duplicate
solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int arr[105] = {0}; int main() { int n, d, res; cin >> n >> d; for (int i = 0; i < n; i++) cin >> arr[i]; res = 2; for (int i = 1; i < n; i++) { int dd = arr[i] - arr[i - 1]; if (dd > 2 * d) res += 2; else if (dd == 2 * d) res++; } cout...
1
#include <bits/stdc++.h> using namespace std; char in[40][40]; int n, m, cnt[40][40], pl[40][40], all[40][4][2], aa[15], now[15], used[7], ans, domu[70], dom[70], mk[300]; int inv(int a) { return ((a & 7) << 3) + (a >> 3); } void dfs(int np) { int i, j; if (np == 14) { ans++; for (i = 0; i < 14; i++) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, a[505] = {0}, b[1005] = {0}, ans = 0; scanf("%I64d%I64d", &n, &m); for (i = 1; i <= n; i++) { scanf("%I64d", &a[i]); } for (i = 1; i <= m; i++) { scanf("%I64d", &b[i]); long long int s = 0; bool visited[505] =...
3
#include <cstring> #include <cstdio> char str[200005], ans[200005]; int nxt[200005][35], dp[200005], ch[200005]; int main() { // freopen("ARC081-E.in", "r", stdin); scanf("%s", str); int n = strlen(str); for (int i = 0; i < 26; i++) nxt[n + 1][i] = n + i + 1; for (int i = n; i >= 0; i--) { memcpy(nxt[i]...
0
#include<bits/stdc++.h> #define N 200010 #define mod 1000000007 using namespace std; int n,x,y,ans=1,tot,min1,min2,c[N],w[N],minc[N],numc[N]; int fac[N],inv[N]; void getmin() { for(int i=1;i<=n;i++) { if(minc[i]<minc[min1]) { min2=min1; min1=i; } else if(minc[i]<minc[min2]) min2=i; } } int poww...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<long long int> v; sort(a, a + n); ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,n; cin >> n >> a; int rslt = 1; for(int i=1;i<n;i++) { cin >> b; if(a<=b){rslt++;a=b;} } cout << rslt; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); set<pair<long long, int> > t; for (int i = 0; i < k; i++) t.insert(make_pair(0, i)); for (int i = 0; i < n; i++) { long long s, m; scanf("%lld %lld", &s, &m); pair<long long, int> p = *t.begin(); t.era...
4
#include <bits/stdc++.h> using namespace std; int a[110]; int d[110]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &a[i], &d[i]); } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] >= a[j]) { if (a[i] < a[j] + d[j...
5
#include <bits/stdc++.h> using namespace std; int a[200001]; int main() { int n, idx1 = 0, idx2 = 0; long long res1 = 0, res2 = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] == 1) { idx1++; } else { res1 += idx1; } } for (int i = n - 1...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9')...
5
#include<bits/stdc++.h> using namespace std; int main(){ int r,g,b,n; cin>>r>>g>>b>>n; int cnt=0; for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ int z=n-(i*r+j*g); if(0<=z && z%b==0)cnt++; } } cout<<cnt<<endl; }
0
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main(){ int n, k; cin >> n >> k; vector<int> a(n); rep(i,n) cin >> a[i]; vector<bool> ans(k+1,false); rep(i,k) if(!ans[i]) rep(j,n) if(i+a[j] <= k) ans[i+a[j]] = true; cout << (ans[k] ? "First" : "Second") << en...
0
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,L,T; struct evol{long long x,w;}a[101010]; bool cmp(evol u,evol v){return u.x<v.x;} int main() { scanf("%d%d%d",&n,&L,&T); for(int i=1,x,y;i<=n;i++) scanf("%lld%lld",&a[i].x,&a[i].w); long long rk=0; for(int i=1;i<=n;i++) { if(a...
0
#include <bits/stdc++.h> using namespace std; const int MAX = (int)100 + 5; int pr[MAX]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < (int)(n); ++i) cin >> pr[i]; sort(pr, pr + n); map<string, int> ma; multiset<int, greater<int>> li; string...
3
#include <bits/stdc++.h> using namespace std; #define fn(i,n) for(i = 0; i < n; i++) #define fg(i,a ,n) for(i = a; i < n; i+=2) #define ft(i,a ,n) for(i = a; i < n; i++) #define fp(i,a, n) for(i = a; i >= n; i-- ) #define ld double #define ll long long int #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.ti...
1
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcnt(...
4
#include <bits/stdc++.h> char str[2000000]; int l; int calc(int a, int b, char c) { if (c == '|') return (a | b); if (c == '&') return (a & b); if (c == '^') return (a ^ b); } int dfs() { if (str[l] == '0') { l++; return 1 << 0; } if (str[l] == '1') { l++; return 1 << 1; } if (str[l] == ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[101], total_score = 0; for (int i = 0; i <= 101; i++) a[i] = 0; int x; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; a[x]++; } for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { int ch; if ...
3
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long ans; long long a[200010]; bool cmp(int a, int b) { return a > b; } int main(void) { ios::sync_with_stdio(false); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1, cmp); ans += (m / (k + 1)) ...
2
#include <bits/stdc++.h> using namespace std; vector<int> e[303], ans; bool dfs(int x, int y, int last) { if (x == y) return 1; for (int i = 0; i < e[x].size(); i++) if (e[x][i] != last) if (dfs(e[x][i], y, x)) { ans.push_back(x); return 1; } return 0; } int n, x, y; int main() { ...
4
#include <bits/stdc++.h> using namespace std; double as[100005]; int main() { int n, a, d; while (scanf("%d%d%d", &n, &a, &d) > 0) { for (int i = 1; i <= n; i++) { int x, y; scanf("%d%d", &x, &y); double s = (1.0 * y * y) / (2.0 * a); double t = 0.0; if (s <= d) t = (y * 1....
1
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n, w, d, p, s; while(cin >> n >> w >> d){ if(!w) break; vector < pair<int, int> > cake; cake.push_back(make_pair(w, d)); for(int i=0;i<n;i++){ cin >> p >> s; int nw = cake[p-1].first, nd = cake[p-1].second;...
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, char> > grp[112345]; bool mark[112345]; vector<int> ans[2], p[3]; map<int, int> vp; int n, e; bool dfs(int part, char cl, int vx) { p[part].push_back(vx); mark[vx] = true; vp[vx] = part; for (int i = 0; i < grp[vx].size(); i++) { int v = grp[vx]...
2
#include <bits/stdc++.h> using namespace std; int main() { int t[5], i, j, b[101], sum = 0, temp, t1, t2, ans; for (i = 0; i < 101; i++) b[i] = 0; for (i = 0; i < 5; i++) { cin >> t[i]; sum += t[i]; b[t[i]]++; } ans = sum; for (i = 1; i < 101; i++) { if (b[i] >= 2) { if (b[i] == 2) { ...
1
#include <bits/stdc++.h> typedef long long LL; #define SORT(c) sort((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; // N,E,S,W = 0,1,2,3; int dx[4]={0,1,0,-1}; int dy[4]={-1,0,1,0}; bool inrange(int x,int y,int w,int h){return 0<=x&&x<w && 0<=y&&y<h...
0
#include <bits/stdc++.h> using namespace std; int n; vector<int> tree[3010], treeT[3010]; bool vis[3010]; int cost[3010], delta[3010][3010], lineL[3010][3010], dp[3010][3010]; int dfs(int base, int root, int sum, int deep, int dpv, int state) { if (base == root) dp[base][root] = 0; else dp[base][root] = min...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 110005; int n, qq, fa[maxn], f[maxn], sz[maxn], up[maxn], edge[maxn], dep[maxn], son[maxn], q[maxn]; int tot = 0, V[maxn << 1], N[maxn << 1], F[maxn], ans[maxn]; struct event { int c, k, a, b; } events[maxn << 1]; struct info { int ls, rs, len, val;...
5
#include <bits/stdc++.h> using namespace std; long long int MOD = 998244353; long long int mod = 1e9 + 7; long long int INF = 1e18; long long int dx[] = {1, -1, 0, 0}; long long int dy[] = {0, 0, 1, -1}; long long int a[100009] = {0}; long long int sum[100009]; long long int par[100009]; bool dfs(vector<long long int> ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; int cnt=0; cin >> n; for(int i=0;i<n;i++){ int a; cin >> a; int c=0; while(a%2==0){ a/=2; c++; } cnt+=c; } cout << cnt; }
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } bool isperfect(long long n) { long long y = sqrt(n); if (n % y == 0 && y * y == n) return true; return false; } bool comp(pair<int, int> a, pair<int, int> b) { if (a.first ==...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 30; int n; string s, ans = ""; int mp[maxn], ct[maxn], in[maxn], out[maxn], used[maxn]; void span(int s) { ans = ans + char('a' + s); ct[s]--; if (mp[s] != -1) span(mp[s]); } int main() { cin >> n; memset(mp, -1, sizeof(mp)); memset(ct, 0, sizeo...
4
#include <bits/stdc++.h> using namespace std; string s; int main() { int i, j, k; cin >> s; int n = (int)(s.size()); if (n & 1) { cout << -1 << endl; return 0; } int x = 0, y = 0; for (i = 0; s[i]; i++) { if (s[i] == 'U') y++; if (s[i] == 'D') y--; if (s[i] == 'R') x++; if (s[i] ==...
2
#include <bits/stdc++.h> using namespace std; struct treeNode { int num[21]; int lazy; treeNode() { for (int i = 0; i < 21; i++) num[i] = 0; lazy = 0; } }; treeNode st[100000 << 2]; int inp[100000]; void Build(int node, int l, int r) { if (l == r) { int x = inp[l], i = 0; while (x) { st[...
5
#include <bits/stdc++.h> using namespace std; int a[3], b[3]; bool large() { if (b[2] + 18 != a[2]) return b[2] + 18 < a[2]; if (b[1] != a[1]) return b[1] < a[1]; if (b[0] != a[0]) return b[0] < a[0]; return true; } bool legal() { int leap = (b[2] % 4 == 0); if (b[1] == 2) return b[0] <= 28 + leap; if (b[...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100 * 1000 + 5; bool Mark[maxn]; vector<pair<int, int> > adj[maxn]; int decompose(int v) { queue<int> q; while (q.size()) q.pop(); for (int i = 0; i < adj[v].size(); i++) { int e = adj[v][i].second; if (!Mark[e]) { q.push(adj[v][i].first...
5
#include <bits/stdc++.h> using namespace std; char s[100]; long long n, len = 0; int main() { scanf("%s", s); long long ans = 0; for (int i = strlen(s) - 1; i >= 0; i--) { if (s[i] == '9') { ans += 9; s[i] = '\0'; } else { break; } } for (int i = 0; s[i]; i++) ans = ans + s[i] - ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n, ans = 0; string s; cin >> n >> s; for(int i = 0;i<n-2;i++){ if("ABC" == s.substr(i,3)) ans++; } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; vector<int> v[maxn]; string s; int n, m, dp[maxn], vis[maxn], flag; void dfs1(int x) { if (vis[x] == 1) { flag = 1; return; } if (vis[x]) return; vis[x] = 1; for (auto i : v[x]) { dfs1(i); } vis[x] = 2; } void dfs2(int x,...
4
#include <bits/stdc++.h> using namespace std; long long n, m, s, X, Y, x, y, cnt, ans; int main() { scanf("%I64d%I64d%I64d", &n, &m, &s); for (X = 1; X <= n; X += 2) for (Y = 1; Y <= m; Y += 2) { if (X * Y == s) ans += (n - X + 1) * (m - Y + 1) * ((X + 1) / 2 * (Y + 1) - 1); else if (X * Y >...
3
#include <bits/stdc++.h> using namespace std; const int maxno = 5e4 + 5; string s[maxno]; bool cmp(string a, string b) { string ab = a + b; string ba = b + a; return ab < ba; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) cin >> s[i]; sort(s, s + n, cmp); for (int i = 0; i < n; i++) ...
3
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k, t; long long num[5]; int main() { while (cin >> n >> num[1] >> num[2] >> num[3]) { long long min = 1; long long ans = n % 4; if (ans == 0) { ans = 0; } else { ans = 4 - ans; switch (ans) { case 1: { ...
1
#include <bits/stdc++.h> using namespace std; bool vis[31622777]; int prime[2000000], tot; long long exgcd(long long a, long long b, __int128 &x, __int128 &y) { if (!b) { x = 1, y = 0; return a; } long long g = exgcd(b, a % b, y, x); y -= a / b * x; return g; } void get_prime(int n) { for (int i = 2; i <= ...
0
#include <bits/stdc++.h> using namespace std; int binarySearch(vector<long long>& v, long long l, long long r, long long x) { int mid = l + (r - l) / 2; if (l <= r) { if (v[mid] == x) return mid; else if (v[mid] > x) return binarySearch(v, l, mid - 1, x); else return binarySearch(v, mi...
2
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int h,w; while(1){ cin >> h >> w; if(!h && !w)break; vector<string> grid; for(int i=0;i<h;i++){ string tmp; cin >> tmp; grid.push_back(tmp); } int ans = 0; for(int i=0;i<h;i...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, i; cin >> a >> b; c = a; while ((a / b) != 0) { c += (a / b); i = a % b; a /= b; a += i; } cout << c; }
1
#include "bits/stdc++.h" using namespace std; // コンテスト中のみ //#define int long long #define ll long long #define rep(i,n) for(int i = 0; i < (n); i++) #define P pair<ll,ll> #define ld long double ll INF = (1LL << 60); int MOD = 1000000007; struct UnionFind { vector<ll>p; UnionFind(ll n) { p.resize(n, -1); } ll f...
0
#include <bits/stdc++.h> using namespace std; int a[1111111]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int mx = a[n - 1], ans = 1; for (int i = n - 2; i >= 0; i--) { if (mx > 0) { mx--; } else { ans++; } mx = max(mx, a[i]); } ...
2
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int a[4]; cin >> a[0] >> a[1] >> a[2] >> a[3]; while ((a[0] != 1) || (a[1] != 1) || (a[2] != 1) || (a[3] != 1)) { bool step = false; for (int i = 0; i < 4; i++) { int j = (i + 1) % 4; if ((a[i] % 2 == 0) && (a[j] ...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define ri register int const long double PI=3.141592653589793238462643383279; const int N=500005,M=998244353; int n,i,ans,p,e[N],vis[N]; struct str{ int a,x; }a[N],b[N]; bool cmp(str a,str b) { return a.a<b.a; } int main() { scanf("%d",&n); for(i=1...
0
#include <bits/stdc++.h> using namespace std; int n, m, d, a[100005], b[100005], l, r; int main() { scanf("%d%d%d", &n, &m, &d); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] = -a[i]; for (int i = 1; i <= m; i++) scanf("%d", &b[i]); sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + m); l = 0, r = min(n, m...
4
#include<cstdio> const int N=1e5+5; int n,s,x[N]; long long p[N]; int main(){ scanf("%d%d",&n,&s); for(int i=1;i<=n;++i){ scanf("%d%d",&x[i],&p[i]); } int l=1,r=n,dir=-1; long long ans=0; while(1){ if(s<=x[l]){ ans+=x[r]-s; break; } if(s>=x[r]){ ans+=s-x[l]; break; } if(p[l]>=p[r]){ if(dir!=0) ans+=x...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc; cin >> tc; while (tc--) { int len; cin >> len; string str; cin >> str; int maxP = 0; int consecP; bool initiate = false; for (int i = 0; i <...
1
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const int MAXN = 300005, MAXV = 1000000, B = 1000; int a[MAXN], b[MAXN], v[MAXV], sum[1005], mn[1005]; void update(int d, int x) { int b = d / 1000; v[d] += x; sum[b] = 0; mn[b] = INT_MAX; for (int i = b * 1000; i < (b + 1) * 1000; i++) { ...
3
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long long seve[1000000] = {...
1
#include <bits/stdc++.h> using namespace std; const int N=2002; const int B=4000000+1; int n,a[N],sum=0; bitset<B> f; int main(){ scanf("%d",&n); f[0]=1; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); f=f|(f<<a[i]); sum+=a[i]; } for(int i=(sum+1)/2;;i++)if(f[i]){ return !printf("%d\n", i); } } /* 1 3 0 1 3 4 ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int t[105] = {}; for (int i = 0; i < n; i++) cin >> t[i]; vector<int> x, y; int r = 0; for (int I = 0; I < k; I++) { pair<int, int> h, g; h.first = 0, h.second = t[0]; g.first = 0, g.second = t[0]; for (int...
2
#include <bits/stdc++.h> using namespace std; template <class T> void _Print(T &&x) { cerr << x << ")" << "\n"; } template <class T, class... S> void _Print(T &&x, S &&...y) { cerr << x << ", "; _Print(y...); } template <class T> class compare { public: bool operator()(pair<T, T> &x, pair<T, T> &y) { ...
2
#include <bits/stdc++.h> using namespace std; bool debug_disabled = true; int dp[51][51]; int board[51][51]; void solve() { memset(dp, 0, sizeof dp); memset(board, 0, sizeof board); int n; cin >> n; for (int i = 0; i < n; ++i) { string s; cin >> s; for (int j = 0; j < n; ++j) if (s[j] == '1'...
5
#include <bits/stdc++.h> using namespace std; long long bigMod(long long x, long long y) { long long res = 1; while (y) { if (y & 1) { res = (res * x) % 1000000007; y--; } else { x = (x * x) % 1000000007; y >>= 1; } } return res; } struct query { int l, r, id; } Q[200005]; ...
4
#include <bits/stdc++.h> using namespace std; int main() { double A,B;cin>>A>>B; cout<<fixed<<A*B/(A+B)<<endl; }
0
#include <bits/stdc++.h> using namespace std; bool sortbysec(const int a, const int b) { return abs(a) > abs(b); } int main() { int test; cin >> test; while (test--) { long long int n, lastn, lastp = 0, prod = 1, flag = 0; cin >> n; vector<int> arr; for (int p = 0; p < n; p++) { int x; ...
2
#include<iostream> using namespace std; int main() { char a,b,c,d; cin>>a>>b>>c>>d; cout<<((a==b&&b==c)||(b==c&&c==d)?"Yes":"No")<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) == 6) { if (b * d * f > a * c * e) puts("Ron"); else if (b * d * f == 0 && a * c * e == 0) { if (d != 0) { if (c == 0) puts("Ron"); else...
1
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(n); set<long long> r; for (long long i = 0; i < n; i++) { cin >> a[i]; r.insert(a[i]); } sort(a.begin(), a.end()); if (r.size() ==...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 2009; int n; bool a[MAXN][MAXN]; bool u[MAXN][MAXN]; bool b[MAXN][MAXN]; int maX = -1, may = -1, mix = -1, miy = -1; int q[MAXN * MAXN][2], top = 0; int l = 1, r = 0; void bfs(int x, int y) { u[x][y] = true; l = 1; r = 0; top = 0; r++; q[r][0] =...
5
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { vector<priority_queue<long long, vector<long long>, greater<long long> > > w( 4); long long k1, k2, k3, t1, t2, t3, n, nn, me = -1; cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n; nn = n; while (n--) { long long...
2
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, x; cin >> n; vector<long long int> set_bit(20, 0); for (long long int i = 0; i < n; i++) { cin >> x; long long int curr_bit = 0; while (x) { if (x & 1) { set_bit[curr_bit]++; } x /= 2; curr_...
4
#include <bits/stdc++.h> const int MAXN = 100000 + 10; int n, a[MAXN], b[MAXN]; std::map<int, int> M; template <typename T> inline void read(T &x) { T data = 0, w = 1; char ch = 0; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (ch >= '0' && ch <= '9')...
5
#include<iostream> using namespace std; int main(){ int a,b,w; cin>>w>>a>>b; cout<<max(0,max(b-a-w,a-b-w))<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long MOD = 1e9 + 7; const int inf = 1e9; const int N = 1e3 + 2; bool flag; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void solve() { long long k; cin >> k; long long x = 0, y = 0, tmp = 1, sm = 3, i...
3
#include <bits/stdc++.h> using namespace std; int n, u, r; int a[50], b[50], p[50], k[50]; long long sol = 0; bool first = true; int rec(int t, bool ch) { if ((u - t) % 2 == 0) { long long tt = 0; for (int i = 1; i <= n; i++) { tt = tt + (((long long)a[i]) * ((long long)k[i])); } if (first) { ...
4
#include <bits/stdc++.h> using namespace std; const int maxl = 2e5 + 7; const int inf = 0x3f3f3f3f; int dp[5007][5007]; char s1[5007], s2[5007]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; cin >> s1 + 1 >> s2 + 1; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m;...
4
#include<bits/stdc++.h> using namespace std; const int N=3e5+5; int n,a[N]; struct each{ int a,b; }b[N]; bool com(each x,each y){ return x.a<y.a; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&b[i].a); b[i].b=i,a[b[i].a]=i; } int now=1; sort(b+1,b+n+1,com); for(int i=1;i<=n;i++){ for(int...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<set<int>> g; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<int> d(n, 0); g = vector<set<int>>(n); for (int i = 1; i < n; i++) { ...
6
#include<bits/stdc++.h> using namespace std; const int M=155; const int INF=2e9; int n,cost[M][M],from[M],lx[M],ly[M],slack[M],vx[M],vy[M]; int path(int v){ int t; vx[v]=1; for(int i=1;i<=n;i++) { if(vy[i])continue; t=lx[v]+ly[i]-cost[v][i]; if(t==0) { vy[i]=1; if(from[i]==0||path(fro...
0
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX / 2, NINF = INT_MIN / 2; const long double PI = acos(-1.0); void prepareIO() { if (strlen("") != 0) { freopen( "" ".in", "r", stdin); freopen( "" ".out", "w", stdout); } } void debout() {} t...
1
#include <bits/stdc++.h> using namespace std; int const INF = 2 * 10e5 + 123; int simple(int n) { int i, sq; if (n % 2 == 0) { return 0; } sq = (int)sqrt(n); for (i = 3; i <= sq; i++) { if ((n % i) == 0) { return 0; } } return 1; } long long gcd(long long a, long long b) { if (a > b) s...
2
#include<bits/stdc++.h> #define MAXN 5005 #define INF 1000000000 #define MOD 1000000007 #define F first #define S second using namespace std; typedef long long ll; typedef pair<int,int> P; int n,a,b; int dp[MAXN][MAXN][2]; int s[MAXN][MAXN],diag[MAXN][MAXN]; void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;} void dec(in...
0
#include <bits/stdc++.h> using namespace std; char ar[1000], er[1000]; void oku() { int i, t, a; scanf("%s", ar); scanf("%d", &t); a = strlen(ar); for (int i = 0; i < a; i++) if (ar[i] <= 'Z') ar[i] += 32; for (int i = 0; i < a; i++) { if (ar[i] < 97 + t) ar[i] = ar[i] - 32; } cout << ar << endl...
4
#include<iostream> using namespace std; int main(){ int a[100]; int ans[100]; int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=n-1;i>=0;i--){ int add=-1; for(int j=0;j<=i;j++){ if(a[j]==j+1){add=j;}} if(add==-1){cout<<-1<<endl;return 0;} else{ ans[i]=add+1...
0
#include <bits/stdc++.h> #define forn(i,s,t) for(register int i=(s);i<=(t);++i) using namespace std; const int N = 5e2 + 10; int t, n, m; char mp[N][N]; int main() { scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m); forn(i,0,n + 1) forn(j,0,m + 1) mp[i][j] = 0; forn(i,1,n) scanf("%s", mp[i] + 1); int lst =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; map<int, int> buy; map<int, int> sell; for (int i = 0; i < n; i++) { char d; int p, q; scanf(" %c %d %d", &d, &p, &q); if (d == 'B') buy[p] += q; else sell[p] += q; } map<int, int>::iterator...
2
#include <bits/stdc++.h> using namespace std; template <class T> void read(vector<T> &mas) { for (auto &it : mas) cin >> it; } template <class T> void print(vector<T> &mas) { for (auto it : mas) cout << it << " "; cout << endl; } int main() { int n, m; cin >> n >> m; vector<int> days(n); vector<int> preps...
4
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; map<string,int> m; int ma=0; for(int i = 0;i < N;i++){ string s; cin >> s; m[s]++; ma=max(ma,m[s]); } for(auto b : m){ if(b.second != ma){ continue; } cout << b.f...
0
#include<cstdio> #include<queue> #include<map> #include<cstring> #include<string> #include<algorithm> using namespace std; map<string,int> table; int nex[4]={-4,4,-1,1}; void bfs(string str) { queue<string> que; table[str]=1; que.push(str); while(!que.empty()){ str=que.front(); que.pop(...
0
#include<bits/stdc++.h> #define N 200010 #define ll long long using namespace std; ll a[20]; ll solve(int l,int r,int T1,int T2){ if(l>r)return 0; ll SS=1e18; for(int i=l;i<=r;i++){ SS=min(SS,solve(l,i-1,T1,T1+T2)+solve(i+1,r,T1+T2,T2)+(T1+T2)*a[i]); } return SS; } int main(){ int n; scanf("%d",&n); for(int i...
0
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcnt(...
4
#include <algorithm> // #include <cstdlib> #include <cstring> #include <cstdio> #include <string> #include <queue> #include <cmath> #include <set> #include <map> #include <bitset> using namespace std; typedef long long LL; typedef double db; const int oo=2139063143; const int N=12010; const int P=1000000007; const db e...
0
#include<iostream> #include<string> #include<map> #include<algorithm> using namespace std; #define rep0(i,n) for(int i=0;i<(int) n;i++) typedef long long ll; int n; string s; ll m; map<string,ll> mp; string ret,res; int main (){ cin>>n>>s; m=(1<<n); rep0(i,m){ ret={}; res={}; rep0(j,n){ if(i&(1...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MAXN = 1e6 + 5, inf = 1e9; const ll INF = 1e18; const ld PI = 3.1415926535897932384626433832795; int cnt[MAXN]; ll dp[MAXN], tab[MAXN]; bool vis[MAXN], used[MAXN]; vector<int> G[MAXN]; vector<ll> V; set<ll> S; map<ll, ...
2
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e17; bool can1[100100], can2[100100]; int a[100100], b[100100], lst[100100]; long long sum[100100], s[100100], val[100100]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i =...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int pow3[600005]; int fact[900005]; int invf[900005]; int Power(int x, int y) { int re = 1; while(y) { if(y & 1) { re = 1ll * re * x % MOD; } x = 1ll * x * x % MOD; y >>= 1; } return re; } int C(int n, int m) { if(m < 0) { r...
0
#include <bits/stdc++.h> using namespace std; const int N = 110000; const unsigned long long P = 1000000007; unsigned long long p[N], h[N]; int n, a[N], nxt[N]; char s[N]; map<int, int> was; vector<pair<int, int> > ans; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); map<int, int>::...
3
#include <bits/stdc++.h> using namespace std; int n, d, a[10001], ans; int main() { cin >> n >> d; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 2; i <= n; i++) { int j = i - 1; if (a[i] <= a[j]) { ans += (a[j] - a[i]) / d + 1; a[i] += ((a[j] - a[i]) / d + 1) * d; } } ...
1
#include <bits/stdc++.h> #define ll long long #define coutp(a) cout << "(" << a.first << ", " << a.second << ")" using namespace std; const int mx = 2e5; int parent[mx + 10], Rank[mx + 10]; int get(int a) { if(parent[a] != a) parent[a] = get(parent[a]); return parent[a]; } void Union(int a, int b) {...
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; for (int i = 0, _n = (c + 1); i < _n; i++) { if (i % a == 0 && (c - i) % b == 0) { puts("Yes"); return 0; } } puts("No"); return 0; }
1
#include<bits/stdc++.h> using namespace std; void serch(int n,int now) { if(n==1)cout<<now<<endl; else if(n%2==0)serch(n/2,now+1); else serch(n*3+1,now+1); } int main() { int n; while(cin>>n,n)serch(n,0); }
0
#include <bits/stdc++.h> using namespace std; int main() { int w, h, k; cin >> w >> h >> k; int count = 0; while (k) { count += 2 * (w + (h - 2)); w -= 4; h -= 4; k--; } cout << count; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n, l; cin >> n >> l; long long a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); double r, d; r = max((double)a[0], (double)(l - a[n - 1])); for (int i = 1; i < n; ++i) { d = (a...
2
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
2