solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> char mp[100][100]; int main() { int n, m, i, j, k; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf(" %s", mp[i]); k = 0; for (i = 1; i <= n; i++) for (j = 0; j < m; j++) { if (mp[i][j] == 'P') { if ((i - 1) && (mp[i - 1][j] == 'W')) { k++; m...
2
//test https://blog.csdn.net/rising_shit/article/details/80739593 #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #define maxn 2005 #define _x1 x1 #define _x2 x2 using namespace std; typedef long long ll; const ll mod=1e9+7; int n,m; ll v; int fa[maxn],id[maxn],x[maxn],y[maxn]; ll w[maxn]; i...
0
#include<iostream> using namespace std; bool find(int a){ for(int i=2;i*i<=a;i++){ if(a % i == 0){ return false; } } return true; } int main(){ int a; cin>>a; while(1){ if(find(a) == true){ cout<<a; return 0; } a++; } }
0
#include <bits/stdc++.h> using namespace std; int cnt1 = 0; const int maxn = 1e5; int fac[maxn + 5], vis[maxn + 5]; vector<int> prime; void init() { memset(vis, 0, sizeof(vis)); for (int i = 2; i <= maxn; i++) { if (!vis[i]) prime.push_back(i); for (int j = 0; j < prime.size() && i * prime[j] <= maxn; j++) ...
2
#include<iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; cout << min(min(a+b, b+c), c+a) << endl; }
0
#include <bits/stdc++.h> using namespace std; void adjust(int &k, int n) { if (k < 1) k = 1; if (k > n) k = n; } void solve() { int n, S, C; cin >> n >> S >> C; string sdir; cin >> sdir; cin >> sdir; int dir = (sdir == "head") ? -1 : 1; string train; cin >> train; int min = 0; for (int i = 0; i ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 10 || n > 21) { cout << 0 << endl; } else if (n == 20) { cout << 15 << endl; } else if (n <= 21) { cout << 4 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int max_n = 500; pair<bool, int> dp[max_n][max_n]; int dp2[max_n][max_n]; int pref[max_n]; int a[max_n]; signed main() { cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i...
5
#include<iostream> using namespace std; string s; int main() { cin>>s; for(int i=0;i<3;i++)cout<<s[i]; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, unb, sum; int zero[100003]; string s[100003]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> s[i]; int cnt = 0; int len = s[i].length(); for (int j = 0; j < len; j++) { zero[i] += (s[i][j] == '0'); cnt += (s[i][j] ...
2
#include <bits/stdc++.h> using namespace std; int solve(int x) { if (x % 2) { const int y = x - 1; for (int n = 1;; n += 2) { const int h = n / 2; if (y % 4 == 2 && h <= 1) continue; const int m = h * (h + 1) / 2; if (m * 4 >= y) return n; } } else { for (int n = 1;; n++) { ...
1
#include<cstdio> #include<algorithm> using namespace std; const int maxn = 1e3; int a[maxn+10]; int main() { int n,X,Y; scanf("%d%d%d",&n,&X,&Y); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int ans; if(n==0) ans=abs(X-Y); if(n==1) ans=abs(a[n]-Y); if(n>=2) ans=max(abs(Y-a[n]),abs(a[n-1]-a[n])); printf("%d\n",ans...
0
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; long long fact[110], inv[110]; long long ksm(long long x, long long y) { long long ret = 1; while (y > 0) { if (y & 1) { ret = (ret * x) % 1000000007; } x = (x * x) % 1000000007; y >>= 1; } return ret; } long long GetC(l...
5
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { char c = getchar(); long long tot = 1; while ((c < ...
5
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <climits...
0
#include <bits/stdc++.h> using namespace std; int M; int dp[255][255][255]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); M = 100005; int n, i, j, k, q; int sa[] = {0, 0, 0, 0}; vector<char> ca[4]; cin >> n >> q; string w; cin >> w; int lca[n + 1][26]; for (i = 0; i < 2...
2
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; int l[500], r[500], d[500], ans[500]; for (int i = 0; i < q; i++) { cin >> l[i] >> r[i] >> d[i]; int quo; if (d[i] < l[i]) { ans[i] = d[i]; } else { quo = int(r[i] / d[i]); ans[i] = d[i] * (quo + 1); ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n], p[n]; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int m; cin >> m; set<int> s[4]; for (int i = 0; i < n; i++) { s[a[i]].inser...
2
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex...
0
#include <bits/stdc++.h> using namespace std; long long n, k, a, b; int main() { cin >> n >> k >> a >> b; long long mn, mx; mn = min(a, b); mx = max(a, b); if (mx > ((k) * (mn + 1))) { cout << "NO" << endl; return 0; } char c = 'G', d = 'B'; if (a == mn) { swap(a, b); swap(c, d); } l...
4
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main() { vector<int> a(100, 0); int d = 0; int g = 0; bool c = false; for (int i = 0; i < 4; i++) { cin >> a[i]; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i != j) { if (a[i]...
0
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main(){ ll N; cin >> N; vector<ll> A(N),B(N+1); for(int i=0;i<N;i++){ cin >> A[i]; B[A[i]]++; } vector<ll> cnt(N+1,0),D(N+1,0); for(int i=1;i<=N;i++) cnt[B[i]]++; ve...
0
#include <bits/stdc++.h> using namespace std; int main() { int k; scanf("%d", &k); int pos = 0; for (int i = 0; i < 20; ++i) { if ((k >> i) & 1) { pos = i; } } int incre = k + (1 << (pos + 1)), incre_no_k = 1 << (pos + 1); printf("%d %d\n", 2, 3); printf("%d %d %d\n%d %d %d\n", incre, incr...
4
#include<bits/stdc++.h> using namespace std; template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; ...
0
#include <bits/stdc++.h> int main() { long n; scanf("%ld\n", &n); if (n % 3 == 1) { --n; } else if (n % 3 == 2) { ++n; } long feet = n / 36; long inches = (n - 36 * feet) / 3; printf("%ld %ld\n", feet, inches); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; if (n == 2) { cout << "2\n1 2\n"; continue; } cout << "2\n"; cout << n << " " << n - 2 << "\n"; cout << n - 1 <...
3
#include <bits/stdc++.h> using namespace std; int n, k, a[2005], res, temp, s; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a, a + n + 1); s = 1; for (int i = a[1]; i <= a[n]; i++) { temp = 0; for (int j = 1; j <= n; j++) if (a[j] >= i) temp++; if (temp == 0) br...
2
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 10, inf = 1e-10; int main() { int book[40], n, m; scanf("%d%d", &m, &n); bool flag = 1; for (int i = 1; i <= n; i++) { printf("1\n"); fflush(stdout); scanf("%d", &book[i]); if (!book[i]) { flag = 0; break; } } ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); int mx = 0; for (auto &it : a) { cin >> it; mx = max(mx, it); } int idx = -1; for (int i = 0; i < n; ++i) { if (a[i] != mx) continue; ...
3
#include <bits/stdc++.h> enum Opcodes { A = 'A', B = 'B', C = 'C', MAX }; uint32_t askFor(Opcodes opcode, uint32_t num) { assert(opcode >= Opcodes::A && opcode < Opcodes::MAX); assert(num > 0); assert(opcode != Opcodes::B || num > 1); printf("%c %u\n", (char)opcode, num); fflush(stdout); uint32_t res = 0; ...
5
#include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { std::string s; std::cin >> s; if (s.length() % 2 == 0 && s[0] != ')...
1
#include <bits/stdc++.h> int main() { int n; char cad[15]; scanf("%s", cad); n = strlen(cad); int i = 0, j = n - 1, cont = 0; while (i < j) { if (cad[i] != cad[j] && cont == 0) { cont++; } else if (cad[i] != cad[j] && cont == 1) { printf("NO\n"); return 0; } i++; j--; ...
1
#include <bits/stdc++.h> using namespace std; int n, m, q, x, y; int connect[100001]; vector<int> g[100001]; void dfs(int v, int c) { connect[v] = c; int size_ = g[v].size(); for (int i = 0; i < size_; ++i) { if (connect[g[v][i]] == 0) { dfs(g[v][i], c); } } } int mai...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:64000000") using namespace std; struct Lesson { long long L, R; int D, N; Lesson() {} Lesson(long long L, long long R, int D, int N) : L(L), R(R), D(D), N(N) {} bool operator<(const Lesson& lesson) const { return D < lesson.D; } }; struct Prev { int n...
3
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define sc second typedef pair<int,int> P; int N,K; int C[5003],R[5003]; int A,B; vector<int>G[5003];int s1[5003];bool f[5003]; vector<P>G2[5003]; int main() { scanf("%d%d",&N,&K); for(int i=0;i<N;i++){ scanf("%d%d",&C[i],&R[i]); } ...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 100000 + 10; const int Mod = (int)1e9 + 7; const int Mod1 = 239482903; const int Mult = 142341; const int Mult1 = 238478989; int n; char str[MAX]; long long sum[MAX]; long long sum1[MAX]; long long P[MAX], P1[MAX]; void init() { int i; for ((i) = (1); (i...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n; long long f[MAXN], a[MAXN]; int main() { scanf("%d", &n); for (int i = n; i; i--) scanf("%lld", &a[i]); for (int i = n - 1; i; i--) a[i] = min(a[i], a[i + 1]); a[0] = 1; for (int i = 1; i <= n; i++) { for (long long j = a[i], ...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; inline int gcd(int a, int b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? ((a - b) ? gcd(a % b, b) : a) : a; } void solve() { int n, a, b, cur = 1; cin >> n; vector<pair<int, int> > v(n); for (int i...
1
#include<iostream> #include<stack> #include<vector> using namespace std; typedef long long ll; typedef vector<ll> V; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) //グラフの隣接リスト vector<ll> g[100010]; //頂点の入次数の管理 ll h[100010]={0}; //頂点の番号 ll num[100010]; int main(){ ll v,e; ...
0
#include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> given(n); // the given sequence vector<int> prev(n); // the previous permutation vector<int> next(n); // the next permutation for_each(given.begin(),given.end(),[](int &_e){cin >> _e;}); pr...
0
#include <bits/stdc++.h> int main() { static const int MOD = 998244353; int n; std::cin >> n; std::vector<int> a(n * 2); std::vector<int64_t> fact(n * 2 + 5); std::vector<int64_t> inv(n * 2 + 5); std::vector<int64_t> inv_fact(n * 2 + 5); fact[0] = inv[0] = inv_fact[0] = 1; fact[1] = inv[1] = inv_fact[...
2
#include <bits/stdc++.h> using namespace std; string s; class node { public: string s; vector<node *> next; node *f; node() { s = ""; next.clear(); f = NULL; } }; node *root; vector<string> p; int dfs(node *cur, int k) { int ret = 0; if (k == p.size() - 1) { for (int i = 0; i < cur->next....
5
/* _____ _ _ ____ __ __ _ / ____| | | | | | _ \ _ \ \ / /(_) | | ___ __| | ___ __| | | |_) | _ _ (_) \ \ /\ / / _ ____ | | / _ \ / _` | / _ \ / _` | | _ < | | | | \ \/ \/ / | ||_ / | |...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N; vector<pair<int, int>> red(101); vector<pair<int, int>> blue(101); int main(void){ cin >> N; for(int i = 0; i < N; ++i) cin >> red[i].first >> red[i].second; for(int i = 0; i < N; ++i) cin >> blue[i].first >> blue[i].second; ...
0
#include <bits/stdc++.h> using namespace std; struct Shoe { int cost; int sz; int idx; Shoe() {} Shoe(int cost, int sz, int idx) : cost(cost), sz(sz), idx(idx) {} }; struct Customer { int money; int sz; int idx; Customer() {} Customer(int money, int sz, int idx) : money(money), sz(sz), idx(idx) {} }...
4
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> ans; void gogo(int n, int pre) { for (int offset = 1; offset < n; offset *= 2) for (int i = 1; i + offset <= n; i += offset << 1) for (int j = 0; j < offset; j++) ans.emplace_back(pre + i + j, pre + i + j + offset); } void test_cas...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b; cin >> n; a = 9 * n; b = 8 * n; cout << a << " " << b; }
1
#include <bits/stdc++.h> using namespace std; int main() { string s = "12345"; int x; int G[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> x; G[i][j] = x; } } int maxima = 0; do { int si = 0, sum = 0; while (si < 4) { for (int i = si; i < 4; i +...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, a[5]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (a[i] < a[j]) swap(a[i], a[j]); cout << a[n / 2]; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k; cin >> k; int a, b; b = 2000 - (k % 2000); while (1999 * b <= k) b += 2000; a = (k + b) / 2000 - b; cout << "2000\n"; for (int i = 0; i < 1998; ++i) { cout << "0 "; } cout << a << ' ' << b ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[2 * n]; for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } sort(a, a + 2 * n); cout << (a[n - 1] == a[n] ? "NO" : "YES") << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int x; cin>>x; cout<<((x>=30)?"Yes":"No")<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char str[n + 1]; cin >> str; int res = 0; for (int i = 1; i < n; i++) { if (str[i] == str[i - 1]) res++; } cout << res; return 0; }
1
#include <bits/stdc++.h> using namespace std; int dx[5] = {-1, 0, 1, 0}; int dy[5] = {0, -1, 0, 1}; int dp[1001][1001][41]; bool colour[45]; vector<pair<int, int>> v1[45]; queue<pair<int, int>> q1; int n, m, K; bool check(int r, int c) { if (r <= 0 || r > n || c <= 0 || c > m) { return false; } return true; }...
6
#include <bits/stdc++.h> using namespace std; const int md = 1000003; long long binpow(long long n, long long k) { long long ans = 1; while (k != 0) { if (k % 2 == 1) ans = (ans * n) % md; n = (n * n) % md; k >>= 1; } return ans; } int main() { long long n, k; long long ed = 1; cin >> n >> k; ...
5
#include <bits/stdc++.h> using namespace std; const long long int INF = 98769876987698889LL; const int MOD = 1e9 + 7; const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx4[] = {1, -1, 0, 0}; const int dy4[] = {0, 0, 1, -1}; const int N = 2e5 + 5; long long int dp1[N...
4
#include <bits/stdc++.h> int main() { char s[110]; scanf("%s", s); int len = strlen(s); if (len == 1) { if (s[0] >= 'A' && s[0] <= 'Z') s[0] = tolower(s[0]); else s[0] = toupper(s[0]); puts(s); return 0; } int acnt = 0, bcnt = 0; if (s[0] >= 'A' && s[0] <= 'Z') acnt++; for (i...
1
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } int board[8][8]; bool valid(int x, int y) { return 0 <= x && x < 8 && 0 <= y && y < 8; } void Input(int t) { string s; cin >> s; int x = s[0] - 'a'; int y = s[1]...
2
#include <bits/stdc++.h> using namespace std; int t, n, i, j, k, f, b[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}, a[1008], c[1008]; int main() { for (scanf("%d", &t); t--; printf("\n"), i = 0) { for (scanf("%d", &n); i++ < n; scanf("%d", a + i), c[i] = 0) ; for (k = 1, j = 11; j-...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool comp(string s, string t){ for(int i = 0; i < min(s.size(), t.size()); i++){ if(s[i] < t[i]) return true; if(s[i] > t[i]) return false; } return s.size() <= t.size(); } int getDist(const string& s, const string& t){ int dp[20][20]; for(i...
0
#include <stdio.h> #include <algorithm> #include <utility> #include <set> #include <queue> using namespace std; typedef long long ll; int main(void) { ll i, j, k, n, m, ans = 0, a, b, t, nowx, nowy; scanf("%lld%lld", &n, &m); set<ll> x, y; set<ll>::iterator it; pair<ll, pair<ll, ll> > vx[m], vy[n]; for(i =...
0
#include <bits/stdc++.h> using namespace std; vector<set<int>> segs, cur; vector<int> ans; set<int> ins; void init() { segs.clear(); } void solve() { init(); int n, cnt = 0; scanf("%d", &n); for (int i = 1; i < n; ++i) { ins.clear(); cnt = 0; int a = 0; scanf("%d", &cnt); for (int j = 1; j <...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; bool check(string s1,string s2){ int l=0,r=0; bool flag=false; int cnt=0; while(l<s1.size() || r<s2.size()){ if(s1.size()==l || s2.size()==r)return false; if(s1[l]!=s2[r])return false; if(s1[l]=='"'){ l++; stri...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 333; const long long linf = 1e18 + inf; const int N = 1e5 + 5; const int SQRT = 100; int n, q, ptr; char str[N]; string s[N]; long long ans[N]; int fin[N], fail[N], trie[N][26]; vector<int> v[N], ___ends[N]; int x[N], y[N], k[N]; vector<int> ord; vecto...
6
#include<bits/stdc++.h> using namespace std; class range { private: struct Iterator { int val; int operator*() {return val;} bool operator!=(Iterator &itr) {return val < itr.val;} void operator++() {++val;} }; Iterator i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int upper[n], lower[n], u = 0, l = 0, ans = 0; for (int i = 0; i < n; i++) { cin >> upper[i] >> lower[i]; u += upper[i]; l += lower[i]; } if (u % 2 == 0 && l % 2 == 0) cout << "0"; else { for (int i = 0; i < n;...
1
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, s, t; int co[501], si[501], L[501], R[501]; long long dis[501][501]; short f[501][501][501], g[501][501]; vector<int> zi[501]; vector<pair<int, int> > a[501]; void sou(int x, int y, int id) { int i; for (i = 0; i < a[x].size(); i++) { pair<int, in...
5
#include <bits/stdc++.h> using namespace std; const int N = 2020; int n, k, c[N][N] = {}, d[N] = {}; int main() { scanf("%d%d", &n, &k); long long sum = 0; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) scanf("%d", &c[i][j]); if (k == 1 || k == n - 1) { for (int i = 1; i <= n; ++i) ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, i, s1 = 10e10, s2 = 10e10, ans = 0; cin >> n; long long int a[n], b[n]; for (i = 0; i < n; i++) { cin >> a[i]; s1 = min(s1, a[i]); } for (i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = -1; const long long INF = (long long)1e18 + 50; map<long long, int> F; void fact(long long n) { F.clear(); for (long long p = 2; p * p <= n; p++) { while (n % p == 0) F[p]++, n /= p; } if (n > 1) F[n]++; } long long countp(long long n, long long...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 20; template <typename T> struct Treap { T key; int f, maxf; int height, s; int addk, addf; Treap *left, *right, *parent; Treap(T a, int b = 0, Treap *parent = 0) : key(a), f(b), parent(parent) { height = rand(); maxf = f, s = 1; ...
5
#include <bits/stdc++.h> using namespace std; pair<int, int> comb(pair<int, int> a, pair<int, int> b) { pair<int, int> res; if (a.first < b.first) res.first = b.first; else res.first = a.first; if (a.second > b.second) res.second = b.second; else res.second = a.second; if (res.first <= res.s...
4
#include <iostream> #include <iomanip> #include <vector> #include <map> #include <cmath> #include <algorithm> #include <string> #define shosu(x) fixed<<setprecision(x) using namespace std; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,P> pip; typedef long long ll; const int i...
0
#include <bits/stdc++.h> using namespace std; int c[100100], visi[100100]; set<int> gr[100100]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n - 2; ++i) { int x, y, z; cin >> x >> y >> z; gr[x].insert(y); gr[x].insert(z); gr[y].i...
3
#include <bits/stdc++.h> using namespace std; #define F first #define S second typedef pair<int,int> P; typedef pair<P,P> PP; int n,m,INF=1<<29,dxx[4]={-1,0,1,0},dyy[4]={0,-1,0,1}; int dx[8]={-1,-1,0,1,2,2,0,1},dy[8]={0,1,-1,-1,0,1,2,2}; string s[55]; bool check(int x,int y) {return x>=0&&x<n&&y>=0&&y<m;} bool check(in...
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return i; } templat...
4
#include <bits/stdc++.h> using namespace std; int main() { set<int>x; for(int i=0;i<3;i++){ int y; cin>>y; x.insert(y); } cout<<x.size(); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int z = n / 3; int x = n % 3; int ans1 = z; int ans2 = z; if (x == 1) ans1++; if (x == 2) ans2++; cout << ans1 << " " << ans2 << endl; } return 0; }
1
#include <bits/stdc++.h> const long long N = 2e5 + 1; using namespace std; clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } void init_code() {} signed main() { startTime = clock(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long T = 1; ...
4
#include <bits/stdc++.h> using namespace std; long long int calDis(long long int x1, long long int y1, long long int x2, long long int y2) { return abs(x1 - x2) + abs(y1 - y2); } void solve() { long long int x0, y0, ax, ay, bx, by; cin >> x0 >> y0 >> ax >> ay >> bx >> by; long long int xs, ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); string H, A; int n; cin >> H >> A >> n; int Hc[101] = {}, Ac[101] = {}; while (n--) { int t, nr; char team, type; cin >> t >> team >> nr >> type; if (team == 'h') { if (Hc[nr] < 2) { Hc[nr] += (...
1
#include <bits/stdc++.h> using namespace std; using namespace std; int a[100000 + 5]; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int inv = 0; int n; cin >> n; int a[100000 + 5]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) for (in...
4
#include <cstdio> #include <vector> #include <algorithm> #include <iostream> using namespace std; unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ...
0
#include<iostream> using namespace std; int main(){ ios::sync_with_stdio(false); int n,a,b,c,d;cin >> n >> a >> b >> c >> d; string s; cin >> s;s='?'+s; for(int i=a; i<c ;i++){ if(s[i]=='#' && s[i+1]=='#') return cout << "No\n",0; } for(int i=b; i<d ;i++){ if(s[i]=='#' && s[i+1]=='#') return cout << "No\n",0...
0
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, y, z; scanf("%d", &n); int a[n], x[n + 2]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); if (n % 2 == 0) { j = n - 1; for (i = 0; i < n / 2; i++) { x[i] = a[j]; j = j - 2; } j++; ...
2
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; map<string,int>m; for(int i=0;i<n;i++) { string s; cin>>s; m[s]++; } cout<<"AC x "<<m["AC"]<<endl; cout<<"WA x "<<m["WA"]<<endl; cout<<"TLE x "<<m["TLE"]<<endl; cout<<"RE x "<<m["RE"]<<endl; }
0
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; const long long MOD = 1e9 + 7; const int lim = 2e5 + 10; int h[lim]; int main() { int n, k; cin >> n >> k; memset(h, 0, sizeof(h)); for (int i = 0; i < n; ++i) { int a; sc...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; const int inf = 0x3f3f3f3f; bool vis[maxn]; int n, m, s, t, x, y, z, f, dis[maxn], pre[maxn], last[maxn], flow[maxn], maxflow, mincost; struct Edge { int u, to, next, flow, dis; } edge[3000005]; int head[maxn], num_edge; queue<int> q; struct nod...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const double PI = acos(-1.); const double eps = 1e-9; char s[1000005]; char t[1000005]; int fs[11]; int ft[11]; int fx[11]; char y[1000005]; int main() { int i, j, k, _T; while (~scanf("%s%s", s, t)) { if (strcmp(s, "01") == 0 || st...
6
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); double w, h, alpha; double a, b, c, d, e, f; double x, y; int main() { ios::sync_with_stdio(0); cin >> w >> h >> alpha; if (w < h) swap(w, h); alpha = min(alpha, 180 - alpha); if (alpha == 0) { return printf("%.9f\n", 1.0 * w * h), ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1001; int a[N]; int vis[N]; int n; struct edge { int from, to, w; bool operator<(const edge& e) const { return w > e.w; } }; vector<edge> adj[N]; priority_queue<edge> q; int MST() { int mstCost = 0; int edges = 0; while (!q.empty()) { edge e = q....
2
#include<bits/stdc++.h> using namespace std; #define inf INT_MAX #define INF LLONG_MAX #define ll long long #define ull unsigned long long #define M (int)(1e9+7) #define P pair<int,int> #define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++) #define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--) #define rep(i,n) FOR(i,0,n) #d...
0
#include <bits/stdc++.h> using namespace std; vector<set<pair<int,int>>> X(100000); vector<int> Bl(100000,5); void dfs(int x,int y){ auto it=X[x].begin(); while(it!=X[x].end()){ int a=(*it).first; int c=(*it).second; it++; if(a==y) continue; Bl[a]=(Bl[x]+c)%2; dfs(a,x); } return; } in...
0
#include <bits/stdc++.h> using namespace std; map<vector<string>, bool> state; vector<string> matr; void printm(int n) { for (int i = 0; i <= n - 1; i++) { for (int j = 0; j <= n - 1; j++) cout << matr[i][j] << ' '; cout << '\n'; } cout << '\n'; } void compute_states(int li) { for (int q = 0; q <= li + ...
1
#include <bits/stdc++.h> using namespace std; vector<int> v[101]; int n, m, a, b, len; char dp[33][101][101], c; int g[101][101]; inline char winner(int cost, int x, int y) { if (isalpha(dp[cost][x][y])) return dp[cost][x][y]; else { for (int i = 0; i < v[x].size(); ++i) { if (g[x][v[x][i]] >= cost &&...
2
# include <cstdio> # include <iostream> # include <string> using namespace std; int main () { string s; int n,a=0,flag=1; cin>>s; n=s.length(); for (int i=0;i<n;++i) { if (isupper(s[i])) a++; } if (s[0]=='A'&&s[1]!='C'&&s[n-1]!='C'&&a==2) printf ("AC\n"); else printf ("WA\n"); }
0
#include <bits/stdc++.h> bool a[100001]; class op { public: int first, delta; inline op(int first, int delta) : first(first), delta(delta) { a[first] ^= 1, a[first + delta] ^= 1, a[first + (delta << 1)] ^= 1; } }; std::vector<op> ans; int main() { std::ios_base::sync_with_stdio(0), std::cin.tie(0); int n...
5
#include<iostream> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<vector> #include<cmath> #include<cstdio> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(),in.end...
0
#include <cstdio> int N, M, a, b, l, r, z = 1 << 29, q[5009], c[5009], t[5009], s[5009], d[5009], g[5009][5009], v[5009][5009]; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) scanf("%d%d", &c[i], &t[i]); for (int i = 0; i < M; i++) scanf("%d%d", &a, &b), a--, b--, g[a][s[a]++] = b, g[b][s[b]++] = a;...
0
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 2; const int INF = (int)1e9 + 7; const long double pi = acos(-1); const long long linf = (long long)1e18; int w, h, k, ans; int main() { cin >> w >> h >> k; for (int i = 1; i <= k; ++i) { ans += ((w * 2) + (h * 2) - 4); h -= 4; w -= ...
1