solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; const long long inf = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<long long> v(n + 1, 0); for (long long i = 0; i < n; i++) { long long x; cin >> x; v[i + 1] = v[i] + x; } long l...
3
#include <bits/stdc++.h> using namespace std; int dp[2][10000002]; int main() { long long n; cin >> n; dp[1][0] = 1; dp[0][0] = 0; for (long long i = 1; i < 10000002; i++) { dp[0][i] = (2LL * dp[0][i - 1] + dp[1][i - 1]) % 1000000007; dp[1][i] = (3LL * dp[0][i - 1]) % 1000000007; } cout << dp[1][n...
5
#include <iostream> using namespace std; int main(){ int a,b,ans=0; cin >> a; for(int i = 0;i<a;i++){ cin >> b; if(b!=(i+1))ans++; } if(ans<3)cout << "YES"; else cout << "NO"; }
0
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(char c) { return '\'' + string(1, c) + '\''; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B...
1
#include <bits/stdc++.h> using namespace std; /*{{{*/ //template #define rep(i,n) for(int i=0;i<(int)(n);i++) constexpr int INF = numeric_limits<int>::max()/2; constexpr long long LINF = numeric_limits<long long>::max()/3; #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se se...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long N = 1e6 + 10; const long long Bsz = 340; const long long inf = 1e18; const long long mod = 998244353; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); long long d; long long q; long long fact[N]; map<lo...
5
#include <iostream> #include <algorithm> using namespace std; int main(){ while(1){ int d, w; cin >>d>>w; if(!d && !w) break; int e[10][10]; for(int y=0; y<d; y++){ for(int x=0; x<w; x++){ cin >> e[y][x]; } } int ans=0; for(int i=0; i<d; i++){ for(int j=0; j<w; j++){ for(int k=0; k<d;...
0
#include <iostream> using namespace std; int main(){ int N; long long p=1; cin >> N; for(int i=1;i<=N;i++){ p *= i; p %= 1000000007; } cout << p << endl; }
0
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; int64_t dp[101][101]; string s1, s2; int64_t solve(int64_t i, int64_t j) { if (i < 0 || j < 0) return 0; if (dp[i][j] != -1) return dp[i][j]; if (i == j) { if (s1[i]...
4
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b)...
6
#include <algorithm> #include <cmath> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <cassert> #include <func...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 50005; struct Song { int len; double poss; bool operator<(const Song &t) const { double a = len * poss * (1 - t.poss); double b = t.len * t.poss * (1 - poss); return a > b; } } s[MAXN]; ; int n; void load() { cin >> n; for (int i = 0...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int MaxN = 4e5 + 10; const int MAXN = 120 * 1000; void fun() {} long long phi(long long n) { long long result = n; for (long long p = 2; p * p <= n; ++p) { if (n % p == 0) { while (n % p == 0) n /= p; result -= res...
5
#include <bits/stdc++.h> using namespace std; void _co() { cout << '\n'; } template <typename T, typename... Ts> void _co(const T& value, const Ts&... values) { cout << ' ' << value; _co(values...); } template <typename T, typename... Ts> void co(const T& value, const Ts&... values) { cout << "deb: " << value; ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, k = 0; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) { long long r = 0; if (a[lower_bound(a, a + n, a[i] * 3) - a] != a[i] * 3) r++; if (a[i] %...
4
#include <bits/stdc++.h> using namespace std; int main() { string Scale, left, right, rest_elements; int Slash; cin >> Scale; Slash = Scale.find('|'); left = Scale.substr(0, Slash); right = Scale.substr(Slash + 1, Scale.size()); cin >> rest_elements; for (auto i : rest_elements) if (left.size() <= r...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; int n; string s; int a[maxn], ps[maxn]; int32_t main() { cin >> n >> s; for (int i = 0; i < s.size(); i++) { int p = i + 1; if (s[i] == '(') { a[p] = a[p + n] = 1; } else { a[p] = a[p + n] = -1; } } for (int i = ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { if (i % 4 == 0) cout << "a"; else if (i % 4 == 1) cout << "b"; else if (i % 4 == 2) cout << "c"; else cout << "d"; } cout << endl; }
2
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int m[55],p[55]; long long v[55]; int siz[55]; int t[55]; bool cmp(const int &x,const int &y) { return v[x]*siz[y]<v[y]*siz[x]; } long long dp[202020]; void getmin(long long &a,long long b) { if(a==-1) a...
0
#include <bits/stdc++.h> using namespace std; const int N = 2005, mod = 998244353; int n, a[N][N], ans, pw[N], frc[N]; int bit[N], sme[N], g[N][N], cnt[N], cot; char cp; inline void rd(int &x) { cp = getchar(); x = 0; for (; !isdigit(cp); cp = getchar()) ; for (; isdigit(cp); cp = getchar()) x = x * 10 + (c...
5
#include <bits/stdc++.h> long long sum[50010]; long long arr[50010]; void solve(int n) { long long ans = 0, presum, s, need, avg = sum[n - 1] / n, start = 0, end, i, dist; while (start < n) { if (arr[start] >= avg) { if (start + 1 < n) { dist = arr[start] - avg; ans += dist; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int pa[N], pb[N], n; vector<pair<int, int> > cha[N], chb[N]; vector<int> va, vb; void shift() { int temp = va[0]; for (int i = 1; i < n; i++) { va[i - 1] = va[i]; } va[n - 1] = temp; } int getAns() { int ans = n; for (int i = 0; i < n;...
3
#include <bits/stdc++.h> using namespace std; bool get_win(long long a, long long b) { if (a > b) return 1; if (b % 2 == 1) { if (a % 2 == 1) return 0; return 1; } long long mid = (b + 2) / 2; if (a >= mid) { if (a % 2 == b % 2) return 0; else return 1; } long long l = (mid + 1...
6
#include <bits/stdc++.h> using namespace std; struct Matrix { int x[2][2]; Matrix operator+(const Matrix &x2) { Matrix ans; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) ans.x[i][j] = (x[i][j] + x2.x[i][j]) % 1000000007; ; return ans; } Matrix operator*(const Matrix &x2) ...
3
#include <bits/stdc++.h> using namespace std; static int INF = 1000000009; void build(int *st1, int N) { for (int i = N - 1; i >= 1; --i) { st1[i] = min(st1[i << 1], st1[i << 1 | 1]); } } void update_min(int *st2, int *st1, int N, int pos) { for (; pos > 1; pos >>= 1) { st1[pos >> 1] = min(st1[pos] + st2[...
5
#include <bits/stdc++.h> using namespace std; const int N = 100005, D = 50; const int V = N * D; vector<int> g[N]; int S[V], ssz; int low[V], num[V], cnt, vis[V]; int scc[V], scc_cnt; int all[V], sz; int n, m, d; long long val[N]; void push(int i, int j) { if (val[i] >> j & 1) { all[sz++] = i; while (sz >= V)...
3
#include <bits/stdc++.h> using namespace std; long long a[100010], b[100010], k[100010], c[100010]; int n, x[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%I64d", &b[i]); for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), c[i] = b[i] - a[i]; for (int i = 2; i <= n; i++) scanf("%d%I...
5
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define pb push_back #define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0); using namespace std; namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(cons...
0
#include <bits/stdc++.h> using namespace std; int n; long long a[(1 << 15)], dp[(1 << 15)]; long long upper; long long getMax(int i) { int left = 2 * i, right = 2 * i + 1; if (i > upper || left > upper || right > upper) return 0; long long &state = dp[i]; if (state != -1) return state; return state = max(a[le...
2
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { int n; cin >> n; vector<ll> h(n), v(n); for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> v[i]; vector<ll> bit(n + 1, 0); // 列の右端がiのときの、総和の最大値 for (int i = 0; i < n; i++) { ll res = 0; ...
0
#include <bits/stdc++.h> using namespace std; int a[(int)(1e+6) * 5]; int main() { int n, i, j, k, l, r; cin >> n; for (i = 1; i <= n; i++) a[i] = i; for (i = 2; i <= n; i++) { l = a[i - 1]; for (j = i - 1; j <= n + i - 2; j += i) { r = a[j + i]; a[min(j + i, n + i - 1)] = l; l = r; ...
4
#include <bits/stdc++.h> using namespace std; constexpr int INF = INT_MAX / 4; constexpr long long LL_INF = LLONG_MAX / 4; const double EPS = 1e-9; int n, m; pair<int, int> directions[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; vector<v...
5
#include <bits/stdc++.h> using namespace std; void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); if (s.size()) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } long long int Ax, Ay; long long int ...
3
#include <iostream> #include <functional> #include <queue> using namespace std; const int INF = 10000000; typedef pair<int, int> P; typedef pair<int, P> PP; typedef priority_queue<PP, vector<PP>, greater<PP> > Q; int C, N, M, S, D; int m[100][100]; int u[11][100]; bool input() { cin >> C >> N >> M >> S >> D; if...
0
#include <bits/stdc++.h> using namespace std; void solve(); int main() { int t = 1; while (t--) { solve(); } return 0; } const int N = 1e5 + 5; int ans[N]; void fail() { printf("No solution\n"); exit(0); } void solve() { int n, m, t; scanf("%d %d %d", &n, &m, &t); int sum = 0; deque<int> dq; i...
4
#include <iostream> using namespace std; int main(){ int n,s,j,k,a[11][46]; for(int s=0;s<46;s++)for(int n=0;n<11;n++)a[n][s]=0; for(int i=0;i<1024;i++){ for(j=i,n=0;j>0;j/=2) n += j%2; for(j=i,s=0,k=0;j>0;j/=2,k++) s += j%2*k; a[n][s]++; } for(cin>>n>>s;n||s;s<46?cout<<a[n][s]:cout<<0...
0
#include <bits/stdc++.h> using namespace std; int D[2005][2005], N, K; void precalc() { for (int i = 1; i <= N; i++) D[i][1] = 1; for (int l = 1; l <= K; l++) { for (int x = 0; x <= N; x++) { for (int divideby = 1; divideby * divideby <= x; divideby++) { if (x % divideby == 0) { D[x][l] ...
2
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define VI vector<int> #define VII vector<vector<int> > #define VPI vector<pair<int,int> > #define PII pair<int,int> #define yo cout<<oogabooga++<<endl; #define INF 9999999999 ...
3
#include <bits/stdc++.h> using namespace std; int main() { int y, k, n; cin >> y >> k >> n; int i; int from = ceil((double)y / k); if (k * from - y == 0 && y != n) from++; int to = n / k; if (from > to) cout << -1; else if (from == to) { if (k * from - y > 0) cout << k * from - y; else...
1
#include <bits/stdc++.h> int main() { int n, len, i, j; char ans[30], inpu[30]; scanf("%d", &n); scanf("%s", inpu); strcpy(ans, inpu); len = strlen(ans); n--; while (n--) { scanf("%s", inpu); for (j = 0; j < strlen(ans) && j < strlen(inpu); j++) if (ans[j] != inpu[j]) break; ans[j] = 0...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; const long long INF = 1e18; long long nn[MAXN], mm[MAXN]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> nn[i]; for (int i = 0; i < m; i++) cin >> mm[i]; long long ans = INF; f...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; long long int n, d, A0[MAXN], A1[MAXN], A2[MAXN], tmp[MAXN], sz, dp[MAXN]; pair<long long int, long long int> tree[4 * MAXN]; pair<long long int, long long int> max(pair<long long int, long long int> a, pair<l...
5
#include<bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int>res(n); for (int i = 0; i < n; i++)cin >> res[i]; int q; cin >> q; for (int i = 0; i < q; i++) { int b, e; cin >> b >> e; reverse(res.begin() + b, res.begin() + e); } for (int i = 0; i < n; i++) if (i == 0)cout ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, count = 0; cin >> n; map<string, int> m; for (int i = 0; i < n; i++) { string s, t, g, h = "", j = "", k = "", l = ""; cin >> s >> t; if (i < n - 1) cin >> g; h += s[0]; ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") using namespace std; int a, b, c, d, e, f, p = 1000000007, base = 157, mi = 1e9, i...
4
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long inf = 1ll << 62; inline long long read() { register long long x = 0, f = 1; register char c = getchar(); ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { if (i % 4 == 1) cout << 'a'; else if (i % 4 == 2) cout << 'b'; else if (i % 4 == 3) cout << 'c'; else cout << 'd'; } cout << endl; }
2
#include <bits/stdc++.h> using namespace std; const char letters[] = {'A', 'G', 'C', 'T'}; const int NMAX = 3e5 + 5; int N, M; int A, G, C, T; int best; vector<vector<int> > a, b; vector<int> prm, bestprm; int fqlin[NMAX][2][4], fqcol[NMAX][2][4]; char gletter() { char ch = getchar(); while (ch < 'A' || 'Z' < ch) c...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int x4[] = {1, -1, 0, 0}; int y4[] = {0, 0, 1, -1}; int x8[] = {0, 0, +1, -1, -1, +1, -1, +1}; int y8[] = {-1, +1, 0, 0, +1, +1, -1, -1}; deque<int> d; map<int, int> m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); i...
2
#include<iostream> #include<vector> using namespace std; int m,n,q; vector<int> a,b,c,d; int ans=0; void dfs(vector<int> v){ if(v.size()==n){ int tmp=0; for(int i=0;i<q;i++){ if(v[b[i]]-v[a[i]]==c[i]) tmp+=d[i]; } ans=max(ans,tmp); return; } v.push_back(v.back()); while(v.back()<=m){...
0
#include <bits/stdc++.h> using namespace std; bool delimiter, unof = 1; inline namespace IO { template <class t> using con = vector<t>; template <class t, class u> using pi = pair<t, u>; template <class t, class u> istream& operator>>(istream& is, pi<t, u>& pr) { is >> pr.first >> pr.second; return is; } template <...
3
#include <bits/stdc++.h> using namespace std; int findHF(int x) { int HF = 1; for (int i = 2; i < x; i++) { if (x % i == 0) HF = i; } return HF; } int main() { int x; cin >> x; int sum = 0; while (x > 1) { sum += x; int HF = findHF(x); x = HF; } sum++; cout << sum; }
2
#include <bits/stdc++.h> using namespace std; vector<vector<int> > G(26); vector<bool> vis(26, false); vector<bool> ex(26, false); void dfs(int root) { vis[root] = true; for (int i = 0; i < G[root].size(); i++) { int v = G[root][i]; if (!vis[v]) { dfs(v); } } } int main() { int n; cin >> n; ...
4
#include <bits/stdc++.h> using namespace std; const long long Max = 1e6; long long n; long long sum(long long x) { long long sum = 0; while (x) { sum += (x % 10); x /= 10; } return sum; } long long ar[Max]; void normtest() { long long t; cin >> t; while (t--) { long long m, k, pro = 1, cnt = 0...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<long long> steps(n); for (int i = 0; i < int(n); ++i) cin >> steps[i]; int m; cin >> m; int index = 0; long long height = 0; for (int it = 0; it < int(m); ++it) { int w, h; cin >> w >> h; while (index < w ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1005; long long sum[N][N]; int A[N][N], B[N][N], C[N][N], D[N][N]; long long val[N][N]; int main() { int n, m, a, b; scanf("%i %i %i %i", &n, &m, &a, &b); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%i", &A[i][j]), sum[i][j...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = (int)1e9; const int MAX_N = 3000 + 100; int n; vector<int> arr[MAX_N]; int tour[MAX_N]; int visit[MAX_N]; vector<int> grey; int dist[MAX_N]; vector<int> q; int dfs(int here, int par, int depth) { if (visit[here] != -1) { for (i...
4
#include<iostream> #include<cstring> #include<cassert> #include<cmath> #include<map> #include<set> #include<queue> #include<stack> #include<cstdio> #include<vector> #include<time.h> #include<algorithm> using namespace std; #define REP(i,x,y) for(ll i=x;i<=y;i++) #define rep(i,n) REP(i,1,n) #define rep0(i,n) REP(i,0,n-1...
0
#include <bits/stdc++.h> using namespace std; string g[51]; int pre[52][52]; int dp[51][51][51][51]; bool chk(int x1, int x2, int y1, int y2) { int r = pre[x2][y2] - pre[x1][y1 - 1] - pre[x1 - 1][y1] + pre[x1 - 1][y1 - 1]; if (r >= 1) return true; return false; } int fun(int r1, int r2, int c1, int c2) { if (ch...
6
#include <bits/stdc++.h> const int N = 30003; using namespace std; int n, d, c[N], dp[N][555]; bool used[N][555]; int rec(int x, int p) { int l = p - d + 250; if (x >= N) return 0; if (used[x][l]) return dp[x][l]; used[x][l] = true; if (p > 1) dp[x][l] = rec(x + p - 1, p - 1); dp[x][l] = max(dp[x][l], rec(x...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; signed main() { int i, n; cin >> n; vector<int> a(n); vector<int> tr, no; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= 2) { tr.push_back(i); } els...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; struct node { int u, v, val; } ans[maxn * 10]; std::vector<int> g[maxn]; int n, tot; int in[maxn]; int x[maxn], y[maxn], val[maxn]; void addedge(int u, int v, int val) { ans[++tot] = (node){u, v, val}; } void find(int u, int fa, int &x3, int &x4) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int m, n, r[3], k[3], o, p, l = 0; cin >> n >> m; char a[101][1011]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; if (a[i][j] == '*') { r[l] = i; k[l] = j; l++; } } } ...
1
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979; const double eps = 1e-6; const long long _INF = 1e18; const int INF = 1e9; const int maxn = 100000; const int maxm = 200000; int g[30] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, ...
4
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >>A >>B; cout <<max(0, A-B-B) <<endl; return 0; };
0
#include<bits/stdc++.h> using namespace std; int dp[3001][3001]; int arr[3001]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; for(int i=1; i<=n ; i++) { cin>>arr[i]; } dp[1][1]=0; for(int i=2; i<=n ; i++) { for(int j=i ; j<=n ; j++) { dp[i][j]=1e9; } int cnt=0; f...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, value; cin >> n; vector<vector<int> > v(n); vector<int> res; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { cin >> value; v[i].push_back(value); } } for (int i = 0; i < n; i++) { int j; for (j = 0; j...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, b, d; cin >> n >> b >> d; int waste = 0; int numCleans = 0; for (int i = 0; i < n; ++i) { int k; cin >> k; if (k > b) continue; waste += k; if (waste > d) { numCleans++; waste = 0; } } cout << numCleans <...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct gg { int a, b, num; } g[maxn], out[maxn]; bool cmp(gg g1, gg g2) { return g1.a < g2.a || (g1.a == g2.a && g1.b > g2.b); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> g[i].a >> g[i].b; g[i].num ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n, m; int ans[N + 10]; vector<int> h[4]; vector<int> g[N + 10]; set<pair<int, int> > myset; bool ok(int k1, int k2) { int len1 = h[k1].size(); int len2 = h[k2].size(); for (int i = 0; i < len1; i++) for (int j = 0; j < len2; j++) { int...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; string a, b; cin >> a >> b; int ans = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i]) continue; ans++; if (i == n - 1) { continue; } if (a...
3
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) { v.emplace_back(x); } return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vecto...
2
#include<iostream> #include<algorithm> #include<numeric> #include<vector> #include<set> #include <math.h> #include <string> #define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i]; typedef long long int ll; const ll INF =1LL << 62; using namespace std; int dy[4] = { 0, -1, 0, 1 }; int dx[4] = { 1, 0, -1, 0 }; bool inside(...
0
#include <bits/stdc++.h> using namespace std; const int Maxn = 10100; map<vector<int>, int> mp1; int n, a[Maxn], b[Maxn]; int main() { scanf("%d", &n); int all = (1 << 15) - 1; for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int s = 0; s <= all; ++s) { vector<int> t; for (int i = 1; i <= n; ++i) b...
6
#include <bits/stdc++.h> using namespace std; char st[105]; bool check(char a, char b) { if (a == b) return true; if (abs((int)a - (int)b) == 2) return true; return false; } int main() { double an; int t, tst = 1; long long n, q; scanf("%lld %lld", &n, &q); while (q--) { long long x, y; scanf("%...
2
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 5; pair<double, double> v[nmax]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> v[i].first >> v[i].second; if (n % 2 == 1) { cout << "NO"; return 0; } pair<double, double> mijl = {(v[1].first + v[n / 2 + 1].first...
4
#include <bits/stdc++.h> const double eps = 1e-9; const int oo = 1000000000; const double E = 2.7182818284590452353602874713527; const double pi = 3.1415926535897932384626433832795; using namespace std; int f[5001][5002], c[5001], mi[5001], g[2][5001], l[1000001], r[5002]; int gcd(int a, int b) { return b ? gcd(b, a % ...
5
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int i = 0, j = a.size() - 1; vector<int> ans; while (i < j) { if (a[i] == ')' && a[j] == '(') { i++; j--; } else if (a[i] == '(' && a[j] == '(') j--; else if (a[i] == ')' && a[j] == ')') i++; ...
2
#include <bits/stdc++.h> using namespace std; int a, b, k, m, maxa, minb, tem; int main() { cin >> a >> b >> k >> m; for (int i = 0; i < a; i++) { cin >> tem; if (i == k - 1) maxa = tem; } for (int i = 0; i < b; i++) { cin >> tem; if (i == b - m) minb = tem; } cout << (maxa < minb ? "YES" : ...
1
#include <bits/stdc++.h> using namespace std; const long long int Maxn = 1e5 + 5, Mod = 1e9 + 7, Inf = 1e9; int n, m, comp_sz, cnt[Maxn], ans = Inf; vector<int> adj[Maxn], Lucky_Numbers; vector<pair<int, int> > arr; set<int> st; set<int>::iterator it; bool mr[Maxn]; void Dfs(int v) { mr[v] = 1; comp_sz++; for (in...
5
#include <bits/stdc++.h> using namespace std; int read() { char c = getchar(); int d = 0, f = 1; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1; for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar()) ; return d * f; } int r, d, n; const int N = 100001; struct xint { int x, ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAXA = 2e5 + 10; const int MAX = 2e3 + 10; int n, m, k; int a[MAXA]; int M = 0; pair<int, int> p[MAX]; long long sum[MAX]; long long memo[MAX]; long long get(int i) { if (i > k) return LINF; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int h, w; bool A[100][100]; char C; cin >> w >> h; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) { cin >> C; A[i][j] = (C == '*'); } for (int i = 0; i < 2 * w; ++i) { for (int j = 0; j < 2 * h; ++j) { cout << ...
1
#include <stdio.h> typedef long long ll; int main(void) { ll i, j, k, n, q, a = -1, b; scanf("%lld%lld", &n, &q); b = n; char s[n + 10], t[q][3], d[q][3]; scanf("%s", s); for(i = 0; i < q; ++i) scanf("%s%s", t[i], d[i]); for(i = q - 1; i >= 0; --i) { if(d[i][0] == 'L') { if(t[i][0] == s[a + 1])...
0
#include <bits/stdc++.h> using namespace std; const int IINF = 1 << 28; const long long MOD = 1000000007; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v(n); for (int i = 0; i < (int)(n); i++) cin >> v[i]; if (n > ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a + 1 == b) cout << a << 9 << " " << b << 0; else if (a == b) cout << a << 1 << " " << b << 2; else if (a == 9 && b == 1) cout << a << 9 << " " << b << "00"; else cout << -1; }
1
#include <bits/stdc++.h> using namespace std; int dp[1005][55][55]; vector<int> z1, z2; string s, a, b; int solve(int idx, int i, int j) { if (idx == s.size()) return 0; if (dp[idx][i][j] != 2e9) return dp[idx][i][j]; int ans = -1e9, x, y; for (char c = (s[idx] == '*' ? 'a' : s[idx]); c <= (s[idx] == '*'...
4
#include <bits/stdc++.h> const int maxn = 5010, maxm = 10010; using namespace std; int n, m, pre[maxm], now[maxn], son[maxm], val[maxm], f[maxn][maxn][2], g[maxn][2], siz[maxn], tot, in[maxn]; bool isl[maxn]; void add(int a, int b) { pre[++tot] = now[a], now[a] = tot, son[tot] = b, in[b]++; } void dfs(int x, int ...
6
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; int f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); x *= f; } const int maxn = 100100; ...
5
#include<cstdio> const int B=10000; int H,W,h,w; int main(){ scanf("%d%d%d%d",&H,&W,&h,&w); if(H%h==0&&W%w==0)puts("No"); else{ puts("Yes"); for(int i=0;i<H;i++) for(int j=0;j<W;j++) printf("%d%c",H%h?i%h<h-1?B:-B*(h-1)-1:j%w<w-1?B:-B*(w-1)-1," \n"[j==W-1]); } }
0
#include<bits/stdc++.h> using namespace std; #define reps(i,f,n) for(int i=f;i<int(n);i++) #define rep(i,n) reps(i,0,n) typedef complex<double> P; vector<P> point; const double EPS = 0.0000000001; void init(){ point.clear(); } bool input(){ int n; cin>>n; if(n==0)return false; rep(i,n){ double ...
0
#include <bits/stdc++.h> using namespace std; int arr[103][103]; int n; set<pair<pair<int, int>, int> > to; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> arr[i][j]; for (int i = 0; i < n; i++) { to.insert(make_pair(make_pair(i, n / 2), arr[i][n / 2])); to.insert...
1
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; typedef pair<int, int>P; int w[2], h[2], l[2][500][500], sx[2], sy[2], r; int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 }; int ans[2][100001], d[250000]; bool vis[500][500], used[500][500]; vector<P>que[250000]; int compress(int k) { vector<int>...
0
#include <bits/stdc++.h> using namespace std; const int maxr = 100; const int maxc = 100; const int maxm = 10000; int nrow, total, ncol[maxr + 5], book[maxr + 5][maxc + 5], best[maxr + 5][maxc + 5], dprow[2][maxc + 5][maxc + 5], dp[maxr + 5][maxm + 5]; void init(int r) { int n = ncol[r]; best[r][0] = 0; m...
5
#include <bits/stdc++.h> using namespace std; int v[100005], c[100005], l[100005], r[100005]; int dp[100005], pre[100005], res[100005]; vector<int> vec[300005]; map<int, int> mx; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d%d", v + i, c + i, l + i, r + i); vec...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int INF = 0x3f3f3f3f; const int M = 200000 + 5; int main() { int a[M], b[M], n, i, m, t, mark, tt; while (~scanf("%d", &n)) { t = 0; for (i = 1; i <= n; i++) { scanf("%d", &tt); if (tt != 0)...
2
#include <bits/stdc++.h> using namespace std; int solve(int); int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int k; cin >> k; int ans = solve(k); cout << ans << endl; } return 0; } int solve(int k) { if (k == 1) return 1; int cnt = 1; int ele = 1; while...
1
#include<iostream> #include<math.h> #include<algorithm> #include<string> #include<vector> using namespace std; int main() { int N; cin >> N; int n = -1; for (int i = 1; i <= N; i++) { if (N == i*(i + 1) / 2)n = i; } if (n == -1) { cout << "No" << endl; return 0; } vector<vector<int>> ans(n + 1, vector<in...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; m = max(m, a[i]); } cout << m; }
2
#include <bits/stdc++.h> using namespace std; map<char, pair<int, int> > ins; void operator+=(pair<int, int> &i, pair<int, int> &j) { i.first += j.first, i.second += j.second; } int main() { ins['U'] = pair<int, int>(0, 1), ins['D'] = pair<int, int>(0, -1), ins['L'] = pair<int, int>(-1, 0), ins['R'] = pair<int, i...
1