solution
stringlengths
52
181k
difficulty
int64
0
6
#include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> using namespace std; const long long mod=1000000...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; long long int k; cin >> n >> k; if (k % 2 != 0) cout << 1; else { long long int p = pow(2, n); p = p / 2; while (k != p) { if (k > p) { k = k - p; } p = p / 2; } cout << (log(p) / log(2)) + 1; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t, n, key, pos = 0, negative = 0; cin >> t; n = t; while (t--) { cin >> key; if (key > 0) pos++; else if (key < 0) negative++; } if ((n + 1) / 2 <= pos) cout << 1 << endl; else if ((n + 1) / 2 <= negative) cout ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 200009; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; vector<int> longest(n + 1), shortest(n + 1); int pos = 0, cur = n; ...
4
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int N = 2005; int m, d; int n; char a[N], b[N]; int mem[N][N][2]; int add(int a, int b) { int ret = a + b; if (ret >= mod) ret -= mod; return ret; } int sub(int a, int b) { int ret = a - b; if (ret < 0) ret += mod; return ret;...
4
#include <bits/stdc++.h> using namespace std; char a[2000002], b[2000002], s[2000002]; int n, m, i, j, k, nxt[2000002], match[2000002], ex[2000002]; int main() { cin.getline(a + 1, 2000002); cin.getline(b + 1, 2000002); n = strlen(a + 1); m = strlen(b + 1); if (n != m) { puts("-1 -1"); return 0; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n; cin >> n; cout << n << endl; for (long long i = 1; i <= n; i++) { cout << 1; if (i < n) cout << " "; else cout << endl; } }
1
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k, m, mid; cin >> n >> k; long long int l = -1, r = n + 1; while ((l + 1) < r) { mid = (l + r) / 2; long long int sum = mid, p = 1; while (mid / p) { p = p * k; m = (mid / p); sum = sum + m; } if ...
2
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-11; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } const int MAXN = 250...
3
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
2
#include <algorithm> #include <cctype> #include <cstring> #include <cstdio> #define add(x, y) x = x+y<P?x+y:x+y-P using namespace std; inline int read(int f = 1, int x = 0, char ch = ' ') { while(!isdigit(ch = getchar())) if(ch == '-') f = -1; while(isdigit(ch)) x = x*10+ch-'0', ch = getchar(); return f*x; ...
0
#include <bits/stdc++.h> using namespace std; long long a[200001], b[200001]; int fail[200001], n, m; void getfail() { int i, j; fail[0] = 0; for (i = 1, j = 0; i < m; i++) { while (j > 0 && b[j] != b[i]) { j = fail[j - 1]; } if (b[i] == b[j]) j++; fail[i] = j; } } int getans() { int ans...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } const int maxn = 3e5 + 7; con...
4
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD=1e9+7; int main() { ll t1,t2,a1,a2,b1,b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; if(a1*t1+a2*t2==b1*t1+b2*t2) { cout<<"infinity"; return 0; } ll c1=(a1-b1)*t1,c2=(a2-b2)*t2; if(c1>=0&&c2>=0) { c...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; std::vector<int> v(2 * n); for (int i = 0; i < 2 * n; i++) cin >> v[i]; sort(v.begin(), v.end()); if (v[n] == v[n - 1]) cout << "NO\n"; else cout << "YES\n"; }
1
#include <bits/stdc++.h> using namespace std; long long solve(long long x) { long long sum = 0, i; for (i = 1; i <= x; i++) { if (i % 2) sum += (x + 1) / 2; else sum += (x / 2); } return sum; } int main() { long long i, x, low, high, mid, j, k, l, m, n, ans = 1e6; cin >> x; if (x == 3)...
3
#include <bits/stdc++.h> using namespace std; string a; int main() { int n,k; cin>>n>>k; int h=0; cin>>a; for(int i=0;i<n;i++){ if(a[i]=='L' and i!=0) {if(a[i-1]=='L') h++;} if(a[i]=='R' and i!=n-1){if(a[i+1]=='R') h++;} } cout<<min(n-1,h+2*k); }
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") const int L = 1e6; char buf[L], *bs, *bt; char fr() { if (bs == bt) { bt = (bs = buf) + fread(buf, 1, L, stdin); if ...
5
#include <bits/stdc++.h> using namespace std; const int INF=1e9+9; int dp[1<<12]; int main() { int n,m; cin>>n>>m; for(int i=1;i<(1<<n);i++) dp[i]=INF; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; int mask=0; for(int j=0;j<b;j++){ int c; cin>>c; c--; ...
0
#include <bits/stdc++.h> int main() { char a[1001], b[1001]; scanf("%s", a); scanf("%s", b); int na = strlen(a), nb = strlen(b); int ka = 0, kb = 0; for (int i = 0; i < na; i++) if (a[i] == '1') ka++; for (int i = 0; i < nb; i++) if (b[i] == '1') kb++; if (ka % 2 == 1) ka++; if (kb <= ka) ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000000; char s[N], tmp[N], p[N]; int main() { int n; scanf("%d", &n); int l = 0; s[l++] = '<'; s[l++] = '3'; for (int i = (0); i <= (int(n) - 1); i++) { scanf("%s", tmp); int m = strlen(tmp); for (int j = (0); j <= (int(m) - 1); j++) s...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long len = s.length(); long long a[len + 1], b[len + 1]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (long long i = 0; i < len; i++) { if (s[i] == ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T,class U> using P = pair<T,U>; template<class T> using vec = vector<T>; template<class T> using vvec = vector<vec<T>>; constexpr int inf = 1e9+1; int ma[4][2010][2010] = {}; int mi[4][2010][2010] = {}; int exist[4][2010] = {}; int A[4]...
0
#include <bits/stdc++.h> using namespace std; void fastio() { cin.tie(nullptr); cin.sync_with_stdio(false); } using LL = long long; using LD = long double; const LL MOD = 1e9+7; const LL INF = LLONG_MAX; const LL N = 3e5+1; #define S second #define F first #define vt vector LL sgn (LL x) { if (x == 0) return 0...
4
#include<iostream> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; int main(){ int x,y; while(1){ cin>>x>>y; if(!(x||y))break; int status[y][x],dp[y][x]; rep(i,y){ rep(j,x){ cin>>status[i][j]; } } int sum=0; rep(i,y){ rep(j,x){ if(i==0 && stat...
0
#include <bits/stdc++.h> using namespace std; int n; vector<int> res; vector<int> s, t; map<int, char> mapa; void process(string a, string b) { vector<queue<int> > v(26); for (int i = 0; i < a.size(); i++) { s.push_back(i); mapa[i] = a[i]; v[a[i] - 'a'].push(i); } for (int i = 0; i < b.size(); i++) ...
5
#include <bits/stdc++.h> using namespace std; inline void splay(long long &v) { v = 0; char c = 0; long long 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; } long long a...
5
#include <bits/stdc++.h> using namespace std; vector<pair<long long, pair<long long, long long>>> adj1; vector<pair<long long, long long>> adj2[200005]; map<long long, long long> dist; map<long long, bool> vis; set<long long> s; void init() { for (auto it = s.begin(); it != s.end(); ++it) { vis[*it] = false; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < (int)s.length() - 1; i++) { if (s[i + 1] != s[i]) { s = s.erase(i, 2); i = max(i - 2, -1); } } std::cout << s.length() << std::endl; return 0; }
1
#include "bits/stdc++.h" #define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i) using namespace std; using i64 = int_fast64_t; template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);} template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string check; cin >> check; map<int, int> mindex; int ret = 0; mindex[0] = -1; vector<int> bal(n); bal[0] = (check[0] == '1' ? 1 : -1); mindex[bal[0]] = 0; for (int i = 1; i < n; i++) { bal[i] = bal[i - 1] + (check[i] ...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { long long a, b; while (cin >> a >> b) { long long ans; ans = a * (a + 1) / 2; ans %= mod; ans *= b; ans %= mod; ans += a; ans %= mod; ans *= (b * (b - 1) / 2) % mod; ans %= mod; cout << ans <<...
1
#include <bits/stdc++.h> const int MAXN = 1e5 + 10; int n; int s[MAXN]; namespace solver1 { int seq[MAXN]; bool cmp(int a, int b) { return s[a] > s[b]; } void main() { for (int i = 1; i <= n; i++) seq[i] = i; std::sort(seq + 1, seq + n + 1, cmp); int ans = 0; std::set<int> add; add.insert(seq[1]); for (int ...
2
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { int d, v, l, r; cin >> d >> v >> l >> r; int lat = d / v; cout << lat - (r / v) + ((l - 1) / v) << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; long long int n = min(a, b); long long int m = max(a, b); if ((n + m) % 3 == 0 && n * 2 >= m) { cout << "YES" << endl; } else { cout << "NO" << endl; ...
2
#include<iostream> #include<string> using namespace std; int main() { string s[3]; cin >> s[0] >> s[1] >> s[2]; int n[3] = {}, now = 0; while (1) { if (n[now] == s[now].size()) { cout << (char)('A' + now) << endl; return 0; } n[now]++; now = s[now][n[now] - 1] - 'a'; } }
0
#include <bits/stdc++.h> using namespace std; long long int fen[200005]; void upd(long long int x, long long int a) { for (long long int i = x; i < 200005; i += (i & (-i))) { fen[i] += a; } } long long int ret(long long int x) { long long int o = 0; for (long long int i = x; i > 0; i -= (i & (-i))) { o ...
4
#include <bits/stdc++.h> using namespace std; int n; double arr[110]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); reverse(arr, arr + n); double ret = arr[0], bad = 1 - arr[0]; for (int i = 1; i < n; i++) { if (ret >= bad) break; ret += arr[i] * (bad - ret); ...
2
#include <bits/stdc++.h> #pragma optimize("-O3") using namespace std; const long long mod = 998244353; string s, a, b; int k, n; char tem[30], teminv[30]; char c = char('a' - 2); void no() { cout << "NO" << '\n'; } void yes() { cout << "YES" << '\n'; } void calc() { yes(); for (int i = (int)0; i != (int)k; i = i + ...
5
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a...
0
#include <bits/stdc++.h> using namespace std; using vint = vector<long long>; using vvint = vector<vint>; using pint = pair<long long, long long>; using vpint = vector<pint>; template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double PI = 3.141592653589793238462643383279...
5
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; const int maxn = 1e5 + 10; int n, d, a[maxn]; double f[maxn][15]; PII pre[maxn][15]; int num[maxn][15]; int idx, ans[maxn]; int main() { cin >> n >> d; for(int i = 0; i <= 9; ++ i) f[0][i] = -1e9, pre[0][i] = {-1,-1}; for(int i = 1; i...
4
#include <iostream> #include <vector> using namespace std; int main(){ while(1){ string str; cin >> str; if(str=="#") break; vector<int> seq(str.length()); for(int i=0; i<(int)str.length(); i++){ seq[i] = (str[i]-'0'+2)%3; } int leg=-1; int count=0; for(int i=1; i<(int)str...
0
#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; template <typename T> inline bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } inline void read(int &x) { char ch = getchar(); int f = 1; x = 0; while (ch < '0' || ch > '9...
2
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int> > v[100005]; vector<pair<int, int> > t[100005]; void init() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); v[x].emplace_back(y, i); t[y].emplace_back(x, i); } } int deg[100005]; ...
4
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; i64 MOD = 1e9 + 7; i64 solve(){ i64 n; cin >> n; if(!n) return MOD; vector<i64> a(n + 1); for(auto& x : a) cin >> x; for(int j = 0; j <= n; ++j){ vector<int> b; for(int i = 0; i <= n; +...
0
#include <bits/stdc++.h> using namespace std; long long calculate(int x, int y, int m) { long long ans = 0; for (int i = 1; i <= x; i++) { for (int j = 1; j <= y; j++) { int c = i * i + j * j; if (c % m == 0) { ans++; } } } return ans; } long long cal2(int m, int n) { long lo...
2
#include <iostream> using namespace std; int main(){ int h,w; cin >> h >> w; int r[h+1][w+1]; int n; cin >> n; int a[n+1]; int color=1; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(i%2==1) r[i][j]=color; else r[i][w-j+1]=color; a[color]--; ...
0
#include<iostream> using namespace std; int main(){ int a,i,sum; sum = 0; cin >> a; for(i=0;i<6;i++){ sum += a%10; a = a/10; } if(sum == 1) sum = 10; cout << sum << "\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 75; bool visit[MAXN][MAXN][MAXN]; int n, ans[MAXN][MAXN][MAXN], p1[MAXN][MAXN][MAXN], p2[MAXN][MAXN][MAXN], p3[MAXN][MAXN][MAXN], fr[MAXN][MAXN][MAXN], to[MAXN][MAXN][MAXN], vf1, vf2, vf3, l1 = -1, l2, l3; string s[MAXN]; void vist(int x1, int x2, i...
4
#include<bits/stdc++.h> #define int long long int using namespace std; const int INF = 3e18; const int MOD = 1e9 + 7; int n, a, b, s[100010]; queue<int> qx, qy; int dpx[100010], dpy[100010]; signed main() { cin >> n >> a >> b; for(int i = 1; i <= n; i++) cin >> s[i]; s[0] = -INF, s[n + 1] = INF, dpx[0] = ...
0
#include "bits/stdc++.h" #define ll long long using namespace std; void solve() { int n, k; cin >> n >> k; vector<vector<int>> a(n, vector<int>(2)); bool sw = 1; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; for(int i = 0; i < n; i++) { bool flag = 0; for (int ...
2
#include <bits/stdc++.h> using namespace std; long long int d[2000]; long long int visited[2000] = {0}; int main() { long long int x = 0, t, s, n, y, i, src, m, x2, y2; cin >> t >> s >> x; if (x < t) { cout << "NO"; return 0; } if (((x - t) % s == 0) || ((x - t - 1) % s == 0 && (x - t - 1) != 0)) ...
1
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; int N; vector<int> id; vector<int> weight; vector<int> dist; double cost(int from, int to, int bit) { double w = 0; for(int i = 0; i < N; i++) { if(bit & (1 << i)) w += weight[i]; } return abs(dist[f...
0
#include <bits/stdc++.h> using namespace std; int Test, len; long long ans; long long q[5000010], qs[5000010]; int fs[5000010], l2[5000010]; int f[5000010], p[5000010]; class rec { public: int len; long long sum; int a[1000010], s[1000010]; void Read(bool); } N, M, S; void rec ::Read(bool flag) { len = 0; ...
3
#include <iostream> #include <cstdlib> #include <string> using namespace std; void solve() { int sum = 0; string str; while(cin >> str) { int n = str.size(); for(int i = 0; i < n; ++i) { string s; if('0' <= str[i] && str[i] <= '9') { while(i < n && '0' <= str[i] && str[i] <= '9') { s +...
0
#include <bits/stdc++.h> using namespace std; vector<long double> ar(5); double a, b, c; double manhattan_distance(double x1, double y1, double x2, double y2) { return abs(x1 - x2) + abs(y1 - y2); } double get_x(int y) { return (-b * y - c) / a; } double get_y(int x) { return (-a * x - c) / b; } double ro(double ax, ...
1
#include <bits/stdc++.h> using namespace std; #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define _rep(i,n) _repl(i,0,n) #define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int N, K; cin >> N >> K; vector<bool> bad(N, false); auto Ask = [&](int x) { cout << "? " << x + 1 << endl; char ans; cin >> ans; if (ans == 'Y') bad[x] = true; }; auto Reset = [&]() { cout << "R" ...
4
#include <bits/stdc++.h> using namespace std; int main() { char name[101]; int i, j, count = 0; cin >> name; for (i = 0; name[i] != '\0'; i++) { if (name[i] != '1') { for (j = i + 1; name[j] != '\0'; j++) if (name[j] == name[i]) name[j] = '1'; } } for (i = 0; name[i] != '\0'; i++) ...
1
#include <bits/stdc++.h> using namespace std; int n,m,ans; int main(){ while(1){ char s[1000004]; cin >> n; ans = 0; if(n == 0)break; cin >> m; scanf("%s",s); int ren=0; for(int i = 0;i < m-2;i++){ if(s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I'){ ren++; i++; }else{ ans += max(ren - n + 1,0); ...
0
#include <bits/stdc++.h> using namespace std; long long n, k, a[400005]; string s; list<long long> q[27]; signed main() { scanf("%lld%lld", &n, &k); cin >> s; for (long long i = 1; i <= n; i++) { q[s[i - 1] - 'a'].push_back(i); } for (long long i = 1; i <= k; i++) { for (long long j = 0; j < 26; j++) ...
3
#include <bits/stdc++.h> #define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define rep(i,n) rep2(i,0,n) using namespace std; using ll = long long; int main(){ int n; cin >> n; vector<int> p(n+1),inv_p(n+1); rep2(i,1,n+1)cin >> p[i]; rep2(i,1,n+1)inv_p[p[i]]=i; multiset<int> s; s.emplace...
0
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(),(c).end() #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++) #define rep(i,n) REP(i,0,n) #define iter(c) __typeof((c).begin()) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) #def...
0
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define pb emplace_back typedef long long ll; typedef pair<ll,ll> pint; int a[100001]; vector<int> v; int main(){ int n; cin>>n; rep(i,n) cin>>a[i]; int cnt=1; rep(i,n-1){ ...
0
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); pair<long double, long double> intersect(long double x, long double y, long double r, long double x1, long double y1, long double r1) { long double dist = sq...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 10; char s[1005][1005]; int vis[1005][1005]; int speed[maxn]; struct Node { int x, y; int steps; } node[maxn]; queue<Node> q[maxn]; int num[maxn]; long long int k = 0; int n, m, p; bool ok(Node b) { int x = b.x, y = b.y; if (x < 0 || x >= n || y < 0...
4
#include <iostream> using namespace std; int main() { string s; cin >> s; cout << s.substr(0, 3) << endl; }
0
#include <iostream> #include <vector> #include <queue> #include <utility> #include <algorithm> using namespace std; typedef long long ll; typedef pair<ll,ll> P; ll n,m,s,t,u,v,a,b; ll Cy[100010],Cs[100010]; ll have = 1e15,inf = 1e18; vector<vector<P>> Y(100010),S(100010); int main(){ cin >> n >> m >> s >> t; for(int...
0
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(a, b % a); } class ST { private: int st[400013]; int size; int left(int w) { return w << 1; } int right(int w) { return (w << 1) + 1; } int queryI(int w, int L, int R, int a, in...
6
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 6; const long long MOD = 1e9 + 7; bool comparator(long long i, long long j) { return (i < j); } long long power(long long x, long long i) { long long ans = 1; while (i > 0) { if (i & 1) ans = (ans * x) % MOD; i >>= 1; x = (x * x)...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, q; while (cin >> n >> q) { map<int, pair<char, long long> > mp; mp[0] = make_pair('U', 0); mp[n + 1] = make_pair('L', 0); for (int i = 0; i < q; i++) { long long x, y; char c; scanf("%I64d%I64d %c", &x, &y, &c)...
3
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(a) (a).begin(),(a).end() #define EQ(a,b) (abs((a)-(b))<EPS) #define fs first #define sc second using namespace std; typedef double D; typedef pair<int,int> P; typedef pair<P,P> L; typedef pair<D,int> pdi; const D EPS = 1e-8; inline D fu...
0
#include<iostream> using namespace std; int main(){ int a,b; while(cin>>a>>b,a|b){ int c[10]={},hit=0,blow=0; for(int i=0;i<4;i++){ if(a%10==b%10)hit++; c[a%10] |= 1; c[b%10] |= 2; a/=10; b/=10; } for(int i=0;i<10;i++){ if(c[i]==3)blow++; } blow -= hit; cout<<hit<<' '<<blow<<endl; }...
0
#include <cstdlib> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void){ int d; int n,m; int a,b; long long int ans=0; while(1){ cin >> d; if(d==0)break; ans=0; vector<int> data; data.push_back(0); cin >> n; cin >> m; for(a=0;a<n-1;a++){ scanf("%d"...
0
#include <bits/stdc++.h> using namespace std; const double PI = atan(1.0) * 4; const int64_t INF = 100000000000000003; const int32_t LOG = 21; const int BIG = pow(2, 20); const int N = 100005; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n, m, k; cin >> n >> m >> k; if (...
3
#include<cstdio> int main(void){ int x,y; scanf("%d%d",&x,&y); if(x>y)x--; printf("%d\n",x); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, k, q; set<int, greater<int> > st; set<int, greater<int> >::iterator it; int a[160000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> q; for (int i = 1; i <= n; i++) cin >> a[i]; while (q--) { int type, id; cin >> type >> id; ...
2
#include <cstdio> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); long long ans; if (n <= k) { ans = n-1; } else { ans = 0; for (int i=0;i<n-1;i++) { ans += ans/(k-1) + 1; } } printf("%lld\n", ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; int b, n, o, ox, r, x, w, N[1001], O[1001], P[1001]; vector<int> W; int main() { scanf("%d %d", &n, &x); for (int i = 1; i <= n; i++) { scanf("%d", P + i); N[P[i]] = i; } for (int i = 1; i <= n; i++) { if (P[i]) continue; O[o] = 1; b = i; whi...
2
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #incl...
0
#include <bits/stdc++.h> using namespace std; int n; char mat[40][40]; int dp[42][1 << 20]; int add(int x, int y) { if (mat[x][y] == 'a') return 1; if (mat[x][y] == 'b') return -1; return 0; } inline int solve(int diagonala, int masca) { if (dp[diagonala][masca] != -1) return dp[diagonala][masca]; if (diagona...
4
#include <bits/stdc++.h> using namespace std; int A[2][500005]; string S[2]; void Z(int x){ A[x][0] = S[x].size(); int i=1,j=0; while(i<S[x].size()){ while(i+j<S[x].size() && S[x][j]==S[x][i+j])j++; A[x][i]=j; if(j==0){ i++; continue; } int k = 1; while(i+k<S[x].size() && k+A[x][k]<j) A[x][i+k]=A[x][k...
0
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-12; const int INF = 1e9 + 10; template <typename T> inline void UpdateMax(T& x, T v) { x = max(x, v); } template <typename T> inline void UpdateMin(T& x, T v) { x = min(x, v); } template <typename T> using MinPQ = priority_queue<T, vector<T>, great...
5
#include <bits/stdc++.h> using namespace std; int par[30], siz[30]; int getPar(int u) { return par[u] == u ? u : par[u] = getPar(par[u]); } vector<pair<char, char> > vec; int main() { int n; cin >> n; string s, t; cin >> s >> t; for (int i = 1; i <= 26; ++i) par[i] = i, siz[i] = 1; for (int i = 0; i < n; ++...
4
#include <bits/stdc++.h> using namespace std; long long n, a, c, b, skrng; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; a = 1; b = 1; skrng = 0; while (a + b <= n) { c = a; a = b; b = c + b; skrng++; } cout << skrng << '\n'; return 0; }
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epo...
6
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x...
2
#include <bits/stdc++.h> using namespace std; int main() { int n,x1,y1,z1,x2,y2,z2; cin >> n >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; int ans=1<<29; for(int i=0; i<4; i++) { for(int j=0; j<4; j++) { for(int k=0; k<4; k++) { int a[3]={0,1,2}; do { int x=x1,y=y1,z=z1,d=0; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const long long inf = 0x3f3f3f3f; int dp[N]; int dfs(int x) { if (x == 0) return 0; if (dp[x] + 1) return dp[x]; int t = x; int &ret = dp[x]; ret = inf; while (t) { if (t % 10) ret = min(ret, dfs(x - t % 10) + 1); t /= 10; } re...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (int)(1e9 + 1e6); const long long LINF = (long long)(4e18); const double EPS = 1e-9; const long long mod = 1e9 + 7; mt19937 ggen; int main(int argc, char* argv[]) { int a[] = {4, 8, 15, 16, 23, 42}; map<int, pa...
2
#import<iostream> int main(){int K,n,i=-1,j,k;std::cin>>K;std::cout<<(n=(K+3)/4*2);while(++i<n){std::cout<<'\n';j=-1;while(++j<n)std::cout<<((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1<<' ';}return 0;}
0
#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<iostream> using namespace std; int main() { int a,b,c,A,B,C,d,e,f,i,n; for(i=0;i<3;i++){ cin>>a>>b>>c>>A>>B>>C; n=(3600*A+60*B+C)-(3600*a+60*b+c); d=n/3600; e=(n-3600*d)/60; f=n-(3600*d+60*e); cout<<d<<' '<<e<<' '<<f<<'\n'; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const unsigned long long int INF = 1 << 29; const unsigned long long int mod = 1e9 + 7; unsigned long long int f1(unsigned long long int n) { unsigned long long int counts = 0; while (n > 0) { n = n / 2; counts++; } return counts - 1; } unsigned long long in...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 100000 + 10; const long long mod = 998244353; int a[maxn], b[maxn], vis[maxn]; vector<int> vec[maxn], dan; set<int> st[maxn]; int tot = 0; int main() { int n; scanf("%d", &n); fo...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int cnt[maxn], in[maxn]; vector<int> G[maxn]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= 2 * k; i++) { int x; scanf("%d", &x); cnt[x] = 1; } for (int i = 1; i <= n - 1; i++) { int u, v; scanf("%d...
2
#include <bits/stdc++.h> using namespace std; int a[(int)3e5]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = n; i > 0; i /= 2) { for (int j = 0; j < n; j += i) { bool f = 1; for (int z = j + 1; z < j + i; z++) if (a[z] < a[z - 1]) f = 0; ...
1
#include <bits/stdc++.h> int used[10], ans[10], n, k; int nums[10][10], min = 1000000000; void recurse(int); int main(void) { scanf("%d %d\n", &n, &k); int i, j, tmp; for (i = 0; i < n; ++i) { scanf("%d", &tmp); for (j = k - 1; j >= 0; --j) { nums[i][j] = tmp % 10; tmp /= 10; } } recur...
2