solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long MAX = 2e5 + 5; long long n = 0, i = 0, j = 0; void solve() { cin >> n; vector<long long> v(n); long long mp[n + 1]; memset(mp, 0, sizeof(mp)); for (long long i = (0); i < (n); i++) { cin >> v[i]; mp[v[i]]++...
5
#include <bits/stdc++.h> using namespace std; int bsearch(int l, int r, int I, int n) { int mid, ans = 1; long double tmp; while (l <= r) { mid = l + ((r - l) >> 1); tmp = ceil(log2(mid * 1.)) * n; if (tmp <= I * 8) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; ...
1
#include <bits/stdc++.h> using namespace std; int n, m; double a[5005][5005]; int M[100008][20], mx[5005], sz[5005]; int b[100009]; vector<int> G[5005]; struct node { int l, r; double p; bool operator<(const node &rhs) const { if (l != rhs.l) return l < rhs.l; else return r > rhs.r; } } p[50...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; string s, t; cin >> n >> m >> q >> s >> t; vector<int> ans; for (int i = 0; i < n; i++) { bool flag = 1; for (int j = 0; j < m; j++) { if (t[j] != s[j + i]) { flag = 0; ...
2
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-12; const double PI = acos(-1.0); enum {}; template <int N> class Dsets { int p[N], r[N]; public: Dsets() { clear(); } void clear() { for (int i = 0; i < N; ++i) p[i] = i; memset(r, 0, sizeof(r)); } int parent(int a) { if (p[a] ...
4
#include <iostream> #include <vector> #include <cstdio> using namespace std; class dice { private: int _top; int _front; public: dice(int top, int front, int height); int x; int y; int height; int top(); int front(); int left(); int right(); int back(); int under(); void rollFront(); voi...
0
#include<iostream> using namespace std; int main() { int q_lower,bud,c_aizu,c_normal,q_aizuupper; while(cin>>q_lower>>bud>>c_aizu>>c_normal>>q_aizuupper){ int q_aizu=0,q_normal=0; q_aizu+=q_aizuupper; bud-=q_aizu*c_aizu; if(bud<0){ q_aizu-=(-bud+(c_aizu-1))/c_aizu; bud+=((-bud+(c_aizu-1))/c_aizu)*c_ai...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, m = 0, m_m; scanf("%d%d%d", &n, &a, &b); for (int i = 1; i < n; i++) { m_m = min(a / i, b / (n - i)); if (m_m > m) m = m_m; } printf("%d\n", m); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int p = sqrt(i * i + j * j); if (sqrt(i * i + j * j) <= n && sqrt(i * i + j * j) == p) ans++; ...
1
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using vecint = vector<int>; using vecll = vector<ll>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vecint d(m); for (int i = (0); i < (m); ++i) cin >> d[i]; sort(begin(d), end(d)); int g, r; cin >> g >>...
3
#include <bits/stdc++.h> using namespace std; pair<int, int> c[505050]; int a[505050], b[505050], l, r, mid, s, t, n, L; bool check(int x) { for (int i = 0; i < n; i++) { c[i].first = lower_bound(b, b + n * 2 + 1, a[i] - x) - b; c[i].second = lower_bound(b, b + n * 2 + 1, a[i] + x + 1) - b; } s = c[0].fir...
6
#include <bits/stdc++.h> using namespace std; int N, X, i, j; void fill(int P, bool W, int A[][2], int B[]) { B[P] = 1 + W; if (B[A[P][0]] == 0) { fill(A[P][0], !W, A, B); } if (B[A[P][1]] == 0) { fill(A[P][1], !W, A, B); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e9 + 1; long long n, m_z, ans; vector<pair<int, int> > comp; int main() { cin >> n; for (int i = 0; i < n; i++) { long long a; cin >> a; long long u = 0; for (int j = 0; j < a; j++) { long long b; cin >> b; u = ma...
1
#include <bits/stdc++.h> using namespace std; int cost[505][26][26]; int dp[505][26][26]; int arr[505][505]; int coll[505][2]; char str[505][505]; int row, col; void pre() { int i, j, k, l, c; memset(dp, 1000000, sizeof dp); memset(cost, 1000000, sizeof cost); for (i = 0; i < row; i++) { for (k = 0; k < 26;...
5
#include<cstdio> using namespace std; int main() { int n,fi,se,th,fo,x1,x2,y1,y2,z1,z2,w1,w2; while(true) { scanf("%d",&n); if(n==0)break; for(int i=0;i<n;i++) { scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2); fi=x1*x2+(-1)*(y1*y2)+(-1)*(z1*z2)+(-1)*(w1*w2); se=x1*y2+y1*x2+z1*w2+(-1)*w1*z2; th=x1*z2+(-1)*(...
0
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <complex> #include <queue> #include <map> #include <set> #include <cstring> #include <cstdlib> #include <string> #include <cmath> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin...
0
#include <bits/stdc++.h> using namespace std; int n, dp[100005], a, b; int ts[10][10] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 2, 2}, {0, 0, 0, 0, 0, 0, 0, 4, 4, 4}, {0, 0, 0, 0, 0, 4, 4, 5, 5, 5}, {0, 0, 0, 0, 0, 5, 5, ...
3
#include <bits/stdc++.h> using namespace std; int f[35][35][2]; int c[35][35]; int n; int main() { for (int i = 0; i <= 30; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007; } scanf("%d", &n); f[30][0][1] = 1; for (int i = 30; i >= 1; i--) ...
4
#include <bits/stdc++.h> using namespace std; int n, m; int a[105], b[35]; int bb[35]; long long ans, sum; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; sum -= a[--b[i]]; bb[i] = a[b[i]]; } sort(bb, bb + m...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, sum, count; cin >> n; int a[n][n]; int row[n], col[n]; for (i = 0; i < n; i++) { sum = 0; for (j = 0; j < n; j++) { cin >> a[i][j]; sum += a[i][j]; } row[i] = sum; } for (j = 0; j < n; j++) { sum = 0; ...
1
#include <bits/stdc++.h> #define INF (2e9) #define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i)) #define REP(i, n) FOR(i, 0, n) using namespace std; template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T& a, ...
0
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793; const long double DEL = 1e-10; const int mod = 1000000007; inline void read(long long &x) { long long c = getchar(); x = 0; long long neg = 0; for (; ((c < 48 || c > 57) && c != '-'); c = getchar()) ; if (c == '-') { ...
4
#include <bits/stdc++.h> using namespace std; const int MX = 3e5 + 7; vector<int> g[MX]; const int INF = 1e9 + 7; vector<int> comp; bool used[MX]; void dfs(int v) { used[v] = 1; for (int i : g[v]) if (!used[i]) dfs(i); comp.push_back(v); } set<pair<int, int> > gr; int main() { iostream::sync_with_stdio(0); ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n, ans, temp; pair<int, int> arr[N + 9]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d %d", &arr[i].first, &arr[i].second); sort(arr, arr + n); for (int i = 1; i < n; ++i) { if (arr[i].first > arr[temp].first && arr[i...
3
#include<bits/stdc++.h> using namespace std; #define N 5000 + 10 int f[N][N],n,ans; char s[N]; int main(){ ios::sync_with_stdio(false); cin>>n>>s; for(int i=n-1;i>=0;i--) for(int j=n-1;j>=0;j--){ if(s[i]==s[j]) f[i][j]=max(f[i][j],f[i+1][j+1]+1); ans=max(ans,min(f[i][j],j-i)); } cout<<ans; }
0
#include <bits/stdc++.h> using namespace std; const int MN = 201234, MX = 42; int dp[MX][MX], k[MN]; vector<pair<int, int> > all[MN], gd[MN]; void get(vector<pair<int, int> > &vec, int now, int x) { for (auto &p : vec) { int v = p.first, y = p.second; int mark[MX] = {}; for (int i = 0; i < v; i += y) mark...
6
#include <bits/stdc++.h> using namespace std; int N, M; long long dp[1005][1005]; int lft[505]; int rht[505]; int arr[1000005]; vector<int> v; vector<int> idx[505]; const long long MOD = 998244353; long long add(long long a, long long b) { return (a + b) % MOD; } long long mult(long long a, long long b) { return a * b ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 200; typedef long double matrix[maxn][maxn]; typedef long double vec[maxn]; matrix a; vec f; long double P[maxn]; int M, n, i, j; void mul(matrix a, matrix b, matrix res) { matrix c = {0}; int i, j, k; for (i = 0; i <= n; i++) for (j = 0; j <= n; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b, c, d, i, j, k, l, g, s; cin >> a; map<long long int, long long int> m; for (i = 0; i < a; i++) { cin >> b; auto it = m.find(b); if (it == m.end()) { m.insert(pair...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); map<int, int> m; std::map<int, int>::iterator it; int i; for (i = 0; i < n; i++) { c...
3
#include<iostream> #include<map> using namespace std; int C[10][10], A[50000]; int main() { int H, W; cin >> H >> W; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> C[i][j]; for (int i = 0; i < H*W; i++) cin >> A[i]; for (int k = 0; k < 10; k++) for (int i = 0; i < 10; i++) for (i...
0
#include <iostream> using namespace std; int main(){ int a,b; while(cin>>a>>b){ int a2=a; int b2=b; while(true){ if(a>b){ a=a%b; }else{ b=b%a; } if(a==0||b==0)break; } cout<<max(a,b)<<" "<<a2/max(a,b)*b2<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; struct cmp { bool operator()(const pair<int, int>& a, const pair<int, int>& b) const { int len1 = a.second - a.first + 1; int len2 = b.second - b.first + 1; if (len1 == len2) return a.first < b.first; return len1 > len2; } }; int main() { int t; cin ...
4
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #define SF scanf #define PF printf #define MAXN 1010 #define MOD 1000000007 using namespace std; typedef long long ll; vector<int> a[MAXN],id[MAXN]; int vis[MAXN]; int n,m,k,cnt; int dfn[MAXN],low[MAXN]; ll mi[MAXN],inv[MAXN],fac[MA...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, N = 1e6 + 5; int a, b, n; long long ans, f[N]; bool good(int sum) { while (sum != 0) { if (sum % 10 != a && sum % 10 != b) return 0; sum /= 10; } return 1; } long long power(long long b, long long p) { if (!p) return 1; if (p == 1)...
3
#include <bits/stdc++.h> using namespace std; int ntest = 0, test = 0; inline void init(); inline void run(); inline void stop() { ntest = test - 1; } int main() { init(); while (++test <= ntest) { run(); } return 0; } const int INF = (int)1E9 + 5; const double EPS = 1E-11; const long long MOD = (long long)...
5
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 7; const int base = 19260817; int a[mx]; int n; unsigned long long hs[mx * 2]; void init() { hs[0] = 1; for (int i = 1; i <= 2 * n; i++) hs[i] = hs[i - 1] * base; } int main() { int m, x; scanf("%d", &n); init(); for (int i = 1; i <= n; i++)...
5
#include<bits/stdc++.h> #define N 1000005 using namespace std; int n,m,q; int z,g,mod; int u[N],v[N],w[N]; int fa[N * 6]; bool vis[2][N]; template <class T> inline void read(T &x) { char c;int sign=1; while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1; x=c-48; while((c=getchar())>='0'&&c<='9') x=(x<<1)+(x<<3)+c-48;...
0
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> ans; vector<pair<int, int> > a; bool solve() { int ind = 0; for (int i = 0; i < ((int)a.size()); ++i) { int num = a[i].first; num = min(num, n / 2); for (int j = 0; j < num; ++j) { if (ans[ind] == -1) { ans[ind] = a[i].sec...
4
#include <bits/stdc++.h> using namespace std; int binomial(int n, int k) { int C[k + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1]; } return C[k]; } int prime(int x) { int flag = 0; for (int i = 2; i <= sqrt(x); i++) ...
2
#include <bits/stdc++.h> using namespace std; const int N = 10005; const double eps = 1e-12; struct P { int x, y; inline void in() { scanf("%d%d", &x, &y); } inline bool operator==(const P& rhs) { return x == rhs.x && y == rhs.y; } inline P operator-(const P& rhs) const { return (P){x - rhs.x, y - rhs.y}; } i...
5
#include <bits/stdc++.h> using namespace std; map<int, long long> help; map<int, long long>::iterator it; map<int, int> done; int modulo(int a, long long b, int c) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % c; } y = (y * y) % c; b /= 2; } return x % c; } int ...
4
#include <bits/stdc++.h> long long l, r; long long lower, upper, base; long long opt; int p[] = {5, 4, 6, 3, 7, 2, 8, 1, 9, 0}; bool check(long long L, long long R) { if (R < l || L > r) return false; return true; } bool dfs(long long a, long long b, long long base) { if (a == 0) b = 0; long long L = a; long ...
1
#include <bits/stdc++.h> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } const ...
5
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; namespace Xrocks {} using namespace Xrocks; namespace Xrocks { class in { } user_input; class out { } output; in& operator>>(in& X, int& Y) { scanf("%d", &Y); return X; } in& operator>>(in& X, char* Y) { scanf("%s", Y); return X; } in...
3
#include <bits/stdc++.h> long long int const MOD = 1000000007; long long int const N = 3000005; long long int const LN = 20; long long int const inf = 8e18; using namespace std; long long int n, m, a[N]; long long int ok[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; f...
6
#include <bits/stdc++.h> using namespace std; const double eps = 1e-5; const double Pi = 3.1415926535897932; const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1}; const int N = 2e6 + 100; int cnt[N]; map<int, int> mp[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long long ans = 0; f...
5
#include <bits/stdc++.h> using namespace std; int n, m, k; int arr[100100]; int A[23][100100]; int B[23][100100]; int C[100100]; int tree[100002 * 4]; void update(int node, int i, int j, int idx, int val) { if (idx < i || idx > j) return; if (idx >= i && idx <= j && i == j) { tree[node] = val; return; } ...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5; const int MAX2 = 1e9; const long long MAX3 = 1e12; int gcd(int a, int b) { if (b == 0) { return a; } int a1 = a % b; return gcd(b, a1); } void swap1(char& x, char& y) { char t = x; x = y; y = t; } int main() { int n, a, b, c, sum = 0...
1
#include <bits/stdc++.h> using namespace std; int main(){ int A,B,C; cin >> A >> B >> C; cout << ( (A-C)*(C-B)>0?"Yes":"No" ) << endl; }
0
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second typedef vector<int> vi; typedef pair<int,int> pii; typedef pair<int,pii> pip; const int INF = (1<<25); const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; struct DATA{ string s; int score; }; int main(){ int n; int cn...
0
#include <bits/stdc++.h> const int maxn = 1e6 + 9; int Read() { int x(0), f(1); char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3ll) + (x << 1ll) + c - '0'; c = getchar(); } return x * f; } struct node { int...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 9; const int maxk = 9; int n, k; char s[maxn][maxk]; int a[maxn], num[maxn]; int main() { while (scanf("%d%d", &n, &k) != EOF) { for (int i = 0; i < n; i++) scanf("%s", s[i]); for (int i = 0; i < k; i++) a[i] = i; int ans = 1000000000; do ...
2
#include<iostream> using namespace std; int set[10002]; int find(int); int main(){ int n,q; cin>>n>>q; for(int i=0;i<=n;i++) set[i]=i; int qu,x,y; for(int i=0;i<q;i++){ cin>>qu>>x>>y; if(qu){ if(find(x)==find(y)) cout<<1<<endl; else cout<<0<<endl; }else{ set[find(x)]=find(y); } } return 0;...
0
#include <bits/stdc++.h> using namespace std; const int NMAX = 400000; int h[NMAX]; vector<int> all_vals; struct Op { int type; int p, x; long long int v; } ops[NMAX]; int sz; int aib_cnt[2 * NMAX]; long long int aib_sum[2 * NMAX]; template <class T> void update(T aib[], int where, T val) { for (; where <= sz; ...
5
#include <bits/stdc++.h> using namespace std; string s; map<string, int> M; char op; int main() { int T; cin >> T; getchar(); while (T--) { op = getchar(); cin >> s; getchar(); if (op == '?') { while (s.length() > 1 && s[0] == '0') s.erase(s.begin()); cout << M[s] << endl; } else...
1
#include <bits/stdc++.h> int a, b; int ans = 0; void check(int x) { if (x > b) { ++ans; } } int main() { scanf("%d %d", &a, &b); a -= b; if (a == 0) { printf("infinity\n"); } else { for (int i = 1; i * i <= a; ++i) { if (a % i == 0) { check(i); if (i != a / i) { c...
2
#include <bits/stdc++.h> using namespace std; int answer(unsigned long long int k) { unsigned long long int xx = 9; unsigned long long int i = 1; long long int aivyn = 0; while (xx * i <= k) { aivyn += xx; k = k - xx * i; xx = xx * 10; i++; } aivyn += (k / i); if (k % i) { aivyn++; }...
5
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long long INF64 = (long long)1e18; #pragma comment(linker, "/STACK:16777216") #pragma warning(disable : 4786) int Set(int N, int pos) { return N = N | (1 << pos); } int Reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, i...
2
#include <bits/stdc++.h> using namespace std; bool check = false; string ans = "", s; void solve() { if (cin >> s) { ans += s; if (s == "pair") { ans += "<"; solve(); ans += ","; solve(); ans += ">"; } } else { check = true; } } int main() { int n; cin >> n; sol...
3
#include <bits/stdc++.h> using namespace std; const int N = 202020; int a[N], n, m, x; string s; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> s; n = s.size(); cin >> m; for (int i = 1; i <= m; i++) { cin >> x; int y = n - x + 1; a[x]++, a[y + 1]--; } for (int i = 1; i ...
2
#include <bits/stdc++.h> using namespace std; char c[123]; int main() { fill(c, c + 123, '.'); string s; cin >> s; set<char> p = {'A', 'H', 'I', 'M', 'O', 'o', 'T', 'U', 'V', 'W', 'w', 'v', 'X', 'x', 'Y'}; c['A'] = 'A'; c['b'] = 'd'; c['d'] = 'b'; c['H'] = 'H'; c['I'] = 'I'; c['M'] ...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& a) { char c = getchar(); int f = 1; a = 0; for (; c > '9' || c < '0'; c = getchar()) if (c == '-') f = -1; for (; c <= '9' && c >= '0'; c = getchar()) a = a * 10 + c - 48; a *= f; } const int o = 1e5 + 10; inline long l...
3
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } static void redirec...
2
#include<bits/stdc++.h> using namespace std; int main(){ int y,m,d; string g; while(cin>>g&&g!="#"){ cin>>y>>m>>d; if(y==31&&m>=5){ g='?'; y-=30; } if(y>31){ g='?'; y-=30; } cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> v(n); for (int i = 0; i < n; i++) { cin >> a[i]; v[i] = a[i]; } int z = 0; int o = 0; for (int i = 0; i < n...
2
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) :...
2
#include "bits/stdc++.h" using namespace std; int main() { int n; scanf("%d", &n); bitset<10001> a(1); for(int i = 0, j; i < n; ++i) { scanf("%d", &j); a |= a << j; } for(int i = 10000; i >= 0; --i) { if(i % 10) { if(a.test(i)) { printf("%d\n", i); return 0; } } } printf("0\n"); re...
0
#include <array> #include <iostream> #include <vector> #include <unordered_map> using namespace std; int judge(array<int, 30>& cards, int rem) { if (rem == 0) return 1; for (int i = 0; i < 30; i++) { if (cards[i] >= 3) { cards[i] -= 3; int res = judge(cards, rem - 3); ...
0
#include <bits/stdc++.h> using namespace std; void err(istringstream *iss) {} template <typename T, typename... Args> void err(istringstream *iss, const T &varVal, const Args &...args) { string varName; *iss >> varName; if (varName.back() == ',') varName.back() = ' '; cout << varName << " = " << varVal << "; ",...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int inf = 1e9; map<pair<int, int>, int> vis, used, str; set<pair<int, int> > crd; ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } struct Line { int l, r, y; }; int gcd(...
5
#include <bits/stdc++.h> using namespace std; int main() { int k, i, j; cin >> k; i = k / 2; j = k % 2; if (k > 36) cout << -1; else { for (k = 0; k < i; k++) cout << 8; for (k = 0; k < j; k++) cout << 4; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, N; int cnt[25]; int myAbs(int x) { return max(x, -x); } vector<pair<int, int>> ans; void print(int a, int b, int n) { for (int i = 0; i < n; i++) { ans.push_back({a, b}); } } void solve1(int ind, int a, int b, int c) { if (ind == n) return; solve1(ind + 1...
4
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; typedef vector<int> vi; int main() { int N, M; cin >> N; vi vec1(N); rep(i, N) cin >> vec1.at(i); cin >> M; vi vec2(M); rep(i, M) cin >> vec2.at(i); vi vec3; set_un...
0
#include <bits/stdc++.h> using namespace std; void print(bool n) { if (n) cout << "YES"; else cout << "NO"; cout << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long ttt; cin >> ttt; for (long long T = 1; T <= ttt; T++) { long long n; cin >> n; long l...
1
#include<iostream> using namespace std; int main() { char S; cin >> S; if(S=='S')cout << "Cloudy"; else if(S=='C') cout<<"Rainy"; else cout<<"Sunny"; return 0; }
0
#include <algorithm> #include <iostream> #include <limits.h> #include <math.h> #include <set> #include <stack> #include <stdlib.h> #include <string> #include <vector> #define el endl #define fd fixed #define INF INT_MAX/2-1 #define pb push_back using namespace std; int main() { int n, tmp; string s, res, station...
0
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, -1, 1}; int dy[] = {-1, 1, 0, 0}; int a[305][305]; int p[305][305]; int bounds(int x, int y, int n, int m) { if (x >= 0 && x < n && y >= 0 && y < m) return 1; return 0; } int main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf(...
2
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; int n, m, x, p[111111], cnt[111111], y, cc, used[111111], timer; pair<int, int> a[111111], curp; long long ans, sum, cursum, v[111111]; vector<vector<int> > g; bool w[111111]; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { int x; cin >> x; arr[i] = x; } int answer = 0; int previous = arr[0]; int sizee = 1; for (int i = 1; i < n; i++) { if (arr[i] > previous) { sizee++; previou...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3002; const long long MOD = 1000000007; int n, k, x, bigger; vector<int> a; bool same[maxn]; map<int, bool> visit; map<int, int> Lit; queue<int> q; int main() { cin >> n >> k; for (int i = 1; i <= k; i++) { scanf("%d", &x); if (!same[x]) a.push_...
3
#include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef long long LL; void iostream_init() { ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(5); } typedef complex<double> P; P input() { double x, y; cin >> x >> y; re...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t, j = 0, i, a, b, n; cin >> t; while (j < t) { cin >> a >> b >> n; if (a > n) { cout << b << endl; } else { if (n % a == b) cout << n << endl; else { if (n % a > b) { i = n - ((n % a) - b)...
1
#include <bits/stdc++.h> using namespace std; int main() { long long x2, x1, x3, ort, mn, mx, q, w; cin >> x1 >> x2 >> x3; mn = min(min(x1, x2), x3); mx = max(max(x1, x2), x3); if ((x1 > x2 && x1 < x3) || (x1 > x3 && x1 < x2)) ort = x1; else if ((x2 > x1 && x2 < x3) || (x2 > x3 && x2 < x1)) ort = x2...
1
#include <bits/stdc++.h> const int MAXN = 2000; const int MOD = 998244353; int pow_mod(int b, int p) { int ret = 1; while (p) { if (p & 1) ret = 1LL * ret * b % MOD; b = 1LL * b * b % MOD; p >>= 1; } return ret; } int fct[MAXN + 5], ifct[MAXN + 5], pw[MAXN + 5]; int comb(int n, int m) { return 1LL...
5
#include <bits/stdc++.h> using namespace std; int dp[500010]; int c[100]; int main() { int n, d; scanf("%d%d", &n, &d); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 500000 - c[i]; j >= 0; j--) { if (dp[j]) dp[j +...
4
#include <bits/stdc++.h> using namespace std; #define MAX 100000 #define INF (1LL<<55) typedef long long ll; typedef pair<ll, ll> pll; int main() { ll N, M, K, S, P, Q; cin >> N >> M >> K >> S >> P >> Q; vector<ll> z(N, INF); queue<int> q; for (int i = 0; i < K; i++) { ll c; ...
0
#include <bits/stdc++.h> int FASTBUFFER; const int mo = 1000000009; using namespace std; struct Matrix { int n; int a[4][4]; Matrix() {} Matrix(int n) : n(n) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) a[i][j] = 0; } friend Matrix operator*(Matrix a, Matrix b) { int n = a.n; ...
3
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long all = 0; long long ans = 0; for (long long i = 0; i < n; i++) { long long x; cin >> x; ans = max(ans, x); all += x; } n = n - 1; lon...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 300010; int n, m, fa[105]; int g[105][105], deg[105]; queue<int> q; int fnd(int x) { return fa[x] == x ? x : fa[x] = fnd(fa[x]); } int main() { scanf("%d%d", &n, &m); if (m != n) { printf("NO"); return 0; } for (int i = 1; i <= n; i++) fa[i]...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) ...
4
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> bool Max(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; } template <typename T1, typename T2> bool Min(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; } int hsb_loc(int n) { return 31 - __builtin_clz(n); } int hsb_loc(long long n) { return 6...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double eps = 1e-9; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; const int N = 5e5 + 50; vector<int> g[N]; char s[N]; int n, q; bool ans[N]; vector<pair<int, int> > v[N]; int son[N]; int sz[N]; int dep[N]; void dfs_so...
4
#include <bits/stdc++.h> using namespace std; struct str_hash { vector<int> h1, h2, b1, b2; const static int BASE = 37, M1 = 1e9 + 7, M2 = 1e9 + 9; str_hash() {} str_hash(const string& s) : h1(s.size() + 1), h2(s.size() + 1), b1(s.size() + 1, 1), b2(s.size() + 1, 1) { for (int ...
5
#include <bits/stdc++.h> using namespace std; struct P {int x,y,z;}; int main() { int a,d,n,m,k; cin >> n >> a >> d >> m; P p[m]; for(int i=0; i<m; i++) cin >> p[i].x >> p[i].y >> p[i].z; cin >> k; for(int i=m-1; i>=0; i--) { if(!p[i].x&&p[i].y<=k&&k<=p[i].z) k=p[i].z+p[i].y-k; } int ans=a+d*(k-1);...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m; cin >> n >> m; long long int arr[m]; for (long long int i = 0; i < m; i++) cin >> arr[i]; long long int sum_len = 0; for (long long int i = 0; i < m; i++) { sum_len += arr[...
3
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<double> v(N), w(N); for (int i=0; i<N; ++i) { cin >> v[i]; w[i] = v[i]; } sort(w.begin(), w.end()); int p, q; for (int i=0; i<N; ++i) { p = lower_bound(w.begin(), w.end()...
0
#include <string> #include <set> #include <iostream> using namespace std; int main() { string s, t; cin >> s >> t; int cnt[2][30]; for (int i = 0; i < 30; i++)cnt[0][i] = cnt[1][i] = 0; for (auto e : s) cnt[0][e - 'a']++; for (auto e : t) cnt[1][e - 'a']++; multiset<int> c[2]; for (int i = 0; i < 2; i++)for (...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 3e5 + 5; int N, A[MAXN]; struct E { int i, j, x; }; void solve() { cin >> N; vector<E> v; int sum = 0; for (int i = 1; i <= N; i++) cin >> A[i], sum += A[i]; if (sum % N) { cout << -1 << '\n'; return; } for (...
2