solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; bool checkPrime(long long int x) { if (x == 1) { return false; } if (x <= 3) { return true; } long long int t = 2; if (x % 2 == 0) { return false; } t = 3; for (t; t <= sqrt(x); t += 2) { if (x % t == 0) { return false; } } re...
3
#include <bits/stdc++.h> using namespace std; int l[6], r[6]; int n; double ans; inline int wei(int x, int y) { return (x >> y) & 1; } inline int cnt(int x) { int pa = 0; for (int i = (0); i <= (int)n - 1; i++) pa += wei(x, i); return pa; } int main() { scanf("%d", &n); for (int i = (1); i <= (int)n; i++) sca...
3
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } int kk, tt = 1005; for (int t = 1; t <= 1000; t++) { int s = t; int op = 0; for (int i = 1; i <= n; i++) { if (a[i] != s) { op...
2
#include <bits/stdc++.h> using namespace std; const constexpr int INF = 1e9; const constexpr long long MOD = 1e9 + 7; const int BITSIZE = 100010; struct Less { bool operator()(const pair<int, int>& x, const pair<int, int>& y) const { return x.first < y.first; } }; struct More { bool operator()(const pair<int,...
1
#include <bits/stdc++.h> int main(int argc, char** argv) { std::cin.tie(0); std::ios_base::sync_with_stdio(0); std::cout << std::fixed << std::setprecision(6); std::cerr << std::fixed << std::setprecision(6); int n, m[111111], o[111111]; std::cin >> n; for (int i = 0; i < n; i++) std::cin >> m[i]; o[0] ...
4
#include <queue> #include <vector> #include <iostream> using namespace std; typedef long long ll; struct edge { int to; ll cost; }; struct state { int pos; ll cost; }; bool operator<(const state& s1, const state& s2) { return s1.cost > s2.cost; } int dx[] = { 0, 1, 0, -1 }; int dy[] = { 1, 0, -1, 0 }; int H, W, A, B, C...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,t,mx,cnt,mn=(1ll<<30); int main(){ ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>t; for(ll i=0,a;i<n;i++){ cin>>a; mn=min(mn,a); if(a-mn>mx)mx=a-mn,cnt=1; else if(a-mn==mx...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 100500; vector<int> gen(int n) { int s = 1; vector<int> res; for (int i = 0; i < (int)(n); ++i) { res.push_back(s); res.push_back(s + 1); res.push_back(s + 2); res.push_back(s + 4); s += 6; } return res; } int main() { i...
2
#include <bits/stdc++.h> using namespace std; int INF = 1e9; int const N = 5e4 + 16; int const M = 1e9 + 7; int const M2 = 999999983; int n; int main() { scanf("%d", &n); bool found = false; for (int i = 1; i < 44722; ++i) { long long t1 = i * (i + 1) / 2; if (t1 > n) break; int l = i + 1, r = 44722; ...
1
#include <bits/stdc++.h> int n, a, d, i, j, top; double t, s[100010]; int v[100010], st[100010], r[100010]; int main() { scanf("%d%d%d", &n, &a, &d); for (i = 1; i <= n; ++i) { scanf("%d%d", &st[i], &v[i]); t = v[i] * 1.0 / a; if (v[i] / 2 * t > d) t = sqrt(2 * (double)a * d * 1.0) / a; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { int m; cin >> m; int j = 0; vector<int> v(100005, -1); for (int i = 1;; i++) { if (j > m) break; if (i % 5 == 0) { int k = i; while (k % 5 == 0) { k = k / 5; j++; } v[j] = i; } } if (v[m] == -1) ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; struct Point { long long x, y; Point() {} Point(long long _x, long long _y) : x(_x), y(_y) {} Point operator+(const Point &t) const { return Point(x + t.x, y + t.y); } Point operator-(const Point &t) const { return Point(x - t.x, y - t.y);...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, num, max = 0, diff, sum = 0; cin >> n; for (long long int i = 0; i < n; ++i) { cin >> num; sum += num; if (num > max) { max = num; } } diff = sum - max; diff = max - diff; cout << diff + 1 << endl; return 0...
2
#include <bits/stdc++.h> const int MAX = 200005; long long n, t, a[MAX], x[MAX], b[MAX], i; int main() { scanf("%lld %lld", &n, &t); for (i = 1; i <= n; i++) scanf("%lld", &a[i]); for (i = 1; i <= n; i++) scanf("%lld", &x[i]); for (i = 1; i <= n; i++) { if (x[i] < x[i - 1] || x[i] < i) { if (n == 2000...
1
#include <iostream> using namespace std; void swap(int *a, int *b){ int temp = *a; *a = *b; *b = temp; } int partition(int *a, int p, int r){ int x, i; x = a[r]; i = p - 1; for(int j=p;j<r;++j){ if(a[j]<=x){ ++i; swap(&(a[i]),&(a[j])); } } swap(&(a[i+1]),&(a[r])); return i+1; } int main() { int ...
0
#include <bits/stdc++.h> using namespace std; bool SR(int &x) { return scanf("%d", &x) == 1; } bool SR(long long &x) { return scanf("%lld", &x) == 1; } bool SR(double &x) { return scanf("%lf", &x) == 1; } bool SR(char *s) { return scanf("%s", s) == 1; } bool RI() { return true; } template <typename I, typename... T> bo...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a1[4], a2[4], a3[4], a4[4]; cin >> n; for (int i = 0; i < 4; i++) cin >> a1[i]; for (int i = 0; i < 4; i++) cin >> a2[i]; for (int i = 0; i < 4; i++) cin >> a3[i]; for (int i = 0; i < 4; i++) cin >> a4[i]; if (a1[0] + a1[2] <= n) cout <...
1
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n, k = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int m = n + 1, mm = -1; for (int i = n - 1; 0 <= i; i--) { if ((a[i] > m) || (a[i] < mm)) { k++; if (a[i] > mm) mm = a[i]; } if (a[i] < m) m = a[i]...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:128000000") using namespace std; void solve(); void precalc(); clock_t start; bool doing = true; int main() { int t = 1; cout.sync_with_stdio(0); cin.tie(0); precalc(); cout.precision(10); cout << fixed; start = clock(); int testNum = 1; while (...
4
#include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; const int N = 1e5 + 4; int n, p; ll ans[N]; pair<int, int> a[N]; bool done[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> p; for (int i = (1); i <= (n); +...
5
#include <bits/stdc++.h> using namespace std; int n, s; pair<int, int> d[200005]; long long int fon(int k) { long long int ret = 0; int say = 0; vector<int> v, v2; for (int i = 0; i < n; i++) if (d[i].first <= k - 2 || d[i].first > k) { v.push_back(d[i].second); if (d[i].first <= k - 2) say++; ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, ans = 0; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = n - 1; i >= 0; i--) { if (a[i] <= 0) break; if (i == 0) { if (a[i] > 0) ans += a[i]; break; } ans += a[i]; if...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; const int mo = 1e9 + 7; const int iv2 = 5e8 + 4; const int jzm = 2333; const int orG = 3, invG = 332748118; const double Pi = acos(-1.0); const double PI = acos(-1.0); template <typename _T> _T Fabs(_T x) { return x < 0 ? -x : x; } template <ty...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { long long n; cin >> n; long long tong = n * (n + 1) / 2; long long tongam = 0; int k = 1; while (n >= pow(2, k)) { tongam = tongam + pow(2, k); k++; } cout << tong ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, array[10]; cin >> n >> m; int ansc = m; int ans = 0; for (i = 0; i < n; i++) { array[i] = i + 1; ans += (i + 1) * (n - i); } do { int sum = 0, minn = 2e9; for (i = 0; i < n; i++) { minn = 2e9; for (j = i...
2
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[100005]; int b[100005]; int main() { while (~scanf("%d%d", &n, &k)) { for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) scanf("%d", b + i); sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); int rk = n; f...
4
#include<iostream> #include<algorithm> using namespace std; int main(){ int t,n; string str; bool book[2][50000]; int v[3][20000],a[3][20000]; cin >> t; while(t--){ cin >> n >> str; for(int i=0;i<2;i++){ for(int j=0;j<2*n;j++)book[i][j+1] = (str[i*2*n+j]=='Y'); book[i][0] = book[i][2*n...
0
#include <bits/stdc++.h> using namespace std; const long long MXN = 3e5 + 1; const long long MAXN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long INF = 1e18; inline void f_math(bool ok = 0) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ok) { freopen("aquarium.in", "r", stdin); f...
5
#include <iostream> using namespace std; int main(){ int s; cin>>s; cout<<s/3600<<":"<<(s%3600)/60<<":"<<s%60<< endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; pair<int, int> a[MAXN], b[MAXN]; inline int match(pair<int, int> x, pair<int, int> y) { if (x.first == y.first && x.second != y.second || x.first == y.second && x.second != y.first) return x.first; if (x.second == y.first && x.first != y.s...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; int arr[2000]; int arr1[2000]; int count = 0; int n1 = 0; cin >> n; for (int i = 0; i < 2000; i++) { arr[i] = 0; arr1[i] = 0; } for (int i = 0; i < n; i++) { cin >> arr[i]; cout << " "; } while (n != n1) { for (i...
1
#include <bits/stdc++.h> using namespace std; long long ar[10000000]; int main() { long long n; while (cin >> n) { long long i, j, a, b, c, p = 0; for (i = 1; i <= n; i++) cin >> ar[i]; sort(ar + 1, ar + n + 1); for (j = 1; j <= n - 2; j++) { a = ar[j], b = ar[j + 1], c = ar[j + 2]; if (...
2
#include <bits/stdc++.h> using namespace std; bool chon[101]; vector<int> card[101]; vector<int> b; int a[101]; double val[101]; double lon, nho; int n, k, q; bool diff(vector<int> a, vector<int> b) { for (int i = 0; i < a.size(); i++) if (a[i] != b[i]) return true; return false; } int main() { cin >> n >> k;...
2
#include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; const int N = 15; int K, nxt[N * 5001], nmp, idBox[N * 5001], par[N * 5001], val[N * 5001], track[1 << N]; ll tot[N], atot; vector<int> ele[N]; map<int, int> mp; bool vis[N * 5001], in[N * 500...
5
#include<stdio.h> int main (void) { char inp[1024]; scanf("AtCoder %s Contest", &inp); printf("A%cC\n", inp[0]); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; struct segtree { struct node { long long int min, max, sum; }; vector<node> st; long long int ans = 0; int n; template <typename M> segtree(vector<M> &a) { n = (int)a.size(); st.resize(4 * n); } void combine(node &a,...
2
#include <bits/stdc++.h> using namespace std; int n, i, a[100010], j, k; long long f[1010][1010], g[1010][1010]; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); if (n == 1) { printf("1"); return 0; } n--; for (i = 1; i <= n; i++) { g[i][i] = 1; f[i][i] = 1; } fo...
6
#include <bits/stdc++.h> using namespace std; void true_main() { int n, r, i, j; cin >> n >> r; vector<double> x(n), y(n); for (i = 0; i < n; i++) { cin >> x[i]; y[i] = r; for (j = 0; j < i; j++) { int t = x[i] - x[j]; y[i] = max(y[i], y[j] + sqrt(4 * r * r - t * t)); } cout << f...
3
#include <bits/stdc++.h> using namespace std; using pi = pair<int, pair<int, int> >; const int N = 2e5 + 5; pi p[N]; int a[N]; deque<int> dq; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } for (int i = 0; i < m; ++i) { int t, r; scanf("%d %d", &t...
3
// 基本テンプレート #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #in...
0
#include <bits/stdc++.h> using namespace std; int main() { int p; cin >> p; while (p--) { string s, t; cin >> s >> t; int n = s.length(); int m = t.length(); int i = 0, j = 0, f = 0; char c; while (i < n && j < m) { if (n > m) { f = 1; break; } while (...
2
#include <bits/stdc++.h> namespace util { template <typename T, typename DataT> struct Event { T time; char type; DataT data; Event(char type_, T time_, DataT data_) : time(time_), type(type_), data(data_) {} bool operator<(const Event<T, DataT> &other) const { return time < other.time; } bool o...
5
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int n4, n7, n47, n74; bool solve() { if (abs(n47 - n74) > 1) return false; for (int fst = 0, _n = (10); fst < _n; fst++) if (fst == 4 || fst == 7) { if (fst == 4 && n47 < n74) continue; if (fst == 7 && n47 > n74) continue; ...
2
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; enum Type{ YOKO, TATE, }; int H,W,change_limit,base_num; int table[10][10]; bool FLG; void recursive(Type type,int changed_count,int...
0
#include <bits/stdc++.h> using namespace std; int a[202]; int main() { int i, j, n, t1, t2, x, y; while (~scanf("%d", &n)) { t1 = 0; t2 = 0; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); t2 += a[i]; } scanf("%d%d", &x, &y); for (i = 1; i <= n; i++) { t1 += a[i]; t2 -...
1
#include <bits/stdc++.h> using namespace std; const int N = 22; int d[N], spos[N], n, m; vector<pair<int, int> > res; void solveRev(int id, int a, int b, int c) { if (id > m) return; solveRev(id + 1, a, c, b); for (int i = spos[id]; i < spos[id + 1]; ++i) res.push_back(pair<int, int>(a, c)); solveRev(id + 1...
4
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; const long long M = 1e6 + 5; long long ft[N], D[M], a[N]; void update(long long id, long long val) { while (id < N) { ft[id] += val; id += (id & -id); } } long long query(long long id) { long long res = 0; while (id > 0) { re...
6
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define N 100007 #define fo(i,a,b) for(i=a;i<=b;i++) using namespace std; int i,j,k,n,x,y,gx,gy,cnt,ans; int a[N],b[N],c[N],d[N]; int fa[N]; bool bz[N]; int get(int x){return fa[x]==x?x:fa[x]=get(fa[x]);} int read(){ int fh=1,res...
0
#include <bits/stdc++.h> int main() { long n, k; scanf("%ld %ld", &n, &k); long m = 2 * k + 1; if (n <= m) { printf("1\n%ld\n", (n + 1) / 2); } else if (n % m == 0) { printf("%ld\n", n / m); for (long p = k + 1; p <= n; p += m) { printf("%ld ", p); } puts(""); } else if (n % m > k)...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; vector<int> a, b; vector<pair<int, int> > cost; struct Item { long long cost; int id, day; bool operator<(const Item &t) const { return cost < t.cost; } }; int n, m, k, s; bool solve(int days, bool print = false) { int a_best = MOD, b_best =...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; string s; string t; cin >> s; k -= 1; int c = 0; while (k--) { t.push_back('('); t.push_back(')'); c += 2; } c = n - c; c /= 2; for (int i = 0; i < c; i++) t.push_back('('); for (int i = 0; i < c;...
3
#include <bits/stdc++.h> int main() { char a[15], b[15]; int c, d, s; scanf("%s%s", a, b); if (strcmp(a, "monday") == 0) c = 1; if (strcmp(a, "tuesday") == 0) c = 2; if (strcmp(a, "wednesday") == 0) c = 3; if (strcmp(a, "thursday") == 0) c = 4; if (strcmp(a, "friday") == 0) c = 5; if (strcmp(a, "satur...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) int main(){ int q,k,x; cin >> q; set<int> se; while(q--){ cin >> k >> x; if(k){ cout << se.count(x) << "\n"; }else{ se.insert(x); cout << se.size() << "\n"; } } }
0
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long large = 2000000000000000000LL; struct Vector { long long x, y; Vector(long long x = 0, long long y = 0) : x(x), y(y) {} }; Vector operator+(Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); } Vector operator-(Vector A, Ve...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, m; pair<int, int> tl = {-100, -100}, br = {-100, -100}; cin >> n >> m; char paper[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> pap...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 105; int n; char s[N]; int a[N]; ll dp[N][N][N]; ll f(int l, int r, int pref) { if (l > r) return 0; ll &ans = dp[l][r][pref]; if (~ans) return ans; ans = f(l + 1, r, 1) + a[pref]; for (int k = l + 1; k <= r; k++) if (s[l] =...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; const int inf = (1 << 30) - 1; const ll INF = (1LL << 60) - 1; template <typename T> bool chmax(T &x, const T &y) { ...
6
#include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> pii; namespace io { const int maxb = 1 << 15; char b[maxb], *s = b, *t = b; bool Getchar(char &ch) { return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++; } int Getint() { char c...
0
#include <bits/stdc++.h> using namespace std; int main() { int b[10], c[10]; int m[4] = {0}; int i = 0; int d = 0; for (int a = 0; a < 10; a++) { cout << a << a << a << a << endl; cin >> b[a] >> c[a]; if (b[a] > 0) { m[i] = a; i++; } } cout << m[0] << m[1] << m[2] << m[3] << en...
2
#include <bits/stdc++.h> using namespace std; int k; struct sptman { int minstr[10], maxstr[10]; int sz; sptman() { sz = 1; int t; for (int i = 0; i < k; i++) { scanf("%d", &t); minstr[i] = maxstr[i] = t; } } void merge(const sptman &a) { for (int i = 0; i < k; i++) { min...
3
#include <iostream> #include <cstdio> #include <map> using namespace std; int main() { int n; char b[2]; map<string,int> m; m["A"]=0; m["B"]=0; m["AB"]=0; m["O"]=0; while(~scanf("%d,%s",&n,b)){ m[b]++; } printf("%d\n",m["A"]); printf("%d\n",m["B"]); printf("%d\n",m["AB"]); printf("%d\n",m["O"]); ...
0
#include <iostream> #include <algorithm> using namespace std; #define ll long long int main() { int t; cin >> t; while (t--) { int x, y; cin >> x >> y; ll ans = 0; for (int i = 2; (i - 1) * (i + 1) <= x && i <= y; i++) { ll cnt = min(x / (i - 1), (y + 1)) - i; ans += cnt; } cout << ans << '\n'; }...
3
#include <bits/stdc++.h> using namespace std; void Fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void File() {} using ll = long long; using ull = unsigned long long; ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } int dx[] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, 1, -...
6
#include <bits/stdc++.h> using namespace std; map<int, long long int> dp[200005]; int closest[500005][2]; vector<int> tr[500005]; vector<int> safe; void update(int i, int j, long long int val) { if (dp[i + 1].find(j) == dp[i + 1].end()) dp[i + 1][j] = val; else dp[i + 1][j] = min(dp[i + 1][j], val); } int m...
4
#include <bits/stdc++.h> using namespace std; typedef pair<int,char> P; bool ok(P a,P b,P c){ return a.second == b.second && b.second == c.second && ((a.first-b.first == 1 && b.first-c.first == 1) || (a.first == b.first && b.first == c.first)); } bool comp(P a,P b){ return a.first + (int)a.second * 10 < b.fir...
0
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &o, vector<T> v) { for (auto u : v) o << u << " "; return o; } template <typename T> ostream &operator<<(ostream &o, unordered_set<T> v) { for (auto u : v) o << u << " "; return o; } int n, h, g, m; std::vector<int> ...
3
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; long long a[N], b[N]; vector<long long> v; int32_t main() { long long t; cin >> t; while (t--) { long long a, b, c, q; cin >> a >> b >> c; if (b > a) swap(a, b); if (b > a / 2) cout << "-1\n"; else { long lo...
2
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define lb(v,n) lower_bound(v.begin(),v.end(),n) #define ub(v,n) upper_bound(v.begin(),v.end(),n) #define srt(v) sort(v.begin(),v.end()) #define fas ios::sync_with_stdio(0), cin.tie(0), co...
3
#include <bits/stdc++.h> using namespace std; map<string, pair<int, int> > ma; int main() { ma["ABU"] = make_pair(1, 3); ma["AIDS"] = make_pair(3, 4); ma["Action"] = make_pair(3, 6); ma["Agreement"] = make_pair(3, 4); ma["Agriculture"] = make_pair(3, 7); ma["American"] = make_pair(3, 27); ma["Arab"] = mak...
4
#include <bits/stdc++.h> using namespace std; char ch[4][4]; int pic[4][4]; int cal() { int i, j; for (i = 0; i < 4; i++) { for (j = 0; j <= 1; j++) { if (ch[i][j] == 'x' && ch[i][j + 1] == 'x' && ch[i][j + 2] == 'x') { return 1; } } } for (j = 0; j <= 1; j++) { for (i = 0; i < 4...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int N, M, K; cin >> N >> M >> K; long long int a, b, c, i, j, k, start, end, mid; if ((2 * N * M) % K != 0) { cout << "NO"; return 0; } c = N * M * 2; c /= K; for (i = 1; i *...
4
#include <cstdio> #pragma warning(disable : 4996) int N, Q, v[1048588], vx[1048588], vy[1048588], pc[75]; char s[1048588], qs[29]; int main() { scanf("%d%d%s", &N, &Q, s); for (int i = 0; i < 1 << N; ++i) { v[i] = s[i] - '0'; vx[i] = v[i]; vy[i] = v[i]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < 1 ...
0
#include <bits/stdc++.h> using namespace std; int r[25][6] = { {0, 0, 0, 0, 0, 0}, {1, 2, 3, 4, 5, 6}, {1, 2, 4, 5, 6, 3}, {1, 2, 5, 6, 3, 4}, {1, 2, 6, 3, 4, 5}, {2, 1, 5, 4, 3, 6}, {2, 1, 4, 3, 6, 5}, {2, 1, 3, 6, 5, 4}, {2, 1, 6, 5, 4, 3}, {5, 3, 1, 4, 2, 6}, {5, 3, 4, 2, 6, 1}, {5, 3, 2, 6, 1, 4}, ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, mn, mx, x; bool I = 0; scanf("%d %d %d %d", &n, &m, &mn, &mx); for (int i = 0; i < m; i++) { cin >> x; if (x < mn || x > mx) { printf("Incorrect"); return 0; } if (x == mn || x == mx) I = 1; } if (I || n - m > 1...
1
#include <bits/stdc++.h> using namespace std; int a[200100], n, m, s, d, run[200100], jump[200100], l = 0; int main() { scanf("%d%d%d%d", &n, &m, &s, &d); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); if (a[0] - 1 < s) { printf("IMPOSSIBLE"); return 0; } for (int i = 0; i < n; i++)...
4
#include <iostream> using namespace std; int main() { int x; unsigned long long int ret=1; cin >> x; for(int i=1;i<=x;i++) ret*=i; if(!x)ret=0; cout << ret << endl; }
0
#include <bits/stdc++.h> using namespace std; const long long M = 1000000009, N = 300010; long long F1[N], F2[N], f1[N], f2[N], Fib[N], fib[N], st[N * 4], lazy[N * 4][3], l, r, n, m, flag, a[N], s[N]; inline long long P(long long x) { return x >= M ? x % M : x; } long long get(long long x, long long y, long long z)...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1 * 1000 + 10; int n, a[maxn], p; vector<pair<int, int>> vec, ans; vector<pair<int, bool>> idk; vector<int> loc; void solve(int l, int r) { if (r - l == 1) return; int mid = (l + r) / 2; solve(l, mid); solve(mid, r); loc.clear(); idk.clear(); ...
5
#include <bits/stdc++.h> using namespace std; int a[200001], l[200001], r[200001], ans[200001]; int main() { int n, x; while (cin >> n) { for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { x = i - 1; while (x >= 0 && a[x] >= a[i]) x = l[x]; l[i] = x; } fo...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, s = 0, i = 1, k = 0, m, p = 0; cin >> n; cout << (n / 2) + 1; return 0; }
1
#include <bits/stdc++.h> using namespace std; int A[200200]; deque<int> DQ; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); int N; cin >> N; for (int I = 0; I < N; I++) { cin >> A[I]; } if (N & 1) { DQ.push_front(A[N / 2]); } for (int I = N / 2 - 1; I >= 0; I--) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, games; cin >> n >> m; int c[n]; int a[m]; for (int i = 0; i < n; i++) cin >> c[i]; for (int i = 0; i < m; i++) cin >> a[i]; i = 0; j = 0; games = 0; while (i < n && j < m) { if (c[i] <= a[j]) { games++; i++; ...
1
#include <bits/stdc++.h> using namespace std; struct yy { int id, val; } f[8000]; int a[8000], p[8000][2], d[8000]; bool b[8000]; bool cmp(yy x, yy y) { return x.val > y.val; } int main() { int i, j, n, m, t, x; bool tm; scanf("%d%d", &n, &m); for (i = 1; i <= 2 * n; ++i) { scanf("%d", &f[i].val); f[i...
3
#include <iostream> using namespace std; int n,m,a,b,c,dp[(1<<12)],L; int main(void){ for(int i=1;i<(1<<12);i++)dp[i]=1e9; cin>>n>>m; for(int i=0;i<m;i++){ cin>>a>>b; L=0; for(int j=0;j<b;j++){ cin>>c; c--; L|=(1<<c); } for(int i=0;...
0
#include <cstdio> int main(){ int l; while(scanf("%d", &l), l){ int cm = -1; for(int i=1;i<=12;i++){ int m, n; scanf("%d%d", &m, &n); l -= m - n; if(l <= 0 && cm < 0) cm = i; } if(cm<0)puts("NA"); else printf("%d\n", cm); } }
0
#include"bits/stdc++.h" using namespace std; int main() { string S; cin >> S; if (S.size() == 3) { reverse(S.begin(), S.end()); } cout << S << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> v[100004]; int main() { cin>>n>>m; for(int i = 0;i<n;i++){ int a, b; cin>>a>>b; v[a].push_back(b); } priority_queue<int> pq; int ans = 0; for(int i = 1; i<=m; i++){ for(int val : v[i]) pq.push(val); if(!pq.empty()){ ans += pq.top()...
0
#include <bits/stdc++.h> using namespace std; int n, a; set<int> s; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; s.insert(a); } for (auto i : s) if (i == 0) { cout << s.size() - 1; return 0; } cout << s.size(); }
1
#include <bits/stdc++.h> using namespace std; int main() { string s[100]; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i]; } vector<char> v; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int t = 0; for (int k = 0; k < n; k++) { if (s[k][j] == s[...
2
#include <bits/stdc++.h> using namespace std; template <class T> T min3(T a, T b, T c) { return min(a, min(b, c)); }; template <class T> T max3(T a, T b, T c) { return max(a, max(b, c)); }; void openFile() { freopen("/home/khaihanhdk/MyWorkplace/cpp file/a.inp", "r", stdin); } bool con7(int h, int k) { return (...
1
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <cfloat> #include <ctime> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include...
0
#include <bits/stdc++.h> using namespace std; int dp[1000005]; int leftt = 100000000; int rightt = 0; int le[5005]; int ri[5005]; vector<int> ans; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; r--; le[i...
3
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int T = 1; cin >> T; while (T--) { int n, x, ans = INT_MAX, f = 0; cin >> n >> x; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] == x) f = 1; ans = min(ans, x / a[i] + (x % a[i] > 0)); } if...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, m; pair<int, int> nt[100002]; bool cmp(int a, int b) { if (nt[a].first == nt[b].first) return nt[a].second < nt[b].second; return nt[a].first < nt[b].first; } int wh[100002], v[100002], lft[100002]; struct actor { int x, y, k, pi; }; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, max; cin >> n; int A[n]; int ctr[100] = {0}; for (i = 0; i < n; i++) { cin >> A[i]; ctr[A[i] - 1]++; } max = *max_element(ctr, ctr + 100); cout << max; return 0; }
1
#include <bits/stdc++.h> int n, ans, S; char a[111111], b[111111], a2[111111], b2[111111]; short z[1111111]; void mul() { for (int i = 0; i < S; i++) z[i] *= 25; for (int i = 0; i < S; i++) z[i + 1] += z[i] / 10, z[i] %= 10; for (int i = S; z[i] > 0; i++) z[i + 1] += z[i] / 10, z[i] %= 10, S++; } void f() { z[0...
5
#include <bits/stdc++.h> using namespace std; long long x, y, z, w; int main() { cin >> x >> y >> z >> w; cout << (max(x, z) + y + w) * 2 + 4 << endl; return 0; }
1
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) #define repb(i,a,b) for(int i=a;i>=b;i--) #define all(a) a.begin(),a.end() #define o(a) cout<<a<<endl #define int long long #define fi first #define se second using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l, s, m, a, b, c; cin >> n; string s1, s2; cin >> s1; cin >> s2; int p, q; n = s1.size(); n = s2.size(); int cot = 0; for (int i = 0; i < s1.size(); i++) { if (s1[i] > s2[i]) { a = abs(s2[i] - s1[i]); b = s2[i] + 10...
1
#include <bits/stdc++.h> using namespace std; struct state { int x, y, cost; }; int sx, sy, fs, fy, n, r, a, b; map<pair<int, int>, int> mp, vis; queue<state> q; int dxx[] = {1, 0, -1, 0, -1, 1, 1, -1}; int dyy[] = {0, 1, 0, -1, -1, 1, -1, 1}; bool check(int x, int y) { return x > 0 && y > 0; } int bfs() { state s;...
3