solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int n, mx = 0, s = 0; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; mx = max(mx, a); s += a; } cout << 2 * mx - s + 1 << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 23; char s[N]; int f[1 << M], T, t[M], a[M][M]; int vis[M]; signed main() { int n, k, all = 0; scanf("%d%d%d", &n, &k, &T); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[i] -= 'A', all |= (1 << s[i]); for (int i = 0; i < k; i++) scan...
3
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << (N - K) + 1 << endl; }
0
#include <bits/stdc++.h> using namespace std; long long int n, m, k, l, r, county1, ans, county2, pos, index1, index2; int a[200005], b[400005]; int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); r = 0; county2 = 0; county1 = 0; pos = -1; index1 = 0; if (n == 1) ...
4
#include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; template<typ...
0
#include <bits/stdc++.h> using namespace std; long long h[100005], a[100005], home[100005], away[100005], tmp; int main() { long long n, i; map<long long, long long> mp; while (cin >> n) { mp.clear(); for (i = 0; i < n; i++) { cin >> h[i] >> a[i]; home[i] = (n * (n - 1)) / n; away[i] = 0...
2
#include <iostream> #include <string> #include <list> #include <algorithm> #include <iterator> using namespace std; void show(int x); int main() { list<int> L; int q; cin >> q; // L.push_front(9); list<int>:: iterator it = L.begin(); while (q--) { int cmd; cin >> cmd; if (cmd == 0) { int x; cin >...
0
#include <bits/stdc++.h> using namespace std; int n; string strs[202]; bool pref[102]; bool sref[102]; int sla, slb; string fullstr; bool check() { memset(pref, 0, sizeof(pref)); memset(sref, 0, sizeof(sref)); for (int i = 0; i < 2 * n - 2; i++) { string& custr = strs[i]; size_t slen = custr.length(); ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000500, MOD = 1e9 + 7; int n; int Res[MAXN][2]; int Ans[MAXN]; int main() { for (int i = (1); i < (int)(MAXN); i++) { Res[i][0] = (Res[i - 1][1] + Res[i - 1][0] + 1) % MOD; Res[i][1] = Res[i - 1][0]; } while (scanf("%d", &n) >= 1) { print...
1
#include <bits/stdc++.h> using namespace std; long long int power(int k) { long long int ans = 1; for (int i = 0; i < k; i++) ans *= 10; return ans; } int main() { ios::sync_with_stdio(0); long long int l, r; cin >> l >> r; long long int t1 = 0, t2 = 0, k1 = 0, k2 = 0, n = l, m = r; vector<long long int...
1
#include <bits/stdc++.h> using namespace std; #define el '\n' typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; const int N = 1e5; const ll MOD = 1e9 + 7; void solve() { string s; cin >> s; cout << s.size() << el; } int main() { ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(n...
1
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; #define MAX_V 110000 #define MAX_LOG_V 20 vector<in...
0
#include <bits/stdc++.h> using namespace std; int tc; long long n; long long get_first(long long x) { long long rl = 1; long long rr = x - 1; long long mult = 1; vector<long long> li; while (rl <= rr) { long long mid = (rl + rr) / 2; mult *= -1; li.push_back(mult * mid); rl = mid + 1; } lo...
1
#include <bits/stdc++.h> using namespace std; struct Node { int cnt, sz, total; }; Node tree[200010 * 4]; void init(const vector<int> &src, int v, int l, int r) { if (r - l == 1) { tree[v] = {0, src[r] - src[l], 0}; return; } int mid = (r + l) >> 1; init(src, v * 2 + 1, l, mid); init(src, v * 2 + 2,...
4
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { int n,a,b; cin>>n>>a>>b; bool f=false; ll temp=1; while(temp<=n) { if((n-temp)%b==0) { f=true; }...
2
#include <bits/stdc++.h> using namespace std; int main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); }; set<char> st; string s; int k; cin >> s; cin >> k; int p = s.size(); if (k > p) { cout << "impossible" << endl; return 0; } for (int i = 0; i < s.size(); i++) { st.i...
1
#include <bits/stdc++.h> using namespace std; int n, m, d, ans; pair<int, int> best1[100003]; pair<int, int> best2[100003]; bool evil[100003]; vector<int> adj[100003]; pair<int, int> dfs1(int node, int dad) { best1[node] = best2[node] = pair<int, int>(-1, -1); if (evil[node]) best1[node] = pair<int, int>(0, node); ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, q, h, s, n, k, j; vector<long long> tab; cin >> q; for (int i = 0; i < q; i++) { cin >> n >> k; s = 0; tab.clear(); tab.resize(n); for (int j = 0; j < n; j++) { cin >> tab[j]; s += tab[j] % 2; } ...
2
#include <bits/stdc++.h> using namespace std; int func(int x) { if (x < 10) return max(x, 1); return max(x % 10 * func(x / 10), 9 * func(x / 10 - 1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; cout << func(n) << endl; }
2
#include <bits/stdc++.h> #pragma optimize("Ofast") using namespace std; using ll = long long; const int N = 1e5 + 5; int main() { ios_base::sync_with_stdio(0); int n, m, k; cin >> n >> k >> m; map<string, ll> mp; string s; for (int i = 0; i < n; ++i) { cin >> s; mp[s] = i; } ll a[n]; for (int ...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e2 + 5; int N; vector <int> E[MAXN]; int dist[MAXN]; int mx[MAXN]; void add(int a, int b) { E[a].push_back(b); E[b].push_back(a); } void remove(int a, int b) { vector <int> nxt; for (auto it : E[a]) if (it != b) nxt.push...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; int n, i, j, k; vector<pair<int, int>> a(4); for (i = 0; i < 4; i++) { cin >> s; s = s.substr(2); a[i] = {s.length(), i}; } sort(a.begin(), a.end()); vector<int> ans; if (a[0].fi...
1
#include<iostream> #include<algorithm> using namespace std; int main(){ int n; cin >> n; int a[n]; for(int i = 0; i < n; i++) cin >> a[i]; int q; cin >> q; while(q-- > 0){ int k; cin >> k; cout << (a[lower_bound(a, a+n, k)-a] == k) << endl; } return 0; }...
0
#include<bits/stdc++.h> using namespace std; const int maxn=200010; int n,a[maxn],b[maxn]; vector<int> ans; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=n;i>=1;i--) { int yi=0; for(int j=2*i;j<=n;j+=i) yi^=b[j]; yi^=a[i]; if(yi==1) { b[i]=1; ans.push_back(i); } } cout<<an...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, i, flag = 0; cin >> n >> a >> b; if (a * b >= 6 * n) { cout << a * b << '\n' << a << " " << b << endl; return 0; } if (a > b) { swap(a, b); flag = 1; } for (i = 6 * n;; i++) { long long div1, div2; div1 =...
2
#include <bits/stdc++.h> using namespace std; int n, k, b[1000010]; int main() { scanf("%d%d", &n, &k); int i; if (k * 3 > n || k == 1) puts("-1"); else { for (i = 1; i <= (int)(k); ++i) b[i] = b[i + 2 * k] = i, b[i + k] = i - 1; b[k + 1] = k; for (i = 3 * k + 1; i <= n; ++i) b[i] = 1; for (...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 3010; int n, m, p[MAX]; bool odw[MAX]; void wczytaj_dane() { cin >> n; for (int i = 0; i < (n); i++) { cin >> p[i]; p[i]--; } cin >> m; } int zlicz_cykle() { fill(odw, odw + n, false); int licz = 0; for (int i = 0; i < (n); i++) if ...
4
#include <iostream> #include <string> using namespace std; int main(){ int N, i, diff = 0; cin >> N; string A, B, C; cin >> A >> B >> C; for (i=0; i<N; i++){ if (B[i] != A[i]) diff++; if (C[i] != A[i] && C[i] != B[i]) diff++; } cout << diff << '\n'; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'x' && s[i + 1] == 'x' && s[i + 2] == 'x') { cnt++; } } cout << cnt; return 0; }
2
#include <bits/stdc++.h> using pii = std::pair<long long, long long>; using namespace std; long long n, m, a[1005][1005], dp[1005][1005][4] = {0}; class BWorkingOut { public: void solve(std::istream& in, std::ostream& out) { in >> n >> m; for (long long i = (0); i < (n); i++) for (long long j = (0); j ...
2
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; const double PI = acos((double)-1); int ts, ts2, ts3, ts4; int n, m, K; int makepair[15][15], f[1024][1024], ans; long long gcd(long long x, long long y) { long long t; for (; y != 0;) { t = x % y; x = y; y = t; } return x; } dou...
5
#include<bits/stdc++.h> using namespace std; int a,b; int main() { cin>>a>>b; if(a%3==0||b%3==0||(a+b)%3==0) cout<<"Possible\n"; else cout<<"Impossible\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; map<pair<long long, int>, pair<long long, int> > MP; long long n; pair<long long, int> solve(long long n, int mx) { if (n == 0) { return make_pair(0, 0); } if (n < 10) { if (mx > n) return make_pair(1, n - mx); else return make_pair(1, 0); } ...
3
#include <bits/stdc++.h> using namespace std; struct __s { __s() { srand(time(NULL)); if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); int n...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <typename T> struct modular { constexpr modular() : val(0) {} constexpr modular(const modular<T>& _m) : val(_m.val) {} template <typename U> constexpr modular(const U& _r = U()) { val = -MOD <= _r && _r < MOD ? _r : _r % MOD;...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, h[maxn], ecnt, deg[maxn]; struct enode { int v, n; enode() {} enode(int _v, int _n) : v(_v), n(_n) {} } e[maxn << 1]; inline void addedge(int u, int v) { ecnt++; e[ecnt] = enode(v, h[u]); h[u] = ecnt; } int sz[maxn]; void dfs...
4
#include <bits/stdc++.h> using namespace std; const int MM = 120000; long long int m, n, k, p1, p2, p3, p, f; struct guy { long long int s, a, b, diff; }; guy guys[MM]; long long int ceel(long long int num, long long int den) { assert(den > 0); if (num % den) return (num / den) + 1; return (num / den); } int ma...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a; vector<pair<int, int> > vec; cin >> n; for (int i = 0; i < n; i++) { cin >> a; vec.push_back(make_pair(a, i + 1)); } sort(vec.begin(), vec.end()); cout << (n + 1) / 2 << "\n"; for (int i = 0; i < n; i += 2) cout << vec[i].secon...
3
#include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> using namespace std; #define FOR(i,k,n) for(int i=(k); i<(int)(n);...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, s1; s = "<3"; while (n > 0) { cin >> s1; s += s1; s += "<3"; n--; } string ss; cin >> ss; bool flag = true; if (ss.length() < s.length()) flag = false; int j = 0, co = 0; for (int i = 0; i < s.l...
2
#include <iostream> #include <complex> #include <sstream> #include <string> #include <algorithm> #include <deque> #include <list> #include <map> #include <numeric> #include <queue> #include <vector> #include <set> #include <limits> #include <cstdio> #include <cctype> #include <cmath> #include <cstring> #include <cstdli...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k, m, z; cin >> n >> k; m = n / 2; if (n == 1 && k == 0) { cout << 1; return 0; } if (m > k || n == 1) { cout << -1; return 0; } z = k - m + 1; cout << z << " "; for (int i = 1; i < ...
1
#include <bits/stdc++.h> using namespace std; long long a, b; int main() { long long ans = 0; cin >> a >> b; while (a != 1 && b != 1) { if (a > b) { ans += a / b; a = a % b; } else swap(b, a); } cout << ans + b + a - 1 << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; using xy_t = double; constexpr xy_t eps = 1e-6; constexpr double pi = 3.14159265358979323846; struct Point { xy_t x, y; Point() {} Point(xy_t x_, xy_t y_) : x{x_}, y{y_} {} Point operator+(const Point p) const { return {this->x + p.x, this->y + p.y}; } Point...
3
#include <stdio.h> #define MAX 100000 int A[MAX],n; int Partition(int p,int r){ int x=A[r],i=p-1,j,t; for(j=p;j<r;j++){ if(A[j]<=x){ t=A[++i]; A[i]=A[j]; A[j]=t; } } t=A[++i]; A[i]=A[r]; A[r]=t; return i; } int main(){ scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&A[i]); int q=Partition(0,...
0
#include<bits/stdc++.h> clock_t t=clock(); namespace my_std{ using namespace std; #define pii pair<int,int> #define fir first #define sec second #define MP make_pair #define rep(i,x,y) for (int i=(x);i<=(y);i++) #define drep(i,x,y) for (int i=(x);i>=(y);i--) #define go(x) for (int i=head[x];i;i=edge[i].nxt) #d...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, a; cin >> n; a = 1; for (int i = 1; i < n; i++) { a *= i; } cout << a * 2 / n; return 0; }
5
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; string S; cin>>S; int a=0; for(int i=1;i<N;i++){ if(S[i-1]!=S[i]){ a++; } } a+=1; cout<<a<<endl; }
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const long long mod = 1e9 + 7; const long long N = 1e6 + 5, K = 105; const int si = (1 << 20); const long long M = 50 + 5; const double INFdb = 1e10; int n, m; vector<int> matrix[N]; vector<int> S[N]; vector<int> mask[N], tmp[N]; vector<bool> ans...
3
#include <bits/stdc++.h> using namespace std; int degree[70000]; int sum[70000]; int main() { ios_base::sync_with_stdio(false); queue<int> q; while (!q.empty()) q.pop(); int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { cin >> degree[i] >> sum[i]; if (degree[i] == 1) q.push(i); ans +...
1
#include <bits/stdc++.h> #define show(x) cerr << #x << " = " << x << endl using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typ...
0
#include <bits/stdc++.h> using namespace std; struct node { double x, y; bool operator<(const node &t) const { return x > t.x; } } p[100005], a[100005], b[100005]; int main() { double ax, ay, bx, by, tx, ty; cin >> ax >> ay >> bx >> by >> tx >> ty; int n; cin >> n; double ans = 0; for (int i = 0; i < n;...
1
#include <bits/stdc++.h> using namespace std; int main() { int h1, a1, c1, h2, a2; cin >> h1 >> a1 >> c1 >> h2 >> a2; int attacks = ceil(((double)h2) / a1); int reqHeal = (attacks - 1) * a2 + 1; reqHeal -= h1; reqHeal = max(0, reqHeal); int healChances = ceil(((double)reqHeal) / (c1 - a2)); printf("%d\n...
2
#include<cstdio> int main(){ int a,b; scanf("%d %d",&a,&b); printf("%d %d %.7f\n",a/b,a%b,(double)a/(double)b); }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int> > a(n + 1); for (int i = 1; i <= n; i++) { for (int j = 2; j * j <= i; j++) if (i % j == 0) { a[i].push_back(j); if (j != i / j) a[i].push_back(i / j); } a[i].push_back(i); ...
2
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long double PI = 2 * acos(0.0); const vector<long long int> dx = {1, -1, 0, 0}; const vector<long long int> dy = {0, 0, 1, -1}; vector<long long int> ga(long long int n, bool oneIndexed = false) { vector<long long int> a; if (...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); if (n % k == 0) { cout << n + k << endl; } else { int div = (n / k) + 1; div *= k; cout << div << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; long long a[1000000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t, n, i, j, c, k, m, x, y, f, ans; cin >> t; while (t--) { cin >> n; priority_queue<pair<long long, long long> > pq; for (i = 1; i <= n; i++) { cin >> a[i]; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n; pair<int, int> s[N]; int a[N], b[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &s[i].first); s[i].second = i; } sort(s, s + n); for (int i = 0; i < n / 3; i++) { a[s[i].second] = i; b[s[i]....
5
#include<bits/stdc++.h> #define LL long long int #define INF 734858 using namespace std; int main(void) { LL b,ka,t,w,ki,y,m,d,sum,cnt,mon,day,year; LL i,j,k; LL maya[5]={144000,7200,360,20,1}; LL month[2][12]={ {31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31} }; char s[1...
0
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; cout << n+n*(n%2) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MaxN = int(1e5); const int INF = int(1e9); const int MOD = int(1e9) + 7; long long n, k, d[2015][2015], res; vector<long long> v[2015]; long long calc(long long x, long long len) { long long sum = 0; for (int i = 0; i < v[x].size(); ++i) { sum += d[v[x][i]...
4
#include <bits/stdc++.h> using namespace std; int a[401], n, i, j, k, p, c, t, S = -1; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { for (j = i; j < n; j++) { p = a[i] - 1; c = 1; t = a[j]; for (k = 0; k <= j; k++) { c += p / a[k]; ...
5
#include<iostream> #include<stdio.h> #include<cmath> #include<cstdio> using namespace std; int main(){ double a,b,c,S,L,h; cin>>a>>b>>c; double l=2*acos(-1)*c/360; S=a*b*sin(l)/2; h=b*sin(l); L=a+b+sqrt(a*a+b*b-2*a*b*cos(l)); printf("%.8f\n%.8f\n%.8f",S,L,h); return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[200000 + 10]; int val[200000 + 10]; int max_gcd(int a, int b) { if (b == 0) return a; return max_gcd(b, a % b); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int max = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[...
4
#include <bits/stdc++.h> using namespace std; long n, bst; string w[2000]; long tests, k, cc, gt, bp; string z[2000]; void generate(vector<long> v) { if (v.size() < n) { for (int j = 1; j <= k; j++) { v.push_back(j); generate(v); v.pop_back(); } return; } for (int i = 0; i < v.size()...
4
#include <string> #include <iostream> #include <algorithm> using namespace std; int d; string s; int p[11] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }; int main() { while (cin >> d >> s, d) { long long v = 0; for (int i = 0; i < s.size(); i++) v = v * d + (s[i] <= '9' ? s[i] - 48 : s[i] - 55); long long ret = 9...
0
#include <bits/stdc++.h> using namespace std; int a[200]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int sum = 0; for (int i = 0; i < n; i++) sum += a[i]; int cnt = 0; for (int i = 0; i < n; i++) if (...
1
#include <bits/stdc++.h> using namespace std; void domod(int &a, long long b) { a = (a + b) % 1000000007; } void mulmod(int &a, long long b) { a = (a * b) % 1000000007; } int getint() { int a; scanf("%d", &a); return a; } int power(int a, int b) { int res = 1; while (b > 0) { if (b & 1) { mulmod(res...
2
#include <iostream> using namespace std; int main() { int N; cin >> N; int point[N][3]; for(int i=0; i<N; i++){ for(int j=0; j<3; j++){ cin >> point[i][j]; } if(point[i][0] > point[i][1]) swap(point[i][0], point[i][1]); if(point[i][1] > point[i][2]) swap(poin...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; int i, j, cont = 0; for (i = 0; i <= 30; i++) { for (j = 0; j <= 30; j++) { long long int ans; ans = pow(2, i) * pow(3, j); if (ans >= a && ans <= b) cont++; if (ans >= b) { break; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; string h; for (int i = 0; i < m - 1; i++) { h += 'L'; } for (int i = 0; i < n - 1; i++) { h += 'U'; } while (n) { for (int i = 0; i < m - 1; i++) { h += 'R'; } if (n - 1 > 0) { h +...
3
#include <iostream> using namespace std; #define ll long long #define MAXN 100100 int t; ll n, k; ll ans[MAXN]; void solve(int c, ll remk) { if (c > n) return; // cout << c << "-> " << remk << endl; int res = 0; ll undersofar = 0; for (int sz = 1; sz + c - 1 < n; sz++) { int rem = n - c + 1 - sz; if (r...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int a, b, c, d; int x, y, z; cin >> a >> b >> c >> d; cout << b << ' ' << c << ' ' << c << '\n'; } return 0; }
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } long double pointdist(long double x, long double y, long double point) { return ((x - point) * (y - point)) / abs(x - y); } lo...
3
#include <bits/stdc++.h> using namespace std; long long dp_max(vector<long long> f, map<vector<long long>, long long>& memo) { sort(f.begin(), f.end()); if (memo.find(f) == memo.end()) { long long result = 0; if (f[0] >= 1) { vector<long long> f_new(f); f_new[0]--; f_new[1]--; f_new[...
2
#include <iostream> #include <algorithm> #include <vector> using namespace std; const int INF = 1<<28; struct E { int to, cost, cap, rev; E(int to, int cost, int cap, int rev) : to(to), cost(cost), cap(cap), rev(rev) {} E() {} }; typedef vector<vector<E> > G; void addEdgeF(int from, int to, int cost, int ...
0
#include<bits/stdc++.h> using namespace std; const int MAXN = 10000; int n,m,src; struct ed{ int u,v,cost; }; vector<ed> e; long long dis[MAXN]; void ballmanf(){ memset(dis,63,sizeof dis); long long inf = dis[0]; dis[src] = 0; bool nc = false; for(int i=0; i<n; i++){ nc=false; ...
0
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int k; cin>>k; int len = s.size(); vector<string> v; for(int i=0;i<len;i++) { for(int j=i;j<len && (j-i+1)<=k;j++) { string a = s.substr(i,j-i+1); v.push_back(a); } } sort(v.begin(),v.end()); unique(v.begin(),v...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using li = __int128; using uli = unsigned __int128; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; void doReplace() {} template <typename T, typename U, typename... Vs> void doReplace(T& t, c...
1
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする #include <math.h> //数学関数と数学定数を利用する #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; template<class T> void chmax(T &a,T b) { if (a<b) a=b;} template<class T> void chmin(T &a,T b) { if (a>b) a=b;} const int MAX = 100005; cons...
0
#include<iostream> #include<algorithm> #include<functional> using namespace std; int main() { while (true){ char num[4]; int ans; for (int i = 0; i < 4; i++){ cin >> num[i]; } if (num[0] == num[1] && num[1] == num[2] && num[2] == num[3]){ if (num[0] == '0') break; cout << "NA" << endl; continue;...
0
#include <bits/stdc++.h> using namespace std; string a, b; int main() { cin >> a >> b; for (int i = 0; i < a.size(); i++) if (a[i] != b[i]) cout << 1; else cout << 0; cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a > b) { cout << b << " "; } else { cout << a << " "; } if (a > b) { cout << (a - b) / 2; } else { cout << (b - a) / 2; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int ara[102][4], temp[4], mem[102][1 << (4)], n, m; void sft(int c, int kth) { int cnt = 0; for (int i = kth; i < n; i++) temp[cnt++] = ara[c][i]; for (int i = 0; i < kth; i++) temp[cnt++] = ara[c][i]; return; } int dp(int pos, int msk) { if (pos == m) return 0; ...
5
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll N=2e5+5; int main(){ ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,x;cin>>n>>x; if(x==1 || x==2*n-1)return cout<<"No" , 0; cout<<"Yes\n"; vector< ll > ans(2*n-1); for(ll i=0;i<2*n-1;i++)ans[...
0
#include <bits/stdc++.h> using namespace std; void solutionB(); int main() { ios_base::sync_with_stdio(false); solutionB(); return EXIT_SUCCESS; } int n, a[128][5], c[5], cost[5]; int ans; int base[6] = {500, 1000, 1500, 2000, 2500, 3000}; int get_score(int index) { int r = 0; for (int i = 0; i < 5; ++i) { ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); int n; cin >> n; priority_queue<int, vector<int>, greater<int>> que; ll sum = 0; for (int i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; vector<int> Bad[100005]; int from[100005], to[100005]; int badEdge[100005]; int deg[100005]; int sz[100005]; int childEdge[100005]; int childN[100005]; int parentEdge[100005]; vector<int> adj[100005]; vector<int> adjEdge[100005]; struct UF { int a[100005]; int find(int ...
3
#include <bits/stdc++.h> using namespace std; bool compareInterval(pair<long long int, long long int> a, pair<long long int, long long int> b) { if (a.first == b.first) { return a.second > b.second; } return (a.first > b.first); } bool compareInterval1(pair<long long int, long long int> a...
2
#include<bits/stdc++.h> using namespace std; #define chmax(a,b) if(a<b)a=b #define pb push_back const int N=1e5+5; int n,m; int dp[N]; vector<int> e[N]; int dfs(int x) { int ans=0; if(dp[x]) return dp[x]; for(int i=0;i<e[x].size();i++) chmax(ans,dfs(e[x][i])+1); return dp[x]=ans; } int main() { cin>>n>>m; ...
0
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int n, elm, m; cin >> n; int prefixsum = 0; for (int i = 0; i < n; ++i) { cin >> elm; prefixsum += elm; v.push_back(prefixsum); } cin >> m; for (int i = 0; i < m; ++i) { cin >> elm; int ans = lower_bound(v.begin(...
2
#include <bits/stdc++.h> using namespace std; const int NMAX = 2000005; set<int> st; set<int>::iterator it; char ans[NMAX + 5], t[NMAX + 5]; int main() { int n, i, j, k, x, z, len, sz; for (i = 1; i <= NMAX; i++) { st.insert(i); ans[i] = '0'; } scanf("%d", &n); sz = 0; for (i = 1; i <= n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000000000ll; vector<pair<int, int> > v[110]; struct spaceship { int x, a, f; long long p; } s[100010]; int n, m, p[110], f[110][110], x, y, id[100010], d, g, S, B, K, D[100010], e[100010][2]; bool cmp(const int &a, const int &b) { ret...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; stack<int> st; int a[MAXN], b[MAXN]; int ans[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int x; cin >> x; a[x]++; } for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e9 + 7, OO = 0x3f3f3f3f; int n, m; int mem[20][1 << 20]; int a[20], b[20]; string as[20], bs[20]; vector<int> adj[11000]; int solve(int i, int msk) { if (i == m) return 1; int &ret = mem[i][msk]; if (~ret) return ret; ret = 0; int cur =...
5
#include <bits/stdc++.h> using namespace std; void init() { freopen("CF_18.inp", "r", stdin); freopen("CF_18.out", "w", stdout); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; int q; cin >> n >> q; long long mid = (n * n) / 2; if (n % 2 == 1) mid++; long lon...
2
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; long long int a = 1; for (long long int i = 1; i <= n - 1; i++) { a *= i; } a = a / (n / 2); cout << a << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; long long read() { long long w = 0, h = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') h = -h; ch = getchar(); } while (ch >= '0' && ch <= '9') { w = w * 10 + ch - '0'; ch = getchar(); } return w * h; } long long n, y, m;...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 5 * (int)1e4 + 10; int n, m; vector<pair<int, pair<int, int> > > vert, hor; const int maxK = 4 * maxN; int fenw[maxK + 10]; const int ASK = 0; const int ADD = 1; const int DEL = 2; void upd(int v, int d) { while (v <= maxK) { fenw[v] += d; v = (v ...
4