solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int N = 1e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; double ans = 0; for (int i = n; i >= 1; --i) { ans += (double)1 / i; } cout << setprecision(6) << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
13
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
6
#include <bits/stdc++.h> using namespace std; int N, K; int A[303030], B[303030]; signed long long dp[303030][2]; void solve() { int i, j, k, l, r, x, y; string s; scanf("%d%d", &N, &K); 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++) { ...
8
#include <bits/stdc++.h> using namespace std; int p[5005], cnt[5005], qwq[5005]; vector<int> v; int main(int argc, char** argv) { int n; srand((unsigned long long)new char); cin >> n; for (int i = 1; i <= n; i++) p[i] = i - 1; for (int i = 1; i <= n; i++) cnt[i] = cnt[i ^ i & -i] + 1; random_shuffle(p + 1, ...
9
#include <bits/stdc++.h> using namespace std; const int MAXH = 8 + 2; const int MAXW = 8 + 2; char G[MAXH][MAXW]; int has_stat[MAXH][MAXH][MAXW]; const int dy[] = {0, 1, 0, 1, -1, 0, 1, -1, -1}; const int dx[] = {-1, 0, 0, -1, -1, 1, 1, 0, 1}; int vis[2 * MAXH][MAXH][MAXW]; bool outOfRange(int x, int y) { return x < 0 ...
3
#include <bits/stdc++.h> int n, m, v; inline void print(int a, int b) { if (a == n - 1) a = v; else if (a == v) a = n - 1; if (b == n - 1) b = v; else if (b == v) b = n - 1; printf("%d %d\n", a, b); } int main() { int i; scanf("%d%d%d", &n, &m, &v); if (m < n - 1 || m - 1 > ((long long)(...
4
#include <bits/stdc++.h> using namespace std; long long expo(long long x, long long n, long long m) { if (n == 0) return 1; else if (n % 2 == 0) return expo((x * x) % m, n / 2, m); else return (x * expo((x * x) % m, (n - 1) / 2, m)) % m; } string toBinary(long long n) { std::string r; while (n != ...
4
#include <bits/stdc++.h> using namespace std; const signed inf = 0x3f3f3f3f; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> long long chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> long long chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <class T> T sqr...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long n; int arr[5001][2]; int nbr[5001][2]; int mkd[5001][2]; int main() { cin >> n; for (int i = 0; i < n; i++) { cout << "? " << 0 << " " << i << endl; cin >> arr[i][0]; cout << "? " << i << " " << 0 << endl; cin >> arr[i]...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using dd = long double; namespace { static bool constexpr dbg = 0; ll constexpr N = 1.1e5, MO = 1e9 + 7; ll n, x, a[N]; ll power(ll x, ll pw) { ll ret = 1; for (ll i = 1; i <= pw; i <<= 1, x = x * x % MO) if (pw & i) r...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n % 2 == 0) cout << -1; else { for (int i = 0; i < n; i++) cout << i << " "; cout << endl; for (int i = 1; i < n; i++) cout << i << " "; cout << 0 << endl; for (int i = 1; i < n; i++) cout << (i + i - 1...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using Vi = vector<int>; using Pii = pair<int, int>; int uplg(int n) { return 32 - __builtin_clz(n); } int uplg(ll n) { return 64 - __builtin_clzll(n); } void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18...
3
#include <bits/stdc++.h> using namespace std; int main() { int i, j, r, c, row[12], col[12]; char a[12][12]; cin >> r >> c; for (i = 0; i < r; i++) cin >> a[i]; memset(row, 0, sizeof(int) * r); memset(col, 0, sizeof(int) * c); for (i = 0; i < r; i++) { for (j = 0; j < c; j++) { if (a[i][j] == 'S...
0
#include <bits/stdc++.h> struct data { int val; int pos; int ranks; } p[2005]; bool cmp1(const data &a, const data &b) { if (a.val == b.val) return a.pos < b.pos; return a.val < b.val; } bool cmp2(const data &a, const data &b) { return a.val > b.val; } bool cmp3(const data &a, const data &b) { return a.pos < ...
0
#include <bits/stdc++.h> using namespace std; typedef class Edge { public: int u, v; long long w; Edge() {} Edge(int u, int v, long long w) : u(u), v(v), w(w) {} void read() { scanf("%d%d%lld", &u, &v, &w); } bool operator<(Edge b) const { return w < b.w; } } Edge; typedef class Node { public: int p; ...
9
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); } long long mod(long long x, long long m = 1000000007) { retu...
0
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; long long n, k; vector<int> primes; bool isprime[1 << 20]; int main() { fill_n(isprime, 1 << 20, 1); for (int i = 2; i <= 1024; ++i) if (isprime[i]) { for (int j = i * i; j < 1 << 20; j += i) isprime[j] = 0; } for (int i = 2...
6
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 333; const long long linf = 1e18 + 333; const int mod = 1e9 + 7; bool h[1000005]; int pws[1000005]; int p, k; int pw(int x, int k) { int res = 1; while (k) { if (k & 1) res = (long long)res * x % mod; x = (long long)x * x % mod; k >>= 1...
5
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; long long mana = 0; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } vector<long long> v; long long i = 0; for (i = 0; i < n - 2; i++...
1
#include <bits/stdc++.h> using namespace std; void f() { int T; cin >> T; for (int i = 0; i < T; i++) { int n, m; cin >> n >> m; vector<bool> covered(3 * n + 1); int uncovered = 3 * n; vector<int> matching; for (int j = 0; j < m; j++) { int u, v; cin >> u >> v; if (covere...
6
#include <bits/stdc++.h> using namespace std; using i64 = long long; using f64 = double; using pii = pair<int, int>; using pll = pair<i64, i64>; vector<i64> b, a; int n; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); bool flag; int p = 0; cin >> n; b.resize(n); for (auto &i : b) cin >>...
8
#include <bits/stdc++.h> using namespace std; int main() { int q, w, e, r, t, a[26][26]; char c, v, d[100001], f[100001]; for (w = 0; w < 26; w++) for (e = 0; e < 26; e++) if (w == e) a[w][e] = 0; else a[w][e] = 100000; scanf("%s%s", d, f); q = strlen(d); if (strlen(f) != q) ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, c = 0; cin >> n >> m; while (n--) { int a[2 * m]; for (i = 0; i < 2 * m; i++) { cin >> a[i]; } for (i = 0; i < 2 * m; i = i + 2) { if (a[i] || a[i + 1] == 1) c++; } } cout << c << "\n"; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, d; cin >> n >> m >> d; vector<int> a(n * m); vector<int> cnt(d); for (int i = 0; i < n * m; i++) cin >> a[i], cnt[a[i] % d]++; int mi = *min_element(a.begin(), a.end()); int ma = *max_element(cnt.begin(), cnt.end()); if (ma != n * m) {...
3
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> x, y, z; int partial() { int ret = 0; for (int i = 0; i < (int)(min<int>(m, x.size())); i++) if (z[m - 1 - i] >= x[i]) ret += z[m - 1 - i] - x[i]; return ret; } int all() { if (n > m) return 0; vector<int> v = z; int ret = 0; for (int...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 30; vector<int> pos[MAXN]; string inp; int countdiff(int l, int r) { int res = 0; for (int i = 0; i < 26; i++) { auto it = lower_bound(pos[i].begin(), pos[i].end(), l); if (it != pos[i].end() && *it <= r) res++; } return res; } int main() { ...
5
#include <bits/stdc++.h> using namespace std; int64_t mod = 998244353; int64_t mod1 = 1e9 + 5; int64_t power(int64_t a, int64_t b) { if (b == 0) return 1; else if (b % 2 == 0) return power(((((a) % mod) * ((a) % mod)) % mod), b / 2) % mod; else return (((a) % mod) * (power(((((a) % mod) * ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; for (int j = 0; j < t; j++) { long long x, y; cin >> x >> y; if (y <= x) cout << "YES\n"; else { if (x == 1) cout << "NO\n"; ...
1
#include <bits/stdc++.h> using namespace std; const char lend = '\n'; const int N = 300; string last, res; int vet[N], n; bool build(int p, int s, int k) { if (last[p] + k > '9') return false; for (int i = 0; i < p; ++i) res[i] = last[i], s -= last[i] - '0'; res[p] = last[p] + k; s -= res[p] - '0'; if (s < 0)...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int a, b, c, d; cin >> a >> b >> c >> d; cout << max(abs(c - a), abs(d - b)); }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long x = n / 2; x += n % 2; if (k <= x) cout << 2 * k - 1; else { k -= x; cout << 2 * k; } }
0
#include <bits/stdc++.h> using namespace std; pair<double, double> pt[100001]; int n, kth; double getDist(int i1, int i2) { pair<double, double> &a = pt[i1]; pair<double, double> &b = pt[i2]; double x = a.first - b.first; double y = a.second - b.second; return sqrt(x * x + y * y); } double getAns(int till, in...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, k, v, ans = 0; cin >> k >> a >> b >> v; while (b && a) { if (b >= k - 1) { b -= k - 1; ans++; if (a >= k * v) a -= k * v; else a = 0; } else { ans++; if (a >= (b + 1) * v) a -= ...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double err = 1e-12; const double PI = 3.141592653589793; const int N = 1e5 + 5; int n, m; vector<int> A(N), B(N); unordered_map<int, int> cnt; void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n;...
4
#include <bits/stdc++.h> using namespace std; int d, x, n, a; int main() { cin >> d >> n; for (int i = 0; i < n - 1; i++) { cin >> a; x += d - a; } cout << x; return 0; }
1
#include <bits/stdc++.h> using namespace std; template <class T> string toString(T n) { ostringstream ost; ost << n; ost.flush(); return ost.str(); } long long toInt64(string s) { long long r = 0; istringstream sin(s); sin >> r; return r; } int main() { int t = 0; int m = 0; char buff[100]; cin....
4
#include <bits/stdc++.h> using namespace std; class classcomp { public: bool operator()(const int& l, const int& r) const { return l < r; } }; vector<int> a[100010]; vector<vector<int> > ed; int n, m, in; bool cmp(int x, int y) { return a[in][x] < a[in][y]; } vector<int> vis; bool fail = false; set<int> inq; list<in...
7
#include <bits/stdc++.h> using namespace std; long long ans, res; int n, m, cnt, k, valy[3050], suf[3050], pre[3050], f[3050]; struct P { int x, y; } p[3050]; bool cmpy(P a, P b) { return a.y < b.y; } bool cmpx(P a, P b) { return a.x < b.x; } void ins(int x) { suf[pre[x]] = x, pre[suf[x]] = x; } void del(int x) { suf...
11
#include <bits/stdc++.h> using namespace std; int zhao(int n, int m) { int c; int a = m, b = n; while (b) { c = a % b; a = b; b = c; } return m * n / a; } void solve() { int l, r; cin >> l >> r; int i; bool bad = false; if (l == 1) { cout << l << " " << r << '\n'; return; } i...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; if (n == 2 && x == 0) { cout << "NO" << endl; return 0; } cout << "YES" << endl; if (n % 4 == 0) { for (int i = 610000; i < 610000 + n - 4; i++) cout << i << " "; cout << (x + 13) << " " << (x + 17) << " " <<...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; int n; int nxt[N]; vector<int> g[N]; int res[N]; int cur; bool used[N]; int nxt2[N]; void dfs(int v) { used[v] = true; for (int u : g[v]) { if (!used[u]) dfs(u); } res[v] = cur++; } void build() { vector<int> st; for (int i = 0; i < n;...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n + 1]; for (long long i = 1; i <= n; i++) cin >> a[i]; long long result = 0; for (long long i = 2; i < n; i++) { if (a[i] > a[i - 1] && a[i] > a[i + 1]) result++; else if (a[i] < a[i - 1] && a[i] < a...
0
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T v) { cerr << v << " "; return *this; } } dbg; int gap(int a, int b) { if (b >= a) return b - a; else return b + 10 - a; } int shift(int a, int b) { return (a + b + 10) % 10; } int ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000; const int mod = 1e9 + 7; long long h[maxn + 10], f[maxn + 10], g[maxn + 10]; int inv(int x, int y) { int s = 1; while (y) { if (y & 1) s = 1LL * s * x % mod; x = 1LL * x * x % mod; y >>= 1; } return s; } int main() { h[0] = 1;...
8
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a, b; cin >> t; while (t--) { cin >> n >> a >> b; int temp; int mx1 = 0, mx2 = 0; for (int i = 0; i < a; i++) { cin >> temp; mx1 = max(mx1, temp); } for (int i = 0; i < b; i++) { cin >> temp; mx2 =...
0
#include <bits/stdc++.h> using namespace std; const int sz = 2e5 + 5; int n, q, v, a[sz], arr[sz], Tree[sz * 3], Lazy[sz * 3], Time = 0; vector<int> x[sz]; pair<int, int> Range[sz]; string s; void dfs(int u, int par) { Range[u].first = ++Time; arr[Time] = u; for (auto i : x[u]) { if (i != par) { dfs(i, ...
6
#include <bits/stdc++.h> using namespace std; int n, m, h, s; int main() { int i, j, d, tot = 0, our = 0; scanf("%d %d %d", &n, &m, &h); --n; for (i = 1; i <= m; ++i) { scanf("%d", &s); if (i == h) { our = s - 1; tot += s - 1; } else tot += s; } if (n > tot) { printf("-1.0\...
4
#include <bits/stdc++.h> using namespace std; string ch = ""; string chr = ""; string table[1000000]; string cht[1000000]; string cht2[1000000]; string mat[100][100]; long long int t[1000000]; long long int t2[1000000]; long long int t3[1000000]; long long int t4[1000000]; long long int n, m, k, s, s1, p, x, y, z; stri...
0
#include <bits/stdc++.h> const int N = 100500; using namespace std; int main() { long long l, n, a[N]; cin >> n >> l; for (long long i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); double mini = a[1]; mini = max((long long)mini, l - a[n]); for (int i = 1; i <= n; i++) { mini = max(m...
2
#include <bits/stdc++.h> using namespace std; const int N = 155; int n, m; struct Matrix { int n, m; bool a[N][N]; Matrix(int _n = 0, int _m = 0) { n = _n, m = _m; memset(a, 0, sizeof(a)); } bool* operator[](int x) { return a[x]; } const bool* operator[](int x) const { return a[x]; } }; Matrix opera...
9
#include <bits/stdc++.h> using namespace std; int a, b, c, k1, k2, k3; int main() { cin >> a >> b; for (int i = 1; i <= 6; i++) { if (abs(i - a) < abs(i - b)) k1++; if (abs(i - b) < abs(i - a)) k3++; if (abs(i - a) == abs(i - b)) k2++; } cout << k1 << " " << k2 << " " << k3; }
0
#include <bits/stdc++.h> using namespace std; const int N = 105, mo = 1e9 + 9; int n, m, i, j, k, ans, inv[N], fac[N], x, y, d[N], g[N][N], f[N]; queue<int> q; bool inq[N], vi[N]; vector<int> e[N], F = {1}; int xb, dfn[N], be[N], en[N], sz[N]; void getdfn(int x, int fa) { vi[x] = 1; dfn[be[x] = ++xb] = x; sz[x] =...
10
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10, L = 30 + 10; long long n, h[N], wei[N], str[N], q, out = 0, t = 0, par[N][L]; vector<pair<long long, long long> > mat[N]; set<pair<long long, long long> > nodes; set<pair<long long, long long> >::iterator it; void input(); void process(); int main...
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100001; const long long MOD = 1000000007; const long long INF = 1e18; long long add(long long a, long long b) { return (a + b) % MOD; } long long sub(long long a, long long b) { return (a - b + MOD) % MOD; } long long mul(long long a, long long b) { return...
8
#include <bits/stdc++.h> using namespace std; double dp[2][10010][210], p[2], ans; int n, x, y, a[2], t[2], l[2], r[2]; int main() { for (int i = 0; i < 2; i++) scanf("%d%d%d%d%lf", &a[i], &t[i], &l[i], &r[i], &p[i]); if (abs(p[0] - 100.0) < (1e-8)) { puts("0.000000"); return 0; } if (abs(p[1] - 100...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int n, a[2005], b[2005]; int dp[2005][9][10][10][10]; int solve(int i, int f, int x, int y, int z) { if (i == n && x == 9 && y == 9 && z == 9) return 0; if (dp[i][f][x][y][z] != -1) return dp[i][f][x][y][z]; int ans = INF; if (x != 9) ans = ...
8
#include <iostream> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; cin >> TESTS; while (TESTS--) { long long n; cin >> n; long long a[200005]; for (long long int i = 0; i < n + 1; i++) a[i] = 0; for (long long int i = 0; i...
3
#include <bits/stdc++.h> const int MAX = 1e3 + 5; using namespace std; int edge, mx, ans, seen[MAX], a, n, m, k, spec[MAX], check[MAX][MAX]; vector<int> adj[MAX]; vector<int> cur; void dfs(int node) { if (seen[node] == 1) return; seen[node] = 1; cur.push_back(node); for (int i = int(0); i <= int(adj[node].size(...
3
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; vector<pair<int, int> > a; int rev[200005]; int n, m; vector<pair<int, int> > s; int model(int p, int l, int d) { if (l == 0) return p; int id = lower_bound(a.begin(), a.end(), make_pair(a[p].first + l * d, -1)) - a....
8
#include <bits/stdc++.h> using namespace std; inline int gi() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar(); } return x * f; } template <typename T> inline boo...
9
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 5; const long long mod = 1e9 + 7; long long pw(long long b, long long r, long long md = mod) { b = b % md; long long ans = 1; while (r) { if (r & 1) ans = (ans * b) % md; b = (b * b) % md; r >>= 1; } return ans; } long long...
7
#include <bits/stdc++.h> using namespace std; struct SAM { int trans[26], len, fa; } sam[2000005]; int tot, root, tail; char s[2000005], ch; void add(int ch, int len) { int p = tail, np = ++tot, q, r; sam[np].len = len; for (; p && !sam[p].trans[ch]; p = sam[p].fa) sam[p].trans[ch] = np; tail = np; if (!p) ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c; cin >> a >> b >> c; cout << min(a, min(b - 1, c - 2)) * 3 + 3 << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; string z[2000]; string st; char bl; long tests, er, bad[2000]; char gett(char x) { if (x >= 'A' && x <= 'Z') return x - 'A' + 'a'; return x; } long flag; bool upper(char x) { if (x >= 'A' && x <= 'Z') return 1; return 0; } int main() { ios_base::sync_with_stdio(0)...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, a, b, i, k = 0, j; cin >> n >> m; vector<int> id(n + 1, 0); vector<vector<int> > vec((n / 3) + 1, vector<int>()); for (i = 0; i < m; ++i) { cin >> a >> b; if (id[a] == 0 && id[b] =...
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; int n, m; struct ufind { int p[100005], t; void init() { memset(p, 0, sizeof(p)); } void set_friend(int i, int j) { for (; p[t = i]; i = p[i], p[t] = (p[i...
7
#include <bits/stdc++.h> using namespace std; int T; long long sum, cnt, cnt1; string s; int main() { cin >> T; while (T--) { cnt = 0; cnt1 = 0; sum = 0; cin >> s; for (int i = 0; i < s.size(); i++) { sum = sum + (s[i] - '0'); if (s[i] == '0') { cnt++; } if ((s[i]...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t; cin >> t; while (t--) { ll n; cin >> n; vector<ll> sides(n); for (int i = 0; i < (n); ++i) cin >> sides[i]; if (sides[1] > (sides[n - 1] - sides[0])) ...
0
#include <bits/stdc++.h> using namespace std; void solve() { double n, x; cin >> n >> x; long long mx = INT_MIN, md = INT_MIN; for (long long i = 0; i < n; i++) { long long d, h; cin >> d >> h; if (mx < d - h) mx = d - h; md = max(md, d); } if (mx <= 0) { if (md >= x) cout << 1 << ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, e, f, sum = 0, Min = 0, flag; cin >> a >> b >> c >> d >> e >> f; long long Max = max(e, f); if (Max == f) { Min = min(b, c); Min = min(Min, d); sum = sum + Min * f; d = d - Min; b = b - Min; c = c - Min; ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pii = pair<int, int>; using Vi = vector<int>; void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18); run(); return 0; } int uplg(int n) { return 32 - __builtin_clz(n); } int uplg(ll n) { return 6...
8
#include <bits/stdc++.h> using namespace std; const int nax = 3000005; string to_stringa(long long a) { string ans; while (a) { char c = a % 10 + '0'; ans = c + ans; a /= 10; } return ans; } int main() { long long n, t; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<long lon...
5
#include <bits/stdc++.h> using namespace std; int maxn = 100000010; struct person { int atk, hp, def; }; int a, b, c; person least_hp, least_atk, least_def; person yang, mon; long ans = maxn; bool survive(int i, int j, int k) { int yangatk = yang.atk + i; int yanghp = yang.hp + j; int yangdef = yang.def + k; ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; int w, h, x1, y1, x2, y2, a, b; cin >> t; while (t--) { cin >> w >> h; cin >> x1 >> y1 >> x2 >> y2; cin >> a >> b; int delW = w - x2, delW2 = x1...
2
#include <bits/stdc++.h> using namespace std; int main() { string str[3]; for (int i = 0; i < 3; i++) { cin >> str[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (str[i][j] != str[2 - i][2 - j]) { cout << "NO"; return 0; } } } cout << "YES"; }
0
#include <bits/stdc++.h> using namespace std; void doRoutine() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); srand(322179); } const int C = 5010; int tr[C * 8]; bool cross(pair<pair<int, int>, int> hor, pair<int, pair<int, int> > vert) { return (vert.second.first <= hor.second && ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); vector<pair<int, int>> a(3), ans; for (int i = 0; i < 3; i++) { int x, y; cin >> x >> y; a[i] = {x, y}; } sort(a.begin(), a.end()); if ((a[0].second - a[1].second) * (a[2].second - a[1].second) > 0)...
4
#include<bits/stdc++.h> using namespace std; void solve() { int n,odd=0,even=0; cin>>n; for(int i=1; i<=2*n; i++) { int x; cin>>x; (x&1)?odd++:even++; } if(odd == even) cout<<"Yes"<<endl; else cout<<"No"<<endl; } int main() { int t; cin>>t; ...
0
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int h[n + 1]; for (int i = 1; i <= n; i++) { cin >> h[i]; } int pos; int count = 0; for (int i = 1; i <= n; i++) { pos = i; int count1 = 1; for (int i = pos - 1; i > 0; i--) { if (h[i] > h[i + 1]) ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> void sci(T& t) { cin >> t; } template <typename T, typename... Ts> void sci(T& t, Ts&... ts) { sci(t); sci(ts...); } int c[111111]; vector<int> g[111111]; long long ans[111111]; map<int, int>* cnt[111111]; set<pair<int, int>>* cs[111111]; long lo...
7
#include <bits/stdc++.h> using namespace std; int a, b, c; map<int, int> mp; int main() { int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) { if (i + j > (i ^ j) && (i ^ j) <= n && (i ^ j) >= j) { cnt++; } } cout << cnt; return 0; }
2
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void program(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); program(); } const int MX = 19, BIT = 1 << MX; int n, bit, sbit; string s[MX]; bitset<MX> knows[MX]; lo...
12
#include <bits/stdc++.h> using namespace std; int64_t dp[305][3]; char s[305]; int32_t main() { { cin.tie(0); ios_base::sync_with_stdio(false); }; cin >> s; int64_t n = strlen(s); s[n] = s[0]; dp[0][0] = 1; for (int64_t i = 1; i <= n; i++) { if (s[i - 1] == 'A') { dp[i][0] = dp[i - 1][0]...
6
// 2020.12.13 // Code by LTb // #pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; // #define int long long #define debug puts("QwQ"); inline int read(){ int x=0,f=1; char ch; while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();} ...
9
#include <bits/stdc++.h> using namespace std; long double PI = 3.14159265359; int inf = 1000000000000000007; int mod = 1000000007; int mod1 = 998244353; const bool multi = 0; vector<int> G[2500007]; vector<int> RG[2500007]; bool odw[2500007]; int scc[2500007]; vector<int> post; void dfs(int v) { odw[v] = 1; for (au...
9
#include <bits/stdc++.h> using namespace std; const long long mx = (1 << 22); long long f[mx], ans[mx]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; memset(ans, -1, sizeof(ans)); for (l...
7
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf("%d %d", &x, &y); int ans = (x + y) / 3; if (y > 2 * x) ans = x; if (x > 2 * y) ans = y; printf("%d\n", ans); return 0; }
2
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); unsigned long long int t; cin >> t; while (t--) { unsigned long long int n; cin >> n; if (n > 14 && n % 14 <= 6 && n % 14 > 0) cout << "YES" << e...
1
#include <bits/stdc++.h> int main() { int n, a, b, c, cnt = 0; scanf("%d", &n); while (n) { scanf("%d%d%d", &a, &b, &c); if (a + b + c >= 2) { cnt++; } n--; } printf("%d\n", cnt); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 5e6 + 5; const int base = 13331; char s[maxn]; unsigned long long p[maxn], sum[maxn], suf[maxn]; int f[maxn]; int idx(char c) { if (c >= 'a' && c <= 'z') return c - 'a' + 1; if (c >= 'A' && c <= 'Z') return c - 'A' + 27; ret...
7
#include <bits/stdc++.h> using namespace std; namespace caide { template <typename C> int SZ(const C& c) { return (int)c.size(); } template <typename T> vector<vector<T>> makeVector(int n, int m) { return vector<vector<T>>(n, vector<T>(m)); } } // namespace caide namespace caide { class ModInt { public: static ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> a(n); for (int i = 0; i < n; ++i) { long long x; scanf("%lld", &x); a[i] = __builtin_popcountll(x); } long long answer = 0; vector<int> sum(n + 1); for (int i = 0; i < n; ++i) { sum[i + 1] = su...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, pos, l, r; while (cin >> n >> pos >> l >> r) { if (l == 1 && r == n) cout << 0 << endl; else if (l == 1) cout << (abs(r - pos) + 1) << endl; else if (r == n) cout << (abs(l - pos) + 1) << endl; else if (pos < l || po...
2
#include <bits/stdc++.h> using namespace std; int n, m; int dis[100009], par[100009], road[100009]; vector<pair<int, int> > v[100009]; queue<pair<int, int> > q; set<pair<int, int> > s; vector<pair<int, int> > res; pair<int, int> dif(int x, int y) { if (x > y) swap(x, y); return {x, y}; } int main() { scanf("%d%d"...
6
#include <bits/stdc++.h> const int INF = 2147483647; using namespace std; int n, a[50005]; int solve(int l, int r) { int num = r - l + 1; if (num <= 0) return 0; if (num == 1) return 1; int times = 0, minh = INF; for (int i = l; i <= r; i++) minh = min(minh, a[i]); times = minh; for (int i = l; i <= r; i+...
5
#include <bits/stdc++.h> using namespace std; int main() { int taxi = 0, k, a, all[5] = {0}; cin >> a; for (int i = 0; i < a; i++) { cin >> k; all[k]++; } taxi += all[4]; taxi += all[3]; all[1] = all[1] - all[3]; all[1] = all[1] < 0 ? 0 : all[1]; taxi += all[2] / 2 + all[2] % 2; all[1] = all...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; inline int min(const int& x, const int& y) { return (x - y >> 31) ? x : y; } namespace ST { int lg[N], t[20][N]; inline void build(int* a, int n) { copy(a + 1, a + 1 + n, t[0] + 1); for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1; for (int i...
13