solution
stringlengths
52
181k
difficulty
int64
0
6
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define Fast_IO ios::sync_with_stdio(false); #define int long long #define mod 998244353 inline int read() { char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();} int ans=0; while(isdigit(ch)) {ans...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long updiv(long long a, long long b) { if (a % b == 0) return (a / b); else return (a / b) + 1; } long long mymod(long long x, long long m) { if (x > 0) return x % m; else return ((x) % (m) + (m)) % (m); } long long X...
1
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e3; long long a[20]; long long b[20]; int main() { long long n, m, ans, piu, pia, sum; while (~scanf("%I64d", &a[1])) { ans = 0; for (int i = 2; i <= 14; i++) scanf("%I64d", &a[i]); for (int i = 1; i <= 14; i++) { if (a[i] == 0) conti...
2
// #include {{{ #include <iostream> #include <cassert> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype> #include <cmath> #include <ctime> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <bitset> #include <vector> #include <complex> #include <algorithm>...
0
#include <bits/stdc++.h> const int MAXN = 55; const int d[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; int n, m; char map[MAXN][MAXN]; int last[MAXN][MAXN]; bool vis[MAXN][MAXN]; bool BFS(int x0, int y0) { static int que[MAXN * MAXN][2]; char color = map[x0][y0]; int x, y; memset(vis, 0, sizeof(vis)); que[0][0...
2
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long MOD = (long long)1e9 + 7; long long add(long long x, long long y) { x += y; if (x >= MOD) return x - MOD; return x; } long long sub(long long x, long long y) { x -= y; if (x < 0) ...
6
#include <bits/stdc++.h> using namespace std; int ans, n; vector<int> factors; int logCal(long long int a, long long int b) { int power = 0; while (a > b) { b *= 2; power++; } return power; } void setAns(long long int a, long long int b, long long int h, long long int w, int i) { if (h >= ...
4
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; int pos1 = s.find('C'), pos2 = s.rfind('F'); if (pos1 == -1 || pos2 == -1) puts("No"); else if (pos2 > pos1) puts("Yes"); else puts("No"); }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; pair<int, int> A[MAXN], L[MAXN], R[MAXN]; const int inf = 1e9 + 7; int N; long long sqr(int x) { return x * 1LL * x; } pair<int, int> update(pair<int, int> q, pair<int, int> p) { pair<int, int> ans; ans.first = min(q.first, p.first); ans.secon...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll p = 998244353; const int M = 1e6+5; ll fact[M], invfact[M]; ll n, m; ll exp(ll x, ll k) { if (k == 0) return 1; ll y = exp(x, k/2); if (k%2 == 0) return y*y%p; return y*y%p*x%p; } ll inv(ll x) { return exp(x, p-2); } void precomp(...
0
#include <bits/stdc++.h> using namespace std; #define repl(i, a, n) for(int i = ((int) a); i < ((int) n); i++) #define rep(i,n) repl(i,0,n) #define INF INT_MAX/3 typedef long long ll; typedef pair<int,int> P; bool is_prime[1100001]; int cav[2000][2000]; P mem[2000][2000]; int dx[]={1,0,-1,0}; int dy[]={0,-1,0,1}; P d...
0
#include <bits/stdc++.h> using namespace std; int dp[30][30][5005]; int good[30]; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); string s; cin >> s; int len = s.length(); double ans = 0.0; for (int i = 0; i < len; ++i) { good[s[i] - 'a']++; int dist = 0; for (int j = i + 1; j...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 50005; const double inf = 0.000001; const int INF = ~0U >> 1; const int mod = 1000000007; int n, a[maxn][6], m; int equal(double x, double y) { if (x - y >= -inf && x - y <= inf) return 0; else if (x - y > inf) return 1; return -1; } int main(...
2
#include <bits/stdc++.h> using namespace std; int solve(int* h_orient, int a, int b, int n, int i, int j) { int orient = h_orient[i] + h_orient[n - 1] - h_orient[j - 1]; orient *= b; int time = orient + (i - j + n) % n + 1; int r = i, l = n - j; time += (l + r + min(l, r)) * a; return time; } int main() { ...
2
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS ios_base::sync_with_stdio(0);cin.tie(0) #define infinite 9123456789 #define PRECISION cout.precision(3); cout.setf(ios::fixed); #define db cout << "Debug" << "\n"; #define ler_entrada freopen("test_input.txt", "r", stdin); int n, m, a[2000...
4
#include <bits/stdc++.h> using namespace std; int n, K, i; char s[200005]; int main() { scanf("%d%d%s", &n, &K, s + 1); if (K == 0) { printf("%s", s + 1); return 0; } if (n == 1) { printf("0"); return 0; } if (s[1] > '1') { s[1] = '1'; --K; } for (i = 2; i <= n && K > 0; ++i) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005, M = 2; const long long sta = 1000, ed = 10000000000000LL; struct mix { long long a[M][M]; } fir, one, zero; long long qcheng(long long a, long long b, long long p) { long long ret = 0; while (b) { if (b % 2) ret = (ret + a) % p; a = (a + ...
5
#include <cstdio> #include <cstring> #include <cassert> #include <algorithm> #define MAXN 1006010 #define LL long long using namespace std; const LL P=998244353; LL getPow(LL x,LL y){ LL res=1; while(y){ if(y&1) res=res*x%P; x=x*x%P; y>>=1; } return res; } int n,n1,n2,sizew; LL fac[MAXN],invfac[MAXN]; LL ...
0
#include <bits/stdc++.h> using namespace std; int hm, am, dm; int check(int ay, int dy) { int m = max(0, ay - dm), y = max(0, am - dy); if (!m) return -1; return (hm / m + (hm % m != 0)) * y + 1; } int main() { int hy, ay, dy, h, a, d, mn = 1e9; cin >> hy >> ay >> dy >> hm >> am >> dm >> h >> a >> d; for (i...
3
#include<bits/stdc++.h> using namespace std; int a,b,c,i,j,n,s; int main() { cin>>a>>b>>c>>n; for (i=0;i<=a;i++) for (j=0;j<=b;j++) if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) ++s; cout<<s<<endl; return 0; }
0
#include <iostream> #include <string> #include <cctype> using namespace std; int main(){ string W,T; int cnt=0; cin >> W; for(int i=0;i<W.size(); i++)W[i] = tolower(W[i]); while(1){ cin >> T; if(T == "END_OF_TEXT")break; for(int i=0;i<T.size(); i++)T[i] = tolower(T[i]); if(T == W)cnt++; } cout << c...
0
#include <stdio.h> int main(void) { int N, D; scanf("%d %d", &N, &D); printf("%d", (N+(D*2))/(D*2+1)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int h[7], s[110], c, m[7][7], p[110], u[7]; vector<int> v[7][7]; void dfs(int i) { int j; u[i] = 1; for (j = 0; j < 7; j++) if (m[i][j]) { m[i][j]--; m[j][i]--; dfs(j); } s[c++] = i; } int main() { int i, n, j, k; for (scanf("%d", &n), ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 5; long long a[MAXN], pre[MAXN], mn[MAXN], first; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int md = n / 2 + n % 2; long long fsthalf = 0; for (int i = 0; i < md; i++) cin >> a[i], fsthalf += a[i]; cin...
5
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; else return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int binpow(int a, int p) { if (!p) return 1; int g = binpow(a, p >> 1); if (p % 2 == 0) return (g * g) % 1000000007; else ...
1
#include <bits/stdc++.h> template <class Z> void Swap(Z &a, Z &b) { Z temp; temp = a; a = b; b = temp; } using namespace std; int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; cout << min(a, min(b, min(c / 2, min(d / 7, e / 4)))); return 0; }
3
#include <bits/stdc++.h> using namespace std; long long n, i, j, ans; inline bool out_of_round(long long x, long long y) { y++; if (x * x + y * y > n * n) return true; return false; } int main() { scanf("%I64d", &n); ans = n - 1; for (i = 1; i < n; i++) if (!out_of_round(trunc(sqrt(n * n - i * i)), i)) ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int ans[3]; cin >> ans[0] >> ans[1] >> ans[2]; sort(ans, ans + 3); if (ans[2] == ans[1] && ans[1] != ans[0]) { ans[2]--; ans[1]--; } if (ans[2] > ans[1]) ans[2]--; if (...
1
#include <bits/stdc++.h> using namespace std; const int SZ = 75; const int inf = numeric_limits<int>::max(); set<int> ch[SZ]; struct nd { int k, p, cnt; nd *l, *r; nd(int k, int p) : k(k), p(p), l(NULL), r(NULL), cnt(1) {} }; nd* root = NULL; int get_cnt(nd* t) { return !t ? 0 : t->cnt; } void upt_cnt(nd*& t) { ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m, vis[N]; vector<vector<int> > graph; vector<int> color; map<int, set<int> > mp; void dfs(int u) { vis[u] = 1; for (int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if (!vis[v]) dfs(v); if (color[v] != color[u]) mp[...
4
#include<iostream> using namespace std; int h,w; string g[100]; bool use[100][100]; int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1}; void rec(int y,int x,char c){ if(use[y][x])return; use[y][x] = true; for(int i=0;i<4;i++){ int ny = y+dy[i], nx = x+dx[i]; if(ny<0 || nx<0 || ny>=h || nx>=w)continue; if(g[n...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; const long double EPS = 1e-12; int d, s; bool...
1
#include <bits/stdc++.h> int main() { long long int b, ans = 1, z; scanf("%I64d", &b); z = sqrt(b); for (long long int i = 2; i <= b; i++) { if (i > z) { ans *= 2; break; } long long int c = 1; while (b % i == 0) { b /= i; c++; z = sqrt(b); } ans *= c; i...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9; int n, x, y; map<int, int> mp; vector<int> v; void check(int x) { if (mp[x] == 0) mp.erase(x); } int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } int main() { ios::sync_with_stdio(false); cin >> n; for (int i...
1
#include <bits/stdc++.h> using namespace std; constexpr long double m_pi = 3.1415926535897932L; constexpr long long MOD = 1000000007; constexpr long long INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = vector<vector2<T>>;...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int d[N], n, m, cntlp; bool loop[N], mark[N]; long long ans; vector<int> adj[N]; void input() { cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; if (u == v) { loop[u] = true; cntlp++; ...
2
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int md=1000000007; int n,m,f[3005][3005][2],i,j,k; int main() { scanf("%d%d",&n,&m); for(i=1;i<=n;++i) f[0][i][0]=1; f[0][0][1]=1; for(i=0;i<m;++i) for(j=0;j<=n;++j) for(k=0;k<=1;++k) if(f[i][j][k]) { ...
0
#include <bits/stdc++.h> using namespace std; void solve() { int n, q; scanf(" %d %d", &n, &q); vector<int> A(n); for (int i = 0; i < n; ++i) scanf(" %d", &A[i]); long long res = 0; bool up = true; int prev = 0; for (int i = 0; i < n; ++i) { if (i && A[i - 1] > A[i]) { if (up) { res +=...
3
#include <bits/stdc++.h> using namespace std; void no() { cout << "-1\n"; exit(0); } void yes() { cout << "YES\n"; } int nxt() { int x; cin >> x; return x; } void solve() { int n = nxt(); vector<int> a(5); for (int i = (int)0; i < (int)n; i++) a[nxt()]++; int ans = 0; int x = min(a[1], a[2]); ans ...
3
//2017-10-18 //miaomiao // #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> using namespace std; #define For(i, a, b) for(int i = (a); i <= (int)(b); ++i) #define N (100+2) char mp[N][N]; short f[N][N][N][N], sumr[N][N], sumc[N][N]; inline short Calc(...
0
#include<bits/stdc++.h> using namespace std; long long m,x,y; int n,ans; int main() { cin>>n>>m; for(int i=0;i<n;i++) { cin>>x>>y; if(x*x+y*y<=m*m)ans++; } cout<<ans; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int main() { int T; cin >> T; while (T--) { int x, y, a, b; cin >> x >> y >> a >> b; int t = (y - x) % (a + b); if (t) cout << "-1" << endl; else cout << (y - x) / (a + b) << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const double pi = 3.141592; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m; cin >> n >> m; long long x[n + m]; for (int i = (0); i < (n + m); i++) { cin >> x[i]; } bool taxi[n + m]; f...
2
#include <bits/stdc++.h> using namespace std; const int maxn = int(1e5) + 10; int n, m; set<int> eage[maxn]; int p[maxn]; void work() { for (int i = 1; i <= n; i++) p[i] = i; random_shuffle(p + 1, p + 1 + n); p[n + 1] = p[1]; for (int i = 1; i <= m; i++) if (eage[p[i]].count(p[i + 1])) return; for (int i ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, x, y, z, k; cin >> a >> b >> c >> x >> y >> z; k = x - min(x, a) + y - min(b, y) + z - min(z, c); a = (a >= x) * (a - x); b = (b >= y) * (b - y); c = (c >= z) * (c - z); if (k > (a / 2) + (b / 2) + (c / 2)) cout << "No"; e...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int m, b, x = 0, y = 0, mx = 0, num1 = 0, num2 = 0, ans = 0; cin >> m >> b; long long int i; for (i = 0; i <= 10000000; ++i) { if (i % m == 0) { x = i; y = ...
2
#include<iostream> #include<cstdio> using namespace std; int main(void) { int N,M,X,Y; scanf("%d %d %d %d",&N,&M,&X,&Y); int a; for(int i=0;i<N;i++){ scanf("%d",&a); if(X<a) X=a; } for(int i=0;i<M;i++){ scanf("%d",&a); if(Y>a) Y=a; } if(X<Y) puts("No War"); else puts("War"); return 0; }
0
#include <bits/stdc++.h> using namespace std; using LL = long long int; using uLL = unsigned long long int; using uint = unsigned int; using ld = long double; inline bool compare(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) { return a.second < b.second; } return a.first > b.first; } int main(...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; for (long long i = 1; i <= n; i++) { if (i * (n / i) == n && n / i <= i) { cout << n / i << " " << i; return 0; } } }
1
#include <iostream> #include <vector> #include <queue> using namespace std; typedef long long lli; lli n; vector<lli> r,l; priority_queue<lli> pqr; priority_queue<lli,vector<lli>,greater<lli> > pql; lli ans; int main(){ cin >> n; r = vector<lli> (n); l = vector<lli> (n); for(lli i = 0;i < n;i++) ...
0
#include<iostream> #include<vector> using namespace std; typedef long long ll; int n, v[2000]; ll dp[2000][2000][2] = {}; bool visit[2000][2000][2] = {}; void joi(int op, int &a, int &b, int &c){ if(op == 0){ if(c == 0) a++; else a--; if(a < 0) c = 0, a = b, b = n-1; } if...
0
#include<bits/stdc++.h> using namespace std; int main(){ double a,b,c; cin>>a>>b>>c; c=c*3.14159265358979/180; cout<<fixed<<setprecision(10)<<((a*b)/2)*sin(c)<<endl; cout<<fixed<<setprecision(10)<<a+b+sqrt(a*a+b*b-2*a*b*cos(c))<<endl; cout<<fixed<<setprecision(10)<<(a*b*sin(c))/a<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, c, g, s, b, i, t, si, j; cin >> t; while (t--) { cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; g = s = b = 0; vector<pair<long long int, long long int> > v; k = a[0]; c = 1; for (i =...
1
#include <bits/stdc++.h> using namespace std; vector<int> Grupa; vector<int> Pozycja; bool Met[333]; int Liczba[333]; bool ok[333][333]; char Ciag[333]; int Answer[333]; int N; void Skacz(int n) { Met[n] = 1; Grupa.push_back(Liczba[n]); Pozycja.push_back(n); for (int i = 1; i <= N; ++i) { if (Met[i] == 0 &&...
2
#include <bits/stdc++.h> using namespace std; const int MAX = 400005; struct Edge { int v, next; } edge[MAX * 2]; int head[MAX]; int num[MAX]; int maxv[MAX]; int tot; int n; int up[MAX], down[MAX]; void init() { memset(head, -1, sizeof head); tot = 0; } void add_edge(int a, int b) { edge[tot] = (Edge){b, head[a...
3
#include <bits/stdc++.h> using namespace std; long long read() { long long xx = 0, flagg = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') { flagg = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = xx * 10 + ch - '0'; ch = getchar...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int M = 5005; int n, m, p, a[N], fac[N], d[M][M]; int Cm[M], dp[2][M], sum[2]; int main() { scanf("%d%d%d", &n, &m, &p); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 0; i <= m; i++) { fac[i] = i ? 1ll * fac[i - 1] * i...
5
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <iostream> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; int** dp; bool** map; char* buf; void func(){ int N,limit; scanf("...
0
#include <bits/stdc++.h> using namespace std; long long C[1111][1111], s[1111][1111]; long long f[111][10005]; long long pow_big(long long n, long long k) { if (k == 0) return 1; long long tmp = pow_big(n, k / 2); long long res = (tmp * tmp) % 1000000007; if (k % 2 == 1) res = (res * n) % 1000000007; return r...
4
#include <bits/stdc++.h> using namespace std; long long read() { int f = 1; long long res = 0; char ch; do { ch = getchar(); if (ch == '-') f = -f; } while (ch < '0' || ch > '9'); do { res = res * 10 + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9'); return f == 1 ? res : -res...
5
#include <bits/stdc++.h> using namespace std; ; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b, ac, bc, cc; ac = bc = cc = 0; cin >> a >> b; for (int i = 0; i < 6; i++) { if (abs(a - 1 - i) < abs(b - 1 - i)) ac++; else { if (abs(a - 1 - i) == abs(b - 1 - i)) ...
1
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; #define nmax 20 #define kmax 10 #define smax 155 int C(int n, int k, int s) { int count = 0; if( k == 0 ) { if( s == 0 ) return 1; else return 0; } for(int i = 1; i <= n; i++) { count += C(i - 1, k - 1, s - i...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 250005; using lint = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lint n, i, j; cin >> n; lint a[n][n], l[2]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } for (i = 0; i < n...
2
#include <bits/stdc++.h> using namespace std; const int MaxN = 1 << 9; const int MaxT = 1 << 18; const long long int MOD = 1000000007LL; int N, Q, Degree[MaxN]; bool Visited[MaxN]; long long int T, A[MaxN], DP[MaxT]; vector<int> E[MaxN], ReverseE[MaxN], TopSort, Coins; long long int DFS(int idx) { Visited[idx] = true...
5
#include <bits/stdc++.h> using namespace std; pair<long long, long long> f(long long a, long long b) { if (b == 1) return {1, 1 - a}; vector<long long> quo; while (b) { long long q = a / b, r = a % b; if (r) quo.push_back(q); a = b; b = r; } long long u = 1, v = -quo.back(); quo.pop_back(); ...
5
#include<stdio.h> #include<algorithm> #pragma GCC optimize("O2") #define rep(i,N) for(int i=0;i<(int)N;i++) using namespace std; const int MOD=1e9+7; static inline int IN(void) { int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x; } int main() ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 1000100; map<char, int> go[MAXN]; int len[MAXN]; int link[MAXN]; ll cnt[MAXN]; int last; int nodesCnt = 1; vector<int> vals[MAXN]; void extend(char c) { if (go[last].count(c) && len[go[last][c]] == len[last] + 1) { last = go[last...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; int n, d, first; long long arr[maxn], dp[maxn][maxn]; deque<pair<int, long long> > q[maxn]; int main() { cin >> n >> d >> first; if (n / d > first) { cout << -1 << endl; return 0; } for (int i = 1; i <= n; ++i) scanf("%lld", &arr[i...
6
#include <bits/stdc++.h> long long int mod = 1000000007; using namespace std; int palindrome[2000][2000]; long long int dp[2000]; long long int ans[2000] = {0}; string s; int pal(int x, int y) { if (x > y) { return 0; } while (x <= y) { if (s[x] == s[y]) { x++; y--; } else { return 0...
4
#include <bits/stdc++.h> using namespace std; int a[200005]; int n, t, c; class tree { private: vector<int> st; int N; public: tree(int N) { this->N = n; st.assign(4 * N, 0); build(1, 0, N - 1); cout << endl; } void build(int id, int l, int r) { if (l == r) { st[id] = a[l]; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 200005; const long long INF = 1e18; int n, x; struct Node { int l, r; long long c; int id; }; bool cmp(Node a, Node b) { if (a.l == b.l && a.id == b.id) return a.r < b.r; if (a.l == b.l) return a.id > b.id; return a.l < b.l; } long long mi[N]; vect...
3
#include <bits/stdc++.h> int main() { int a, b, l, r, i, j, k, p = 0; char c[100]; scanf("%s", c); l = strlen(c); if (l <= 20) { b = l; } else { b = 20; } a = (l - 1) / b + 1; b = (l - 1) / a + 1; r = a * b - l; printf("%d %d\n", a, b); for (j = 1; j <= a - r % a; j++) { for (i = 1; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 * 100 + 100; bool mark[maxn], WasPar[maxn]; int n, dis[maxn], a[maxn], par[maxn], ch[maxn]; vector<int> G[maxn]; void dfs(int u) { mark[u] = 1; for (int i = 0; i < G[u].size(); i++) if (!mark[G[u][i]]) { par[G[u][i]] = u; ch[u]++; ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1677721600") using namespace std; const int MAXN = 5000000 + 100; const int MAXM = 110000; const double eps = 1e-10; long long MOD = 1000000007; int phi[MAXN], rub[MAXN]; bool v[MAXN]; void phi_table(int n) { phi[1] = 0; for (int i = 2; i <= n; i++) { phi...
1
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; void solve() { int n; cin >> n; string s; cin >> s; s = '-' + s; vector<vector<int> > pref(n + 1, vector<int>(2)); for (int i = 1; i <= n; i++) { if (s[i] == 'a') { pref[i][0] = pref[i - 1][0] + 1; pref[i][1] = pref...
1
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; for(int i=(b-a)+1;i<b+a;i++) cout<<i<<' '; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; unsigned long long int k, a[200005] = {}, p[15] = {1}, z = 0; for (int i = 1; i <= 14; i++) p[i] = p[i - 1] * 10; vector<unsigned long long int> b[13] = {}; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]...
4
#include<bits/stdc++.h> using namespace std; int main(){ int n,m,s; while(1){ cin >> n >> m >> s; if(n == 0 && m == 0 && s == 0) break; int ans = 0; for(int i=s-1;i>=1;i--){ for(int j=1;j<=s-1;j++){ int x = i*(100+n)/100; int y = j*(100+n)/100; if(x+y == s) { ans = max(ans,(i*(100+m)/10...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, d = 0, c, k = 0, x = 0, i = 0, m, f = 0, j = 0, j1, sum = 0; cin >> n; cin.ignore(); while (n--) { string a, b, c1; getline(cin, a); f = a.size(); if (f > 4) { b = a.substr(0, 5); c1 = a.substr(f - 5, 5); ...
1
#include <bits/stdc++.h> using namespace std; int almostlucky(int n) { int k, a[10]; a[0] = 4; a[1] = 7; a[2] = 44; a[3] = 47; a[4] = 74; a[5] = 77; a[6] = 444; a[7] = 447; a[8] = 474; a[9] = 477; for (int i = 0; i < 10; i++) { k = n % a[i]; if (k == 0) { return 0; break; ...
1
#include <bits/stdc++.h> using namespace std; int vowel(char c) { return (c == 'a') || (c == 'e') || (c == 'i') || (c == 'u') || (c == 'o'); } char s[1000000]; string get_suf(int k) { int l = strlen(s), i, o = k; for (i = l - 1; i >= 0; i--) { if (vowel(s[i])) { if (--o == 0) { return (s + i); ...
1
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; pair<long long, long long> fib(long long N) { if (N == 1) { return {1, 1}; } if (N % 2) { pair<long long, long long> eff = fib(N - 1); return {eff.second, (eff.first + eff.second) % mod}; } else { pair<long long, long long> e...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,sse4,ssse3,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int N = 2100; int n; long long s, x[N], y[N], c[N][N]; int main() { scanf("%d %lld", &n, &s); s *= 2; for (int i = 0;...
4
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl '\n' llo dp[501*501]; llo dp2[501*501]; llo dp3[501*501]; llo mi; llo n; llo mod; llo ee(llo aa,llo bb){ if(bb==0){ ...
5
#include <bits/stdc++.h> using namespace std; long long n, a[2000][2000]; long long ans[2000]; bool check() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { if (ans[i] * ans[j] != a[i][j]) return false; } } } return true; } int main() { ios_base::sync_with_...
2
#include <bits/stdc++.h> using namespace std; int main() { string n; long long tc; scanf("%lld", &tc); while (tc--) { cin >> n; bool valid = 1; for (int i = 1; i < n.size(); i++) { if (n[i] == n[i - 1]) { valid = 1; } else { valid = 0; break; } } if ...
2
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); ; long long t; cin >> t; while (t--) { long long a, b, n, s, temp = 0; cin >> a >> b >> n >> s; temp += s % n; s -= s % n; s /= n; if (s > a) temp += n * (s - a); if (temp <= ...
1
#include<bits/stdc++.h> #define rep(i,n) for (long long i = 0; i < (n); ++i) //g++ -std=c++11 #define OFFSET 12802 using namespace std; //赤-青 //pos bool memo[85][85][25610]; long long A[85][85]; long long B[85][85]; long long H, W; int main(){ cin >> H >> W; rep(h, H) rep(w, W) cin >> A[h][w]; rep(h, H)...
0
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long long res = power(a, b / 2); long long res2 = (res * res); return (res2 * (b % 2 == 0 ? 1 : a)); } int main() { long long first, second, l, r; cin >> first >> second >>...
2
#include <bits/stdc++.h> const int maxn = 5e5 + 5; using namespace std; int main() { string s; cin >> s; int k = s.size(); char y = s[0]; for (int i = 0; i < k; i++) { if (i == 0) { cout << "Mike" << endl; continue; } if (s[i] > y) { cout << "Ann" << endl; } else { y = ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n, n) { vector<int> v(n); for (auto& i : v) cin >> i; sort(v.begin(), v.end()); int min_sub = 1 << 28; for (int i = 0; i < n - 1; i++) { min_sub = min(min_sub, v[i+1]-v[i]); ...
0
#include <bits/stdc++.h> using namespace std; long double length(long long x, long long y) { return sqrt(x * x + y * y); } int main() { long long a, b, n, x, y, v; long double d = 9e100; cin >> a >> b >> n; cout.setf(ios::fixed); cout.precision(30); for (auto i = 0; i < n; i++) { cin >> x >> y >> v; ...
1
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vpii = vector<pii>; using vpll = vector<pll>; using vs = vector<string>; const int nax = 45; int dp[nax][nax][nax][nax];...
2
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x < y ? x : y; } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; ...
6
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int &x) { char c = nc(), b = 1; for (; !(c >= '0' && c <= '9')...
5
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") const long long INF = 1e18 + 1LL; const double Pi = acos(-1.0); const int N = 1e6 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int a[N], b[N...
3
#include <bits/stdc++.h> using namespace std; void file() { freopen("halfnice.in", "r", stdin); } const int MAX = 3e5 + 1, INF = (1 << 30); int main() { int n; long long ans = 0; scanf("%d", &n); vector<int> l(n), r(n); for (int i = 0; i < n; ++i) { scanf("%d", &l[i]), scanf("%d", &r[i]); } sort(l.beg...
4
#include<bits/stdc++.h> using namespace std; #define EPS (1e-10) const double inf=1e20; struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){} Point operator + (Point p) { return Point(x+p.x,y+p.y); } Point operator - (Point p) { return Point(x-p.x,y-p.y); } Point operator * (doub...
0
#include <bits/stdc++.h> using namespace std; int n; unsigned int dp[200005]; char s[100005]; int main() { cin >> n; scanf("%s", s + 1); if (n % 2 == 1) { cout << 0; return 0; } int p = 100000, cnt = 0; dp[p] = 1; for (int i = 1; i <= n; i++) { p--; if (s[i] == '?') { int q = p + min...
5
#include <iostream> #include <string> #include <cstdlib> #include <algorithm> #include <utility> using namespace std; int main() { string s; string t; cin >>s; cin >>t; int l; l=s.size(); int sc[200]={}; int tc[200]={}; for(int i=0; i<l;i++){ sc[s[i]-97]++; tc[t[i]-97]++; } sort(sc,sc+26); sort(tc,tc+26); f...
0