solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int k, n, b[2001], s = 0, ans = 0; cin >> k >> n; set<int> S; for (int i = 0; i < k; ++i) { int a; cin >> a; s += a; S.insert(s); } vector<int> v; for (auto ss : S) v.push_back(s...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, a; string s; cin >> t; while (t--) { cin >> n; cin >> s; map<pair<int, int>, int> m; pair<int, int> p; p = make_pair(0, 0); m[p] = 0; long long int i = 0, j = 0, len, min = 1000000, l = -1, r; for (int...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long power(long long x, long long y) { long long res = 1; while (y) { if (y % 2) res = (res * x) % mod; x = (x * x) % mod; y = y / 2; } return res; } int main() { long long n, m; cin >> n >> m; cout << power((pow...
2
#include<iostream> using namespace std; #define fr(i,n) for(i=0;i++<n;) int main(){ int i,n,m,a; bool c[100010]={}; cin>>n>>m; for(;cin>>a;) c[a]=!c[a]; fr(i,n){ if(c[i]&1){ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }
0
#include <bits/stdc++.h> using namespace std; vector<int> g[210000]; int n, x, f[210000], size[210000]; void dfs(int x, int fa) { f[x] = fa; size[x] = 1; for (int i = 0; i < g[x].size(); i++) { int t = g[x][i]; if (t != fa) { dfs(t, x); size[x] += size[t]; } } } void find(int x) { for ...
2
#include <algorithm> #include <string> #include <sstream> #include <iostream> #include <math.h> #include <random> #include <cstdio> using namespace std; const int LOOP = 1000; //??????????????° const double EPS = 1e-6; //??????????????¨(?°??????????????????????) int L; int N; //???????????±???????????° //???????????±...
0
#include <bits/stdc++.h> using namespace std; priority_queue<pair<pair<int, int>, int> > Q; vector<pair<int, int> > tab; pair<pair<int, int>, int> p; int n, m, x, l1, l2, ans[200010], ans2[200010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int a = 1; a <= n; a++) { cin >> x;...
5
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, N = 4e5 + 10; long long n, Rt, ans, inv[N]; int r[N], sz[N], lim, son[N], fa[N]; vector<int> g[N]; vector<long long> a[N], f[N]; void Add(long long &x, long long y) { x = (x + y) % mod; } long long add(long long x, long long y) { return (x + y) % ...
6
#include <bits/stdc++.h> using namespace std; const int N = 105; int a[N]; int main() { int n, s, t, s1 = 0, s2 = 0; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; cin >> s >> t; if (s > t) swap(s, t); for (int i = s; i < t; ++i) s1 += a[i]; for (int i = t; i <= n; ++i) s2 += a[i]; for (int i = 1; ...
1
#include <bits/stdc++.h> typedef struct x { int a, b; } move; int n, a[300], b[300]; move ans[1000000]; int idx, temp; int main() { int i, j; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (i = 0; i < n; ++i) { scanf("%d", &b[i]); } for (i = 0; i < n; ++i) { if (a[i] !=...
4
#include <bits/stdc++.h> using namespace std; vector<int> g[200309]; int n, par[200309]; long long s[200309], a[200309]; bool ok = true; void dfs(int u) { if (s[u] == -1) { if (g[u].empty()) a[u] = 0; else { a[u] = 0x3f3f3f3f3f3f3f3f; for (int v : g[u]) { a[u] = min(a[u], s[v] - s[pa...
1
#include <bits/stdc++.h> using namespace std; inline void print(vector<int> &v) { for (int i : v) cout << i << " "; cout << "\n"; } inline void print(vector<long long> &v) { for (long long i : v) cout << i << " "; cout << "\n"; } inline void print(vector<vector<int> > &v) { for (vector<int> i : v) print(i); }...
2
#include<bits/stdc++.h> using namespace std; int main() { int ten[6],ans=0; for(int i=0;i<6;i++)cin>>ten[i]; for(int i=0;i<3;i++){ int kawa=0; for(int j=1;j<4;j++)if(ten[kawa]<ten[j])kawa=j; ans+=ten[kawa]; ten[kawa]=-1; } ans+=max(ten[4],ten[5]); cout<<ans<<endl;...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string str1, str2; cin >> str1; cin >> str2; int arr[30][30], cnt = 0, num[30]; for (int i = 0; i < 30; i++) for (int j = 0; j < 30; j++) { arr[i][j] = -1; num[i] = -1; } for (int i = 0; i < t; i++) { cha...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 444, mod = 1000000007; int mul(long long a, long long b){ return a * b % mod; } int pw[maxn][maxn]; int f[maxn][maxn], a[maxn], b[maxn], sum[maxn][maxn]; int main(){ for(int i = 0; i < maxn; i++){ pw[i][0] = 1; for(int j = 1; j < maxn; j++){ pw[i][...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c[10001], d, e, f, g, h, j, i, cnt = 0; int n; cin >> n >> d; for (i = 0; i < n; i++) { cin >> c[i]; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (abs(c[i] - c[j]) <= d) { cnt++; } } } cout <...
1
#include <bits/stdc++.h> using namespace std; int n, k; int u[4040][4040]; int pre[4040][4040], p[4040][4040]; int dp[880][4040]; void rnc(int K, int l, int r, int lo, int hi) { if (l > r) return; int mid = (l + r) / 2; int mn = 1001001001, mni = -1; for (int i = lo; i <= hi; i++) { if (mn > dp[K - 1][i] + ...
5
#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<queue> #include<utility> #include<cstring> using namespace std; typedef pair<int, int> PII; int w, h, n; int mas_x_s[1010], mas_y_s[1010]; int mas_x_e[1010], mas_y_e[1010]; vector<int> vmas_x, vmas_y; bool plate[2010][2010]; int ans = 0;...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 500; const int mod1 = 1e9 + 9; const int mod2 = 1e9 + 7; const int bas = 33; inline int read() { char ch; while ((ch = getchar()) < '0' || ch > '9') ; int res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 79; vector<int> a(maxn), cnt(maxn), u(maxn, 0), is(maxn, 0); vector<vector<int> > d(maxn); void update_cnt(int in, int delta) { for (int j : d[in]) cnt[j] += delta; } int gcd(int a, int b) { if (a < b) swap(a, b); while (b) { int c = a % b; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int INF = 1e9; const long long mod = 1e9 + 7; int n, arr[N], byk; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (in...
3
#include <bits/stdc++.h> using namespace std; int n, m, k, typ[510], id[510]; int P; vector<int> s[510]; long double mp[510][510]; template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void read(T &x) { x = 0; int f ...
4
#include<bits/stdc++.h> using namespace std; int foo(string a){ int i, size = (int)a.size(); for(i = 0; i < size; i++){ if(!('0' <= a[i] && a[i] <= '9' ))return 0; } return 1; } int huga(int pl[], int count , int m){ int k = 1; while(k <= m){ if(count == m)count = 1; else count++; if(p...
0
#include <bits/stdc++.h> using namespace std; int head[1005], tot = 0, n, m, k, kx[1005], ky[1005], belong[1005], dep[1005], fa[1005][10], lg[1005]; struct edge { int to, nxt; } e[2005]; struct circle { int x, y, r; } c[1005]; bool cmp(circle a, circle b) { return a.r > b.r; } void add_edge(int x, i...
4
#include <bits/stdc++.h> using namespace std; int dp[2005][2005]; int main() { int i, j, k, n, kk, t, s; scanf("%d%d", &n, &t); memset(dp, 0, sizeof(dp)); for (i = 1; i <= n; i++) dp[i][1] = 1; for (j = 2; j <= t; j++) { for (i = 1; i <= n; i++) { for (k = i; k <= n; k += i) dp[k][j] = (dp[k...
2
#include <bits/stdc++.h> using namespace std; using pi = pair<int, int>; const int M = 1e9 + 7; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; } long long mod(long long x) { return ((x % M + M) % M); } long long add(long long a, long long b) { return mod(mod(a) + mod(b)...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define mp make_pair #define fr first #define sc second int lg(ll n) { assert(n > 0); int ans = -1; while (n) { ans++; n >>= 1; } return ans; } void solve() ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long min1, min2, min3; long long max1, max2, max3; long long n; cin >> n; cin >> min1 >> max1; cin >> min2 >> max2; cin >> min3 >> max3; for (long long i = max1; i >= min1; i--) { if (n - i >= (min3 + min2)) { for (long long j = m...
1
#include <bits/stdc++.h> using namespace std; char di[1100000]; int sum[1100000]; char ans[5000000]; int main() { while (scanf(" %s", di) != -1) { int len = strlen(di); reverse(di, di + len); char *ptr = ans; int num = 0; for (int i = 0; i < len; i++) { if (di[i] == '0') continue; int ...
4
#include<iostream> using namespace std; int main() { int X1,A; cin>>X1>>A; if(X1<A) cout<<"0"; else cout<<"10"; }
0
#include<bits/stdc++.h> #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; using namespace std; int main(){ int n;cin>>n; int a[n],x[n][n],y[n][n]; rep(i,n){ cin>>a[i]; rep(j,a[i])cin>>x[i][j]>>y[i][j]; } int mx=0; for(int tmp=0;tmp<...
0
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; if (s1 == s2) { cout << s1 << endl; } else { cout << "1" << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int K = 100; int n; vector<int> p; int sum(int x) { int cnt = 0; if (x <= 0) return 0; while (x) { cnt += x % 10; x /= 10; } return cnt; } int main() { cin >> n; for (int i = 1; i <= K; i++) { if (sum(n - i) == i) p.push_back(n - i); } so...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 10; vector<int> G[MAXN]; int color[MAXN]; long long dp[MAXN][2]; void init() { for (int i = 0; i < MAXN; i++) { G[i].clear(); } } long long qpow(long long x, long long k) { long long res = 1; while (k > 0) { if...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; vector<long long> v(n + 1); for (long long i = 1; i <= n; i++) { cin >> v[i]; } vector<long long> s(n + 1), p(n + 1); for (lo...
4
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <string> #include <vector> #include <queue> #include <map> #include <set> #include <algorithm> #include <sstream> #include <iostream> #include <cassert> using namespace std; typedef long long ll; #define REP(i,n) for (ll i=0; i<(ll)(n); ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e5 + 100); int n; long long num[maxn * 2]; int main() { scanf("%d", &n); for (int i = 1; i <= 2 * n; i++) scanf("%lld", &num[i]); sort(num + 1, num + 2 * n + 1); if (n == 1) { printf("0\n"); return 0; } long long ans = (long long)...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") #pragma GCC optimize("O3") using namespace std; const long long N = 1e5 + 10; const long long mod = 1e9 + 7; const long long INF = 1e18; const long long inf = -1e18; const long long M = 1e6; int n, x, y, us[2 * 1000000], a[2 * 1000000], used[2 * 10000...
4
#include <bits/stdc++.h> using namespace std; 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++; } long long read() { char ch = getchar(); long long x = 0; int op = 1; for (; !isdig...
1
#include<bits/stdc++.h> using namespace std; int s2i(string s){ stringstream ss; int res; ss<<s; ss>>res; return res; } int m,n; map<string,int> t; int l[100],r[100]; vector<int> change(int x){ vector<int> res(256); for(int i=l[x];i<=r[x];i++)res[i]=1; return res; } vector<int> change(string s){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum = sum + arr[i]; } float x = sum / n; if (x != (int)x) cout << "Unrecoverable configuration."; else { int count = 0; vector...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; while (n--) { int m; cin >> m; long long a[2][m]; bool b[2][m]; long long c[2][m]; for (int i = 0; i < 2; i++) { for (int j = 0; j < m; j++) { ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int N, M; int u[MAXN], v[MAXN]; vector<int> E[MAXN]; int dp[MAXN]; int dfs(int x) { if (dp[x]) return dp[x]; for (int i = 0; i < E[x].size(); i++) dp[x] = max(dp[x], dfs(E[x][i])); return ++dp[x]; } bool check(int k) { memset(dp, 0, sizeof d...
4
#include <bits/stdc++.h> using namespace std; int n, k, a, b, Q; int D[200020]; int T[2][2000020]; void Update(int v, int tl, int tr, int cur) { if (tl > cur || tr <= cur) return; if (tl == tr - 1) { T[0][v] = min(a, D[tl]); T[1][v] = min(b, D[tl]); return; } Update(2 * v, tl, (tl + tr) / 2, cur); ...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 100005; vector<pair<long long, char>> adj[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m; cin >> n >> m; for (long long i = 0; i < m; i++) { long long u, v; char c; cin >> u >> v >> c; adj[u]....
3
#include <iostream> #include <string> #include <cstdio> #include <algorithm> #include <cmath> #include <set> #include <vector> #include <map> #define loop(i,a,b) for(int i=a; i<b; i++) #define rep(i,b) loop(i,0,b) #define all(c) (c).begin(), (c).end() using namespace std; typedef vector<int> vi; int main(){ int ...
0
#include<bits/stdc++.h> #define INF 0x7fffffff typedef long long ll; using namespace std; int n,C,d[31][31],col[3][31],ans=INF; bool used[31]; void search(int x,int res) { if(x>2) { ans=min(ans,res); return; } int sum; for(int i=1;i<=C;i++) { if(used[i]) continue; sum=0; for(int j=1;j<=C;j++) sum...
0
/* * author: lcwyyds * time: 2021-05-28 22:05:58 */ #include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <typename T_container, typename T = typename enable_if< ...
5
#include <bits/stdc++.h> const long long MOD = 1000 * 1000 * 1000 + 7; const long long MOD1 = 998244353; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (long long)(res *...
2
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1 << 60; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; vector<pair<long long, long long>> antennas(n); for (auto& i : antennas) { cin >> i.first >> i.second; } antenna...
5
#include<bits/stdc++.h> #define reg register using namespace std; typedef long long ll; const int MN=1e5+5; int n,a[MN],c[MN][2]; int main(){ scanf("%d",&n); for(reg int i=1;i<=n;i++)scanf("%d",a+i); for(reg int i=1;i<=n;i++)c[a[i]][i&1]++; reg int mx1=0,smx1=0,mx2=0,smx2=0; for(reg int i=1;i<=MN-5;i++){ if(c[mx...
0
#include <bits/stdc++.h> using namespace std; inline int getInt() { int ret = 0; char ch = ' '; bool flag = 0; while (!(ch >= '0' && ch <= '9')) { if (ch == '-') flag ^= 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); } return flag ? -ret ...
4
#include <bits/stdc++.h> using namespace std; const int N = 200010; string s; int n, m; long long a[N], sum1[N], b[N], sum2[N], sum3[N], sum4[N], sum5[N], sum6[N]; string s1, s2, s3, s4, s5, s6; void init() { string s11 = "abc", s12 = "acb", s13 = "bca", s14 = "bac", s15 = "cab", s16 = "cba"; for (int i = ...
4
#include <bits/stdc++.h> using namespace std; const int maxx = 15e4 + 7; const int Inf = 1 << 30; const long long INF = 1ll << 60; int n; char S[maxx], T[maxx]; int s[maxx], t[maxx]; int tot[maxx]; int pos[30][maxx]; bool vis[maxx]; bool visT[maxx]; queue<int> qua; queue<int> que; int ans; struct PP { int ss, tt; } f...
4
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long a[n + 1], sum = 0; for (long long i = 0; i < n; i++) { cin >> a[i + 1]; sum += a[i + 1]; } if (sum % n) { cout << -1 << endl; return; } cout << (n - 1) * 3 << endl; long long m = sum / n; fo...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int one = 0; int n = s.length(); for (int i = 0, _i = (n); i < _i; ++i) { if (s[i] == '1') { for (int j = (i), _j = (n); j < _j; ++j) { if (s[j] == '0') one++; ...
1
#include<bits/stdc++.h> using namespace std; const int maxn=305; char s[maxn][maxn]; int a[maxn][maxn]; int main() { int h,w;scanf("%d%d",&h,&w);int k;scanf("%d",&k); for(int i=1;i<=h;i++) scanf("%s",s[i]+1); int now=0;memset(a,-1,sizeof a); for(int i=1;i<=h;i++) { int vis=0; for(int j=1;j<=w;j++) { if(s[...
0
#include <bits/stdc++.h> using namespace std; inline char get() { static char buf[30000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 30000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { register char c = getchar(); register long long f = 1,...
3
#include <bits/stdc++.h> struct treenode { double L, R; }; treenode tree[500000]; int i, m, n, t, x, y, z; inline treenode merge(treenode l, treenode r) { return (treenode){l.L + (1 - l.L) * r.L * (1 - l.R) / (1 - r.L * l.R), r.R + (1 - r.R) * l.R * (1 - r.L) / (1 - r.L * l.R)}; } inline void bu...
5
#include <bits/stdc++.h> using namespace std; int fun(int x) { int res = 0; while (x) { res = res * 10 + x % 10; x /= 10; } return res; } int main() { int a, b; cin >> a >> b; cout << a + fun(b) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, mx = 0, p = -1; vector<int> Tree[100005]; void dfs(int x, int d, int fa) { if (d > mx) { mx = d; p = x; } for (int i = 0; i < Tree[x].size(); ++i) if (Tree[x][i] != fa) dfs(Tree[x][i], d + 1, x); } int main() { scanf("%d%d", &n, &m); for (int...
3
#include<cstdio> #include<iostream> using namespace std; int num[60][3010]; int main(){ int n,m,s; while(scanf("%d %d %d",&n,&m,&s) && (n||m||s)){ n = n*n; for(int i=0;i<=n;i++) for(int j=0;j<=s;j++)num[i][j] = 0; num[0][0] = 1; for(int i=1;i<=m;i++){ for(int j=n-1;j>=0;j--){ for(i...
0
#include <bits/stdc++.h> const int N = 1001; const int s[] = { 0, 4784, 8978, 12981, 16901, 20732, 24523, 28249, 31916, 35585, 39176, 42818, 46430, 49962, 53516, 57023, 60523, 64040, 67489, 70985, 74417, 77879, 81285, 84679, 88055, 91433, 94878, 9824...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, i, j, k; cin >> n >> m; string s[n]; for (i = 0; i < n; i++) { cin >> s[i]; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (s[i][j] == '#') { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int arr[111], n; int res = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int i = 0; i < n; i++) { int tmp = 0; for (int j = i; j < n; j++) { tmp ^= arr[j]; if (tmp > res) res = tmp; } } ...
1
#include <bits/stdc++.h> using namespace std; struct Vote { int p, c; } v[3005]; bool cmp(const Vote &a, const Vote &b) { return a.c > b.c; } int main() { int n, m, vote[3005] = {0}; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d%d", &v[i].p, &v[i].c); int mx = 0; long long ans = 1e16; bool ...
3
#include <bits/stdc++.h> using namespace std; struct mindol { int b, g, r; }; bool check[201][201][201]; queue<mindol> q; int main() { int n; scanf("%d\n", &n); int r = 0, g = 0, b = 0; for (int i = 1; i <= n; i++) { char c; scanf("%c", &c); if (c == 'R') r++; else if (c == 'G') g+...
2
#include <bits/stdc++.h> using namespace std; template <class T> void Read(T& x) { x = 0; int flag = 0, sgn = 1; char c; while (c = getchar()) { if (c == '-') sgn = -1; else if (c >= '0' && c <= '9') x *= 10, x += c - '0', flag = 1; else if (flag) break; } x *= sgn; } const int...
2
#include <bits/stdc++.h> using namespace std; const int N = 3010; int n; int x[N], y[N], top; pair<int, pair<int, int> > st[N * N]; bitset<N> adj[N]; int sqr(int u) { return u * u; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &x[i], &y[i]); } for (int i = 1; i <= n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } const int MAXN = 2010; const long long INF = 1e14; long long a[MAXN], dp[MAXN]; long long N, M; bool judge(long long mid) { for (int i = 1; i <= N; i++) dp[i] = i - 1; for (int i = 2; i <= N; i++) { fo...
4
#include <iostream> #include <vector> #include <utility> #include <algorithm> using namespace std; #define WIN 1000 #define LOSE -1 struct Bigger { bool operator()(pair<int, char>a, pair<int, char>b) { return a.first > b.first; } }; int main() { int n; while (cin >> n) { if (n == 0) b...
0
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> n >> m; string a = ""; bool l = 0; int b, aa; for (int j = 0; j < m; j++) cin >> b >> aa; for (int i = 0; i < n; i++) { if (l) a += "1"; else a += "0"; l = l ^ 1; } cout << a << endl; }
2
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, -1, 0, 1, -1, -1, 1}; int dy[] = {1, 0, 0, -1, 1, -1, 1, -1}; string dim[] = {"R", "D", "U", "L", "RD", "LU", "RU", "LD"}; void File_input(string pathIn) { freopen(pathIn.c_str(), "r", stdin); } void File_output(string pathOut) { freopen(pathOut.c_str(), "...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> adj[N], adjt[N]; int dist[N]; int n, m, k; void bfs(int orig) { memset(dist, -1, sizeof(dist)); queue<int> q; dist[orig] = 0; q.push(orig); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : adj[u]) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const long long mod = 1e9 + 7; const int oo = 1e9; set<int> s[101]; char mat[101][10000]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%s", mat[i]); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j...
1
#include <bits/stdc++.h> int a[2000], b[2000]; int n, k; int t[2000]; long long inverse(long long a, long long mod) { long long b = mod, x = 0, y = 1, t, q, lastx = 1, lasty = 0; while (b) { q = a / b; t = a, a = b, b = t % b; t = x, x = lastx - q * x, lastx = t; t = y, y = lasty - q * y, lasty = t;...
5
#include <bits/stdc++.h> using namespace std; char a[50][50]; int dd[50]; int d[50]; int ind[50][50]; int ans; vector<pair<pair<int, int>, pair<int, int> > > bl; int cc[50]; int cnt[10][10]; void search(int x) { int i, j, xx, yy, b1; if (x == 7) { b1 = 1; memset(cnt, 0, sizeof(cnt)); for (i = 0; i < 28;...
1
#include<bits/stdc++.h> using namespace std; const int N = 1e7; int prime[N]; bool is_prime[N]; int main(){ //高速エラトステネスできるようになりたい int p = 0; fill(is_prime + 2,is_prime + N,1); for(int i = 2; i < N; i++){ if(is_prime[i]){ prime[p++] = i; for(int j = 2*i; j < N; j+=i) is_prime[j] = 0; } }...
0
#include <bits/stdc++.h> using namespace std; long long i, n, j, k, l; long long a[105], b[105]; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] % 2 == 0) { l += a[i]; } else { j++; b[j] = a[i]; } } if (j == 0) { cout << 0 << endl; } else { sor...
2
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; using VI = vector<int>; int n, d, t, x, y; int main() { cin >> t; while (t--) { cin >> n >> x >> y >> d; if (x % d == y % d) cout << abs(x - y) / d << endl; else { int ans = -1; if (y % d ==...
1
#include<stdio.h> int main(){ char str[4]; scanf("%s",str); printf("ABC%s",str); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int x, y; int ct1 = 0, ct2 = 0; map<pair<int, int>, int> m1, m2; for (int i = int(1); i <= int(n); i++) { cin >> x >> y; if (x < y) m1[make_pair(x, y)] =...
4
#include <bits/stdc++.h> using namespace std; int main() { string a1; cin >> a1; char c, d; c = 'a'; d = 'z'; int e, f, s = 0; for (int i = 0; i < a1.size(); i++) { if (i != 0) { e = min((abs(a1[i - 1] - c) + abs(d - a1[i]) + 1), (abs(a1[i - 1] - d) + abs(c - a1[i]) + 1)); f ...
1
#include <iostream> #include <math.h> using namespace std; int main() { int a,b; while(cin>>a>>b) { int i=0; for(i=0;a+b>=pow(10,i);i++){} cout<<i<<endl; } return 0; }
0
#include<iostream> #include<vector> #include<complex> #include<algorithm> #include<set> #define rep(i,n) for(int i = 0;i < n ; ++i) using namespace std; using ll = long long; using Point = complex<double>; const double eps = 1e-7; double dot(Point a, Point b){ return real(conj(a)*b); } double cross(Point a, Poi...
0
#include <bits/stdc++.h> using namespace std; inline int sgn(double x) { return (x > -1e-10) ? ((x > 1e-10) ? 1 : 0) : -1; } struct Point { double x, y; Point() {} Point(double a, double b) : x(a), y(b) {} double ang() { return atan2(y, x); } double len() { return sqrt(x * x + y * y); } Point nor() { do...
6
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 77; long double m, R; long double ans, d = sqrt(2); int main() { cin >> m >> R; ans += R * (2 * (m + 2) * (m + 1) * m / 3 - 2 * m); ans -= R * (2 - d) * ((m - 2) * (m - 1) + m * (m - 1)); ans = ans / m / m; cout << fixed << setprecision(10) ...
2
#include<bits/stdc++.h> using namespace std; #define reps(i,j,n) for(int i = (j) ; i < (int)(n) ; ++i) #define rep(i,n) reps(i,0,n) #define each(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++) typedef pair< int , int > Pi; typedef pair< int , Pi > Pii; typedef long long int64; co...
0
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { while (b) b ^= a ^= b ^= a %= b; return a; } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; inline int src() { int ret; scanf("%d", &ret); return ret; } int x, t, a, b, da, db; int main() { int i, j, k; int TC, tc; cin >> x >> t ...
1
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; long long cnt = 0,ans = 0; for(int i = 0; i < s.size() - 1; ++i){ if(s[i] == 'A') cnt++; else if(s[i] == 'B' && s[i+1] == 'C') { i++; ans += cnt; } else cnt = 0; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline bool isPrime(long long int n) { if (n <= 1) { return false; } if (n <= 3) { return true; } if (n % 2 == 0 || n % 3 == 0) { return false; } for (int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) { return false;...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; for (int i = 1; i < n; i++) { ans += (n - i) * i; } ans += n; cout << ans << endl; }
2
#include <bits/stdc++.h> using namespace std; int main() { double r, x, y, x1, y1; cin >> r >> x >> y >> x1 >> y1; double d = sqrt(pow(x - x1, 2) + pow(y - y1, 2)); cout << ceil(d / (2 * r)) << "\n"; return 0; }
2
#include <bits/stdc++.h> using namespace std; template <typename T, typename L> bool smax(T &x, L y) { return x < y ? (x = y, true) : false; } template <typename T, typename L> bool smin(T &x, L y) { return y < x ? (x = y, true) : false; } void calc(); const int MAXN = 1e6 + 15; string s; bool can; int f[MAXN]; vec...
4
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <stack> #include <cctype> #include <complex> #include <vector> #include <set> #include <map> #include <algorithm> #include <functional> #include <cassert> using namespace std; int f(int n, int k, vector<int> a){ in...
0
#include <bits/stdc++.h> using namespace std; void scan(int &n) { int sign = 1; n = 0; char c = getchar_unlocked(); while (c < '0' || c > '9') { if (c == '-') sign = -1; c = getchar_unlocked(); } while (c >= '0' && c <= '9') n = (n << 3) + (n << 1) + c - '0', c = getchar_unlocked(); n = n * si...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); unsigned long long int n, m, counter = 0; cin >> n >> m; for (int i = 1; i <= n; ++i) { counter += (m + (i % 5)) / 5; } cout << counter << '\n'; return 0; }
1
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383279; const long double EPS = 1e-6; const int INF = 1e9 + 7; const long long MOD = INF; const long long maxn = 5e5 + 2; const long long HASH_MODS[] = {1000000007333, 1000000009367, 1000000075747, ...
4
#include <bits/stdc++.h> using namespace std; long long mo = 1000000007; long long n, p, a[123456], ans; long long f[123456][3][3][3], mul[123456]; int main() { scanf("%lld%lld", &n, &p); for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); mul[0] = 1; for (long long i = 1; i <= n; i++) { mul[i] = (mul[...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; int n, m; int a[maxn], rk[maxn], tr[maxn], ope[maxn], typ[maxn], ans[maxn]; bool cmp1(int q, int w) { return q < w; } bool cmp2(int q, int w) { return q > w; } int main() { while (~scanf("%d%d", &n, &m)) { rk[0] = 0, ope[0] = 0; int l...
3