solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> long long int power(long long int x, long long int b, long long int mod1) { long long int p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= mod1; } b >>= 1; x *= x; x %= mod1; } return p % mod1; } using namespace std; struct lex_compare { bool operato...
1
#include <bits/stdc++.h> const int N = 41; typedef long long ll; ll dp[N][N][N][N], dp1[N][N][N][N]; bool vis[N][N][N][N]; char s[N][N]; void dfs(int i, int j, int u, int v){ if (i > j || u > v || vis[i][j][u][v]){ return; } vis[i][j][u][v] = true; if (i == j && u == v){ if (s[i][u] =...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5, LOG = 22; vector<long long> g[N]; long long child[N], p[N][LOG], d[N]; void dfs(long long node, long long par) { child[node] = 1; for (long long v : g[node]) if (v != par) { d[v] = d[node] + 1; p[v][0] = node; dfs(v, no...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e2 + 5; const int mod = 1e9 + 7; const int INF = 1e8 + 5; const long long inf = 1e15 + 5; const double eps = 1e-8; const long long hp = 2333; const long long base = 1e9 + 13; long long n, l, r; long long cal(long long x) { if (x <= 1) return 1; return ...
2
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3f; using namespace std; const long long maxn = 5009; long long read() { long long qqq; scanf("%lld", &qqq); return qqq; } long long n, m; long long pos[maxn]; long long dp[maxn][maxn], sum[maxn], S; long long q[maxn]; struct node { long long pos, n...
6
#include <bits/stdc++.h> using namespace std; const int M = 100000; const int S = 17; int n, K, len; char buf[M + 5]; int str[M * 2 + 5], bel[M * 2 + 5], rt[M * 2 + 5], st[M + 5], ed[M + 5]; struct suffix_array { int sa[M * 2 + 5], h[M * 2 + 5], v[M * 2 + 5], rk[M * 2 + 5], ST[S][M * 2 + 5], Log2[M * 2 + 5]; ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, m, k; int a[maxn], S[maxn], cnt[maxn], top; int main() { bool single_color = true; scanf("%d%d%d", &n, &k, &m); for (int i = 0; i < n; i++) scanf("%d", a + i); for (int i = 1; i < n; i++) if (a[i] != a[i - 1]) { single_...
2
#include <bits/stdc++.h> using namespace std; const int N = 10000; int k, n = 0, m = 0; char a[N][N]; int main() { cin >> k; for (int i = 5; i < k; i++) { if ((k % i == 0 && i > 4) && (k % (k / i) == 0 && k / i > 4)) { n = i; m = k / i; } } if (n == 0) { cout << "-1" << endl; return ...
2
#include <bits/stdc++.h> using namespace std; #define int long long const int MAXN = 5040, MOD = 1e9 + 7; int dp[MAXN][MAXN], DP[MAXN], a[MAXN], b[MAXN]; int mul(int a, int b) {return (a * b) % MOD;} int sum(int a, int b) {return (a + b) % MOD;} int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ...
0
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; if (n == 1) { cout<<1<<endl; return 0; } if (n == 0) { cout<<2<<endl; return 0; } cout<<2-n*n<<endl; return 0; int SZ = (n+100)*1024*1000/4; vector<int> v(SZ); for (...
6
#include <bits/stdc++.h> using namespace std; const int N = 51; int p[N], s[N]; void init() { for (int i = 0; i < N; i++) p[i] = i, s[i] = 1; } int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } void dsu(int x, int y) { x = find(x), y = find(y); if (s[x] < s[y]) p[x] = y, s[y] += s[x]; else p...
2
#include <bits/stdc++.h> using namespace std; int n; long long l, r; long long func(long long r) { long long sol = 2; while (sol <= r) sol *= 2; if (sol - 1 == r) return sol; return sol / 2; } int main() { scanf("%d", &n); while (n--) { scanf("%lld%lld", &l, &r); if (l == r) { printf("%lld\n",...
1
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } using ll = long long; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; const int inf = 1e9 + 10; struct dsu0 { vector<int> par, siz; int n; int cc; int largest; void init(int n) { assert(...
5
#include <bits/stdc++.h> using namespace std; const long long inf = 4e18; const long long mod = 1e9 + 7; const long long maxn = 1e5 + 10; int mark[maxn]; long long lo[maxn], wi[maxn]; vector<long long> rev[maxn], v[maxn]; stack<long long> st; void dfs(long long u, bool state) { for (long long i = 0; i < (rev[u]).size...
2
#include <bits/stdc++.h> using namespace std; int n, s, e; long long dp[5005][5005]; vector<int> x, a, b, c, d; int main() { cin >> n >> s >> e; x.resize(n); a.resize(n); b.resize(n); c.resize(n); d.resize(n); for (int i = 0; i < n; i++) { cin >> x[i]; } for (int i = 0; i < n; i++) { cin >> a[...
2
#include<iostream> #include<string> using namespace std; #define MAX 50 int main(){ int n; int H,W; string pict[MAX]; int zai['Z'-'A'+1][MAX][MAX]; /* 0..?????? 1..????????? 2..??° 3..?????? */ bool zok['Z'-'A'+1]; cin>>n; while(n--){ cin>>H>>W; for(int i=0;i<H;i++){ cin>>pict[i]; } for(i...
0
#include <bits/stdc++.h> using namespace std; constexpr int MAX_N = 100100; constexpr int MAX_V = 7005; int n, q; bitset<MAX_V> base[MAX_V]; bitset<MAX_V> mask[MAX_V]; bitset<MAX_V> val[MAX_N]; void prt(int x) {} int main() { scanf(" %d %d", &n, &q); for (int i = 1; i < MAX_V; ++i) { for (int j = i; j < MAX_V; ...
6
#include <bits/stdc++.h> using namespace std; long long ans=0,pw[20],d,cur; long long bt(long long now,int rem,int dg){ if(rem==0) return (now==0); if(rem==1) return (now==0)*10LL; long long prd=pw[dg-1]-pw[cur-dg]; long long mul=now/prd,ret=0; if(rem==dg){ ret+=1LL*max(0LL,9-abs(mul))*bt(now-prd*mul,rem-2,dg-1)...
0
#include<bits/stdc++.h> using namespace std; long n,dp[100001],a[100001]; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; dp[2]=abs(a[2]-a[1]); for(int i=3;i<=n;i++) { dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2])); } cout<<dp[n]; }
0
#include <bits/stdc++.h> using namespace std; int main() { int h1, m1, h2, m2; char ch; cin >> h1 >> ch >> m1 >> h2 >> ch >> m2; if (m2 > m1) { h1--; m1 = 60 - (m2 - m1); } else m1 -= m2; h1 -= h2; while (h1 < 0) { h1 = 24 + h1; } string h = (h1 < 10) ? "0" : "", m = (m1 < 10) ? "0" : ...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1, ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline void write(int x) { i...
5
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N,A,B; ll v[55]; long double S,D; ll comb(int n,int r){ if(r==0) return 1; return (n-r+1)*comb(n,r-1)/r; } int main(){ cin>>N>>A>>B; for(int i=0; i<N; i++) scanf("%lld",&v[i]); sort(v,v+N); int i=N; int C=B-A; int E=A; while(E){ i--; ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; constexpr int MAXN = 1003; constexpr int MAXC = 10004; int n; ll w, b, x; int c[MAXN]; ll cost[MAXN]; ll dp[MAXN][MAXC]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)(1e9 + 7); const long long inv = (long long)(5e8 + 4); int main() { long long n, m; cin >> n >> m; long long ans = (n % mod) * (m % mod) % mod; long long l = 1, r = 1; while (l <= min(n, m)) { long long a = n / l; r = min(m...
5
#include <bits/stdc++.h> int tcase, n, m, K; int main() { scanf("%d", &tcase); while (tcase--) { scanf("%d%d%d", &n, &m, &K); int x = 1; for (int k = 1; k <= K; k++) { int y = x; for (int i = 1; i <= n % m; i++) { printf("%d", n / m + 1); for (int j = 1; j <= n / m + 1; j++) ...
6
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); const int maxn = 100000; const long long inf = (~0ull) >> 2; long long p[maxn]; long long yue[2][maxn]; long long all[maxn]; int ynum[2], an, a[maxn]; long long base, ans[3], tmp[3], res, suf, v; int main() { int T, i, ...
4
#include<iostream> #include<string> #include<algorithm> #include<map> #include<set> #include<cstring> #include<queue> #include<stack> #include<cstdio> #include<iomanip> #define pb push_back #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, id_start, id_end, i, j; string s; cin >> n >> s; for (i = 0; i < s.size(); i++) { if (n - i > 2 && s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { id_start = i; id_end = i + 3; j = i + 3; while (j + 1 < s.size() &...
1
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int num = 0, f = 1; for (; !isdigit(c); c = getchar()) f = c == '-' ? -1 : f; for (; isdigit(c); c = getchar()) num = num * 10 + c - '0'; return num * f; } const int N = 25005; int n, m, l; bitset<N> a, b, c, d; char s[10000...
4
#include <bits/stdc++.h> using namespace std; string p, s, ep[2001], es[2001], ans = "233"; int slen, plen, k; int main() { getline(cin, p); getline(cin, s); cin >> k; slen = s.size(); plen = p.size(); for (int i = 0; i < plen; i++) ep[i % k] += p[i]; for (int l = 1; l <= k; l++) { for (int i = 0; i <...
5
#include <bits/stdc++.h> using namespace std; int main() { int h,w,x,y; cin >> h >> w >> x >> y; cout << (h-x)*(w-y) << endl; }
0
#include<stdio.h> #include<string.h> #include<math.h> int main(void) { int a; scanf("%d",&a); printf("%d\n",a*32); return 0; }
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, m, k, z[1000002], v[2][500002]; string second, t; int main() { cin >> n >> m >> k; cin >> second >> t; memset(v, -1, sizeof(v)); for (int h = 0; h < 2; h++) { string a = t + '$' + second; memset(z, 0, sizeof(z)); vector<...
4
#include <bits/stdc++.h> using namespace std; int getnum() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 4010; int n, k...
5
#include<stdio.h> #pragma GCC optimize ("O2") int main(void) { int K,div,N;long long a=0;K=scanf("%d",&N); while(K<=N){div=N/K;a+=1ll*K++*div*(div+1)/2;} return printf("%lld\n",a),0; }
0
#include <bits/stdc++.h> template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) { std::cout << name << " = " << arg1 << std::endl; } template <typename Arg1, typename... Args> void ZZ(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cout.write(names, comm...
2
#include <bits/stdc++.h> using namespace std; // 蟻本そのまま int extgcd(int a, int b, int& x, int& y) { int d = a; if(b != 0) { d = extgcd(b, a%b, y, x); y -= (a/b) * x; } else { x = 1; y = 0; } return d; } int main() { int a, b; cin >> a >> b; int x, y; ex...
0
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1}; const int dy[] = {3, 3, 3}; int n, k; bool inRange(int x, int y) { if (x < 0 || x > 2) return false; if (y < 0 || y >= n) return false; return true; } int main() { int T; cin >> T; while (T--) { int s; string M[3]; vector...
4
#include <bits/stdc++.h> using namespace std; int main() { string x; getline(cin, x); int prev = 0; for (int i = 0; i < x.length(); i++) { string curStr, prevStr; curStr = bitset<8>(x.c_str()[i]).to_string(); reverse(curStr.begin(), curStr.end()); unsigned int cur = std::strtol(curStr.c_str(), N...
1
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> #include<set> #include<bitset> #include<map> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; typedef long long LL; typedef double db; int get(){ char ch; while(ch=getchar(...
0
#include<bits/stdc++.h> using namespace std; string a; int main() { cin>>a; if(a[0]=='7' || a[1]=='7' || a[2]=='7') cout<<"Yes"; else cout<<"No"; }
0
#include <bits/stdc++.h> using namespace std; int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); } struct index { int value; vector<int> pos; }; struct node { int start, end; long long int max_sum; }; struct answer { bool is_valid; long long int max_sum; }; struct node segment_tree[40...
1
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } f ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; for (; t > 0; --t) { int n, r; cin >> n >> r; map<long long int, long long int> aa; map<long long int, long long int> dp; int po[r + 1]; for (long long...
3
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<int(n);++i) using ll = long long; string s[410]; int Y, X; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; void calc(int y, int x, ll &black, ll &white, char pre) { if (y < 0 || x < 0 || x>=X || y>=Y) return; if (s[y][x] == '!' || s...
0
#include <bits/stdc++.h> using namespace std; int dp[3939][50]; int n, m, k; int a[3939]; int getMin(int x, int y) { return x < y ? x : y; } int getMax(int x, int y) { return x > y ? x : y; } void solve() { int i = 0, j, d; vector<int> vec; scanf("%d %d %d", &n, &m, &k); for (i = 0; i < n; i++) { scanf("%d"...
1
#include <bits/stdc++.h> using namespace std; int a[100500]; vector<int> gr[100500]; char res[100500]; int p[100500]; char x[100500]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; p[a[i]] = i; } for (int i = 1; i <= n; i++) { int d = a[i]; for (int j = i; j >= 1; j ...
3
#include <iostream> #include <cstdlib> #include <cstring> #include <vector> #include <cstdio> using namespace std; int main() { double a,b; cin>>a>>b; printf("%.5f\n",a*b/3.305785); }
0
#include <bits/stdc++.h> using namespace std; struct amulet {}; int main() { int n, k, c; scanf("%d%d%d", &n, &k, &c); vector<bool> arr(n + 1, false); for (int i = 0; i < c; i++) { int t; scanf("%d", &t); arr[t] = true; } int pre = 1, now = 1; while (now <= n) { if (arr[now]) pre = 1...
1
#include <cstdio> #include <iostream> #include <cstring> #define maxn 36 using namespace std; char map[6][3][3], tmp[maxn]; int hole[6][4], hpair[6][4]; void clean() { memset(map, 0, sizeof(map)); memset(hole, 0, sizeof(hole)); memset(hpair, 0, sizeof(hpair)); } void read() { char tmp2[maxn]; ...
0
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; typedef pair<int,int> P; int D(P p){ int x = p.first; int y = p.second; return (x * x + y * y); } void solve(){ int x=0, y=0, dx, dy, ans_d=0; vector<P> vp; P ans_p; bool flag = false; while( cin >> dx >> dy , dx |...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; unsigned long long int arr[n], sumarr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } unsigned long long int e, t = 0, m = *min_element(arr, arr + n); bool pos = true; for (int i = 0; i < n && pos == true; i++) { ...
1
#include <bits/stdc++.h> using namespace std; inline void splay(int &v) { v = 0; char c = 0; int p = 1; while (c < '0' || c > '9') { if (c == '-') p = -1; c = getchar(); } while (c >= '0' && c <= '9') { v = (v << 3) + (v << 1) + c - '0'; c = getchar(); } v *= p; } int a[200010], t[200010...
3
#include <bits/stdc++.h> using namespace std; int dp[5001][5001]; int quickpow(int x, int y) { long long res = 1, base = x; while (y) { if (y & 1) res *= base, res %= 1000000007; y >>= 1; base *= base, base %= 1000000007; } return res; } int get_ans(int a, int b, int tot) { if (dp[a][b]) return dp...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 250005; struct gripper { int x, y, m, p; long long dist, r; gripper(){}; gripper(long long a) { dist = a; } } grips[MAXN]; void calc_dist(int i) { grips[i].dist = (long long)(grips[i].x - grips[0].x) * (grips[i].x - grips[0].x) + (long...
5
#include <bits/stdc++.h> using namespace std; int main(){ int N, m; cin >> N >> m; vector<int> c(m), d(m); for (int i = 0; i < m; i++){ cin >> c[i] >> d[i]; } vector<int> cnt(N + 1, 0); for (int i = 0; i < m; i++){ for (int j = c[i]; j < d[i]; j++){ cnt[j]++; } } int ans = N + 1; f...
0
#include <bits/stdc++.h> using namespace std; int n, m, op; int flag[35]; int main() { scanf("%d %d", &m, &n); for (int i = 0; i < n; i++) { puts("1"); fflush(stdout); scanf("%d", &op); if (op == 1) flag[i] = 1; else if (op == -1) flag[i] = -1; else exit(0); } int l = 1...
4
#include<bits/stdc++.h> typedef long long i64; const int P=998244353,M=100007; char s1[M],s2[M]; int A=0,B=0,N,K,rev[M]; i64 fac[M],fiv[M],_A[M],_B[M],E[M]; i64 pw(i64 a,i64 n){ if(n<0)n+=P-1; i64 v=1; for(;n;n>>=1,a=a*a%P)if(n&1)v=v*a%P; return v; } void init(int mx){ for(N=2,K=0;N<mx;N<<=1,++K); for(int i=1;i<N...
0
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; for (long long i = 0; i < n - 1; i++) if ((arr[i] == 2 && arr[i + 1] == 3) || (arr[i] == 3 && arr[...
1
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; int n, m, k, sum[100], a[3][1000005]; struct Matrix { int a[100][100]; int* operator[](int idx) { return a[idx]; } } s, s1, s2, s3; Matrix get(int a[]) { Matrix s; memset(s.a, 0, sizeof(s.a)); memset(sum, 0, sizeof(sum)); for (int i = 0;...
2
#include <bits/stdc++.h> #define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; const ll MOD = 1000000007; ll N, M, A[1000], B[1000]; bool row[1000001], col[1000001]; ll solve() { REP(i, 0, N) { if (row[A[i]]) return 0; row[A[i]] = true; } REP(i, 0, M) {...
0
#include <bits/stdc++.h> using namespace std; int n, T; long long a[25][25]; int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << ((i + 1ll) % 2 << i + j) << ' '; cout << endl; } fflush(stdout); int T; cin >> T; while (T--) { long long k; cin >> k; i...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; long long l; cin >> l; vector<long long> arr(n + 5); for (__typeof(n + 1) i = (1) - (1 > n + 1); i != (n + 1) - (1 > n + 1); ...
2
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[1000010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const int maxn = 5e5 + 10; const int base = 29; const int mod = 1e9 + 7; const int INF = 1e9; inline int getlen...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long MAX = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n]; set<int> s; for (int i = 0; i < n; i++) s.insert(i + 1); for (int i = 0; i < n; i++) { cin >> a[i]; if (...
3
#include <bits/stdc++.h> using namespace std; vector<long long int> g[100010]; int visit[100010] = {0}; double ans = 0; void dfs(long long int n, double prob, long long int d) { visit[n] = 1; int f = 0; for (long long int i = 0; i < g[n].size(); i++) { if (visit[g[n][i]] == 0) { f = 1; if (n == 1)...
3
#include <bits/stdc++.h> using namespace std; const int N = 3010; char s[N], t[N], st[N]; int f[N][N]; int main() { scanf("%s%s", s + 1, t + 1); int n = strlen(s + 1), m = strlen(t + 1); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { f[i][j] = max(f[i - 1][j], f[i][j - 1]); if(s[i] == t[j]) f...
0
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, k, a[N], s[N]; bool check(int x) { for(int i = 1; i <= n; i++) s[i] = s[i - 1] + (a[i] >= x ? 1 : -1); int mi[2] = {1000000, 1000000}; for(int i = k; i <= n; i++) { int j = i - k; mi[j & 1] = min(mi[j & 1], s[j]); ...
4
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int z = 0; z < n; z++) { string s; cin >> s; queue<char> odds; queue<char> evens; fo...
3
#include <bits/stdc++.h> template <typename T, size_t N> struct MakeVector { template <typename... Args, typename R = std::vector<decltype(MakeVector<T, N - 1>::make_vector( std::declval<Args>()...))>> static R make_vector(std::size_t first, Args... sizes) { auto inner = MakeVector<T...
5
#include <bits/stdc++.h> using namespace std; const int N = 5001; int n, m, mod = 1e9 + 7; vector<int> s, v[N]; int calc_inc(int g, int h, int j) { if (g > h) swap(g, h); int b = upper_bound(v[j].begin(), v[j].end(), h) - v[j].begin() - 1; if (b == -1) return 0; if (b == 0) return 1; if (v[j][0] <= g) return ...
5
#include <bits/stdc++.h> using namespace std; int main() { const int n = 8; string chess[n]; char chs[n][n]; int bi = 0, wi = 0, b = 8, w = 8; for (int i = 0; i < n; i++) { cin >> chess[i]; } for (int i = 0; i < n; i++) { wi = 0; for (int j = 0; j < n; j++) { if (chess[j][i] == 'B') brea...
1
#include <iostream> using namespace std; int P[10010]; void init(int N); int root(int a); bool is_same_set(int a,int b); void unite(int a,int b); int main() { int N,Q; cin >> N >> Q; init(N); for (int i=0;i<Q;++i) { int com,x,y; cin >> com >> x >> y; if (com==0) unite(x,y); else { ...
0
#include <iostream> #include <string> #include <cctype> using namespace std; int main() { string s; while(getline(cin, s)) { for (int i=0; i<26; i++) { string s2(s); for (int j=0; j<s.length(); j++) { if (isalpha(s[j])) s2[j] = (s[j]-'a'+i) % 26 + 'a'; } if (s2.find("t...
0
#include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; #define N 5050 const int mod=1e9+7; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } ...
0
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <map> #include <utility> #include <functional> using namespace std; typedef pair<int, int> P; int main() { int n; while (cin >> n && n != 0) { P s[100010]; int go, k = 1, ans = 0; for (int i = 1; i <= n; ...
0
#include <bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl #define dd(x) cout<<#x<<"="<<x<<" " using namespace std; #define int long long const int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, X, D; cin >> N >> X >> D; if (D == 0) { if (X == 0) { cout << 1 << endl; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int y, w; cin >> y >> w; int ma = max(y, w); double re = (6 - ma) + 1; if (re == 6) cout << "1/1"; else if (re == 5) cout << "5/6"; else if (re == 4) cout << "2/3"; else if (re == 3) cout << "1/2"; else if (re == 2) cout <<...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main () { int H,W; cin >> H >> W; for (int i=0; i<H; ++i) { for (int j=0; j<W; ++j) { string s; cin >> s; if( s == "snuke") printf("%c%d\n",'A'+j,i+1); } } return 0; }
0
#include <bits/stdc++.h> using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::max; using std::min; using std::pair; using std::string; using std::vector; template <typename T> inline T input() { T ans; cin >> ans; return ans; } int main() { uint32_t n = input<uint3...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x, i, sum = 0, c = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x; sum += x; } n++; for (i = 1; i <= 5; i++) { if ((sum + i) % n != 1) c++; } cout << c << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int m, n, res, a, b, mas[50][50], i, j, k, l, min = 100000, s = 0; cin >> n >> m; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> mas[i][j]; } } cin >> a >> b; for (i = 0; i <= n - a; i++) { for (j ...
2
#include<iostream> using namespace std; int dp[100001]; int main() { int n, q; string s; cin >> n >> q >> s; for (int i = 1; i <= n; i++) dp[i] = dp[i - 1] + s[i - 1] - 'a' + 1; while (q--) { int l, r; cin >> l >> r; cout << dp[r] - dp[l - 1] << '\n'; } }
2
#include <bits/stdc++.h> using namespace std; const int MaxN = 5000009; char s[MaxN], t[MaxN]; int p[MaxN], q[MaxN], r[MaxN], z[MaxN]; int n; int main(void) { int i, j, k, res; while (scanf(" %s", s + 1) != EOF) { s[0] = t[0] = '\0'; n = strlen(s + 1); for (i = 1; i <= n; i++) t[n - i + 1] = s[i]; t...
4
#include <bits/stdc++.h> void gSr(int n) { int magicSquare[n][n]; memset(magicSquare, 0, sizeof(magicSquare)); int i = n / 2; int j = n - 1; int num; for (num = 1; num <= n * n;) { if (i == -1 && j == n) { j = n - 2; i = 0; } else { if (j == n) j = 0; if (i < 0) i = n - 1; ...
3
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; //const int INF = 1e8; using namespace std; class RollingHash { public: typedef pair<long long,long lon...
0
#include <bits/stdc++.h> using namespace std; long long fac[1000006]; inline long long exp(long long x, long long n) { long long r = 1; x = x % 1000000007; while (n) { if (n % 2) r = (r * x) % 1000000007; x = (x * x) % 1000000007; n = n / 2; } return r; } inline long long mmi(long long a) { retu...
3
#include <iostream> #include <string> #include <deque> #include <algorithm> #include <cctype> using namespace std; int main(){ int n, m; for(cin >> n; n--; ){ string cmd, msgstr; cin >> cmd >> msgstr; deque<char> msg(msgstr.begin(), msgstr.end()); deque<char>::iterator it1, it2; for(int i = cmd.size(...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n % 2; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m, d; int a[N], v[N * 12], cnt[N]; int main() { scanf("%d%d%d", &n, &m, &d); for (int i = 1; i <= m; i++) { int x; scanf("%d", &x); while (x--) { int y; scanf("%d", &y); a[y] = i; } } int p = 0, k = 1 <<...
4
#include <bits/stdc++.h> using namespace std; int n, k, m, u[2000], v[2000], c[2000]; vector<pair<int, int> > G[82]; int INF = (1 << 28); int cache[82][82][82][82]; int rec(int now, int left, int right, int reftk) { int ans; if (cache[now + 1][left + 1][right + 1][reftk + 1] != -1) { return cache[now + 1][left ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; scanf("%lld%lld", &a, &b); if (a == b) return 0 * puts("1"); long long ans = 1; if (b - a < 20) { for (long long i = a + 1; i <= b; i++) { long long t = i % 10; ans = 1ll * ans * t % 10; } } else ans = 0; pr...
2
#include<bits/stdc++.h> using namespace std; int H,W; char F[555][555]; char R[555][555]; char B[555][555]; int main(){ cin >> H >> W; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cin >> F[j][i]; R[j][i] = F[j][i]; B[j][i] = F[j][i]; } } for(int i=0;i<H;i++){ if( i & 1 ) ...
0
#include <bits/stdc++.h> using namespace std; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, fg = 0, x, y, mx = 0, mx1 = 0, mn ...
3
#include <bits/stdc++.h> using namespace std; int n, q; vector<int> a, k; int last(int x) { int cnt = 0; for (auto y : a) if (y <= x) cnt++; for (auto y : k) { if (y > 0 and y <= x) cnt++; if (y < 0 and abs(y) <= cnt) cnt--; } return cnt; } int main() { ios_base::sync_with_stdio(false); cin.ti...
4
#include<stdio.h> int main(void) { int i,h,k,a[3],b[3],c[5]; for(i=0;i<2;i++) scanf("%d %d",&a[i],&b[i]); for(i=0;i<4;i++) scanf("%d",&c[i]); h=a[0]/10*c[2]+a[0]*c[0]; k=a[1]/10*c[2]+a[1]*c[0]; h=h+b[0]/20*c[3]+b[0]*c[1]; k=k+b[1]/20*c[3]+b[1]*c[1]; if(h>k) printf("hiroshi\n"); else if(h==k) printf("even\n"); ...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int i, j, k, n, m, T; double ax, ay, va, xu, yu, vu, r, R, adis, bdis, ao, bo, v, l, rr, mid, b, d, bx, by; double check(double ti) { b = atan2(xu, yu) - ti * v; bx = sin(b) * R; by = cos(b) * R; d = atan2(ax, ay) - atan2(bx, by); i...
3
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 9; const int INF = 1e9 + 7; long long power(long long x, long long y) { if (y == 0) return 1; long long temp = power(x, y / 2); if (y % 2 == 1) return temp * temp * x; else return temp * temp; } int n, m, x, y, ans = 0; int a[N]; vec...
3
#include <bits/stdc++.h> using namespace std; long long int arr[100050], dp[100050]; int main() { double n, k; cin >> n >> k; double sub = 0; for (int i = 1; i < n; i++) { sub += pow((i * 1.0) / n, k); } cout << setprecision(7) << n - sub << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; int n, m; bool possible[100101], occor[100001]; char cmd[100001]; int his[100001]; bool in[100001]; int main() { ios::sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> cmd[i] >> his[i]; } int cnt = 0; for (int i = 0; i < m; i++) { i...
3