solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long a[200100]; long long b[200100]; int main() { int n, m, i; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } a[n + 1] = 1e18; for (i = 0; i < m; i++) { long long x; cin >> x; long long o = lower_bound(a, a + ...
2
#include <bits/stdc++.h> using namespace std; int arr[101][101]; int main() { int n; cin >> n; int x1, y1, x2, y2; for (int i = 0; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2; for (int j = x1; j <= x2; j++) { for (int k = y1; k <= y2; k++) arr[j][k]++; } } int sum = 0; for (int i = 0; i < ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long m, n; cin >> m >> n; long long p; p = m * n; cout << p / 2 << endl; }
0
#include <bits/stdc++.h> using namespace std; long long power(long long n, long long m) { long long res = 1; while (m) { if (m & 1) res = (res * n) % 1000000007; n = (n * n) % 1000000007; m /= 2; } return res; } int main() { long long n, a, b, c, t, i, j; long long k, s = 0, p = 0; cin >> n >>...
5
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 100000, stdin); if (p1 == p2) return EOF; } return *p1++; } inline void read(int &x) { char c = nc(), b = 1; for (; !(c >= '0' && c <= '9');...
11
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; const int MOD = 998244353; long long POW(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } long long C(long long n, long long m) { if (m > n) r...
19
#include <bits/stdc++.h> using namespace std; int par[100001]; vector<int> child[100001]; pair<int, int> counts[100001]; int specialchild[100001]; bool veryspecial[100001]; void dfs1(int x) { int counter = 0; for (int i : child[x]) { dfs1(i); counter += counts[i].second; } int minans = 10000000; for (...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> numbers; int cantidadNegativos = 0; for (int i = 0; i < n; i++) { int aux; cin >> aux; if (aux < 0) cantidadNegativos++; numbers.push_back(aux); } sort(numbers.begin(), numbers.end()); auto aux = lowe...
3
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } co...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 500050; int n; long long ans; long long f[MAXN]; vector<int> v[MAXN]; long long siz[MAXN]; void dfs(int k, int fa) { siz[k] = 1; for (__typeof(v[k].begin()) p = v[k].begin(); p < v[k].end(); ++p) if (*p != fa) { dfs(*p, k); siz[k] += siz...
19
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vecto...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, y; long long x; cin >> n >> x >> y; long long wa = (y - (n - 1)); if (wa <= 0 || (wa * wa + n - 1) < x) return cout << -1, 0; for (int i = 1; i <= n - 1; i++) { cout << 1 << endl; } cout << y - (n - 1) << endl; return 0; }
6
#include <bits/stdc++.h> using namespace std; long long pow(long long c, long long d) { return d == 0 ?: c * pow(c, d - 1); } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } int main() { ios_base::sync_with_stdio(...
3
#include <bits/stdc++.h> using namespace std; const uint64_t mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; uint64_t start = 0, end = s.size(); while (start < end && s[start] == '0') { start++; } if (start == end) { cout << s.size() << endl; ...
20
#include <bits/stdc++.h> const double pi = acos(-1.0); const double eps = 1e-9; const int inf = 2 * 1e9; const int base = 2011; const int raz = (int)1e6 + 1; const double deg = pi / 180; const int mod = 1e9 + 7; using namespace std; int main() { int n; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) scan...
12
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f; } inline void read(lo...
22
#include <bits/stdc++.h> using namespace std; struct T { long long x, l, r; } c[100005], d[100005]; long long n, m, k, a[4000005], tg[4000005], b[4000005], Tg[4000005]; bool cmp(T x, T y) { return x.x == y.x ? x.l > y.l : x.x < y.x; } void dn(long long k, long long l, long long r) { long long mid = l + r >> 1; if...
23
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * f; } int n, ans = 0x3f3f3f3f, tot = 0, pri...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { long long l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; long long a, b; a = l1; b = l2; if (a == b) { if (b < r2) b++; else ...
0
#include <bits/stdc++.h> using namespace std; vector<long long> p; bitset<1000000 + 5> c; void ciur() { int i, j; for (i = 2; i * i <= 1000000; i++) { if (c[i] == 0) for (j = i; j * i <= 1000000; j++) c[j * i] = 1; } for (i = 2; i <= 1000000; i++) if (c[i] == 0) p.push_back(i); } long long cmmdc(l...
10
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, z, w, k, t, d, q, ans, st[100100], par[30][100100], lay[100100]; vector<long long> v[100100]; pair<long long, long long> seg[400100]; void input() { cin >> n >> q; for (int i = 2; i <= n; i++) { int x; cin >> x; v[i].push_back(x); ...
15
#include <bits/stdc++.h> using namespace std; struct vec { int x, y; vec(int _x, int _y) { x = _x; y = _y; } }; int n, x[1005], y[1005], sign; int cross(vec v1, vec v2) { return v1.x * v2.y - v2.x * v1.y; } int main(void) { cin >> n; cin >> x[0] >> y[0]; for (int i = 1; i <= n; i++) cin >> x[i] >> y...
7
#include <bits/stdc++.h> int main() { int q, n, a; scanf("%d", &q); while (q--) { scanf("%d", &n); if (n < 4) { a = 4 - n; } else if (n > 4 && n % 2 != 0) { a = 1; } else { a = 0; } printf("%d\n", a); } }
0
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; n = n / 2; if (n & 1) { cout << "NO"; } else { cout << "YES" << "\n"; for (long long i = 1; i <= n; i++) cout << 2 * i << " "; long long i = 1; for (; i <= n / 2; i++) cout << 2 * i - 1 << " "; ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; vector<pair<pair<int, int>, int> > vc; int n, a[MAXN], qa, qb, p, la = -1, lb = -1; long long ans[MAXN], S[MAXN], K; bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { if (a.first.first == b.first.first) return a.first.seco...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> inline bool uin(T& a, T b) { return a > b && (a = b, true); } template <class T> inline bool uax(T& a, T b) { return a < b && (a = b, true); } class DStringMark { static const ll MOD = 1e9 + 7; vector<ll> factorial, inv_facto...
13
#include <bits/stdc++.h> using namespace std; int x[501]; int main() { int n, m, u, v, c; double ans = 0.0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &x[i]); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &u, &v, &c); ans = max(ans, (x[u] + x[v]) * 1.0 / c); } printf("%.9f", ...
8
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100007; const long long mod = 1000000007; long long Pow(long long x, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } char str[MAX_N]; int a[5], n; int main() { ...
7
#include <bits/stdc++.h> const double eps = (1e-9); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } long long setBit0(long long...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int d, m; cin >> d >> m; if (d == 1) { cout << 1 % m << endl; continue; } long long diff = 1; long long curr = 1; long long ans = 0; for (int i = 1; i <= 30; i++) { curr += d...
9
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& o, pair<A, B>& p) { return o << "(" << p.first << ", " << p.second << ")"; } template <class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } long long t1, t2, x1, x2...
11
#include <bits/stdc++.h> using namespace std; long long rTrav(long long num, long long cur, long long nodes); long long lTrav(long long num, long long cur, long long nodes) { if (cur < 0) return nodes; long long p = (long long)1 << cur; if (num > p) { nodes += (long long)2 * p; return lTrav(num - p, cur -...
9
#include <bits/stdc++.h> const int p = 1000003; long long m, n, q, r, s, t; inline long long power(long long x, long long y) { if (y == 0) return 1; long long t = power(x, y / 2); t = t * t % p; if (y & 1) t = t * x % p; return t; } int main() { scanf("%I64d%I64d", &n, &m); if ((n < 63) && (m > (1LL << n)...
15
#include <bits/stdc++.h> using namespace std; long long gg, ll; long long n; const long long N = 2e5 + 5; vector<long long> g[N]; vector<array<long long, 3>> dp; long long ar[N]; array<long long, 3> dfs(long long s) { array<long long, 3> tmp = {0, 0, 0}; long long mx = 0; vector<array<long long, 3>> vec; for (a...
11
#include <bits/stdc++.h> using namespace std; int um, zero, undef, n; char ent[1000000]; int main() { scanf("%s", ent); for (int i = 0; ent[i]; ++i) { if (ent[i] == '1') ++um; else if (ent[i] == '0') ++zero; else ++undef; ++n; } if (zero + undef > um) printf("00\n"); if (zero...
11
#include <bits/stdc++.h> using namespace std; void read(long long int n = 10) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; } long long int M = 1e9 + 7; long long int M1 = 998244353; class trie { public: map<string, trie*> arr; long long int ca, cb; trie() { ...
10
#include <bits/stdc++.h> using namespace std; const int Maxn = 1000005; const int Maxm = 4194304; struct node { int l, r, f; pair<int, int> mn; node(int l = 0, int r = 0, int f = 0, pair<int, int> mn = pair<int, int>(0, 0)) : l(l), r(r), f(f), mn(mn) {} }; int n, k; int a[Maxn], b[Maxn]; bool was[Max...
14
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int read() { int x; scanf("%d", &x); return x; } void write(int x) { printf("%d\n", x); return; } int n, k, p[N], q[N], deg[N]; vector<int> v[N], tr[N]; int dfn[N], low[N], tim; bool inq[N]; int col[N], id[N], tot; int stk[N], t; char ans[N]...
13
#include <bits/stdc++.h> using namespace std; int pct(int x) { return __builtin_popcount(x); } int pct(long long x) { return __builtin_popcountll(x); } int bit(int x) { return 31 - __builtin_clz(x); } int bit(long long x) { return 63 - __builtin_clzll(x); } int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0)...
16
#include <bits/stdc++.h> using namespace std; long long int arr[200000], tree[200000 * 3]; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long lo...
9
#include <bits/stdc++.h> std::vector<int> adj[100000]; bool bipartite = true; int color[100000]; bool visited[100000]; int count[2]; void dfs(int v, int c) { if (visited[v]) return; visited[v] = true; color[v] = c; count[c]++; for (int u : adj[v]) { if (!visited[u]) { dfs(u, 1 - c); } else { ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 998244353; int n; int siz[N]; double f[N]; vector<int> a[N]; void DFS4Siz(int u, int pa) { siz[u] = 1; for (auto v : a[u]) { if (v == pa) continue; DFS4Siz(v, u); siz[u] += siz[v]; } } void...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> points; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; points.push_back(tmp); } bool intersect = false; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1; j++) { if (i == j) continue...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n, a[100005], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { ans += a[i] * (n - a[i] + 1); if (i...
13
#include <bits/stdc++.h> using namespace std; long long dp[4010][4010]; int n; int main() { scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][i - 1]; for (int j = 1; j <= i; j++) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % 1000000007; } } printf("%I64d\n...
11
#include <bits/stdc++.h> using namespace std; vector<int> v; void SieveOfEratosthenes(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n, k; cin >> n >> k; string s; char a; cin >> s; set<char> s1; for (int i = 0; i < k; i++) { cin >> a; s1.insert(a); } int ide[n], count = 0; for (int i = 0; i <...
4
#include <bits/stdc++.h> using namespace std; long long n; bool ask(long long c) { c += 1; cout << "? " << c << endl; int answer; cin >> answer; return answer; } long long find_start() { long long m = n / 2; long long pos = 0; long long min_pos = 0, max_pos = 0; long long sign = 1; while (m < n) { ...
19
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > domino[100005]; int ans[100005], dy[100005], n; stack<int> gao; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &domino[i].first, &domino[i].second.first); domino[i].second.second = i; } sort(domino, domin...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, temp; cin >> n; int a[n]; int m = 1500000; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { int price = 0; for (int j = 0; j < a[i]; j++) { cin >> temp; price += temp * 5 + 15; } if ...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 2e9; const long long INF64 = 1e18; const long double EPS = 1e-12; const long double PI = acos(-1); const long long MD = 925262732; const long long T = 23917; const int N = 800101; const int M = 1000010; int nn, n, k, kk, type[N], a[N...
22
#include <bits/stdc++.h> using namespace std; void fastInOut(); unsigned long long power(unsigned long long b, unsigned long long pow) { if (b == 0) return 0; else if (pow == 1) return b; else if (pow % 2 == 0) return power(b * b, pow / 2); else return b * power(b * b, pow / 2); } int power(int ...
10
#include <bits/stdc++.h> using namespace std; mt19937 rnd((uint64_t) new char); int64_t rand(int64_t x, int64_t y) { return rnd() % (y - x + 1) + x; } template <typename t> t min(t a) { return a; } template <typename t, typename... ts> t min(const t &a, const ts &...as) { t tmp = min(as...); return tmp < a ? tmp ...
8
#include <bits/stdc++.h> using namespace std; vector<int> v, v1; int main() { int n, m, n1, nn; scanf("%d%d", &n, &m); nn = n; int amin = 0, amax = 0; for (int i = 0; i < m; i++) { scanf("%d", &n1); v.push_back(n1); v1.push_back(n1); } sort(v.begin(), v.end()); for (int i = 0; i < v.size() &...
3
#include <bits/stdc++.h> using namespace std; int n, m, a, b, s; int main() { cin >> n >> m >> a >> b; s = 999999999; for (int i = 0; i <= 1000; i++) { int left = n - m * i; if (left < 0) left = 0; int cost = i * b + left * a; s = min(cost, s); } cout << s; return 0; }
4
#include <bits/stdc++.h> const double EPS = 1e-24; const long long int MOD = 1000000007ll; const double PI = 3.14159265359; int INF = 2147483645; long long int INFINF = 9223372036854775807; template <class T> T Max2(T a, T b) { return a < b ? b : a; } template <class T> T Min2(T a, T b) { return a < b ? a : b; } te...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; vector<pair<int, int> > v; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; v.push_back(make_pair(x, y)); } if (n == 1) { cout << -1 << endl; } else if (n == 2) { if (v[0].first == v[1].first || v[0].second == v[...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = (1 << 20) + 5; int n, f[N]; ll a[100], b[100], sl[N], sr[N]; void get(ll *s, int l, int r) { int m = 1; s[1] = 0; static ll pos[N], neg[N]; for (int i = l; i <= r; i++, m <<= 1) { for (int j = 1; j <= m; j++) pos[j] = s[j] + b...
23
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0); int n; scanf("%d", &n); for (int i = 0; i < n; ++i) printf("%d ", (i + n * 10)); return 0; }
4
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int N = 200000; int n, i, maxx, minn, tab[N]; long long bat[N]; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &tab[i]); minn = 0; maxx = 0; for (i = 0; i < n; i++) { if (tab[i] > tab[maxx]) maxx = i; if...
16
#include <bits/stdc++.h> using namespace std; int ans[200010]; void solve(int l, int r) { if (l > r) return; cout << "? " << l + 1 << " " << r + 1 << endl; int x, f; cin >> x >> f; int st = r - f + 1; int en = l + f - 1; if (st <= en) { for (int i = st, ThxDem = en + 1; i < ThxDem; ++i) ans[i] = x; ...
19
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; if (n1 > n2) cout << "First"; else cout << "Second"; return EXIT_SUCCESS; }
0
#include <bits/stdc++.h> int main() { int i, j, n; char c = 'a'; scanf("%d", &n); if (n < 2) { printf("a\na\nb\nb\n"); return 0; } char Z[4][n]; for (i = 0; i < 4; i++) for (j = 0; j < n; j++) Z[i][j] = '-'; if (n % 2 == 0) { for (i = 0; i < n; i = i + 2) { Z[0][i] = c; Z[0][...
5
#include <bits/stdc++.h> using namespace std; int n, k; void solve() { cin >> n >> k; int ind = 1; while (k > ind) { k -= ind; ind++; } string ans = ""; for (int i = 0; i < n; i++) ans += 'a'; ans[n - (ind + 1)] = 'b'; ans[n - (k)] = 'b'; cout << ans; } int main() { int t = 1; cin >> t; ...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed; cout << setprecision(10); mt19937 rnd(chrono::steady_clock::now().time_since_e...
1
#include <bits/stdc++.h> int main() { long int z, n, m, i, j, k, l, max, S, Sum, c, p, f; scanf("%ld %ld", &n, &m); max = m; S = 0; long int ar[n]; long int ma[n]; for (i = 0; i < n; i++) { scanf("%ld", &ar[i]); ma[i] = -1; } for (i = 0; i < n; i++) { S = S + ar[i]; if (S <= m) { ...
4
#include <bits/stdc++.h> using namespace std; long long n, m, j, b, i, s, a, f; int main() { cin >> n; for (i = 0; i < 4; i++) { cin >> m >> j >> b >> s; if (min(m, j) + min(b, s) <= n) { j = min(m, j); f = n - j; cout << i + 1 << " " << j << " " << f; return 0; } } cout << -...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s; string a, b; int num[200005]; int t = 0; cin >> n >> m >> s; cin >> a >> b; for (int i = 0; i < n; i++) { int flag = 0; for (int j = 0; j < m; j++) { if (a[i + j] != b[j]) { flag = 1; break; } }...
5
#include <bits/stdc++.h> using namespace std; int a, x, y; int main() { cin >> a >> x >> y; if (x > -a && x < a) { if (2 * x > -a && 2 * x < a) { if (y > 0 && y < a) { cout << 1 << endl; return 0; } if (y > a && y < 2 * a) { cout << 2 << endl; return 0; } ...
6
#include <bits/stdc++.h> using namespace std; const int N = 35005; int seg[4 * N]; int lazy[4 * N]; int a[N]; int dp[N]; int n; int Merge(int a, int b) { return max(a, b); } void push(int id, int l, int r) { seg[id] += lazy[id]; if (l != r) { lazy[id * 2] += lazy[id]; lazy[id * 2 + 1] += lazy[id]; } laz...
14
#include <bits/stdc++.h> using namespace std; long long int n, i; double a, d, s1, v, t, p; int main() { cin >> n >> a >> d; p = 0.0; for (i = 0; i < n; i++) { scanf("%lf%lf", &t, &v); s1 = (v * v) / (2.0 * a); if (s1 > d) { t += sqrtl((2 * d) / (1.0 * a)); } else { double k = 0.0; ...
8
#include <bits/stdc++.h> using namespace std; long long int pwr(long long int a, long long int b, long long int mod) { a %= mod; if (a < 0) a += mod; long long int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b /= 2; } return ans; } long long int gcd(long long int a,...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 2507; const long long prime = 99391; const long long mod = 137438953427; inline long long add(long long x, long long y) { return (x + y) % mod; } inline long long sub(long long x, long long y) { return (x - y + mod) % mod; } inline long long mul(long long x,...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 10005; long long n, k, p; char query(long long q) { if (k > 0 && n == q) return 'X'; else if (q % 2 == 1) { long long r = n / 2 - q / 2; long long nk = (n % 2 == 1) ? (k - 1 - n / 2) : (k - n / 2); if (r <= nk) return 'X'; else...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 1; cin >> n; string s; cin >> s; for (int i = 1; i < n - 1; ++i) { int j; for (j = 0; j < i; ++j) { if (j + i < n && s[j] == s[j + i]) continue; else break; } if (j == i) ans = max(ans, i); } ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, ft, inch, r; cin >> n; ft = n / 36; inch = (n % 36) / 3; r = (n % 36) % 3; if (r > 1) inch++; if (inch == 12) { ft++; inch = 0; } cout << ft << " " << inch << endl; return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int n; long long sum = 0; cin >> n; for (int i = 1; i < n; i++) { sum += (n - i) * i; } sum += n; cout << sum; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, a[101]; cin >> t; while (t--) { cin >> n; long long sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long ans = ceil(sum * 1.0 / n * 1.0); cout << ans << '\n'; } }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; struct point { int x, y; bool can; bool operator<(const point &temp) const { if (x == temp.x) return y < temp.y; return x < temp.x; } }; point pt[101000]; int y_list[101000], cnt_y; struct rec { int lx, ly, rx, ry, flag, id; }; rec...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, m, index; string s1, s2; cin >> n >> m; vector<string> v1(m); vector<string> v2(m); for (int i = 0; i < m; i++) { cin >> s1; cin >> s2; v1[i] = s1; v2[i] = s2; } vector<string> v3(n); vector<string> res(n); string s3; ...
2
#include <bits/stdc++.h> using namespace std; double dp[2][201][601]; int main(int argc, char* argv[]) { int n, l, k; cin >> n >> l >> k; vector<int> p(n); for (int i = (0); i < ((n)); ++i) cin >> p[i]; vector<int> a(n); for (int i = (0); i < ((n)); ++i) cin >> a[i]; int const OFFSET = 300; int cur = 0;...
10
#include <bits/stdc++.h> using namespace std; bool issubsequence(char s1[], char s[], int m, int n) { if (m == 0) return true; if (n == 0) return false; if (s1[m - 1] == s[n - 1]) return issubsequence(s1, s, m - 1, n - 1); return issubsequence(s1, s, m, n - 1); } int main() { ios_base::sync_with_stdio(false);...
0
#include <bits/stdc++.h> int main() { int n, i, j; double a[200], temp, max, ch, ch1; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lf", &a[i]); for (i = 0; i < n; i++) { for (j = 0; j < n - 1; j++) { if (a[j] > a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; ...
10
#include <bits/stdc++.h> using namespace std; const int nm = 1000001; int n, k, m, t; int b[nm + 5]; int Get(int x) { if (x <= 0) return 0; if (x > nm) x = nm; return b[x] + Get(x - (x & (-x))); } void Update(int x) { b[x]++; x += x & (-x); if (x <= nm) Update(x); } int res; int main() { int i, j, x, y, z...
13
#include <bits/stdc++.h> using namespace std; const int N = 100004LL; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, l, r; while (cin >> n >> l >> r) { int ma = 0, mi = 0; for (int i = 0; i < r; i++) { ma += (1 << i); } ma += (n - r) * (1 << (r - 1)); ...
1
#include <bits/stdc++.h> using namespace std; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } const int N = 1e3 + 20; long long solve_div(long long l, long long r) { return r / 3 - l / 3; } int mod = 1000000007; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; struct node { int...
11
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> using namespace std; #define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) typedef long long int ll; typedef unsigned long long ull; #define int ll typedef std::vector<...
0
#include <bits/stdc++.h> using namespace std; map<string, string> var, form, val; set<string> us; vector<string> ans; void dfs(string name) { us.insert(name); string va = var[name]; for (int a = 0; a < va.size(); a++) { if (va[a] == '$' or va[a] == '^' or va[a] == '#' or va[a] == '&') { string l = va.su...
19
#include <bits/stdc++.h> using namespace std; map<int, int> mp, pw; int grundy(int mask) { if (mp.count(mask)) return mp[mask]; unordered_set<int> s; for (int i = 1; i < 30; i++) { int msk = (mask >> i) | (mask & ((1 << (i - 1)) - 1)); if (msk != mask) s.insert(grundy(msk)); } int ans = 0; while (s....
14
#include <bits/stdc++.h> using namespace std; int res[111][111]; int main() { int n, a, b; cin >> n >> a >> b; if (n > a * b) { cout << -1 << endl; return 0; } int cnt = 0; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { if (cnt < n) res[i][j] = ++cnt; else ...
2
#include <bits/stdc++.h> template <class c> int popc(c a) { if (sizeof(c) == 8) return __builtin_popcountll(a); else return __builtin_popcount(a); } template <class c> int ctz(c a) { if (sizeof(c) == 8) return __builtin_ctzll(a); else return __builtin_ctz(a); } template <class c> int clz(c a) { ...
9
#include <bits/stdc++.h> using namespace std; template <class T> T mceil(T a, T b) { if (a % b == 0) return a / b; else return a / b + 1; } const long long int M = 1e9; const long long int N = 2e5 + 5; const long long int inf = 9e18; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); long ...
9
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int max_n = 70000 + 1; long long n, a, b, p, q; long long gcd(long long a, long long b) { if (a < b) swap(a, b); if (a % b == 0) return b; return gcd(b, a % b); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; ...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1000 * 1000 * 1000 + 9; const double EPS = 1e-10; const int sz = 100010; long long ms[sz]; int main() { long long n, m; cin >> n >> m; long long res = 1; ms[0] = 1; for (int i = 0; i < (int)(sz - 1); i++) { ms[i + 1] = ms[i] * 2 + 1; ...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int MAXN = 2e5 + 10; int a[MAXN], b[MAXN]; int id[MAXN << 1], len; int n, m; int ans, ansA, ansB; int main() { while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) scanf("%d", &a[i]); scanf("%d", &m); for (int i = 0; i < ...
8
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } int now, nex; const int maxn = 1e6 + 10; long long dp[maxn][2]; int a[maxn]; int n, k; long long l, ans; const int mod = 1e9 + 7; int b[maxn]; long long x, c; inline void add_to_answer(int i, int j) { if (i <= x) ans =...
13
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; string s; int getidx(char c) { if (c >= '0' && c <= '9') return c - '0'; if (c >= 'A' && c <= 'Z') return c - 'A' + 10; if (c >= 'a' && c <= 'z') return c - 'a' + 36; if (c == '-') return 62; if (c == '_') return 63; } int main() { cin >...
7
#include <bits/stdc++.h> int n; char s[50010]; int i, j, k, m; int main() { scanf("%s", s + 1); n = strlen(s + 1); for (i = 1; (i << 1) <= n; ++i) { k = 0; m = i; for (j = i + 1; j <= n; ++j) { if ((k += s[j] ^ s[j - i] ? -k : 1) == i) { k = 0; m -= i; } s[++m] = s[j]...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 400; bool mark[maxn], adj[maxn][maxn]; int h[maxn]; queue<int> Q; int n, m; int bfs(int st, bool isedge) { Q.push(st); mark[st] = true; while (Q.size()) { int v = Q.front(); Q.pop(); for (int u = 0; u < n; u++) if (!mark[u] and (adj[...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; if (n % 2 == 0) { cout << "NO"; } else if (n < 5) { cout << "NO"; } else { cout << 1 << " " << (n - 3) / 2; } }
4