solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int convertToint(string str) { stringstream ss; ss << str; int num; ss >> num; return num; } string convertTostr(int x) { stringstream ss; ss << x; string st; st = ss.str(); return st; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false);...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n,m,i; cin>>n>>m; int u[n],a[m]; memset(u,0,sizeof(u)); for(i=0;i<m;i++) scanf("%d",a+i); for(i=m-1;i>=0;i--) if(!u[a[i]-1]) printf("%d\n",a[i]),u[a[i]-1]=1; for(i=0;i<n;i++) if(!u[i]) printf("%d\n",i+1); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 2050; const int MOD = 1e9 + 7; int n, k, s[N]; int dp[N][N][2]; int solve() { for (int i = 1; i <= n; i++) { if (s[i] == 2 || s[i] == 0) { for (int j = 0; j < N; j++) { int p = min(j + 2, 2049); dp[i][p][1] = (dp[i][p][1] + dp[i - 1...
4
#include <bits/stdc++.h> using namespace std; int d[10001]; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); d[a]++; d[b]++; } long long ans = 0; for (int i = 1; i <= n; i++) { ans += d[i] * (d[i] - 1) / 2; } printf("%I64d\n", ans); ...
6
#include <bits/stdc++.h> using namespace std; int main() { int64_t h,w; cin >> h >> w; if(h==1 || w==1){ cout << 1 << endl; } else{ cout << ((h*w)+1)/2 << endl; } }
0
#include<bits/stdc++.h> using namespace std; int a,b,c; int main() { cin>>a>>b>>c; if(a==b&&b==c)cout<<1<<endl; else if(a==b||b==c||a==c)cout<<2<<endl; else cout<<3<<endl; }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int64_t lol; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int64...
2
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; const int MM = 2e3 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; ; const double eps = 1e-8; const double pi = acos(-1.0); int i, j, k, n, m, sum; int x; bool check(int mid1, int n, int b) { int m = (n - mid1) / b; if ((int)(n / m) >=...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 + 10; int n, k; int vec[MAXN], sec[MAXN], gec[MAXN], t[MAXN]; bool same() { for (int i = 0; i < n; i++) if (vec[i] != sec[i]) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 320; int dir[8][2] = {{-1, 0}, {-1, +1}, {0, +1}, {+1, +1}, {+1, 0}, {+1, -1}, {0, -1}, {-1, -1}}; bool dp[MAXN][MAXN][8][32]; int n, t[32]; bool spot[MAXN][MAXN]; void Rec(int l, int x, int y, int d) { if (l > n) return; if (dp[x][y][d...
4
#include <bits/stdc++.h> using namespace std; long long gcd(long long X, long long Y) { long long x = max(X, Y); long long y = min(X, Y); x = x % y; if (x == 0) { return y; } else return gcd(x, y); } long long fun(long long x, long long n, long long m) { long long c = x * (m - n) + 2 * n - m; retu...
3
#include <bits/stdc++.h> using namespace std; int n, i, a[22], j, x[22][2], k = 0, s[11], b[5][5], s0 = 0; int rec(int x0, int y0) { if (!((x0 == n - 1) && (y0 == n))) { if (y0 == n) { y0 = x0; x0++; } if (x0 == n) { y0++; x0 = y0; } for (int i = 0; i < k; i++) { if (...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int n; cin >> n; string s; cin >> s; set<char> st; for (auto i : s) st.insert(i); map<char, long long int> have; long long int ans = 1e18; long long int l = 0, r =...
3
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); int x, y; std::cin >> x >> y; if (x > 0 && y > 0) { int x1 = 0, y1, x2, y2 = 0; y1 = x + y; x2 = x + y; cout << x1 << " " << y1 << " " << x2 << " " << y2 << "\n"; } else if (x < 0 && y > 0) { ...
1
#include <bits/stdc++.h> template <typename A, typename B> inline bool smax(A &a, const B &b) { return a < b ? a = b, 1 : 0; } template <typename A, typename B> inline bool smin(A &a, const B &b) { return b < a ? a = b, 1 : 0; } template <typename I> inline void read(I &x) { int f = 0, c; while (!isdigit(c = ge...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; ...
2
#include <bits/stdc++.h> template <class T> inline T sqr(T x) { return x * x; } #pragma comment(linker, "/STACK:64000000") using namespace std; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int n, m; string s[50]; int BP, DP = 0, CP = 3; struct point { int x, y; point(int X, int Y) { x = X; y = Y;...
4
#include <bits/stdc++.h> using namespace std; using namespace std; struct Info { int l, r, x; }; int res[333333]; struct Node { int l, r; int flag; } node[333333 * 6]; struct Seg { void pushdown(int x) { if (node[x].flag != -1) { node[(x) << 1].flag = node[(x) << 1 | 1].flag = node[x].flag; node...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000007; vector<int> rec[100008]; int dp[2][100008], a[100008]; int fun(int minn, int val) { int ll = 0, rr, ss = rec[val].size(); if (ss == 0) return maxn; else if (rec[val][0] >= minn) return rec[val][0] + 1; rr = ss; while (ll + 1 !=...
3
#include <bits/stdc++.h> int a[3], i; char s[101010]; int main() { scanf("%s", s); for (i = 0; s[i]; i++) a[(s[i] != '0') + (s[i] == '?')]++; if (a[0] + a[2] > a[1]) puts("00"); int half = i / 2, need0 = half, need1 = half + (i & 1), left = a[2]; bool ok = 1; left -= (need0 - a[0] > 0 ? need0 - a[0] : 0); ...
5
#include <bits/stdc++.h> using namespace std; const int INF = ~0U >> 2; const int MOD = 1000000009; int ok[110], ch[110][4], dep[110], p[110], lnk[110], whi[110], f[1010][110][10]; char s[20]; queue<int> Q; void update(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int fx(char c) { if (c == 'A') return 0;...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m; vector<pair<int, int> > v; bool passed = true; while (m--) { cin >> x >> y; v.push_back(make_pair(x, y)); } sort(v.begin(), v.end()); for (int i = 0; i < v.size() && passed; i++) { if (v[i].first < n) {...
1
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n, a[100005] = {0}; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int ans = min(n - 2, a[n - 2] - 1); cout << ans << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int64_t a, v, b, w, t; cin >> a >> v >> b >> w >> t; if (abs(a - b) <= t*(v - w)) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long long lli; const int mod=1e9+7; void solve() { int n,k; cin>>n>>k; k--; if(n%2==0) { cout<<k%n+1<<endl; } else { cout<<(k+k/(n/2))%n+1<<endl; } } int main() { int t=1; cin>>t; while(t--) { solve(); } }
2
#include<iostream> #define ULL unsigned long long using namespace std; ULL transfer(ULL n,ULL m,ULL tar) { ULL y = (tar - 1) / n + 1; ULL x = tar - n * (y - 1); ULL x0 = 1 + m * (x - 1); ULL ans = (y - 1) + x0; return ans; } int main() { ULL t = 0; ULL n = 0, m = 0, tar = 0; cin >> t; for (ULL i = 1; i <= t; i++) { cin...
1
#include <bits/stdc++.h> using namespace std; using lint = long long int; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); } template<class T, class... Args> void assign(V<T>& v, int n, const Args...
0
#include <bits/stdc++.h> using namespace std; struct node { int L, R, v; int Lf[12], Rf[12]; } Tr[100005 * 4]; int fa[12 * 100005], n, m, h, A[12][100005]; bool bao[12]; int find(int v) { if (fa[v] == v) return v; return fa[v] = find(fa[v]); } void build(int p, int l, int r) { Tr[p].L = l; Tr[p].R = r; if...
5
#include <bits/stdc++.h> using namespace std; inline int rdi() { int d; scanf("%d", &d); return d; } inline char rdc() { scanf(" "); return getchar(); } inline string rds() { string s; cin >> s; return s; } inline double rddb() { double d; scanf("%lf", &d); return d; } template <class T> inline bo...
6
#include <bits/stdc++.h> using namespace std; int main() { const double pi = 3.14159265358979323846; double r, h, v, e; cin >> r >> h >> v >> e; double x = pi; x = pi * r * r * h / 4; double t = x / (v - pi * r * r * e / 4); if (t < 0 || t > 10000) cout << "NO"; else { cout << "YES" << endl; ...
1
#include <bits/stdc++.h> using namespace std; long double EPS = (long double)1e-11L; const double PI = 3.141592653589793238462; const int INF = 1e9 + 7; const long long LINF = 1e18 + 7; const int MOD = 1e9 + 7; const int S = 21; int n, m, s; vector<long long> bad, ans; vector<vector<long long> > T; vector<vector<long l...
5
#include <bits/stdc++.h> using namespace std; long long num[15] = {9, 18, 27, 36, 45, 54, 63, 72, 81, 90}; char N[15]; long long n, cnt; long long output[10005]; long long cal(long long n) { long long sum = 0; while (n) { sum += n % 10; n /= 10; } return sum; } int main() { while (cin >> n) { spri...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define rep(i,m,n) for(int i=m;i<n;i++) ll mod=1e9+7; int main(){ int n,m; cin>>n>>m; ll a[n]; rep(i,0,n){ cin>>a[i]; } ll b[m]; rep(i,0,m){ cin>>b[i]; } ll x[n-1]; rep(i,0,n-1){ x[i]=a[i+1]-a[i...
0
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; long long ans[3000003]; long long cnt, n; inline void read(long long &x) { x = 0; bool flag = false; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') flag = true; c = getchar(); } while (c >= '0' && c <= '9') { x...
3
#include <bits/stdc++.h> using namespace std; const int M = 1000 + 5; struct NODE { int pow; int dam; bool used; int index; } node[M]; int main() { int N, maxh, reg; cin >> N >> maxh >> reg; for (int i = 0; i < N; i++) { cin >> node[i].pow >> node[i].dam; node[i].used = false; node[i].index = ...
2
#include<bits/stdc++.h> using namespace std; int main() { int q,t,f; char c; string s1,s2; cin>>s1>>q; while(q--) { cin>>t; if(t==1) swap(s1,s2); else { cin>>f>>c; if(f==1) s2.push_back(c); else s1.push_back(c); } } reverse(s2.begin(),s2.end()); cout<<s2...
0
#include<bits/stdc++.h> using namespace std; #define REP(i,s,n) for(int i=s;i<n;++i) #define rep(i,n) REP(i,0,n) #define SORT(c) sort((c).begin(),(c).end()) #define IINF INT_MAX #define LLINF LLONG_MAX #define DEBUG false typedef long long ll; typedef pair<int, int> ii; int main() { int n, m; whil...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; int n; char s[maxn], t[maxn], ans[maxn]; int main() { scanf("%s %s", s + 1, t + 1), n = strlen(s + 1); sort(s + 1, s + n + 1); sort(t + 1, t + n + 1); int l1 = 1, r1 = n; int l2 = 1, r2 = n; for (int i = 1, cur = 0; i <= n; i++, cur ^= 1...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; scanf("%d", &n); scanf("%d", &q); int b1 = 1, b2 = 2; while (q--) { int t; scanf("%d", &t); if (t == 1) { int move; scanf("%d", &move); if (move < 0) ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 100007; struct eT { void setd(int _u, int _v, int _w, int _l) { u = _u, v = _v, w = _w, last = _l; } in...
5
#include <bits/stdc++.h> using namespace std; int fx[] = {1, -1, 0, 0}; int fy[] = {0, 0, 1, -1}; int main() { int n, m, i, x, cnt, j; cin >> n >> m; char a[n + 1][m + 1]; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> a[i][j]; } } for (i = 1, cnt = 0; i <= n; i++) { for (j =...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MAXN = 1e5 + 5; const long long LINF = 1e18; const double pi = 3.1415926535; const double EPS = 1e-9; template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>; template <class T> using MaxPQ = priority_queue<T>; int n; vector<...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; int k; bool d[10]; string tmp; int cnt = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> tmp; fill(d, d + 10, 0); bool flag = true; int len = tmp.length(); for (int j = 0; j < len; j++) { d[tmp[j] - '0'] = t...
1
/*jai_ganeshdeva*/ #include<bits/stdc++.h> using namespace std; #define pb push_back #define pu push // adds the value to the last of the queue #define lld long long int #define ldo long double #define ins insert /// used in set to insert the values #define adv advance /// used to increment the iterator #define m...
2
#include <bits/stdc++.h> using namespace std; int main() { int iIn1, iIn2, iIn3, iIn4; cin >> iIn1 >> iIn2 >> iIn3 >> iIn4; int x = ((iIn1 ^ iIn2) & (iIn3 | iIn4)) ^ ((iIn2 & iIn3) | (iIn1 ^ iIn4)); cout << x; return 0; }
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int inf = 0x3f3f3f3f; int t, n; int main() { int n; scanf("%d", &n); getchar(); char str[100005]; scanf("%s", str); int sl = strlen(str); int r = 0; int b = 0; int cr = 0, cb = 0; for (int i = 0; i < sl; i++) { if (i %...
2
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c=0,d,e; cin>>a>>b; for(int i=0;i<a;i++) c+=b+i; if(b<0 && b+a-1<0) cout<<c-(b+a-1); else if(b>0) cout<<c-b; else cout<<c; }
0
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, x[100][100]; int main() { cin >> a; for (b = 1; b <= a + 1; b++) for (c = 1; c <= a * 2 + 1; c++) if (c <= a + 1) x[b][c] = c - a - 2 + b; else x[b][c] = a * 2 + 1 - c - a - 2 + b + 1; for (b = a + 2; b <= a * 2 + 1; ...
2
#include <bits/stdc++.h> int ln[7]; char ll[7] = {"neit"}; int main() { char s[110]; scanf("%s", s); for (int j = 0; j < 4; j++) { for (int i = 0; s[i] != '\0'; i++) { if (ll[j] == s[i]) ln[j]++; } } if (ln[0] >= 3) { ln[0] -= 3; ln[0] /= 2; ln[0]++; } else ln[0] = 0; ln[1] /...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1500000; vector<int> prime; bool is_prime[MAX_N+1]; void siege(int n) { for (int i = 0; i <= n; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { prime.push_back...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; const int INF = 0x3f3f3f3f; int main() { int n, a[MAXN], d, ans = INF, a1; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); sort(a, a + n); for (int i = 0; i <= 20000; ++i) { int mi = INF, ma = -INF; for (int j = 0; j...
4
#include <bits/stdc++.h> using namespace std; int n; bool arr[100000], backup[100000]; vector<pair<int, int>> ans; void flip(int a, int b, vector<pair<int, int>> &ret = ans) { int c = b - a + b; arr[a] = !arr[a]; arr[b] = !arr[b]; arr[c] = !arr[c]; ret.push_back({a, b}); } bool solvesmall(int l, int r) { me...
5
#include <bits/stdc++.h> #define int long long #define N 1001 using namespace std; const int INF = 1LL<<55; const int mod = (1e9)+7; const double EPS = 1e-8; const double PI = 6.0 * asin(0.5); template<class T> T Max(T &a,T b){return a=max(a,b);} template<class T> T Min(T &a,T b){return a=min(a,b);} typedef pair<int,in...
0
#include <bits/stdc++.h> using namespace std; int main(){ long long H, W; cin >> H >> W; if(W == 1 || H == 1){ cout << 1 << endl; }else{ cout << (H * W + 1)/2 << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int MX = 100005; int n, p[MX], lvl[MX], sig[MX], ind; set<int> st[MX]; vector<int> res; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i < n; i++) { cin >> p[i]; lvl[i] = lvl[p[i]] + 1; st[p[i]].insert(i); if (...
6
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } struct UF { int n; vector<int> par, sz, fst; void init(int _n) { n = _n; par = sz = fst = ve...
5
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") struct edge { int u, v; edge() {} edge(int u, int v) : u(u), v(v) {} } e[100100]; int color[100100] = {0}, fa[100100], first[100100], vv[200200], nxt[200200], tot = 0, cnt = 0; long long ans = 1; int f(int x)...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 10; long long dp[maxn][maxn][3]; int a[maxn]; long long pre[maxn], suf[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (a[i] == 1); for (int i = ...
1
#include<iostream> #include<vector> #include<queue> typedef std::pair<int, int> P; int main(){ int n, r, l; std::cin >> n >> r >> l; std::vector<int>point(n, 0); std::vector<int>time(n, 0); std::priority_queue<P>que; int betime = 0; for (int i = 0; i < r; i++){ int d, t, x; std::cin >> d >> t >> x; d...
0
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const long long inf = 1e17 + 7; long long n; vector<char> a, b; long long l, r; bool rev = false; void first(long long num) { vector<char> temp; for (long long i = a.size() - 1; i >= (long lon...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; vector<char> v; cin >> s; v.push_back(s[0]); if (s.size() > 1) { v.push_back(s[1]); } for (int i = 2, j = 2; i < s.size(); i++) { if (v[j - 2] == v[j - 1] && s[i] != v[j - 1]) { v.push_back(s[i]); j++; } else if (...
3
#include <bits/stdc++.h> int main() { int s, v1, v2, t1, t2, a, b; scanf("%d%d%d%d%d", &s, &v1, &v2, &t1, &t2); a = s * v1 + 2 * t1; b = s * v2 + 2 * t2; if (a > b) printf("Second\n"); else if (a < b) printf("First\n"); else printf("Friendship"); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(void) { int a[300000]; vector<int> b; int c; int p; int q; int r; int s; int n; int m; int x, y, z; int v; scanf("%d %d", &n, &m); x = -2; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] < 0) { c++; if (x !...
4
#include <stdio.h> int main(){ int i,n,pm,pj,pe; double avg,emav; char type; scanf("%d",&n); while(n!=0){ for(i=0;i<n;i++){ scanf("%d%d%d",&pm,&pe,&pj); avg = (pm+pe+pj) / 3.0; emav = (pm+pe) / 2.0; if(pm==100.0||pe==100.0||pj==100.0||emav>=90.0||avg>=80.0) type = 'A'; else if(avg>=70.0) type = 'B...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 8 * 100 + 10; int ans[MAXN]; int arr[MAXN][MAXN]; bool row[MAXN], clm[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < 2 * n; i++) for (int j = 0; j < i; j++) cin >> arr[i][j]; for (int k = 0; k < n; k++) { int mx = 0, x, y; for ...
2
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (...
4
#include <bits/stdc++.h> using std::cin; using std::cout; const int maxn = 1e5 + 5; int n; std::vector<int> num; void printTree() { int cur = 0; for (int x : num) { int tmp = cur; cur += x; if (!tmp) continue; for (int y = tmp + 1; y <= cur; y++) printf("%d %d\n", tmp, y); } } int main() { cin >...
3
#include <bits/stdc++.h> using namespace std; int main() { int t, x, y, k = 0, l = 0; cin >> t; while (t--) { cin >> x >> y; if ((x > 0 && y >= 0) || (x > 0 && y < 0)) { k++; } else if ((x < 0 && y >= 0) || (x < 0 && y < 0)) { l++; } } if (k > 1) { if (l == 1) { cout << "...
1
#include <bits/stdc++.h> using namespace std; long long hh(long long p, long long n) { if (p == 1) return 1; if (p % 2) return (p + 1) / 2; if (n % 2 == 0) { return hh(p / 2, n / 2) + n / 2; } else { return hh(p / 2 + 1, (n + 1) / 2) + n / 2; } } int main() { long long n, q; cin >> n >> q; while...
2
#include <vector> #include <iostream> #include <utility> #include <algorithm> #include <string> #include <deque> #include <tuple> #include <queue> #include <functional> #include <cmath> #include <iomanip> #include <map> #include <numeric> #include <unordered_map> #include <unordered_set> #include <complex> #include <it...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e6 + 7; const int INF = (int)2e9 + 7; int cnt[MAXN]; string s; vector<int> pos; vector<pair<int, int>> all; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '(') pos.push_back(i); else { if (pos.empty() |...
3
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } return sum; } int head[200010], nxt[400010], end[400010], value[400010], k, id[200010]; long long is[200010]; long...
6
#include<bits/stdc++.h> using namespace std; using i64 = int64_t; int garden[12][12]={0}; void init(){ for(int i=0;i<=10;++i){ for(int j=0;j<=10;++j) garden[i][j] = 0; } } int main(){ int d, w; while(cin >> d >> w, d != 0){ init(); for(int i=0;i<d;++i){ ...
0
#include <bits/stdc++.h> const int N = 5e4 + 5; const int M = 4e5 + 5; int line[N]; int hang[N]; char s[105], p[105], t[105]; int sum[30]; using namespace std; int n, m, i, j; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { memset(sum, 0, sizeof sum); scanf("%s", s); scanf("%s", t); scanf("...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int t; cin >> t; while (t--) { bool ans = true; int n; cin >> n; string s; cin >> s; int l = 0, r = s.size() - 1; while (l < r) { int valL = s[l] - 'a', valR = s[r] - 'a'; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n][m], b[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; i++) { for (int j = 0; j < m; j++) { cin >> b[i][j]; } } int flag =...
3
#include <bits/stdc++.h> using namespace std; int n, k; int a[100005]; set<long long> present; int ans; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); for (int i = n - 1; i >= 0; i--) { if (present.find((long long)a[i] * k) == present.end()) { ans++...
1
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } using namespace std; string b[12]; int st[(int)(1e5 + 25)]; void solve() { s...
3
#include <bits/stdc++.h> using namespace std; long long int mark[200000], ans[200000]; int main() { long long int n, i, p, val1, val2; cin >> n; for (i = 0; i < n; i++) { cin >> p; mark[p]++; } ans[1] = mark[1]; val1 = 0; val2 = 0; for (i = 1; i < 200000; i++) { ans[i] = max(ans[i - 1], ans[...
3
#include <bits/stdc++.h> int n, a, b; int solve(int countA, int countB) { if (countA == 0 && countB == 0) return 0; else { int answer = countA + countB; for (int cA = 0; cA <= countA; cA++) for (int cB = 0; cB <= countB; cB++) if (0 < cA + cB && cA * a + cB * b <= n) answer = std...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; string s; cin >> s; int ans = 0; int i = 0; while (i != n - 1) { int t = d; while (s[i + t] != '1') { t--; if (t == 0) { cout << -1; return 0; } } ans++; i += t; } ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1002; int n, p, k, a[MAXN], b[MAXN], ans; int n1, n2, f[2][MAXN][52][52]; inline void upd(int &x, int y) { if (y > x) x = y; } inline int getint() { int w = 0, q = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (...
5
#include <bits/stdc++.h> using namespace std; mt19937 mt_rand( chrono::high_resolution_clock::now().time_since_epoch().count()); const int INF = 2e9; const long long ML = 4e18; long long Pow(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = (res * x) % 998244353; x = x * x % 99...
6
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; char s[100001]; int main(){ ull i,j,h,w; cin>>h>>w; for(i=0;i<w+2;i++) cout<<"#"; cout<<endl; for(i=0;i<h;i++){ cin>>s; cout<<"#"<<s<<"#"<<endl; } for(i=0;i<w+2;i++) cout<<"#"; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int32_t MOD = 1000000007; struct WEdge { int32_t u, v; int w; bool operator<(const WEdge& other) { return w < other.w; } WEdge(int32_t u, int32_t v, int w) : u(u), v(v), w(w) {} WEdge() {} void in() { cin >> u >> v >> w; } void trace() { if (0) cout ...
6
#include <bits/stdc++.h> const int MAXN = 100005; char s[MAXN]; using namespace std; struct Node { int* value[4][11]; } tree[MAXN]; void build_tree(int n) { for (int x = 1; x <= n; x++) for (int i = 0; i < 4; i++) for (int j = 1; j <= 10; j++) { tree[x].value[i][j] = new int[j]; for (int k...
3
#include <bits/stdc++.h> using namespace std; double power(float x, int y) { float temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else { if (y > 0) return x * temp * temp; else return (temp * temp) / x; } } bool isPrime(int n) { if (n <= 1) ...
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int h,w,n; int x[100100],y[100100]; int wx[200100],wy[200100]; scanf("%d%d%d",&h,&w,&n); for(int i=0;i<n;i++){ scanf("%d%d",&x[i],&y[i]); wx[2*i] = wx[2*i+1] = x[i]; wy[2*i] = wy[2*i+1] = y[i]; } sort(wx,wx+2*n);...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, a[maxn], b[maxn], ans[maxn]; vector<int> g[maxn]; bool visited[maxn]; void dfs(int i, int status) { visited[i] = 1; ans[i] = status % 2 + 1; for (int x : g[i]) { if (!visited[x]) { dfs(x, status + 1); } } } int main() ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int ans = a + b + c; int A = a, B = b, C = c; for (int i = 1; i <= 10000; i++) { int tmp1 = abs(i - a); for (int j = i; j <= 15000; j += i) { int tmp2 ...
4
#include <bits/stdc++.h> using namespace std; int cmpfunc(const void *a, const void *b) { return (*(int *)a - *(int *)b); } long long int gcd(long long int m, long long int n) { if (n == 0) return m; return gcd(n, m % n); } long long int fastpow(long long int a, long long int b, long long int m) { long long int r...
1
#include <bits/stdc++.h> using namespace std; int main() { string num; cin >> num; int len = num.size(); for (int i = 0; i < len;) { if ((num[i] != '1') && (num[i] != '4')) { cout << "NO" << endl; return 0; } else if (num[i] == '1' && num[i + 1] != '4') { i++; } else if (num[i] == ...
1
#include <bits/stdc++.h> using namespace std; int n, x, y, a[100002]; int main() { cin >> n >> x >> y; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int pd = 1; for (int j = max(1, i - x); j <= min(n, i + y); j++) if (a[j] < a[i]) pd = 0; if (pd) cout << i, exit(0); ...
1
#include <bits/stdc++.h> using namespace std; int n; string s[60]; int xx2, yy2, xx1 = 110, yy1 = 110; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < n; j++) { if (s[i][j] - '0') { xx1 = min(i, xx1); xx2 = max(i, xx2); yy1 = min(j, yy1); ...
2
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline void debug(int x) { fprintf(stderr, "ycx has aked ioi %d times\n", x); } namespace fastio { char ...
5
#include <bits/stdc++.h> using namespace std; string res; vector<string> ele; vector<int> data; int main() { int n; scanf("%d", &n); string tmp; while (cin >> tmp) ele.push_back(tmp); if (ele.size() == 1 && ele[0] == "int") { cout << "int" << endl; return 0; } for (int i = 0; i < (int)ele.size(); ...
3
#include <bits/stdc++.h> using namespace std; pair <int, int> p[200100]; int n[200100], d[200100]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) cin >> p[i].first >> p[i].second; sort (p, p + N); d[N] = 1; for (int i = N - 1; i >= 0; i--) { int c = i + 1; while (c < N && p[c].first < p[i].first + p[i].secon...
0
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; n >>= 1; } return res; } int main(int argc, char** argv) { string S; cin >> S; long long k; cin >> k; ...
3
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); double inff = 1.0 / 0.0; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long int x, y, n, i, z, j, k, w, u, q, m, t, g; long long int fact[200011]; vector<long long int> adj[200011]; void pre_calc() { fact[0] ...
2
#include <bits/stdc++.h> using namespace std; long long n; string a, b; int cnt[50005][26]; int main(void) { cin >> n; cin >> a >> b; long long N = n / 2; long long ans = 0; for (int i = 0; i < N; i++) { char a1 = a[i], a2 = a[n - i - 1]; char b1 = b[i], b2 = b[n - i - 1]; if (b1 == b2) { if...
4