solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int main() { int n; scanf("%d", &n); vector<int> v(n); for (int i = 0; i < n; i++) { scanf("%d", &v[i]); } sort(v.begin(), v.end()); n = unique(v.begin(), v.end()) - v.begin(); if (n > 3) { printf("-1\n"); } else { if (n =...
2
#include <bits/stdc++.h> long long dx[4] = {0, -1, 0, 1}; long long dy[4] = {1, 0, -1, 0}; using namespace std; class pa3 { public: long long x, y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p...
1
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long INFL = 2e18; string s; int p, v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> s; s = '~' + s; for (int i = (1), _b = (26); i <= _b; ++i) for (int j = (i + 1), _b = (27); j <= _b; ++j) if (s[i] ...
3
#include <bits/stdc++.h> using namespace std; const long long N = 1000005; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long l = 0, r =...
3
#include <bits/stdc++.h> using namespace std; int bi_search(int high, int low, long long a[], long long req) { int mid, ans = -1; while (high >= low) { mid = (high + low) / 2; if (a[mid] <= req) { low = mid + 1; ans = mid; } else { high = mid - 1; } } return ans; } int main() {...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 50005; const int MAXE = 100005; struct Node* null; struct Node { Node* c[2]; Node* f; long long cnt; long long sum; int val; int siz; int lazy; int tree_siz; inline void new_node() { sum = val = 0; c[0] = c[1] = f = null; lazy ...
5
#include <iostream> #include <algorithm> #include <string> #include <set> using namespace std; int main() { int n; while(cin >> n) { cin.ignore(); for(int I=0; I<n; I++) { string Arr; getline(cin, Arr); unsigned sz = Arr.size(); set<string> s; string tr1, tr2, ntr1, ntr2; ...
0
#include <bits/stdc++.h> using namespace std; int n, m, mins, maxs, forward; int dis[200001]; int stops[400001]; int pos[400002]; int main(int argc, char** argv) { long long int length, curlen; int k, *path, leftm, dn, diff; cin >> n; for (int i = 0; i < (n); i++) scanf("%d", &(dis[i])); cin >> m; for (int ...
5
#include <bits/stdc++.h> using namespace std; #define F first #define S second typedef pair<int,int> P; typedef pair<P,int> P2; int main() { int n,m; while(cin >> n >> m && n) { vector<P2> a; a.push_back(P2(P(0,0),-1)); a.push_back(P2(P(n,n),-1)); while(m--) { char c; int x,y; cin...
0
#include <bits/stdc++.h> using namespace std; vector<int> V[300]; int parent[300] = {-1}; int capacity[300][300] = {0}; void BFS(int current_number, int goal_number, bool is_visited[]) { queue<int> Queue; Queue.push(current_number); is_visited[current_number] = true; while (!Queue.empty()) { current_number ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, sum = 0; cin >> n >> m >> k; int a[m]; for (int j = 0; j < m; j++) { a[j] = -1; } for (int k = 0; k < n; k++) { int d, c; cin >> d >> c; if (a[d - 1] >= c) { sum = sum - a[d - 1] + c; a[d - 1] = c; } ...
1
#include <bits/stdc++.h> using namespace std; int main() { int w, h; cin>>w>>h; long long p[w], q[h]; for (int i=0; i<w; i++) cin>>p[i]; for (int i=0; i<h; i++) cin>>q[i]; sort(p, p + w); sort(q, q + h); int i = 0, j = 0; long long cost = 0; while (i < w && j < h) { if (p[i] < q[j]) { c...
0
#include<bits/stdc++.h> using namespace std; const int N=20; #define ll long long #define oo 1000000000000 ll n,a[N]; ll dp(int l,int r,int x,int y){ if(r-l<=1)return 0; ll ans=oo; for(int m=l+1;m<=r-1;++m){ ans=min(ans,dp(l,m,x,x+y)+dp(m,r,x+y,y)+(x+y)*a[m]); } return ans; } int main(){ cin>>n; for(int i=1;i<...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } return x * f; } inline ...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; bool S[100]; int main() { unsigned long long cur = 1; int n; unsigned long long m; cin >> n >> m; for (int i = 0; i < n - 2; i++) cur *= 2; vector<int> all; unsigned long long x = cur; int id = 1; while (m > 0) { if (id > n) br...
2
#include <bits/stdc++.h> using namespace std; bool check(long long n, long long pos) { return n & (1LL << pos); } long long Set(long long n, long long pos) { return n = n | (1LL << pos); } long long dist[503][503]; vector<long long> edge; long long ans[503]; bool vis[503]; void solve(long long n) { long long idx = n;...
4
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int in; cin >> in; for (int i = 0; i < in; i++) solve(); return 0; } void solve() { long long n; cin >> n; if (n < 7) cout << 15; else n ^ 2 ? cout << (++n / 2) *...
1
#include <bits/stdc++.h> using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); vector<vector<int> > g; const int MAXN = 100000; bool used[MAXN]; int timer, tin[MAXN], fup[MAXN]; int n; map<pair<int, int>, bool> A; void dfs(int v, int p = -1) { used[v] = true; tin[v] = fup[v] = timer++; for (s...
2
#include <bits/stdc++.h> using namespace std; long n, i, j = 0, l = 0, d = 1, t = 0, a[1]; int main() { cin >> n; if (n < 10) { cout << 9; return 0; } for (i = 1; i >= 0; i++) { n = n + 1; while (n % 10 == 0) { n = n / 10; } if (n == 1) a[1]++; if (t == 0) if (n < 10) { ...
1
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int dx[] = {1, 0}; const int dy[] = {0, 1}; vector<string> board(80); string memo[80][80]; int W, H; inline bool isDigit(int x, int y) { if ('0' <= board[y][x] && board[y][x] <= '9') return true; else retur...
0
#include <bits/stdc++.h> using namespace std; int n, m, h, t, r, x, y, dis[210][210], h1[210], t1[210], h2[210], t2[210], bfs[210 * 210][2], L, R; void renew(int x, int y, int v) { if (x + y > r) return; if (dis[x][y] == -1) { dis[x][y] = v; bfs[++R][0] = x; bfs[R][1] = y; } } int dfs(int x, int y...
5
#include <cstdio> using namespace std; int main() { const int MAX_H = 10; int H, board[MAX_H][5]; int res; bool updated; bool zeroseq; int seq; while(true){ scanf("%d", &H); if (H == 0) { break; } for (int i = 0;i < H;i++) { for (int j = 0;j < 5;j++) { scanf("%d", &board[i][j]); } } u...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t, n; cin >> t; for (long long i = 0; i < t; i++) { cin >> n; vector<long long> v(n, 0); long long count = 0, m = 1, h = 0, ma = 0; for (long long j = 0; j < n; j++) { cin >> v[j]; } for (long long j = 0; j < n - 1;...
3
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; vector<long long> ar(n), br(n); for (int i = 0; i < n; i++) cin >> ar[i]; sort(ar.begin(), ar.end()); if (n == 1) cout << ar[0] << endl; else if (n == 2) cout << max(ar[1] - ar[0], ar[0]...
4
#include <bits/stdc++.h> using namespace std; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T> void setmax(T& a, T b) { a = max(a, b); }; template <typename T> void setmin(T& a, T b) { a = min(a, b); }; template <typename T> bool in(T lo, T v, T hi) { return lo <=...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int te; cin >> te; long long int cg = 3; long long int ans = 1; while (cg < te) { if (te % cg != 0) { ans = te / cg; ans++; break; } else cg *= 3; } cout << ans << "\n"; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >>N; int ans=0; for(int i=1;i<=N;i+=2){ int c=0; for(int j=1;j<=sqrt(i-1);j++){ if(i%j==0)c++; } if(c==4)ans++; } cout <<ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int nxt[maxn], beg[maxn], num[maxn]; int n, k, x; int st; int fa[maxn]; int main() { cin >> n >> k; st = -1; memset(beg, -1, sizeof(beg)); memset(num, 0, sizeof(num)); for (int i = 1; i <= n; i++) { cin >> x; nxt[i] = beg[x]; ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n = 0; cin >> n; vector<pair<int, int> > array(n); for (int i = 0; i < n; ++i) { cin >> array[i].first; --array[i].first; } for (int i = 0; i < n; ++i) { cin >> array[i].second; --array[i].seco...
6
#include <bits/stdc++.h> using namespace std; long long int n, m, i, j, k = 0, T, t = 0, u, v, c = 0, d = 0, q = 0, c1, c2; long long int a[100010], df[100010]; class node { public: vector<int> near; }; node p[100010]; void bfs(int j, int c); int main() { cin >> m >> n; for (i = 0; i < n; i++) { scanf("%d %d...
4
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char c = getchar(); int p = 1; x = 0; while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ '0'); c = getchar(); } x *= p; } int main() { char str[20005];...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC push_options #pragma GCC optimize("unroll-loops") vector<vector<int>> edges; vector<long long> val; vector<long long> cost; vector<int> vis; pair<long long, pair<int, int>> dfs(long long cur, long long ashu) { if (vis[cur]) return {0, {0, 0}}; vis[cur] = 1; ...
5
#include <bits/stdc++.h> using namespace std; int n, r[17], m[17]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) cin >> m[i]; for (int i = 0; i < n; ++i) cin >> r[i]; int cnt = 0; for (int i = 1; i <= 100000; ++i) { for (int j = 0; j < n; ++j) { ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int a, x, b, y, n; int next_x(int x) { if (x == n) return 1; else return x + 1; } int next_y(int x) { if (x == 1) return n; else return x - 1; } int main() { ios::sync_with_stdio(0); cin >> n >> a >> x >> b >> y; whi...
1
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int n; vector<pair<int, int> > A, res; int dep[M], id[M], dfn, pre; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); A.push_back(make_pair(x, i * 2 - 1)); } sort(A.begin(), A.end()); reverse(A....
5
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int vis1[N], vis2[N]; vector<int> g1[N], g2[N]; set<int> s; void dfs2(int u, int p) { if (vis2[u]) return; s.insert(p); vis2[u] = p; for (int v : g2[u]) if (!vis2[v]) dfs2(v, p); } void dfs1(int u) { vis1[u] = 1; dfs2(u, u); for ...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long maxn = 1e6 + 100; const long long maxc = 20; long long n, m, k, t; vector<long long> V[maxc]; vector<long long> V1[maxc]; long long used[maxc]; long long st2[maxn]; long long ans = 0; void dfs(long long v) { used[v] = 2; for (a...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; const int MAXQ = 500; struct Query { int l, r, t, id; bool operator<(const Query &a) const { return t < a.t; } } q[MAXN]; int n, m, Q; int lb[MAXN], rb[MAXN], bl[MAXN]; struct P { int a, b, id; bool operator<(const P &x) const { if (b !=...
5
#include <bits/stdc++.h> using namespace std; long long L, R, n; int c[10], a[19], b[19]; int ret; bool check(int step, int lim) { if (step < 0) return 1; if (lim == 3) { int l = b[step], u = a[step]; if (l == u) { if (!c[l]) return 0; --c[l]; int res = check(step - 1, 3); ++c[l]; ...
3
#include <bits/stdc++.h> using namespace std; char opposite(char x) { if (x == 'N') return 'S'; if (x == 'S') return 'N'; if (x == 'W') return 'E'; if (x == 'E') return 'W'; } const int N = 1e6 + 5; char s[2 * N]; int p[2 * N]; int main() { int n; scanf("%d", &n); --n; scanf("%s\n%s", s + 1, s + n + 1);...
5
#include <bits/stdc++.h> const int maxn = 1000010, maxp = 1000000000, lim = 100000000; int n, p[2], h[1000010][2], pw[1000010][2]; char s[1000010]; bool com(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return 1; return 0; } bool chk(int i, int j) { if (i > 0 && i < j && j < n && (i == 1 || s[0] !...
6
#include <iostream> int findText(std::string text, std::string oldText){ int times = 0, pos = 0; while(pos = text.find(oldText, pos), pos != std::string::npos){ pos++, times++; } return times; } int main(){ std::string s; while(std::cin >> s, !std::cin.eof()){ std::cout << findText(s, "JOI") << std::endl; ...
0
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; int n, m, A, B, bb, tt, first[80], fa[80], num[80], sz[80], ans[80], dp[80][150000]; struct Bn { int to, next, quan; } bn[410]; struct Zt { int u, v, d; bool operator<(const Zt &u) const { return d > u.d; } }; priority_queue<Zt> pq; int ff(...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; bool b[n]; int one = 0, zero = 0; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { cin >> b[i]; if (b[i]) ++one; else ...
2
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <sstream> #include <cmath> #include <queue> using namespace std; vector<int> tree[200]; int cost[200]; int min_cost(int index){ if(tree[index].size() == 0){ return cost[index]; } int sum = 0; int siz = tree[index].size(); fo...
0
#include <bits/stdc++.h> using namespace std; int main() { short w1, w2, r; cin >> w1 >> w2; for (r = 0; w1 <= w2; r++) { w1 *= 3; w2 *= 2; } cout << r; }
1
#include <bits/stdc++.h> using namespace std; bool loop(int x) { return (x % 100 != 0 && x % 4 == 0) || (x % 400 == 0); } int main() { int y; cin >> y; bool org = loop(y); int mod = 0; do { mod = (mod + 365 + loop(y)) % 7; y++; } while (mod || loop(y) != org); cout << y << endl; }
2
#include <bits/stdc++.h> using namespace std; string s; int n; int main() { cin >> n >> s; for (int i = 1; i <= n; i++) { for (int j = 0; j < s.length(); j++) if (j + i * 4 < s.length()) if ((s[j] == '*') && (s[j + i] == '*') && (s[j + i * 2] == '*') && (s[j + i * 3] == '*') && (s[j + ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; string ans = ""; int i = 0, j = s.length() - 1; while (j - i >= 3) { if (s[i] == s[j]) ans += s[i]; else if (s[i + 1] == s[j]) ans += s[i + 1]; else ...
5
#include <bits/stdc++.h> using namespace std; long long pd[100010]; long long tot[100010]; long long inv[100010]; int main() { long long n; scanf("%I64d", &n); pd[1] = 20; tot[1] = 3 * 3 * 3; inv[1] = tot[1] - pd[1]; long long i; for (i = 2; i <= n; i++) { pd[i] = pd[i - 1] * 3 * 3 * 3; pd[i] %= 1...
2
#include <bits/stdc++.h> using namespace std; signed main(){ int n;cin>>n; if(n==1){ cout<<1<<endl<<0<<endl;return 0; } if(n==2){ cout<<2<<endl<<0<<endl<<11<<endl;return 0; } cout<<n-1<<endl; for(int i=1;i<n;i++){ cout<<1;for(int j=1;j<i;j++)cout<<0;cout<<1<<endl; } }
0
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long NOK(long long a, long long b) { long long ret = 1, v; while (v != 1) { v = GCD(a, b); ret *= v; if (a % v == 0) a /= ...
1
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long int> dp(100001, 0); vector<long long int> a(100001, 0); while (n--) { int x; cin >> x; a[x]++; } dp[0] = a[0]; dp[1] = a[1]; for (int i = 2; i < 100001; i++) { dp[i] = max(dp[i - 1], dp[i - 2] ...
1
#include <bits/stdc++.h> using namespace std; int a[2][2][200047]; struct pmin { int x; deque<int> d; deque<int> v; pmin(int x) : x(x) {} int query(int a) { v.push_back(a); while (!d.empty() && d.back() > a) d.pop_back(); d.push_back(a); if (v.size() > x + 1) { if (d.front() == v.front()...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 1e18; const int MOD = 1e9 + 7; const int MAXN = 1e3 + 5; int n, m, p; int s[10]; char g[MAXN][MAXN]; queue<pair<int, int> > nxt[10]; vector<pair<int, int> > temp; int ans[10]; int d[MAXN][MAXN]; int dr[4] = {0, 0, 1, -1}; ...
4
#include <bits/stdc++.h> using namespace std; int arr[100000 + 10]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<string> b1, b2; if (n % 2) { cout << n << endl; return 0; } else { string tmp; char ch; int ans = n; for (int i = 0; i < n; i++) { for (...
2
#include <bits/stdc++.h> using namespace std; long long int powm(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int bestresult[160][160], fulldest[160][160], pali[160][160][160], n, a[160]; string...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int main() { long long n, k, sum = 0, way = 1, old = -1; cin >> n >> k; for (int i = 0, a; i < n; i++) { cin >> a; if (a >= n - k + 1) { sum += a; if (old == -1) old = i; else { long long x = (...
3
#include <bits/stdc++.h> using namespace std; inline long long in() { long long x = 0, flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * flag; } ...
4
#include <bits/stdc++.h> using namespace std; long long tests; string s; long long n, m; void solve() { cin >> n; m = n / 2 + (n % 2); cout << m << " "; for (int i = 1; i <= m; i++) { if (m + i <= n) cout << m + i << " "; if (m - i > 0) cout << m - i << " "; } } int main() { ios_base::sync_with_stdi...
3
#include <bits/stdc++.h> using namespace std; long long int n, m, i, j, k, l, a[1000009], b[1000009], p[1000009], ans, cn, t, x, y, z, mx, mn, s, lo, hi, mid; char c[1000009], d[1000009], ch; long long int isP(long long int flor) { long long int num = n; long long int pos = 0; while (2 + pos * 3 <= num) { ...
3
#include <bits/stdc++.h> using namespace std; namespace Sakurajima_Mai { const int infi = 2e9; const long long infl = 4e18; inline int qi() { int f = 0, 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...
6
#include <bits/stdc++.h> using namespace std; void readline(char *s) { int len = 0; char c; for (c = ((char)fgetc(stdin)); c != '\n'; s[len++] = c, c = ((char)fgetc(stdin))) ; s[len] = 0; } void readstr(char *s) { int len = 0; char c; for (c = ((char)fgetc(stdin)); c != ' ' && c != '\n'; ...
2
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int b = 30; b >= 0; b--) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] & (1 << b)) > 0; } if (cnt % 2 == 0) continue; if...
4
#include <bits/stdc++.h> using namespace std; const int N = 300100; int n, q; struct point { int x, idx; point(int _x = 0, int _idx = 0) { x = _x; idx = _idx; } } M[N * 5]; int global; struct interval { int a, b, idx; interval(int _a = 0, int _b = 0, int _idx = 0) { a = _a; b = _b; idx = _...
5
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; vector<int> isPrime(20, 1); void seive(int range) { isPrime[0] = isPrime[1] = 0; for (int i = 2; i * i <= range; i++) if (isPrime[i]) for (int j = i * i; j <= range; j += i) isPrime[j] = i; } long long mod_expo(long long n, long long e...
1
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6 + 5; const int BL = 1; const int WH = -1; long long int dfs_num[N]; vector<pair<long long int, long long int> > adj[N]; long long int dfs_low[N]; long long int dfs_counter; stack<long long int> dfs_scc; set<long long int> in_stack; long long int ...
4
#include <bits/stdc++.h> using namespace std; int t, a[12], x, ans; string s; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> s; ans = 0; x = 0; for (int j = 0; j < 12; j++) if (s[j] == 'X') { a[j] = 1; x++; } else a[j] = 0; if (x) ans++; if (a...
1
#include <bits/stdc++.h> using namespace std; map<long long, int> M; vector<vector<long long> > v; int main() { int n; cin >> n; multiset<long long> m; for (int i = 0; i < n; i++) { long long x; cin >> x; m.insert(x); } while (1) { if (m.find(1) == m.end()) { break; } vector<lo...
5
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie...
5
#include <bits/stdc++.h> struct Node { int lmax, rmax, mmax, sum; Node() : lmax(0), rmax(0), mmax(INT_MIN), sum(INT_MIN) {} }; int main() { int n, m; std::cin >> n >> m; std::vector<std::vector<int> > arrays(n + 1); for (int i = 1; i <= n; ++i) { int l; std::cin >> l; arrays[i] = std::vector<int...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, up(0), co(0); cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); up += arr[0]; for (int i = 1; i < n; i++) { if (arr[i] >= up) { up += arr[i]; co++; } } cout << ++co << "\n...
4
#include <iostream> #include <queue> #include <algorithm> #include <vector> using namespace std; const int INF = 1e9; //<最小コスト, 町番号> typedef pair<int, int> P; struct edge{int to, cost;}; int c, n, m, s, dist; vector<edge> G[100]; //割引券が残りiの時のj地点における最小コスト int d[10][100]; void dijkstra(int s, int a){ priority_queue<P...
0
#include <bits/stdc++.h> using namespace std; void solve(int n) { int cnt = 0; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { if (n - i - j >= 0) { if (n - i - j <= 1000) { cnt += n - i - j + 1; } else if (n - i - j <= 2000) { cnt += 2000 - (n - i - j) + 1; } } } ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; const ll MOD = 1000000007ll; const ll INF = 0x3f3f3f3f3f3f3f3f; inline ll SUB(ll a, ll b) { return a - b >= 0ll ? a - ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); priority_queue<int, vector<int>, greater<int> > a; long long ans = 0; for (int i = 1; i <= n; i++) { long long x; scanf("%lld", &x); ans -= x; a.push(x); a.push(x); ans += a.top(); a.pop(); } pri...
4
#include <bits/stdc++.h> using namespace std; char s[101][3]; int main() { int n, i, k = 0, c1 = 0, c2 = 0; cin.get(s[0], 3); cin >> n; for (i = 1; i <= n; i++) { cin.get(); cin.get(s[i], 3); } for (i = 1; i <= n && k < 2; i++) { if (s[0][0] == s[i][1] && c1 == 0) { k++; c1 = 1; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; char num[120]; scanf("%d", &n); scanf("%s", num); if (n == 4) { printf("%c%c%c%c%c", num[0], num[1], '-', num[2], num[3]); return 0; } for (int i = 0, j = 0; i < n; i++, j++) { printf("%c", num[i]); if (j == 2 && i < n - 1 &...
2
#include <bits/stdc++.h> using namespace std; const int N = int(2e5) + 99; const int INF = int(1e9) + 99; int tc; string s, t; int nxt[N][26]; int main() { cin >> tc; while (tc--) { cin >> s >> t; for (int i = 0; i < s.size() + 5; ++i) for (int j = 0; j < 26; ++j) nxt[i][j] = INF; for (int i = int...
3
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647;...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int M = 1e9 + 7; const int INF = 0x3f3f3f3f; int n, m; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long ans = 0; long long phi(long long n) { long long res = n; for (long long i = 2; i * i <= n; i++) {...
4
#include <bits/stdc++.h> using namespace std; long long expo(long long a, long long b, long long m) { long long result = 1; while (b) { if (b & 1) { result = (result * a) % m; } b = (b >> 1) % m; a = (a * a) % m; } return result; } double expof(double a, int b) { double result = 1; whi...
1
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 5; void solve() { string s; cin >> s; long long diff = 0; for (long long i = 1; i < (long long)s.size(); i++) { if (s[i] != s[i - 1]) diff = 1; } sort((s).begin(), (s).end()); if (diff) cout << s << endl; else cout <<...
2
#include <bits/stdc++.h> using namespace std; char str[200086]; bool vi[200086]; int main() { vector<char> s; char ch; while ((ch = getchar()) != EOF) { if (s.empty() || s.back() != ch) { s.push_back(ch); } else { s.pop_back(); } } for (int i = 0; i < s.size(); i++) { putchar(s[i])...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int a[MAXN]; map<int, int> mp; int main() { int T; cin >> T; while (T--) { mp.clear(); int n; cin >> n; for (int i = 1; i <= 2 * n; i++) cin >> a[i]; int res = 0; mp[0] = 0; for (int i = 1; i <= n; i++) { if...
3
#include<bits/stdc++.h> using namespace std; char a[105]; int main(){ long long n,cnt=0; cin>>n; while(n){ n--; a[cnt++]=n%26+'a'; n/=26; } for(int i=cnt-1;i>=0;i--) cout<<a[i]; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 50; int n, k; int psum[2][N], ssum[2][N]; string str; string res[3] = {"quailty", "once again", "tokitsukaze"}; void ans(int type) { cout << res[type + 1] << endl; exit(0); } bool one_win(string str) { static int psum[2][N], ssum[2][N]; for ...
3
#include <iostream> using namespace std; int main() { int A[5][2],i,min=10,ans =0; for(i=0;i<5;i++){ cin >>A[i][0]; A[i][1]=A[i][0]%10; if((A[i][1]<min) && (A[i][1]>0)){ min = A[i][1]; }else if (A[i][1]==0){ A[i][0]-=10; } ans+=A[i][0]-A[i][1]+10; } cout << ans-10+min; return 0; }
0
#include <cstdio> int main() { int h,w,k; scanf("%d%d%d",&h,&w,&k); static char s[400][400]; static int c[400]; for(int i=0;i<h;i++){ scanf("%s",s[i]); c[i]=0; for(int j=0;j<w;j++){ c[i]+=(s[i][j]=='#'?1:0); } } static int a[400][400]; int b=1; for(int i=0;i<h;){ int k=i; ...
0
#include <bits/stdc++.h> using namespace std; inline bool comp(int A, int B) { return A > B; } int x[100010], y[100010]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); if (n > m) { printf("YES"); return 0; } for (int i = 1; i <= n; ++i) scanf("%d", &x[i]); for (int i = 1; i <= m; ++i) scanf(...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, d, ans = -1; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; if (i == 0) { c = a; d = b; } if (c > a) { c = a; ans = -1; } if (d < b) { d = b; ans = -1; } if ((a ==...
2
#include <bits/stdc++.h> using namespace std; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1000000000; const long long LINF = 1000000000000000000; const long long MOD = 1000000007; const double PI = acos(-1.0); const double EPS = 1e-10; template <class T>...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[n], lookup[n], visited[100001]; for (int i = 0; i < n; i++) visited[i] = 0; for (int i = 0; i < n; i++) cin >> arr[i]; lookup[n - 1] = 1; visited[arr[n - 1]] = 1; for (int i = n - 2; i >= 0; i--) { int temp =...
2
#include <bits/stdc++.h> #pragma GCC optimize 2 using namespace std; vector<pair<int, int> > e[200005]; bitset<200005> s[10][10]; int D[200005]; int pd[10][10][10][10]; int ans = 0, p[10], k; inline void dfs(int x) { if (x == k + 1) { ++ans; return; } for (int i = 1; i <= x; i++) { int flag = 1; i...
5
#include <bits/stdc++.h> using namespace std; bool st(const pair<int, string>& i, const pair<int, string>& j) { return (i.first < j.first); } int main() { int n; cin >> n; vector<pair<int, string>> v(n); string stat; for (int i = 0; i < n; i++) { cin >> v[i].second >> stat; if (stat == "rat") v[i].f...
1
#include <bits/stdc++.h> const int inf = int(1e9) + 7; const long long INF = 1e18; const double eps = 1e-9; using namespace std; const int maxn = int(1e5 + 10); int c[maxn]; vector<set<int>> colors(maxn); int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j; cin >> n; vector<long long> a(100005), d(100005); map<long long, long long> mp; for (i = 0; i < n; i++) { cin >> a[i]; } d[n - 1] = 1; mp[a[n - 1]]++; for (i = n - 2; i >= 0; i--) { mp[a[i]]++; if (mp[a[i]] == 1)...
3
#include<bits/stdc++.h> using namespace std; void z_algorithm(int *s,int *z,int n){ int c=0; for(int i=1;i<n;i++){ if(i+z[i-c]<c+z[c]){ z[i]=z[i-c]; }else{ int j=max(0,c+z[c]-i); while(i+j<n&&s[j]==s[i+j])j++; z[i]=j; c=i; } ...
0
#include<iostream> #include<math.h> #include<stdio.h> using namespace std; int main(){ int n; cin>>n; while(n!=0){ double s[1000]={},sum=0,a=0; for(int i=0; i<n; i++){ cin>>s[i]; sum+=s[i]; } for(int i=0; i<n; i++){ a+=((sum/n)-s[i])*((sum...
0