solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") long long arr[200005]; void solve() { long long i, j, k, l, r, m, n, a, b, c, d, x, y, z, t; cin >> n;...
5
#include <iostream> using namespace std; int main(void){ int a,b; cin>>a>>b; cout<<"a "; if(a<b)cout<<"< "; if(a>b)cout<<"> "; if(a==b)cout<<"== "; cout<<"b"<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0ULL >> 1; const int maxn = 500000; int c[maxn], cntx, cnty, N, hx[maxn], hy[maxn]; long long ans; vector<pair<int, int> > A[maxn], B[maxn], sx[maxn], sy[maxn]; vector<int> E[maxn]; struct info { int x1, y1, x2, y2; } seg[m...
4
#include <bits/stdc++.h> using namespace std; const int __ = 2e5 + 5; const int inf = 1e9 + 7; int a[__], b[__]; int main() { int n; scanf("%d", &n); int f = 1, zp = 0, fp = 0; a[0] = -inf; for (int i = (1); i <= (n); ++i) { scanf("%d", &a[i]); if (a[i] < 0) { f = -f; if (a[i] > a[fp]) fp ...
3
#include <bits/stdc++.h> bool compare(std::string& a, std::string& b) { for (int i = 0; i < a.size(); ++i) { if (i % 2) { if (std::tolower(a[i]) > std::tolower(b[i])) { return true; } if (std::tolower(a[i]) < std::tolower(b[i])) { return false; } } else { if (std:...
1
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) int main() { int w, n, i; cin >> w >> n; int num[w + 1], a[n + 1], b[n + 1]; REP(i, w) num[i] = i + 1; REP(i, n) scanf("%d,%d" ,&a[i], &b[i]); REP(i, n) swap(num[a[i] - 1], num[b[i] - 1]); REP(i, w) cout << nu...
0
#include <bits/stdc++.h> using namespace std; template <typename T = int, T _mod = 1000000007, typename U = long long> struct Minter { static constexpr int mod = _mod; T val; Minter() : val(0) {} Minter(U x) { x %= mod; if (x < 0) x += mod; val = x; } explicit operator int() const { return val; ...
3
#include <iostream> #include <vector> #include <numeric> #include <queue> #include <algorithm> #include <utility> #include <functional> using namespace std; using Flow = int; template<typename Flow = int> struct PrimalDual { struct Edge { int dst; Flow cap, cap_orig; Flow cost; in...
0
#include <bits/stdc++.h> using namespace std; int const N = 200001; int t, x, c; map<int, int> f, nxt; int find(int u) { return !nxt[u] ? u : nxt[u] = find(nxt[u]); } int main() { scanf("%d%d", &t, &x); int an = 0; while (t--) { scanf("%d", &c); long long a = (c % x) + (x * f[c % x]); ++f[c % x]; ...
4
#include <bits/stdc++.h> #define IL __inline__ __attribute__((always_inline)) #define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++ i) #define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++ i) #define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; -- i) #define REP(i, a, b) for ...
5
#include <bits/stdc++.h> using namespace std; int n, m, k, cnt, ans, mx; int d[200005] = {0}, clr[200005]; vector<vector<int> > g; pair<int, int> c[200005]; void dfs(int i, int t) { d[i] = 1; cnt++; if (c[clr[i]].second != t) { c[clr[i]].first = 1; c[clr[i]].second = t; } else c[clr[i]].first++; m...
3
#include<iostream> #include<cstdio> #define MN 1000 using namespace std; inline int read() { 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; } char c[MN+5][MN+5]; int n,m,A,B; int main() { n=read();m=read();A=read(...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Int(T &a) { bool minus = false; a = 0; char ch = getchar(); while (true) { if (ch == '-' or (ch >= '0' && ch <= '9')) break; ch = getchar(); } if (ch == '-') minus = true; else a = ch - '0'; while (true) { ...
5
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> nei = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, r, c, x, y; cin >> n >> m >> r >> c >> x >> y; vector<vector<bool>> grid(n + 1, vector<bool>(m + 1, true)); ...
4
#include <bits/stdc++.h> using namespace std; template <class T> using Graph = vector<vector<T>>; template <class T> using Maxheap = priority_queue<T>; template <class T> using Minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T, typename T1> inline T max(T a, T1 b) { if (b > a) a = b; return a...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; for (int f = 0; f < t; f++) { long long int n, k; cin >> n >> k; long long int ans = 0; if (k >= n) { ans += (k - n); } else if (n % 2 == 0) { if (k % 2 == 0) { ans = 0; } else { ...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; const int MOD = 1000003; const int N = 2e6 + 10; const ll INF = 9e18; const int M = 1010; int q1[N], q2[N], q3[N]; int cnt[N]; int ans[N]; bool used[N]; vector<pair<pair<int, int>, int> > a[N]; map<pair<int, int>, vector...
3
#include <iostream> using namespace std; int main() { int k[105][105]={0}; int n,l,a,b; cin>>n; for(int j=0;j<n;j++){ cin>>l>>a; for(int i=0;i<a;i++){ cin>>b; k[j][b-1]=1; } } for(int r=0;r<n;r++){ for(int e=0;e<n-1;e++){ cout<<k[r][e]<<" "; ...
0
#include <bits/stdc++.h> using namespace std; int i, j, a, b, cnt = 0; char temp; vector<vector<int> > x; bool is_w(pair<int, int> x1, pair<int, int> x2) { int ret_1 = 1, ret_2 = 1; for (int i = min(x1.first, x2.first); i <= max(x1.first, x2.first); ++i) { if (x[i][x1.second] == 0) { ret_1 = 0; } ...
2
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > sol; vector<bool> point; int main() { int n, m, t1, t2; scanf("%d%d", &n, &m); point.resize(n + 1); for (int i = 0; i < m; ++i) { scanf("%d%d", &t1, &t2); point[t1] = point[t2] = true; } for (int i = 1; i <= n; ++i) { if (!poi...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100020; const int maxk = 620; const int MOd = 1e9 + 7; const int K = 300; int a, b; int fail[maxn]; char ar[maxn]; int main() { scanf("%d %d", &a, &b); for (int i = 1, p = 0; i <= a; i++) { scanf(" %c", &ar[i]); while (p > 0 && ar[i] != ar[p + 1...
1
#include <bits/stdc++.h> using namespace std; long long ans[1 << 13][13][13][14]; int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N, M, Q; cin >> N >> M >> Q; if (N == 1) { cout << "1\n"; return 0; } vector<vector<int> > E(N, vector<int>(N, 0)); for (int...
5
#include <bits/stdc++.h> using namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; vector<int> b(n); for (int i = 0; i < n; i++) cin >> b[i]; vector<long long> a(n); int mx = *max_element(b.begin(), b.end()); int st = -1; for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<ll,ll>P; const int MOD=1000000007; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; int a[100][100],b[100][100]; bool dp[82][82][30000]; int dx[]{1,-1,0,0},dy[]{0,0,1,-1}; int main(){ ...
0
#include <bits/stdc++.h> using namespace std; int binpow(int a, int b) { if (b == 0) return 1; int res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } string to_upper(string a) { f...
3
#include <bits/stdc++.h> //#define MAXN using namespace std; char str[20]; int len,ans,ch; int main() { cin>>str; len=strlen(str); ans=str[0]-'0'; for(int i=1; i<len; i++) if(str[i]!='9') ch=1; if(ch && len!=1) ans-=1; printf("%d\n",(len-1)*9+ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; long long i, j, a, b, n, m, str, stra, strb, raz, k, pa = 1, pb = 1; int main() { cin >> m >> n >> a >> b; if (m % n == 0) str = m / n; else str = m / n + 1; if (a % n == 0) stra = a / n; else stra = a / n + 1; if (b % n == 0) strb = b / n; ...
3
#include<iostream> #include<cstdio> using namespace std; int main(void) { string s[10] = {"NA", "YYMM", "MMYY", "AMBIGUOUS"}; int a,b,y=0; scanf("%2d%2d" ,&a,&b); if(a>=1 && a<=12) y+=2; if(b>=1 && b<=12) y+=1; cout << s[y]; return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> g[300005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long u, v; for (int i = 0, ggdem = m; i < ggdem; ++i) { ci...
5
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long dou...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int count = 0; for (int i = 0; i < n; i++) { for (int j =...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x % y); } template <class T> inline T mod(T x) { if (x < 0) return -x; else return x; } const int MOD = 1e9 + 7; const int INF = 1e9; const int MAX = 1e3 + 5; int b[MAX], w[MAX], s[M...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, k, i, q, x, y; cin >> q; for (i = 0; i < q; i++) { cin >> k >> n >> a >> b; if ((k - b * n) % (a - b) == 0) x = (k - b * n) / (a - b) - 1; else x = (k - b * n) / (a - b); if (x < 0 || b * n >= k) cout <...
3
#include <bits/stdc++.h> using namespace std; int n, k, v[2 * 100000 + 10], aint[4 * 100000 + 10], l[100000 + 10], ans[100000 + 10]; void update(int poz, int val) { poz = poz + k - 1; aint[poz] = val; poz /= 2; while (poz) { aint[poz] = min(aint[2 * poz], aint[2 * poz + 1]); poz /= 2; } } int quer...
5
#include<iostream> #include<iomanip> #include<cmath> int const MAXN = 50; int x[MAXN], y[MAXN], N; int main() { std::cin >> N; double cx = 0.0, cy = 0.0; for(int i = 0; i < N; ++i) { std::cin >> x[i] >> y[i]; cx += x[i]; cy += y[i]; } cx /= N; cy /= N; double ans2; for(double lr=0.1; lr > 1e-9...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> years(n); for (auto i = 0; i < n; i++) cin >> years[i]; sort(begin(years), end(years)); cout << years[n / 2] << endl; }
1
#include <bits/stdc++.h> using namespace std; int x1, x2; int a, b; int mod; int is_reversed; int main() { scanf("%d %d %d %d", &x1, &x2, &a, &b); if (x1 > x2) { int tmp; is_reversed = 1; x1 = -x1; x2 = -x2; tmp = a; a = -b; b = -tmp; } if (a <= x2 - x1 && x2 - x1 <= b) { puts("F...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a; cin >> n >> k; a = k*pow((k-1),(n-1)); cout << a << endl; }
0
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); cout<<a[n/2]-a[(n/2)-1]; return 0; }
0
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> smash; int iwo[100005 + 10]; int main() { int n, m, k; long long ans = 0; cin >> n >> m >> k; for (int i = (1); i < (n + 1); i++) { int omg; cin >> omg; smash[omg] = i; iwo[i] = omg; } for (int i = (0); i < (m); i++) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e5; vector<pair<int, int> > g[N + 100]; vector<int> ans; int d[N + 100], vis[N + 100]; int dfs(int u) { vis[u] = 1; int now = 0; for (auto it : g[u]) { if (!vis[it.first]) { int f = dfs(it.first); if (f) ans.push_back(it.second); n...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> tree[n + 1]; for (int i = 2; i <= n; i++) { int p; cin >> p; tree[p].push_back(i); } bool is_spruce = true; for (int i = 1; i <= n; i++) { if (tree[i...
2
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf("%d", &T); while (T--) { int a, b, i; scanf("%d%d", &a, &b); for (i = 1; i <= a; i++) { printf("%c", 'a' + i % b); } printf("\n"); } return 0; }
1
#include <bits/stdc++.h> using namespace std; int k, n; long long b; pair<int, int> a[100010]; int pos[100010]; int main() { cin >> n >> k >> b; for (int i = 0; i < n - 1; i++) { cin >> a[i].first; a[i].second = i; } sort(a, a + n, greater<pair<int, int> >()); for (int i = 0; i < n - 1; i++) pos[a[i]....
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 600005, INF = 1000000000; int N, K, a[MAXN]; vector<int> V[MAXN]; char S[MAXN]; int fa[MAXN], val[MAXN], ans; int get(int x) { if (fa[x] != x) fa[x] = get(fa[x]); return fa[x]; } void merge(int x, int y) { x = get(x), y = get(y); if (x != y) fa[y] =...
3
#include <bits/stdc++.h> using namespace std; const int N = 205; int id[N][N], n, m, t, mo; int fa[N * N], rn[N * N], t1; int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); } int ty[N][N]; long long c[N][N], cnt, ans; int fail; void merge(int x, int y) { if (gf(x) == gf(y)) fail = 1; fa[gf(x)] = gf(y); } lo...
6
#include <bits/stdc++.h> using namespace std; char a[105][105]; char b[10005]; int whose[10005]; int share[105]; int ans[105][105]; int main(void) { int T; scanf("%d", &T); for (int t = 0; t < T; t++) { int r, c, k; scanf("%d %d %d", &r, &c, &k); int rice = 0; for (int i = 0; i < r; i++) { s...
4
#include <bits/stdc++.h> using namespace std; const int N = 400005; map<int, int> mp; int n, T; int add[N]; int L[N], R[N]; int main() { memset(add, 0, sizeof(add)); cin >> n >> T; set<int> st; mp.clear(); for (int i = 1; i <= n; i++) { int num; scanf("%d", &num); int l = max(0, num - i), r = T - ...
4
#include <bits/stdc++.h> using namespace std; vector<long long> beauty(2100, 0), weight(2100, 0); vector<long long> b; vector<vector<long long> > a(2100, b); vector<vector<long long> > gr(2001); vector<long long> ccc(2101, 0); vector<vector<long long> > dp(2101, ccc); long long w, n, m; vector<long long> group(2100, 0)...
4
#include <bits/stdc++.h> using namespace std; struct Contest { int tasks; int penalty; }; int n, place, answer; vector<Contest> command; bool compare(Contest x, Contest y) { if (x.tasks == y.tasks) { return (x.penalty < y.penalty); } return x.tasks > y.tasks; } int main() { scanf("%d %d", &n, &place); ...
1
#include <bits/stdc++.h> using namespace std; void fastInOut(); const int N = 1e5 + 5; int main() { fastInOut(); string s; cin >> s; int ver_c = 0, hor_c = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') { cout << "1 " << ver_c + 1 << "\n"; ver_c = (ver_c + 1) % 4; } else { ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 300030; const int inf = 0x3f3f3f3f; int n, x, y; int pre[maxn]; bool vis[maxn], xoy[maxn]; vector<int> mp[maxn]; void init() { cin >> n >> x >> y; memset(vis, false, sizeof(vis)); memset(xoy, false, sizeof(xoy)); memset(pre, -1, sizeof(pre)); int ...
3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long powm(long long base, long long exp, long long mod = 1000000007) { base %= mod; long long ans = 1; while (exp) { if (exp & 1LL) ans = (ans * base) % mod; exp >...
2
#include <bits/stdc++.h> using namespace std; const int N = 200; int n, e, idx[N], low[N], T; vector<vector<int> > g; vector<int> S; bool vis[N]; int compID[N], compH[N], cmp; void DFS(int u) { idx[u] = low[u] = ++T; S.push_back(u); vis[u] = true; for (int i = 0; i < g[u].size(); ++i) { int v = g[u][i]; ...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; for (int i = 0; i < n - 1; i++) cout << 4 << ' '; cout << 1 << endl; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int t; cin >> t; while (t > 0) { t--; solve(); } }
1
#include <bits/stdc++.h> using namespace std; const int N = 100010; vector<int> g[N]; vector<int> vec; int n, root; int dist[N], fa[N], ans[N], h[N], son[N]; bool mark[N]; void dfs1(int u, int f) { dist[u] = dist[f] + 1; if (dist[u] > dist[root]) root = u; for (auto v : g[u]) { if (v != f) { dfs1(v, u);...
2
#include <bits/stdc++.h> const int kMaxv = (int)5e6 + 10, kMaxe = (int)6e6 + 10; typedef int IntArr[kMaxv]; struct Edge { int to, next; } E[kMaxe]; int n, m, d, totscc, dfs_clock, top, tote; IntArr dfn, low, last, val, sumv, col, DP, S; std::pair<int, int> E0[kMaxe]; char IN[60]; inline void Umin(int& x, int y) { x >...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string st; cin >> st; int k = 0; vector<int> res; for (int i = 0; i < n; ++i) { if (st[i] == 'B') k++; else { if (k > 0) res.push_back(k); k = 0; } } if (k > 0) res.push_back(k); if (res.empty()...
1
#include <bits/stdc++.h> int main() { int n, i; n = 1000; printf("%d\n", n * 2); for (i = 1; i <= n; i++) { printf("%d 1 %d 2\n", i, i); } for (i = n; i > 0; i--) { printf("%d 1 %d 2\n", i, i); } }
4
#include <bits/stdc++.h> using namespace std; int n, tmp[51], h[100001], tag[100001], rr = 0, a1, a2, sv[100001]; long long s[100001], all, ans[100001], sh = 0; vector<int> Ed[100001]; pair<int, int> W[100001], E[100001]; long long DFS(int now, int cent) { if (tag[now] == rr) return 0; tag[now] = rr; all += s[now...
4
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; int sum[10000001]; int main(){ int n;scanf("%d",&n); rep(i,n){ int h;scanf("%d",&h); sum[h]++; } for(int i=9999999;i>=0;i--)sum[i]+=sum[i+1]; ll cnt=1; int a=4; for(int i=1;i<=10000000;i++){ cnt+=min(...
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(V) (V).begin(),(V).end() #define MOD 1000000007 #define mod 998244353 ll rw1[100010], rw2[100010]; int main(){ for (int i = 0;i < 100010;i++)rw1[i] = rw2[i] = 0; ll N, M, a, b, ans = 0; cin >> N >> M; cin >> a; for (int i = 1;i < N;i+...
0
#include <bits/stdc++.h> using namespace std; int main() { char a[9]; for (int i = 0; i < 9; i++) cin >> a[i]; if (a[0] == a[8] && a[1] == a[7] && a[2] == a[6] && a[3] == a[5]) cout << "YES"; else cout << "NO"; return 0; }
1
#include <bits/stdc++.h> using namespace std; set<int> intersection(set<int> a, set<int> b) { set<int> c; for (int i : a) { if (b.find(i) != b.end()) c.insert(i); } return c; } void solveFunction() { int n, m; cin >> n >> m; vector<pair<int, int> > edges; set<int> s[n + 1]; for (int i = 0; i < m; ...
4
#include <bits/stdc++.h> using namespace std; char buf[1000]; struct Node { int ne[26]; int ecnt; Node() { memset(ne, -1, sizeof ne); ecnt = 0; } int& operator[](int x) { return ne[x]; } }; const int INF = 2e9 + 2e6; int main() { int n, k; while (scanf("%d%d", &n, &k) >= 1) { vector<string> ss...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2048; const long long MOD = 1000000007; bool visited[MAXN][MAXN]; long long cache[MAXN][MAXN]; long long factorial[MAXN]; void factorial_init() { factorial[0] = 1; for (int i = 1; i < MAXN; i++) { factorial[i] = (factorial[i - 1] * i) % MOD; } } l...
3
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wmissing-declarations" multiset<int> have; long long sum; int cnt = 0; int main() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); int q; cin >> q; long long cur = -1; while (q--) { int t; cin >> t; ...
5
#include <stdio.h> #define _USE_MATH_DEFINES #include <math.h> int main(void){ int n , i , buf; float x1,x2,x3,y1,y2,y3,a1,a2,b1,b2,c1,c2,xp,yp,r; scanf("%d" , &n); for(i=1;i<=n;i++){ scanf("%f %f %f %f %f %f" , &x1 , &y1 , &x2 , &y2 , &x3 , &y3); a1 = 2 * (x2 - x1); b1 = 2 * (y2 - y1); c1 = x1 * x1 - x2 *...
0
#include<bits/stdc++.h> using namespace std; int main() { int f,q,x; string s; map<string,int>m; cin>>q; while(q--){ cin>>f; if(f==0){ cin>>s; cin>>x; m[s]=x; } else{ cin>>s; cout<<m[s]<<endl; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b, i; cin >> a >> b; bool flag = 0; long long int max1 = max(a, b); long long int p = a + b; if (p % 2) flag = 1; max1 = 2 * max1; long long int ans = max1 - p; long long ...
2
#include <bits/stdc++.h> using namespace std; char s1[110], s2[110], v[110]; int l1, l2, l3, go[110][110]; int f(int x, char y) { string s = ""; for (int i = 0; i <= x; i++) s += v[i]; s += y; for (int i = l3; i > 0; i--) { int st2 = (int)s.length() - i; if (st2 < 0) continue; bool ok = 1; for (...
2
#include <bits/stdc++.h> using namespace std; const int LIM = 1e5 + 5, MOD = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long fastpowMOD(long long a, long long p, long long MOD) { if (p == 0) return 1; long long z = fastpowMOD(a, p / 2, MOD); z = (z * ...
4
// ๆš—ๅทๅŒ–ใฏใ€ๅ…ฅๅŠ›ใ•ใ‚ŒใŸ้ †็•ชใซใ‚นใƒฏใƒƒใƒ—ๆ“ไฝœใ‚’ใ—ใŸใ‚‚ใฎใจใ™ใ‚‹ใ€€โ†ใ‚(ๅฏŸใ— #include<iostream> #include<cstdio> #include<string> #include<cstdlib> #include<algorithm> using namespace std; int main(){ string message; int n,a[111],b[111],c; while(1){ cin >> n; if(n==0)break; cin >> message; for(int i=0;i<n;i++){ cin >> a[i] >> b[i]...
0
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> string print_iterable(T1 begin_iter, T2 end_iter, int counter) { bool done_something = false; stringstream res; res << "["; for (; begin_iter != end_iter and counter; ++begin_iter) { done_something = true; counter--; r...
4
#include <bits/stdc++.h> using namespace std; const long long maxn = 1 << 8; long long dep[maxn], vis[maxn], c1[maxn], c2[maxn], c3[maxn], c[maxn], s[maxn], up[maxn]; long long h; void Try(long long x, long long from) { if (vis[x]) return; cout << "? " << x << endl; fflush(stdout); cin >> s[x]; vis[x] = 1...
6
#include <bits/stdc++.h> using namespace std; int n, mx[((int)1e5 + 5)], chi; string s; char ch; int main() { cin >> s; n = s.size(); s = '0' + s; for (int i = n; i >= 1; i--) { if (s[i] >= ch) { ch = s[i]; chi = i; } mx[i] = chi; } int i = 1; while (i != n + 1) { cout << s[mx[...
1
#include <bits/stdc++.h> using namespace std; long long int n, p[300007], a[300007]; vector<pair<long long int, long long int>> v; void s(long long int x, long long int y) { swap(a[x], a[y]); swap(p[a[x]], p[a[y]]); v.push_back({x, y}); return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin ...
3
#include <bits/stdc++.h> using namespace std; int n; vector<int> vv[201]; int computer[201], in[201], bk[201], temp[201]; int bfs(int st) { queue<int> q; int ans = n; for (int i = 1; i <= n; i++) { if (in[i] == 0) q.push(i); } while (!q.empty()) { memset(bk, 0, sizeof(bk)); while (!q.empty()) { ...
1
#include <bits/stdc++.h> using namespace std; int n; vector<int> a, dp; int main() { ios_base::sync_with_stdio(false); cin >> n; a.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; } dp.assign(n, 0); for (int i = 0; i < n; ++i) { if (a[i] > 0) dp[a[i]] = max(dp[a[i]], 1 + dp[...
3
#include <bits/stdc++.h> using namespace std; const int kN = 2e5 + 10; int n; int a[kN]; int id[kN]; set<int> s; int le[30][kN], ri[30][kN]; int L[kN], R[kN]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int j = 0; j < 30; j++) { int cur = 0; for (int i = 1; i <= n; ...
4
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; int n; long long t[100100], x[100100]; long long cp[100100], tt[100100]; bool isbet(long long a, long long x, long long y) { if (a >= x && a <= y) return true; if (a >= y && a <= x) return t...
3
#include "bits/stdc++.h" using namespace std; void solve() { long H, W, N; cin >> H >> W >> N; map<long, int> cnt; while(N--) { long h, w; cin >> h >> w; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { long y = h - i - 1, x = w - j - 1; if (0 <= x && x + 2 < W && 0 <= y && y + 2 < H) ...
0
#include <bits/stdc++.h> using namespace std; string s; map<string, int> mp; int n; void FileInit() { { freopen( "" ".inp", "r", stdin); freopen( "" ".out", "w", stdout); }; } void FileDebug() { { freopen( "" ".inp", "r", stdin); ...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3fffffff; const int maxn = 100000 + 10; int n; int color[maxn]; struct edge { int next, to; } e[2 * maxn]; int head[maxn]; int cnt; void insert(int x, int y) { e[++cnt].to = y, e[cnt].next = head[x], head[x] = cnt; e[++cnt].to = x, e[cnt].next = head...
1
#include <iostream> #include <stdio.h> using namespace std; int main() { char w[9][9],e[5]="URDL"; int x=0,y=0,h=1,i,g; int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0}; for (i=0;i<9;i++) gets(w[i]); while(true) { h=(h+3) % 4; for (i=0;i<4;i++) { if (y+dy[h]>=0 && y+dy[h]<=4 && x+dx[h]>=0 && x+dx[h]<=4) { ...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 2e7 + 5; const long double PI = 3.14159265358979323846; const long double EPS = 1e-10; const int MOD = 12345; const int MOD2 = 23456; const int N = 3000 + 10; const int M = 1e5 + 10; using namespace std; vector<int> z; int n; int main() { cin >> n; ...
2
#include <bits/stdc++.h> using namespace std; long long n, rs; string s; deque<pair<long long, long long>> q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; cin >> s; q.push_back({0, 0}); for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) { ...
2
#include <bits/stdc++.h> int main() { int n, d, i; int ans = 0; int a[2005]; scanf("%d%d", &n, &d); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 1; i < n; i++) { if (a[i] < a[i - 1]) { ans += (1 + (a[i - 1] - a[i]) / d); a[i] += (1 + (a[i - 1] - a[i]) / d) * d; } if...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXBOX = 100010; const int BLEN = 400; int d[MAXN]; long long h[2 * MAXN], ps[2 * MAXN]; long long mxDec[MAXBOX], mxAdd[MAXBOX], inside[MAXBOX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ...
3
#include <bits/stdc++.h> using namespace std; int t[300001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int b = n; cout << "1 "; for (int i = 1; i <= n; i++) { int a; cin >> a; t[a] = 1; while (t[b]) b--; cout << i - (n - b) + 1 << " "; } retu...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; const int MN = 5000; const int ML = MN/2; ll dp[2][MN][MN]; ll tp[MN]; ll bd[2][MN]; ll M; int main() { ll n; cin >> n >> M; memset(dp,0,sizeof(dp)); int cu = 0; for(int i=0;i<n;i++) { ll x = i; ll y = n-i-1; bd[cu]...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long f[2000010]; long long inv[2000010]; long long invf[2000010]; inline int comb(int n, int k) { if (k < 0 || k > n) return 0; return f[n] * invf[k] % mod * invf[n - k] % mod; } long long dp[2000010]; int a[10]; int easy(int n, int k) {...
3
#include <bits/stdc++.h> using namespace std; int n; int p[300]; int main() { int i, k, j, l; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (i = 0; i < 2 * n; i++) { cin >> p[i]; } n *= 2; int result = 200000000; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<pair<int, int>> v(n); vector<tuple<int, int, int>> line; for (int i = 0; i < n; i++) { auto& [l,...
4
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { int t; cin>>t; while(t--) { int n; cin>>n; vector <pair<int,int>> arr(n); for(int i = 0; i < n; i++) { cin>>arr[i].first; arr[i].second = i; } ...
5
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double pi = acos(-1); const long long int INF = 1e18; const int inf = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int n, arr[nax], fail[nax]; int main() { ios::sync_with_stdio(0); int n, cnt; cin >> n >> cnt; string s; ...
2
#include <bits/stdc++.h> using namespace std; void solve() { int m, n; scanf("%d", &m); ; scanf("%d", &n); ; double x = m, y = m, z, temp = 0, sum = 0, ans = 0; x = 1 / x; y = 1 / y; for (int i = 1; i <= m; i++) { z = i; temp = pow(x, n); temp -= sum; sum += temp; ans = ans + z * t...
3
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); std::ios::sync_with_stdio(false); long long x, y; cin >> x >> y; if (!y && x != 1) { cout << "No solution" << endl; return 0; } cout << y; for (int i = 0; i < x - 1; i++) { cout << 0; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; multimap<int, int> m; int zo = 1e5; int flag = -1; for (int i = 0; i < n; i++) { int a; cin >> a; m.insert({a, i + 1}); } map<int, vector<int>> b; int i = 1; for (; i <= k; i++) { if ((--m.end())->fir...
2
#include <bits/stdc++.h> #include <cmath> using namespace std; int main() { string S; cin>>S; cout<<S[0]<<S[1]<<S[2]; }
0