solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int t; long long int i, max, n, k, d; cin >> t; while (t--) { max = 0; cin >> n >> k; if (k >= n) { cout << "1" << endl; continue; } for (i = 1; i * i <= n; i++) { if (i > k) break; if (n % i == 0) { i...
4
#include <bits/stdc++.h> using namespace std; 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; return true; } vector<long long int> prime; ...
2
#include <bits/stdc++.h> using namespace std; string suffics(string s, int k) { const string let("aeiou"); int i = s.size() - 1; for (; k && i >= 0; i--) { if (let.find(s[i]) != -1) k--; } if (k > 0) return s.substr(s.size()); return s.substr(i + 1); } string get_rifm(string prev, string a, string b, st...
1
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0; long long res; scanf("%d%d", &n, &m); for (int b = 1; b <= n; ++b) { long long tmp = (long long)b * b; if (tmp <= m) { res += (tmp << 1) - 1; } else { res += m << 1; } } for (int u = -n * 2; u < 0; ++u) ...
5
#include <bits/stdc++.h> using namespace std; int n; int a[200003], b[200003], c[200003], d[200003]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); c[i] = a[i] - a[i - 1]; } for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); d[i] = b[i] - b[i - 1]; } if (a[1...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 1; i < n; ++i) { if (s[i] < s[i - 1]) { cout << "YES\n" << i << ' ' << i + 1; return 0; } } cout << "NO"; return 0; }
1
#include <bits/stdc++.h> using namespace std; void HoH() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } int main() { HoH(); int n; string s; cin >> n >> s; string mini = s; for (int i = 0; i < 99999; i++) { while (s[0] != '0') { for (int i = 0; i < s.size...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> stud(n); vector<int> sec(n, 0); vector<int> poss; int temp, pos, tempPos; for (int i = 0; i < n; i++) cin >> stud[i]; for (int j = 0; j < m; j++) { pos = -1; temp = 0; for (int i = 0; i < n; i+...
1
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; map<string, string> m_ap; for (int i = 1; i <= n; i++) { string s1, s2; cin >> s1 >> s2; s2 = s2 + ";"; m_ap[s2] = s1; } for (int i = 1; i <= m; i++) { string s3, s4; cin >> s3 >> s4; cout << s3 << ...
2
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long double eps = 1e-8; long long read() { char ch = getchar(); long long x = 0; int op = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') op = -1; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - ...
2
#include <bits/stdc++.h> using namespace std; long long solve(long long C, long long H_R, long long H_B, long long W_R, long long W_B) { long long ret = 0; if (W_R > (long long)3e4) { for (long long n = 0; n * W_R <= C; n++) { ret = max(ret, n * H_R + ((C - n * W_R) / W_B) * H_B); } ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int N, ans = 1; cin >> N; int lastA = 0, lastB = 0; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; if (lastA == lastB) lastA++, lastB++; else { if (lastA < lastB) lastA = la...
2
#include <bits/stdc++.h> using namespace std; int arr[100001]; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } long long int mod = 1000000009; int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } long long int pw(long long int b, long long int p) { if (!p) return 1; long long int sq = pw(b, p / 2)...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 998244353; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int sub(int a, int b) { return (a - b + mod) % mod; } inline int mul(int a, int b) { return a * 1ll * b % mod; } int f[N]; int fp(int b, int...
4
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> sides; vector<pair<long long, long long>> diva; vector<pair<long long, long long>> divb; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long a, b; cin >> a >> b; for (long long i = 1; i * i <= a + b; i++) { i...
6
#include <bits/stdc++.h> using namespace std; const int f = 1000002; long long n, a, b, c, d, t[f], e[f], k[f], dp[f], mini = 1e18, es; int main() { ios_base::sync_with_stdio(false); cin >> n >> a >> b >> c >> d; for (int i = 1; i <= n; i++) { dp[i] = mini; cin >> t[i]; k[i] = a * t[i] + c; e[i] =...
3
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
2
#include <bits/stdc++.h> using namespace std; char s[5009][5009]; int cu[5009][5009]; int main() { int i, j, k, n, m, d; while (cin >> n >> m) { for (i = 1; i <= n; i++) scanf("%s", s[i] + 1); for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { if (s[i][j] == '1') cu[i][j] = cu[i][j - 1] + 1...
2
#include <bits/stdc++.h> using namespace std; long long a, b, n; long long i; int main() { scanf("%lld", &n); a = 1, b = 2; i = 1; while (b <= n - a) { i++; a += b; swap(a, b); } printf("%lld", i); return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, c, q, cnt; int ata[500005]; set<int> s[500005]; map<pair<int, int>, int> mp; int bul(int node) { if (ata[node] == node) return node; return ata[node] = bul(ata[node]); } void merge(int a, int b) { if ((a = bul(a)) != (b = bul(b))) { if (((int)s[a].size()...
6
#include <bits/stdc++.h> using namespace std; int main(void) { int n, eight = 0; char s[100010]; cin >> n; cin >> s; for (int i = 0; i < n - 10; i++) { if (s[i] == '8') eight++; } if (2 * eight > (n - 10)) cout << "YES" << endl; else cout << "NO" << endl; }
2
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-10; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long double PI = 3.1415926535897932384626433832795028841; map<string, int> ssol; void checkAdd(string vs) { if (ssol.find(vs) != ssol.end()) { return; } ssol[vs] = 1; }...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, p; long long xx[310]; int mod[310]; int i, j, k; int ans = -1; scanf("%d %d", &p, &n); memset(xx, 0, sizeof(xx)); memset(mod, 0, sizeof(mod)); for (i = 1; i <= n; i++) { scanf("%I64d", &xx[i]); } for (i = 1; i <= n; i++) { m...
1
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { string s; cin >> s; if (s == "01" || s == "10") { cout << 1 << endl; } else { unordered_map<char, long long> m; for (long long i = 0; i < s.size(); i++) { m[s[i]]++; }...
2
#include <bits/stdc++.h> #define For(i, j, k) for(int i = j; i <= k; i++) #define pb push_back using namespace std; const int N = 100010; vector<int> G[N]; int n; bool ans; bool DFS(int o, int f){ int cnt = 0; for(int v : G[o]){ if(v == f) continue; cnt += DFS(v, o); } if(cnt > 1) ans = true; return !cnt;...
0
#include <bits/stdc++.h> using namespace std; int main() { string s[8]; int i, j; for (i = 0; i < 8; i++) cin >> s[i]; for (i = 0; i < 8; i++) { for (int j = 0; j < 7; j++) { if (s[i][j] == s[i][j + 1]) return cout << "NO", 0; } } cout << "YES"; return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<long long> primes; void Sieve(long long n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (long long p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long i = p * p; i <= n; i += p) prime[i] = false; } } for (long long...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n = 1, x = 1; cin >> n; while (n > x) { n -= x; x++; } cout << n; return 0; }
1
#include <bits/stdc++.h> #pragma GCC optimize("03") using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(n...
2
#include <bits/stdc++.h> using namespace std; long long int check(long long int n) { set<long long int> s; long long int cnt = 0; while (n) { s.insert(n % 10); n /= 10; cnt++; } if ((long long int)s.size() == cnt) return 1; else return 0; } signed main() { ios_base::sync_with_stdio(fal...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; scanf("%lld %lld", &n, &k); long long l = 1, r = n; srand(time(NULL)); while (1) { if (r - l + 1 > 40) { long long mid = (r + l) / 2; printf("%lld %lld\n", l, mid); fflush(stdout); string s; cin >> s; ...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, maxn = 1e6 + 5; string s; long long H[maxn], P, rema[maxn], remb[maxn]; int a, b, n; bool check; int main() { cin >> s; cin >> a >> b; n = s.size(); s = " " + s; check = false; rema[1] = (s[1] - 48) % a; remb[n] = (s[n] - 48) % b; fo...
3
#include <bits/stdc++.h> int main() { int n, a[200000], b[200000]; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) scanf("%d", &b[i]); int a_flag = 0, b_flag = 0; for (; a_flag < n; a_flag++) { while (a[a_flag] != b[b_flag] && b_flag < n) b_flag++; if (b_...
3
#include <bits/stdc++.h> using namespace std; int r[10]; int n; char c; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> c; if (c == 'L') { for (int j = 0; j < 10; j++) { if (r[j] == false) { r[j] = true; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int arr[n]; for (long long int i = 0; i < n; i++) { cin >> arr[i]; } string str; cin >> st...
2
#include <bits/stdc++.h> using namespace std; int a[10005]; int main() { int n; for (int i = 1; i < 10005; i++) a[i] = i; scanf("%d", &n); int d = n / 2; int k = 0, r = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < d; j++) { printf("%d %d ", a[r], a[n * n - k]); k++; r++; }...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5; long long k, res, x; long long a[1000000]; int tot; inline bool check(long long x) { for (int i = 2; i <= tot; i++) { if (a[i] >= x) return 1; if (x % a[i] == 0) return 0; } } inline void dismiss(long long x, long long y) { if (res == N) ret...
5
#include <bits/stdc++.h> using namespace std; const int N = 105; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int arr[N]; int idx = 1, n; int teams[N]; cin >> n; for (int i = 0; i < (int)(n); ++i) cin >> arr[i]; sor...
1
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; const ld eps=1e-9; //// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" bool check(con...
0
#include <bits/stdc++.h> using namespace std; bool dfs(int u, vector<vector<pair<int, char> > > &v, vector<int> &m, char color, int &curGood, int &curBad, vector<int> &touched) { bool good = true; if (m[u] == 1) curGood++; else if (m[u] == 0) curBad++; touched.push_back(u); for (int i = 0; i ...
4
#include<bits/stdc++.h> using namespace std; signed main(){ string s; int k; cin>>s>>k; for(int i=0;i<s.size();i++){ if(s[i]!='a'){ if(k-(26-(s[i]-97))>=0){ k=k-(26-(s[i]-97)); s[i]='a'; } } } if(k%26!=0){ k%=26; s[s.size()-1]+=k; } cout<<s<<"\n"; }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int INF = 1000000000; int main() { ios::sync_with_stdio(false); string s; cin >> s; long long n = stoll(s); vecto...
3
#include <iostream> #include <vector> #include <algorithm> #include <numeric> using namespace std; int main() { int t; cin >> t; for(int times = 0; times < t; times++) { int n, k; cin >> n >> k; vector<int> x(n); for(int i = 0; i < n; i++) { cin >> x[i]; } vector<int> y(n-1); for(int ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1111111; int c1, c2, c3, c4; int n, m; int a[N], b[N]; int main() { scanf("%d%d%d%d", &c1, &c2, &c3, &c4); scanf("%d%d", &n, &m); int res1 = 0, res2 = 0, res = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); res1 += min(a[i] * c1, c2); }...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b / __gcd(a, b)); } template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N,...
4
// ※※※ 解答不能 ※※※ // ksun48氏. // https://atcoder.jp/contests/cf17-final/submissions/1804620 #include <bits/stdc++.h> using namespace std; using LL = long long; #define repx(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) vector<pair<int, int>> ints[410...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, m, o1 = 0, o2 = 0, e1 = 0, e2 = 0; cin >> n >> m; for (long long i = 0; i < n; i++) { long long a; cin >> a; if (a % 2) o1++; else e1++; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, d, wk, co, md; int mu[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; while (cin >> n >> d) { wk = mu[n] + d - 1; co = 0; co = wk / 7; if (wk % 7 != 0) co++; cout << co << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; const int N = 52; int g[2][2][N][N][N * 2]; int f[N * 2][N][2]; int n, m, st[N * N], ed[N * N]; vector<int> seq[N * N]; int e[N][N]; pair<int, int> walk(vector<int> &tp, int x, bool fl) { int now = 0; for (; now + 1 <= tp.size();) { int y ...
5
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; long long int gcd(long long int a, long long int b) { if (a ...
2
#include<bits/stdc++.h> int X,k,q; struct ev{ int x,y,id; bool operator<(const ev&e)const{return x<e.x;} }e[500007]; int ep=0,as[500007]; int main(){ scanf("%d%d",&X,&k); for(int i=0,a;i<k;++i){ scanf("%d",&a); e[ep++]=(ev){a,0,0}; } scanf("%d",&q); for(int i=1,a,b;i<=q;++i){ scanf("%d%d",&a,&b); e[ep++]...
0
#include <bits/stdc++.h> using namespace std; map<int, vector<pair<int, string> > > m; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int s, d, a, b; cin >> s >> d >> a >> b; d -= s; d -= a * 8; if (d <= 0) { cout << "0"; return 0; } a = a * 12 - b * 12; if (a <= 0) { cout...
1
#include <bits/stdc++.h> using namespace std; int a[300000]; int main() { int n; cin >> n; for (int i = 0; i < 300000; i++) { a[i] = -1; } for (int i = 0; i < n; i++) { int x; cin >> x; a[x] = n - i; } int mx = -2; int ans = 0; for (int i = 0; i < 300000; i++) { if (a[i] > mx) { ...
2
#include <bits/stdc++.h> using namespace std; void runtime() { cout << fixed << setprecision(5) << 1.0 * clock() / CLOCKS_PER_SEC << endl; } template <class T> void read(vector<T> &a, int n) { T x; a.clear(); for (int i = 0; i < n; i++) { cin >> x; a.push_back(x); } } template <class T> void write(vec...
5
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using i128 = boost::multiprecision::int128_t; #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = v...
0
#include <bits/stdc++.h> using namespace std; const int N = 300010; int n, m, vis[N], d[N]; vector<pair<int, int> > g[N], g1[N]; int sub = 0, fa[N], up[N], cur[N]; vector<int> id; void dfs(int u) { vis[u] = 1; id.push_back(u); if (~d[u]) sub ^= d[u]; for (int i = 0; i < g[u].size(); ++i) { int v = g[u][i].f...
2
#include <bits/stdc++.h> using namespace std; string str; int k; int p[555][555]; int dp[555][555]; int mark[555]; void change(int i, int j) { while (i < j) { if (str[i] != str[j]) str[j] = str[i]; i++; j--; } } int main() { while (cin >> str >> k) { memset(dp, 0, sizeof(dp)); int len = str.le...
4
#include <bits/stdc++.h> using namespace std; #define MAX_N 36 #define MAX 1000 char getChar(int x){ return (x < 10 ? x+'0' : x+'A'-10); } int main(){ int N,M,Q; while(cin >> N >> M >> Q, N){ string S,B[MAX+1]; bool sw[MAX+1][MAX_N]; sw[0][0] = false; for(int i = 1 ; i <= Q ; i++){ cin >> S...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (a == b && c == 0) { cout << "0" << endl; } else if (a - b + c < 0) { cout << "-" << endl; } else if (a - b - c > 0) { cout << "+" << endl; } else { cout << "?" << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(b...
2
#include <bits/stdc++.h> #define mod 1000000007 using namespace std; int main(void){ double A, B, C, D, E, F, sum = 0, sugar = 0, ans1 = 0, ans2 = 0; int i, j, k, l; double max = -1; cin >> A >> B >> C >> D >> E >> F; for(i=0; 100*A*i <= F; i++){ for(j=0; 100*(A*i + B*j) <= F; j++){ for(k=0; k*C<=E*...
0
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main(){ long long n,cnt=0; while(cin>>n&&n!=0){ cnt=0; while(n!=1){ if(n%2==0){ n=n/2; cnt++; }else{ n=n*3+1; cnt++; } } cout<<cnt<<endl; } return 0; }
0
#include <bits/stdc++.h> const int MAXN = 1001000; const int MAXH = 20; int H = 20; int prand; int bits = 0; bool getb() { if (bits < 0) { prand = rand(); bits = 31; } int ans = (prand >> bits) & 1; --bits; return ans; } int geth() { int ans = 0; while (ans + 1 < H && getb()) ++ans; return ans; ...
5
#include <bits/stdc++.h> using namespace std; int n, x, k, x1, y11, x2, y2, r[10]; struct nod { nod *l = 0, *r = 0; int val; } * rev[200010]; nod* updPers(nod* rad, int val, int pos, int low, int high) { nod* ret = new nod; if (!rad) rad = new nod; if (low == high) { ret->val = val; return ret; } ...
5
#include <bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<queue> #include<map> ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> using vec = vector<T>; template <typename K, typename V> using umap = unordered_map<K, V>; template <typename K> using u...
5
#include <bits/stdc++.h> using namespace std; int main() { int c; long long int left = 0, right = 0; bool flag = false; string str; getline(cin, str); int n = str.length(); for (int i = 0; i < n; i++) { if (str[i] == '^') { c = i; break; } } for (int i = 0; i < n; i++) { if (st...
1
#include <bits/stdc++.h> using namespace std; int64_t power(int64_t a, int64_t b) { int64_t ans = 1; while (b) { if (b & 1) { ans = (ans * a) % 1000000007; } a = (a * a) % 1000000007; b >>= 1; } return ans; } int64_t mmi(int64_t n) { return power(n, 1000000007 - 2); } int64_t two(int64_t n...
3
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define eb emplace_back #define all(v) (v).begin(),(v).end() #define fi first #define se second using vint=vector<int>; using pint=pair<int,int>; using vpint=vector<pint>; template<typenam...
0
#include <bits/stdc++.h> using namespace std; vector<int> adjList[100000]; int disc[100000], low[100000], inStack[100000], num = 0; vector<int> com[100000], adjList2[100000]; int c[100000], in[100000], scc = 0; vector<int> S; int doDFS(int u) { int i; disc[u] = low[u] = num++; S.push_back(u), inStack[u] = 1; fo...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, k, lg; int pre[N], post[N], prenum; int p[20][N], lv[N]; int f[N]; vector<int> adj[N]; inline int preorder(int u, int par = 0) { post[u] = pre[u] = ++prenum; lv[u] = lv[par] + 1; p[0][u] = par; for (int i = 0; i < adj[u].size(); i++) { ...
4
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, x, y, z; int a[(int)(5e5 + 10)], s1, s, S[(int)(1e7 + 10)]; int b[(int)(5e5 + 10)], t, t1, pw[(int)(5e5 + 10)]; int last[(int)(1e7 + 10)]; long long ans; vector<int> v; int main() { cin >> n; for (i = 1; i <= n; i++) scanf("%d", a + i); pw[0] = 1; ...
5
#include <iostream> #include <stdio.h> #include <fstream> #include <algorithm> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <limits.h> #include <math.h> #include <functional> #include <bitset> #include <iomanip> #define repeat(i,n) for (long long i = 0; (...
0
#include<cstdio> using namespace std; int main(){ int n,a[100001]={},b,cnt=0; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&b); a[b]++; } for(int i=1;i<=100000;i++) if(a[i]) cnt++; if(cnt%2==1) printf("%d\n",cnt); else printf("%d\n",cnt-1); }
0
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; ll A, B; int a[63], b[63]; int main() { scanf("%lld%lld", &A, &B); swap(A, B); if (A == B) {puts("1"); return 0;} for (int i = 60; i >= 0; --i) if ((A >> i) & 1) a[i] = 1; for (int i = 60; i >= 0; --i) if ...
0
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; } template <typename T> bool chkmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; } inline long long read() { long long x = 0, fh = 1; char ch = getchar(); for (; !isdigit(ch); ch = getcha...
3
#include <iostream> #include <iomanip> #include <algorithm> #include <string> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <stack> using namespace std; typedef vector<int> VI; typedef vector<vector<in...
0
#include <bits/stdc++.h> #pragma GCC optimize(2) namespace OI { template <class T> T gcd(T x, T y) { return !y ? x : gcd(y, x % y); } template <class T> T Fabs(T x) { return x < 0 ? -x : x; } template <class T> void rd(T &x) { x = 0; int pre = 1; char c; while (!isdigit(c = getchar())) if (c == '-') pre...
5
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : (-x); } template <class T> T sqr(T x) { return x * x; } const double eps = 1E-8; struct P { double x, y; P(double x = 0.0, double y = 0.0) : x(x), y(y) {} P operator+(P a) { return P(x + a.x, y + a.y); } P opera...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; const long long MOD = 1000000007; int cnt[MAXN]; long long fac[MAXN], ans = 1; long long POW(long long exp, long long power) { if (power == 0) return 1; long long ansP = POW(exp, power / 2); ansP = ansP * ansP % MOD; if (power % 2 == 1) ansP =...
1
#include <bits/stdc++.h> using namespace std; bool vis[10][10]; int d[10][10]; int dx[8] = {1, 0, 0, -1, 1, -1, 1, -1}; int dy[8] = {0, -1, 1, 0, 1, -1, -1, 1}; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; if (r1 == r2 || c1 == c2) { cout << 1 ...
1
#include <bits/stdc++.h> using namespace std; long long int recpow(long long int x, long long int n, long long int mod) { if (n == 0) return 1; else if (n % 2 == 0) return recpow((x * x) % mod, n / 2, mod); else return (x * recpow((x * x) % mod, (n - 1) / 2, mod)) % mod; } bool sortbysec( const pa...
2
#include <bits/stdc++.h> using namespace std; long long power(int b, int p) { long long i, m = 1; for (i = 1; i <= p; i++) m = m * b; return m; } int main() { long long x = 0, y = 0, bx, by, n, i, j, k, po, t; cin >> n >> bx; po = n - 1; for (i = 1; i <= n; i++) { scanf("%I64d", &t); x += power(bx...
1
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int a, b, c = 0; cin >> a >> b; while (b != 0) { c += b % 10; c *= 10; b /= 10; } c /= 10; cout << c + a << endl; }
1
#include <bits/stdc++.h> int main() { int n, top; std::cin >> n >> top; if (top > 3) top = 7 - top; int left, right; while (n--) { std::cin >> left >> right; if (left > 3) left = 7 - left; if (right > 3) right = 7 - right; if (left + right != 6 - top) { std::cout << "NO\n"; return ...
1
#include "bits/stdc++.h" using namespace std; int main() { string a, b, c; cin >> a >> b >> c; cout << a.at(0) << b.at(1) << c.at(2) << endl; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, m, sl, fh, g[2], f[2], d[200010], p[200010], ex[200010], vis[200010], a[200010][2], b[200010][2], dp[200010][2][2]; int t, h[200010]; struct edge { int to, id, nxt; } e[200010 << 1]; vector<int> vt, VT; int rd() { sl = 0; fh = 1; ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, cl = 1, mlsf = 1, oldci = 0; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i + 1 < n; i++) { if (a[i + 1] > a[i]) { cl++; if (cl > mlsf) mlsf = cl; } else if ((i + 2 < n...
1
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926536; int main() { int n, m, h; cin >> n >> m >> h; int a[m]; for (int i = 0; i < m; i++) cin >> a[i]; int b[n]; for (int i = 0; i < n; i++) cin >> b[i]; int c[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } const int MAX = 1e5; const long long MOD = 1e9 + 7; const long long inf = 1e18; int a[MAX + 5]; int main() { ios_base::sync_with_stdio(false); int n, m, r, i, j; long long ans = 0; cin >> n >>...
2
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int bell[4100]; long long int com[4100][4100]; long long int ans; int n; int main(void) { int i, j; cin >> n; bell[0] = 1; bell[1] = 1; bell[2] = 2; com[0][0] = 1; for (i = 1; i <= n; i++) { com[i][0] = 1; com[i][...
4
#include <bits/stdc++.h> using namespace std; struct team { string name; int jf, jsq, jq; }; int main() { int n, g1, g2; string p1, p2; cin >> n; team a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i].name; cin.ignore(); for (int i = 1; i <= n; i++) { a[i].jf = 0; a[i].jsq = 0; a[i].jq = ...
1
#include<cstdio> #include<vector> #include<queue> #include<algorithm> using namespace std; typedef pair<int,int> PA; int main(){ int v,e,s,t,w; vector<PA> vec[100001]; scanf("%d %d",&v,&e); for(int i=0;i<e;i++){ scanf("%d %d %d",&s,&t,&w); vec[s].push_back(PA(w,t)); vec[t].push_back(PA(w,s)); } ...
0
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; void boost() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long bins(long long a[], long long n, long long key) { int lo = 0, hi = n - 1, ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (a[...
3
#include <bits/stdc++.h> using namespace std; template <int C> struct PersistentStringTrie { PersistentStringTrie* nex[C]; signed long long v; int mp(char c) { if (c >= 'a' && c <= 'z') return c - 'a'; if (c >= 'A' && c <= 'Z') return c - 'A' + 26; assert(0); return 0; } PersistentStringTrie()...
4
#include <bits/stdc++.h> using namespace std; char str[60][5], tmp[10]; map<pair<int, string>, int> M; queue<pair<int, string> > Q; pair<int, string> cur; int main() { int n; scanf("%d", &n); n += 2; for (int i = 0; i < 3; i++) strcpy(str[i], "**"); for (int i = 3; i <= n; i++) scanf("%s", str[i]); strcat(t...
2
#include<iostream> using namespace std; int main(void){ long long A, B, N; cin >> A >> B >> N; cout << (B + N) / N - (A + N - 1) / N << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <class TH, class... TA> void _dbg(const...
3
#include <bits/stdc++.h> using namespace std; int n, m; int s1, t1, l1, s2, t2, l2; vector<int> adj[3005]; vector<int> d[3005]; vector<int> dis; vector<int> getDis(int node) { dis = vector<int>(3005); for (int i = (0); i < int(n); ++i) dis[i] = 1000000; dis[node] = 0; queue<int> q; q.push(node); while (!q.e...
2
#include<cstdio> #include<algorithm> #include<iostream> #include<cstdlib> using namespace std; typedef long long ll; const int M=1e6+5; int n,u,v; ll ans; int A[M]; void check(int line){ if(A[line]==A[line-1]&&line>1)ans=min(ans,min(0ll+u+v,0ll+v+v)); if(abs(A[line]-A[line-1])>=1)ans=min(ans,min(0ll+v,0ll+u)); }...
2