solution
stringlengths
52
181k
difficulty
int64
0
6
#include<bits/stdc++.h> using namespace std; void fail(){ cout<<"No"<<endl; exit(0); } int a[100001]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m=0,s=0; cin>>n; for(int i=1;i<=n;i++) cin>>a[i],m=max(m,a[i]); for(int i=1;i<=n;i++) if(a[i]<m-1) fail(); else if(m-1==a[i]) s++; if(s...
0
#include <bits/stdc++.h> using namespace std; inline long double min(long double a, long double b) { if (a < b) return a; return b; } inline long double max(long double a, long double b) { if (a < b) return b; return a; } vector<string> split(string s, string c) { unsigned long pos2 = s.find(c); unsigned lo...
3
#include <bits/stdc++.h> using namespace std; int menor[100010], maior[100010]; int main() { int n, m; int i; int rig, lef; scanf("%d %d", &n, &m); if (m == 0) { printf("%d\n", n - 1); return 0; } for (i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); if (b < a) { int temp =...
2
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; struct node { int first, second; bool operator<(const node& a) const { return first > a.first || (first == a.first && second < a.second); } }; multiset<node> s; int main() { int i, j, k, m, n; while (~scanf("%d%d", &n, &m)) { s...
3
#include <bits/stdc++.h> const int N = 2097155; char s[N], t[N]; int n, cnt[N], all; unsigned long long a[N], b[N]; int main() { scanf("%d%s%s", &n, s, t); all = (1 << n); for (register int i = 1; i <= all - 1; i++) cnt[i] = cnt[i >> 1] + (i & 1); for (register int i = 0; i <= all - 1; i++) a[i] = (1LL * s[...
5
#include <bits/stdc++.h> using namespace std; const int N = 100005; const double PI = acos(-1); using ll = long long; struct Node { double x; int id; } b[N * 2]; struct Pair { int x, y; } c[N]; double x[N], y[N], dis[N], s[N]; int t[N * 2], n; ll kk; inline int lowbit(int x) { return x & -x; } void add(int x, int...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, ans = 0, i; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } ans = abs(a[0]); for (i = 0; i < n - 1; i++) { ans = ans + abs(a[i] - a[i + 1]); } cout << ans; }
2
#include <cmath> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <unordered_set> using namespace std; typedef unsigned long long ull; const static ull P = 107; signed main(void) { string s1, s2; cin >> s1 >> s2; int len1 = s1.length(); ...
0
#include <bits/stdc++.h> using namespace std; const int kMaxn = 50 + 5; const int kInf = 0x1f1f1f1f; int s[kMaxn], z[kMaxn], f[kMaxn]; int a[kMaxn]; bool vis[kMaxn]; int Min; void Count(int i, int pos, int m, char c) { if (c >= '0' && c <= '9') s[i] = min(min(s[i], pos), min(s[i], m - pos)); if (c >= 'a' && c <= 'z...
3
#include <bits/stdc++.h> using namespace std; int main() { int W; cin >> W >> W; string a, b(W + 2, '#'); for (cout << b << endl; cin >> a; cout << '#' << a << "#\n"); cout << b; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int hh, mm; cin >> hh >> mm; cout << 24 * 60 - hh * 60 - mm << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int x, y; int row[100003], col[100003]; bool counted[100003]; bool flag = false; int counter, rows, cols, counter2; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { scanf("%d %d", &x, &y); row[x] = 1; col[y] = 1; } for (int i = 2; i ...
2
#include <bits/stdc++.h> using namespace std; const long long N = 1e9 + 7; char arr[51][51]; long long vis[51][51]; long long flag; long long n, m, k; long long dx[] = {0, 0, 1, -1}; long long dy[] = {1, -1, 0, 0}; long long isValid(long long x, long long y) { if (x < 0 || y < 0 || x >= n || y >= m || vis[x][y] != 0 ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; map<char, int> cnt; for (auto i : str) ++cnt[i]; for (auto i : cnt) { for (int j = 0; j < i.second; ++j) cout << i.first; } cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long NMAX = 110; int N, K, S; vector<long long> V; long long Fib[NMAX], Sum[NMAX]; int main() { scanf("%I64d %i", &S, &K); Fib[1] = Sum[1] = N = 1; for (int i = 2;; ++i) { Fib[i] = Sum[i - 1] - Sum[max(0, i - K - 1)]; if (Fib[i] > 1LL * S) break; ...
2
#include <bits/stdc++.h> using namespace std; long long a00, a01, a10, a11; int main() { scanf("%lld%lld%lld%lld", &a00, &a01, &a10, &a11); long long n = 1; while (n <= 1000000) { if (a00 + a01 + a10 + a11 == n * (n - 1) / 2) break; else n++; } if (n > 1000000) { printf("Impossible"); ...
2
#include <bits/stdc++.h> using namespace std; inline int readINT() { register int x = 0, ch = getchar(), f = 1; while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } int q; int n; int h[201], ans, a[201]; inline void ...
1
#include <bits/stdc++.h> using namespace std; int a, b, c, d[1000005], i, j, k, ans; int main() { cin >> a >> b >> c; for (i = 1; i <= 1e6; i++) for (j = i; j <= 1e6; j += i) d[j]++; for (i = 1; i <= a; i++) for (j = 1; j <= b; j++) for (k = 1; k <= c; k++) ans += d[i * j * k]; cout << ans; }
5
#include <bits/stdc++.h> using namespace std; const unsigned long long magic = 1e9 + 7; int main() { char s[2005]; char s1[2005]; char s2[2005]; scanf("%s", &s); scanf("%s", &s1); scanf("%s", &s2); int sz = strlen(s); int sz1 = strlen(s1); int sz2 = strlen(s2); unsigned long long t1 = 0, t2 = 0; u...
2
#include <iostream> using namespace std; int main(void){ long int n,m,d; double ans,a,b; cin >> n>>m>>d; a = (double)n; b = (double)m; if (d == 0){ ans = (b-1)/a; } else{ ans = (b-1)*2*(a-d)/(a*a); } printf("%.10f\n",ans); }
0
#include<bits/stdc++.h> using namespace std; #define ll long long int n; ll f[3010][3010],a[3010]; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%lld",&a[i]); f[i][i]=a[i]; } for (int l=1;l<n;l++) { for (int i=1;i+l<=n;i++) { int j=i+l; f[i][j]=max(a[i]-f[i+1][j],a[j]-f[i][j-1]); } ...
0
#include <bits/stdc++.h> using namespace std; long long counts[32]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int tmp, count = 0; cin >> tmp; for (int j = 1; j < tmp; j *= 2) { if ((tmp & j) == j) { count++; } } counts[count]++; } long long res = 0; ...
2
#include <bits/stdc++.h> using namespace std; const long long N = 505; long long n, d[N][N], x[N], a[N], dist[N][N]; void upd(long long &a, long long b) { if (b < a) a = b; } int main() { cin >> n; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= n; j++) cin >> d[i][j], dist[i][j] = 1ll << 60; ...
4
#include <bits/stdc++.h> using namespace std; int a, b, n, k, s = -1e9; int main() { cin >> n >> k; while (n--) { cin >> a >> b; if (k < b) { a -= b - k; } s = max(s, a); } cout << s << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e6 + 100; int t, m, n, k, tmo, ty, ans; multiset<int> st; bool mark[Maxn]; vector<int> nei[Maxn]; void dfs(int v) { mark[v] = true, t++; for (int u : nei[v]) if (!mark[u]) dfs(u); } void dfs_all() { for (int i = 0; i < n; i++) { if (!mark[i])...
4
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
4
#include <bits/stdc++.h> using namespace std; int d, s; int dp[6100][610]; int mul[6100 * 610]; bool used[6100][610]; int len; int xx[6100 * 610], yy[6100 * 610]; void out(int x, int y) { if (dp[x][y] == 0) return; bool Find = false; for (int i = 0; i < 10 && i <= x && !Find; i++) { if (dp[x - i][(((y - mul[d...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int alphabet = 26; const int MAXINT = 1e5 + 1; int n, m, a, b; vector<int> G[MAXINT], test; bool visit[MAXINT] = {}; priority_queue<int, vector<int>, greater<int>> pq; void dfs(int node, int vis) { if (vis <= n) { cout << node << " ";...
4
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int n; scanf("%d", &n); int i; if (n % 2 != 0) { printf("-1\n"); } else { if (n > 2) { for (i = 1; i <= n - 2; i++) { printf("%d ", i + 1); printf("%d ", i); i++; } } printf("%d ", n); printf("%...
1
#include <bits/stdc++.h> using namespace std; const int N = 1 << 18; inline long long f(int k) { return 1ll * k * (k - 1) / 2; } int n, q; vector<int> t[2 * N]; int idxRange(int i, int d, int u) { int resu = upper_bound(t[i].begin(), t[i].end(), u) - t[i].begin(); int resd = lower_bound(t[i].begin(), t[i].end(), d)...
5
#include <bits/stdc++.h> using namespace std; struct DisjointSet { DisjointSet(int n) { pre.assign(n + 1, 0); for (int i = 0; i <= n; i++) { pre[i] = i; } } vector<int> pre; int find(int u) { return pre[u] == u ? pre[u] : pre[u] = find(pre[u]); } void Union(int u, int v) { pre[find(u)] = fin...
6
#include <bits/stdc++.h> using namespace std; namespace io { const int SI = 1 << 21 | 1; char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; int f, t; inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } inline void pc(char x) { *OS++ = x; if (OS == OT) flush(); } template <class I> ...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s = "00" + s; int l = s.length(); int count = 0; for (int i = l - 1; i >= 0; i--) { if (s[i] == '1') { if (s[i - 1] == '1') { while (s[i] == '1') { s[i] = '0'; i--; } s[i] = '...
5
#include <bits/stdc++.h> using namespace std; int main() { long long d, k, a, b, t; cin >> d >> k >> a >> b >> t; if (k >= d) { cout << a * d; return 0; } long long ans = 0LL; if (a * k + t > b * k) { ans += a * k; d -= k; ans += d * b; } else { ans += a * k * (d / k) + (d / k - 1L...
4
#include <bits/stdc++.h> using namespace std; int main() { int hh, mm, h, d, c, n; cin >> hh >> mm; cin >> h >> d >> c >> n; float a; if (h % n == 0) a = (h / n) * c; else a = (h / n + 1) * c; float b; int tim = hh * 60 + mm; if (tim <= 1200) { h += (1200 - tim) * d; float rate = (floa...
1
#include<cstdio> int main() { int A,B,C; scanf("%d%d%d", &A,&B,&C); int Ans = 0; while(Ans < 99) { if(A&1 || B&1 || C&1) break; int D=B+C, E=A+C, F=A+B; A=D/2, B=E/2, C=F/2; ++Ans; } printf("%d", Ans<99?Ans:-1); return 0; } //
0
#include <bits/stdc++.h> #pragma GCC optimize("03") using namespace std; const int maxn = (int)1e5 + 13; const long long INFL = 9223372036854775807; const int INF = 2147483646; const long long MOD = 1e9 + 7; const long long base = 31; long long sum(long long a, long long b) { return (a + b) % MOD; } long long dp[maxn][...
3
#include <bits/stdc++.h> using namespace std; void solve() { long long b, w; cin >> b >> w; long long x = min(b, w); long long y = max(b, w); if (y > (3 * x + 1)) { cout << "NO" << endl; return; } cout << "YES" << endl; long long add = 0; if (y == b) add = 1; for (long long i = 1; i <= (2 * ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, flag = 0; cin >> n; int a[n]; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i != j && (abs(a[i] - a[j]) % 2...
1
#include <bits/stdc++.h> using namespace std; int a[101]; int main() { long int i, n, c; while (cin >> n) { c = 0; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) c++; } for (i = 0; i < n; i++) { if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1) c++; } cout << c << end...
1
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b == 0) ? a : gcd(b, a % b); } template <class T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } using namespace std; vector<long long> L; map<long long, bool> mapa; void go(long long now) { if (now > 1000000000LL) return;...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (k > ((n - 1) / 2)) { cout << "-1"; return 0; } cout << (n * k) << "\n"; for (int j = 1; j <= n; j++) { for (int i = j; i <= j + k - 1; i++) { cout << j << " " << (i) % n + 1 << "\n"; } } return ...
3
#include <bits/stdc++.h> using namespace std; struct Floor { int X, Y; } Edge[15]; struct Floor2 { int X, Y, Z; } A[105]; int N, M, Q; long long DP[15][1000005]; bool Map[15][15]; int QP(int B, int K, int Mod) { int Ans = 1; for (; K; K >>= 1, B = B * B % Mod) if (K & 1) Ans = Ans * B % Mod; return Ans % ...
5
#include <bits/stdc++.h> using namespace std; void test_case() { int n; cin >> n; vector<pair<int, int> > vote(n + 1); priority_queue<int, vector<int>, greater<int> > q; for (int i = int(1); i < int(n + 1); i++) { int m, p; cin >> m >> p; vote[i] = {m, p}; } sort(vote.begin(), vote.end()); i...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long m = n; int cnt = 0; while (m) { cnt++; m /= 10; } int ans = 0; long long a = 0; for (int i = 1; i < cnt; i++) { a *= 10; a += 9; } ans += max(0, (cnt - 1) * 9); long long b = n - a; whil...
2
#include <bits/stdc++.h> using namespace std; int main() { int i, n, arr[1000]; cin >> n; int cnt = 0; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] % 2 == 0) cnt++; } int loc = 0; if (cnt == n - 1) { for (i = 0; i < n; i++) { if (arr[i] % 2 == 1) { loc = i + 1; bre...
1
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; struct point { int x, y; point() {} point(int x1, int y1) { x = x1; y = y1; } double getAng() const { double a = atan2(y, x); if (a < 0...
3
#include <bits/stdc++.h> using namespace std; string s1, s2, t1, t2; int n; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); cin >> s1 >> s2; cin >> n; for (int i = 1; i <= n; i++) { cout << s1 << " " << s2 << "\n"; cin >> t1 >> t2; if (s1 == t1) s1 = t2; e...
1
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); } template<class T, class... Args> void assign(V<T>& v, int n, const Args&...
0
#include <bits/stdc++.h> inline int in(); inline void wr(int); const int N = (int)1e2 + 5; int a[N][N]; std::vector<std::pair<int, int> > v[N * 10]; int main(int argc, char** argv) { register int T = in(); while (T--) { register int n = in(), m = in(); for (register int i = 1; i <= n; ++i) for (regist...
1
#include <bits/stdc++.h> using namespace std; long long dp[(1 << 18) + 3]; int ans[18]; int flag[18]; int pre[20]; int main() { int n, m; long long y; scanf("%d%lld%d", &n, &y, &m); int a, b; for (int i = 1; i <= m; i++) { scanf("%d%d", &a, &b); pre[b] |= 1 << (a - 1); } y -= 2001; for (int i = ...
3
#include <bits/stdc++.h> using namespace std; void add(int &x, int y) { x = x + y < 1000000007 ? x + y : x + y - 1000000007; } int dp[2][405][405]; int main() { int n, m, x; scanf("%d%d%d", &n, &m, &x); if (n > m) return puts("0"), 0; dp[0][0][0] = 1; for (int i = 1; i <= m; i++) for (int l = 0; l <= n; l...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; long long fac[MAXN], pwr[MAXN], pwm[MAXN]; long long pw(long long a, long long b) { long long ret = 1; while (b > ...
4
#include <bits/stdc++.h> using namespace std; long long bin_pow(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long t = bin_pow(a, b / 2); return t * t % 1000000007; } else return a * bin_pow(a, b - 1) % 1000000007; } long long dp[101][101], dp1[101][101]; int main() { ios:...
2
#include <bits/stdc++.h> using namespace std; string s, s1 = "AEIOUYaeiouy"; int main() { getline(cin, s); for (int j = s.size() - 1; j >= 0; --j) { if (s[j] == '?' || s[j] == ' ') s.pop_back(); else break; } for (int j = 0; j < s1.size(); ++j) if (s[s.size() - 1] == s1[j]) { print...
1
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define what_is(x) cerr << #x << " is " << x << endl; int main() { ll n, k; cin>>n>>k; map<ll, ll> mp; for(int i=0;i<n;i++) { string s; cin>>s; mp[s[0]-'A'] ++; } map<ll, ll>::iterator it; vector<ll> v; for(it = mp....
0
#include <iostream> #include <algorithm> using namespace std; #define REP(i,n,m) for(int i=n;i<m;i++) #define rep(i,n) REP(i,0,n) int n,m; int t[102],s[102]; int sumT,sumS; void solve(){ int ti=0,si=0; while(ti < n && si < m){ int swapT = sumT - t[ti] + s[si]; int swapS = sumS - s[si] + t[ti]; if(sw...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 5; vector<int> G[maxn]; int visited[maxn]; int n; int ans; void dfs(int u, int deep) { visited[u] = 1; if (deep == 2) { ans++; return; } for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (!visited[v]) { dfs(v, d...
6
#include <bits/stdc++.h> using namespace std; inline void swap(int &x, int &y) { int tmp = x; x = y; y = tmp; } int a[100001]; int main() { int n, n1, n2; cin >> n >> n1 >> n2; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); double sum1 = 0; double sum2 = 0; if (n1 > n2) sw...
2
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define ...
6
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); vector<long long> nums; void gener(long long x) { if (x > 90000000000) return; long long x1 = x * 10 + 4; if (x1 < 90000000000) { nums.push_back(x1); gener(x1); } x1 = x * 10 + 7; if (x1 < 90000000000) { nums.push_back(x...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; const int NAX = 2e5 + 5, MOD = 1000000007; const ll INF = 1e18; struct Node { long long val; int idx; Node(long long one = 0, int id = -1) : val(one), idx(id) {} Node lazylazyMerge(const Node &rhs) { Node a = *this; a.val = (a.val + rhs...
6
#include <bits/stdc++.h> using namespace std; int arr[100]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j == i) continue; for (int k = 0; k < n; k++) { if (k == j || k == i) continue; if ...
1
#include <bits/stdc++.h> using ll = long long; using namespace std; map<char, char> matching{ {'(', ')'}, {'[', ']'}, }; void Solve(string &str) { int n = str.length(); vector<int> valid(n, false); stack<pair<char, int>> stk; for (int i = 0; i < n; i++) { if (str[i] == '(' || str[i] == '[') { ...
3
#include<bits/stdc++.h> using namespace std; int main(){ int n,sum=0,sqsum=0; cin >> n; int a[n]; for(int i=0;i<n;i++){ cin >> a[i]; sum+=a[i]; sqsum+=a[i]*a[i]; } cout << (sum*sum-sqsum)/2 << endl; }
0
#include <bits/stdc++.h> using namespace std; struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } } _io; using ll = long long; using db = long double; using pi = pair<int, int>; using mi = map<int, int>; const int N = 3e5 + 5, M = 998244353; using vi = vector<int>; ll ri() { ll x; cin >> x; re...
2
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265359; const long long int Maxi = 1e18; long long cr[100000]; vector<long long> v[10005]; long long b[100005]; long long a[100005] = {0}; long long k = 0; void dfs(long long x) { if (a[x] != b[x]) k++; a[x] = b[x]; for (long long i = 0; i < v...
2
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 10, mod = 1e9 + 7; int fail[N], tl, sl, sz, ev[N]; long long dp[2][N], acc[N], ans; char s[N], t[N]; void kmp() { int i, j; fail[0] = j = -1; for (i = 1; i < tl; i++) { while (~j && t[i] != t[j + 1]) j = fail[j]; if (t[i] == t[j + 1]) j++; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 20004, MOD = 1000000007; int f[N]; int power(int x, int y) { int res = 1; while (y > 0) { if (y & 1) { res = (res * 1ll * x) % MOD; } x = (x * 1ll * x) % MOD; y /= 2; } return res; } int c(int n, int r) { return f[n] * 1ll * pow...
1
#include <bits/stdc++.h> using namespace std; int main() { int y, b, r; cin >> y >> b >> r; int m = std::min({y, b, r}); if (m == r) cout << r + (r - 1) + (r - 2); else if (m == b) cout << (b - 1) + b + (b + 1); else { if (y + 2 > r) cout << r + (r - 1) + (r - 2); else cout << y ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x, ans = 0; cin >> n >> k; int place[n]; for (int i = 0; i < n; i++) cin >> place[i]; while (place[0] != k) { for (int i = 0; i < n - 1; i++) if (place[i + 1] > place[i] && place[i] < k) place[i]++; if (place[n - 1] < k) place[...
2
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adjList; bool visited[100]; void dfs(int node) { if (visited[node]) return; visited[node] = true; for (int i = 0; i < adjList[node].size(); i++) dfs(adjList[node][i]); } int main() { int nodes, vertices; cin >> nodes >> vertices; adjList = ve...
2
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("-O3") using ld = long double; const long long int mod = 1000000007; const long long int inf = 1000000000000000000; const long long int rk = 256; const ld PI = 3.141592653589793; ostream& operator<<(ostream& os, pair<long long int, long long int> const&...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N]; int main() { int n; long long sum = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum += a[i] - 1; if (sum % 2 == 1) printf("1\n"); else printf("2\n"); } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k; cin >> n; long long a[n + 1]; map<long long, long long> mp1; for (i = 1; i <= n; ++i) { cin >> a[i]; mp1[a[i]]++; } map<long long, long long> mp; long long ans = 0; for (i = 1; i <= n; ++i) { mp1[a[i]]--; ...
3
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long M = 1e7 + 19; long long Max(long long a, long long b) { if (a > b) return a; return b; } long long Min(long long a, long long b) { if (a > b) return b; return a; } long long big_mul(long long a, long long b, long long m)...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; const double EPS = 1e-8; const double PI = acos(-1.0); const int dx[] = {0, -1, 0, 1}; const int dy[] = {1, 0, -1, 0}; const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; void openfile() { freopen("data.i...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<int> v(m + 1); for (int i = 0; i <= m; i++) { cin >> v[i]; } int ans = 0; for (int j = 0; j < m; j++) { if (__builtin_popcount(v[m] ^ v[j]) <= k) ans+...
2
#include "bits/stdc++.h" #pragma warning(disable:4996) using namespace std; using ld = long double; typedef long long Weight; struct Edge { int src, dest; int cap, rev; Weight weight; bool operator < (const Edge &rhs) const { return weight > rhs.weight; } }; const int V = 4000; typedef vector<Edge> Edges; typed...
0
#include <iostream> #include <algorithm> int main() { int N; std::cin >> N; std::cout << ((N/10)%111==0 || ((N%1000)%111==0) ? "Yes" : "No") << std::endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, w = 0; cin >> n; long long a[n], b[n]; map<long long, pair<int, int> > m; for (int i = 0; i < n; i++) { cin >> a[i]; if (m.count(a[i]) == 0) { m[a[i]].first = i; m[a[i]].second = i; } } for (int i = n - 1; i >= 0; i-...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 11; const int oo = 0x3f3f3f3f; int to[maxn << 1], nxt[maxn << 1], cap[maxn << 1], flow[maxn << 1]; int head[maxn], tot; void init() { memset(head, -1, sizeof head); tot = 0; } void add(int u, int v, int w) { to[tot] = v; nxt[tot] = head[u]; ...
5
#include <bits/stdc++.h> using namespace std; int main() { const int n1 = 100; int n2; string s2; cin >> n2; char s1[n1]; for (int x = 0; x < n2; x++) { cin >> s1[x]; } for (int z = 0; z < n2; z++) { if (s1[z] == 'o' && s1[z + 1] == 'g' && s1[z + 2] == 'o') { if (s1[z + 3] == 'g' && s1[z +...
1
// template version 1.14 using namespace std; #include <bits/stdc++.h> // varibable settings #define int long long const int INF=1e18; const int MOD=1e9+7; // define basic macro {{{ #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define ...
0
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, n, d, h; scanf("%d %d %d", &n, &d, &h); if (n == 2) { printf("1 2\n"); return 0; } double a = ceil((double)d / 2); if (h < (int)a) { printf("-1\n"); return 0; } if (h < 1 || d < 2 || h > d || h > n - 1 || d > n - ...
2
#include <bits/stdc++.h> using namespace std; void cases() { long long int n; cin >> n; unordered_map<long long int, long long int> mpx; unordered_map<long long int, long long int> mpy; for (long long int i = 0; i < n; i++) { long long int k; cin >> k; mpx[k] = (i + 1); mpy[k] = n - i; } l...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int c, d, n, m, k; cin >> c >> d >> n >> m >> k; int people = (n * m) - k; int o1 = ceil((1.0 * people) / n) * c; int o2 = (people)*d; int o3 = (c * (people / n)) + ((people % n) * d); cout << max(0, min(o1, min(o2,...
1
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <numeric> #include <cctype> #include <tuple> #ifdef _MSC_VER #include <agents...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 9; class LazySegmentTree { public: void reset(int sz, bool clr = false) { n = sz; treeMn.assign(n << 2, INT_MAX); treeMx.assign(n << 2, INT_MAX); lazyAssign.assign(n << 2, -1); } void minimize(int L, int R, int value) { minimize(...
6
#include <bits/stdc++.h> using namespace std; string s; int ans[2000000]; int main() { int i, j, n, t, m, k = 0, l; cin >> s; n = s.size(); j = 1; for (i = 0; i < n; i++) { if (s[i] == 'F') { j++; if (k != 0) { if (k - ans[j - 1] + ans[j - 2] <= ans[j - 2]) ans[j] = ans[j - 1...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; const unsigned long long MOD = 1000000007; const int INF = 1000000000; int N, nxt[MAXN], cnt[MAXN][MAXN], len[MAXN][MAXN], tot = 1, sh; string S; unsigned long long P[MAXN], H[MAXN]; inline unsigned long long get(int p, int l) { return (H[p + l] - H...
4
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // ?????¢ // XCode??§???EOF??\??????Ctrl+D // ?\???Alt+\ // ans???????§?INT?????????2,147,483,647????¶????????????¨??????????????§long long?????£??????????????????????????? ///////////////////////...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<long long int, long long int>> v; priority_queue<long long int, vector<long long int>, greater<long long int>> q; long long int b, w; for (int i = 0; i < n; i++) { cin >> b >> w; v.push_back(make_pair(b, w)...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int cnt = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 'A' || cnt == 0) cnt++; else cnt--; } cout << cnt << endl; } return 0; }
3
#include<bits/stdc++.h> using namespace std; int tree[500000]; int n; void update(int i,int x); int find(int s,int t,int node,int left,int right); int main(){ int i,q,com,x,y,a=2; scanf("%d %d",&n,&q); while(a<n){ a*=2; } n=a; for(i=0;i<2*n-1;i++)tree[i]=(1<<31)-1; for(i=0;i<q;i++){ scanf("%d %d %...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") const int INF = 2e9 + 179, MOD = 1e9 + 7; const long long int BIGINF = 2e18 + 179; const long double EPS = ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; typedef long long ll; int T, n; ll a[maxn]; char s[maxn]; ll b[61]; void add(ll x) { for (int i = 60; i >= 0; i--) { if ((x >> i) & 1) { if (!b[i]) { b[i] = x; break; } else x ^= b[i]; } } } int check(ll x) { for (int i = ...
0
#include<cstdio> #define N 100005 int n,a[N]; inline int geta(int i){ if(a[i]) return a[i]; printf("? %d\n",i); fflush(stdout); scanf("%d",&a[i]); return a[i]; } int main(){ scanf("%d",&n); a[0]=a[n+1]=n+1; int L=1,R=n; while(L<=R){ int mid=(L+R)>>1; int x=geta(mid-1),y=geta(mid),z=geta(mid+1); if(x...
1
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typed...
0