solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000050;
int T, x, y, a;
char ans[3][10] = {"Vanya", "Vova", "Both"};
int who[maxn], s;
inline int gcd(int u, int v) { return !v ? u : gcd(v, u % v); }
int main() {
int i, j, g;
long long sx, sy;
scanf("%d%d%d", &T, &x, &y);
swap(x, y);
g = gcd(x,... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
class UnionFind {
public:
vector<int> p, rank;
UnionFind(int N) {
rank.assign(N, 1);
p.assign(N, 0);
for (int i = 0; i < N; i++) p[i] = i;
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSam... | 5 |
#include <bits/stdc++.h>
using namespace std;
using llint = long long;
bool solve(llint a, llint b) {
if (a > b) swap(a, b);
if (!a) return false;
if (!solve(b % a, a)) return true;
return b / a % (a + 1) % 2 == 0;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
llint a, b;
scanf("%lld%lld", ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 201;
inline void NEXT(const char *T, int *next, int t_len) {
next[0] = -1;
for (int i = 1; i < t_len; i++) {
int j = next[i - 1];
while (j >= 0 && T[i - 1] != T[j]) j = next[j];
if (j >= 0 && T[i - 1] == T[j])
next[i] = j + 1;
els... | 9 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 200054;
int n, B, ans, mode;
int a[N], count[N];
int buc[2 * N];
int cur[N];
inline void up(int &x, const int y) { x < y ? x = y : 0; }
void solve(int x) {
int i, p = n;
memset(buc, -1, (2 * n + 1) << 2), buc[p] = 0;
for (i = 0; i < n; ++i) {... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int eps = 1e6 + 5;
const double pi = acos(-1.0);
const int inf = 1 << 29;
int f[1005];
int c[1005];
int n;
int vis[1005];
void dfs(int x) {
int sign = 0;
for (int i = 1; i <= n; i++) {
if (f[i] == x) {
dfs(i);
sign = 1;
}
}
if (!sign)
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int op(int y) {
if (y < 0) y = -y;
return y;
}
int n, pos, l, r;
int main() {
cin >> n >> pos >> l >> r;
if (l == 1 && r == n) {
cout << 0;
}
if (l == 1 && r != n) {
cout << op(r - pos) + 1;
}
if (l != 1 && r == n) {
cout << op(l - pos) + 1;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
int sgn(double x) { return x < -eps ? -1 : x > eps; }
struct point {
double x, y;
point() : x(0), y(0) {}
point(double a, double b) : x(a), y(b) {}
point operator+(const point &b) const { return point(x + b.x, y... | 9 |
#include <bits/stdc++.h>
int t1, t2;
int n;
std::map<int, int> m[2];
long long ans = 0;
int main() {
scanf("%d", &n);
m[0][0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &t2);
t1 ^= t2;
ans += m[i & 1][t1];
m[i & 1][t1]++;
}
printf("%I64d\n", ans);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 5;
long long p[4];
void solve() {
long long n, k;
cin >> n >> k;
long long m = (n - 1) * 6 + 5;
printf("%I64d\n", m * k);
for (long long i = 0; i < n; i++) {
p[0] = i * 6 + 1;
p[1] = i * 6 + 2;
p[2] = i * 6 + 3;
p[3] = i * 6 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N;
int C[204];
vector<int> adj[204];
int go(int start, vector<queue<int> > q, vector<int> in_deg) {
int res = 0;
int h = start;
while (true) {
int d;
for (d = 0; d < 3 && q[h].empty(); ++d, h = (h + 1) % 3)
;
if (d >= 3) break;
res += d;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> V1[500005], V2[500005], ANS;
vector<int> RED(500005, 0), PL(500005, 0);
int DFS(int A, int L) {
int C = 0;
int CS = 0;
stack<int> S;
vector<int> VIS(500000, 0);
S.push(A);
VIS[A] = 1;
RED[A] = 0;
PL[A] = 0;
while (!S.empty()) {
int N = S.to... | 4 |
#include <bits/stdc++.h>
int s[100000];
void func(int n, int k) {
int i;
for (i = n - 2; i >= 0 && s[i] == s[i + 1]; i--)
;
i++;
if (k > i) {
printf("%d\n", i);
} else {
printf("-1\n");
}
}
int main() {
int n, k, i;
while (scanf("%d%d", &n, &k) == 2) {
for (i = 0; i < n; i++) {
sca... | 2 |
#include <bits/stdc++.h>
inline long long MAX2(long long a, long long int b) {
return (a) > (b) ? (a) : (b);
}
inline long long MAX3(long long a, long long b, long long c) {
return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long MIN2(long long a, long long b) {
return (a) < (b) ?... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200100];
vector<pair<long long, long long> > ans;
vector<long long> vec[3];
int main() {
long long t, n, i, j, k, l, m;
ios_base::sync_with_stdio(0);
cin.tie(0);
long long a, b;
t = 1;
while (t--) {
cin >> n;
for (i = 1; i <= n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 405;
const int inf = 0x3f3f3f3f;
int dp[maxn][maxn];
bool check(string s, string t1, string t2) {
memset(dp, -1, sizeof(dp));
int slen = s.size();
int t1len = t1.size();
dp[0][0] = 0;
for (int i = 0; i < slen; i++) {
for (int j = 0; j <= t1len... | 7 |
#include <bits/stdc++.h>
using namespace std;
char str[110][110];
void fill(int x1, int y1, int x2, int y2, int t) {
int i, j;
char ch = 'a';
bool arr[30] = {0};
if (x1 > 0) arr[str[x1 - 1][y1] - 'a'] = 1;
if (y1 > 0) arr[str[x1][y1 - 1] - 'a'] = 1;
if (t == 1) {
if (x1 > 0) arr[str[x1 - 1][y1 + 1] - 'a... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, c, d, k;
cin >> a >> b >> c >> d >> k;
int x, y;
if (a % c == 0) {
x = a / c;
} else {
x = a / c + 1;
}
if (b % d == 0) {
y = b / d;
} else {
y = b / d + 1;
}
if (x + y > k) {
cout << -1;
return;
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long x, y;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
ios_base::sync_with_stdio(0);
cin >> x >> y;
if (gcd(x, y) != 1) {
cout << "Impossible" << endl;
exit(0);
} else {
int cur = -1;
int sz = 0;... | 8 |
#include <bits/stdc++.h>
using namespace std;
set<long long> arr;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, d;
cin >> n >> m >> d;
long long arr1[n];
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
arr1[i] = x;
arr.insert(x);
}
long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[7] = {0, 2, 3, 5, 7, 11, 13};
int n, m, ans[1000000], s, maxx, nm;
void dfs(int x, int t) {
if (t > nm) {
ans[++m] = x;
return;
}
dfs(x, t + 1);
while (x * a[t] <= maxx) x *= a[t], dfs(x, t + 1);
}
int main() {
scanf("%d", &n);
maxx = n * n * 2;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i;
cin >> n;
string A[n];
set<string> s;
for (i = 0; i < n; i++) cin >> A[i];
for (i = 0; i < n; i++) {
if (s.find(A[i]) == s.end()) {
s.insert(A[i]);
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const vector<vector<int> > adj4({{0, 1}, {0, -1}, {1, 0}, {-1, 0}});
const vector<vector<int> > adj8(
{{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}});
int gcd(int a, int b) { return b == 0 ? a : g... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(vector<int> &A, vector<int> &B) {
vector<int> ans;
int n = (int)(A).size(), m = (int)(B).size();
if (n < m) return ans;
map<int, int> MA, MB;
for (int i = (0); i <= (m - 1); ++i) MA[A[i]]++;
for (int i = (0); i <= (m - 1); ++i) MB[B[i]]++;
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 500001;
int n, k;
int a[mxn];
int dfs(int c) {
int i = c - 1;
while (~i && (a[i] == c || a[i] == -2)) i = dfs(i);
a[c] = ++k;
return i;
}
void answer() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
k = 0;
if (~dfs(n)) {
cou... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
string garbage, weekOrMonth;
cin >> x >> garbage >> weekOrMonth;
if (weekOrMonth == "week") {
if (x != 5 && x != 6)
cout << 52;
else
cout << 53;
} else if (weekOrMonth == "month") {
if (x <= 29)
cout << 12;
els... | 0 |
/*
* yaswanth phani kommineni
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n';
void solve(){
ll n;
cin >> n;
n*=2;
vector <ll> v(n);
map <ll,ll> m;
for(ll i=0;i<n;i++){
cin >> v[i];
m[v[i]]++;
}
sort(v.begin(),v.end());
for(ll i=0;i<n-1;i++){
auto mp = m;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> g[N];
bool seen[N], type[N];
int t[N];
int solve(int cur);
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> type[i];
}
while (m--) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
}
int... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
map<string, int> m;
vector<string> vv;
int was[100];
long long h[100], w[100], border[100], spacing[100];
int type[100];
vector<int> v[100];
int pp;
void add(string... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 55;
const int maxK = 20;
long long f[(1 << maxK) + 2];
long long bt[(1 << maxK) + 2];
string s[maxN];
long long val[maxK];
long double num[maxK];
bool bad[(1 << maxK) + 2];
int bits[(1 << maxK) + 2];
long double dp[(1 << maxK) + 2];
int main() {
ios_base:... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const long double PI = acos(0.0) * 2.0;
mt19937_64 rng((unsigned long long)new char);
const int mod = 1e9 + 7;
const long long INF = 9e18;
const int maxn = 510;
char s[maxn][maxn];
long long dp[2][maxn][maxn];
inline void add(long long& x, long long... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
static void redirec... | 6 |
#include <bits/stdc++.h>
int main(void) {
int planes[5001], n, a;
scanf("%d", &n);
for (a = 1; a <= n; a = a + 1) {
scanf("%d", &planes[a]);
}
for (a = 1; a <= n; a = a + 1) {
if (planes[planes[planes[a]]] == a) {
puts("YES");
return 0;
}
}
puts("NO");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long hpy, atky, defy;
long hpm, atkm, defm;
long thpy, tatky, tdefy;
long morehp, moreatk, moredef;
long res, nowm;
long h, a, d;
int main() {
cin >> hpy >> atky >> defy;
cin >> hpm >> atkm >> defm;
cin >> h >> a >> d;
res = 1000000000;
for (moredef = 0; moredef <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, l, m, n, d;
cin >> k >> l >> m >> n >> d;
int count = d;
for (int i = 1; i <= d; i++) {
if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0)
continue;
else
count--;
}
cout << count;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 1000;
const int sq = 256;
int a[maxn], cnt, h[maxn], par[maxn], parsq[maxn], nxt[maxn * 10][2],
gett[maxn][sq], ans[maxn][sq];
vector<int> g[maxn];
inline void dfs(int v, int pp = 0) {
h[v] = h[pp] + 1;
par[v] = pp;
for (auto u : g[v]) {
... | 12 |
//#pragma GCC optimize("Ofast,unroll-loops,omit-frame-pointer,inline")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,arch=native,tune=native,no-zero-upper")
//#pragma GCC target("avx2,fma")
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for ... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(T v) {
cout << ((int)(v).size()) << endl;
for (auto x : v) cout << x << ' ';
cout << endl;
};
template <class T>
void print1(T v) {
cout << ((int)(v).size()) << endl;
for (auto x : v) cout << x + 1 << ' ';
cout << endl;
};
template ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, t, a, b, da, db, i, j;
cin >> x >> t >> a >> b >> da >> db;
for (i = 0; i < t; i++) {
for (j = 0; j < t; j++) {
if (x == (a + b - i * da - j * db)) {
cout << "YES" << endl;
return 0;
}
}
if (x == (a - i * da)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5;
int T, n, m, k, f[N + 5], ans[N + 5];
struct People {
int a, r, d, u, id;
} p[N + 5];
struct Info {
int opt, l, r;
Info() {}
Info(int opt, int l, int r) : opt(opt), l(l), r(r) {}
};
template <int MAX>
struct BIT {
static const int N = MAX;
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
void afify() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const double EPS = 1e-4;
const long long oo = (long long)10e9 + 7;
const long long N = 1e4 + 5;
int main() {
afify();
int n;
cin >> n;
string s;
cin >> s;
in... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 303;
map<int, int> dp[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> l(n), c(n);
for (auto &i : l) {
cin >> i;
}
for (a... | 5 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
int n;cin>>n;
int r=0;
for(int i=0;i<n;i++)
{
ll x;cin>>x;
ll y=sqrt(x);
y*=y;
if(x!=y)r=1;
}
if(r)cout<... | 0 |
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", a + b);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> ans;
deque<int> dq;
for (int i = 1; i <= k; i++) ans.push_back({i, k + 1}), dq.push_back(i);
for (int i = k + 2; i <= n; i++)
ans.push_back({dq.front(), i}), dq.pop_front... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e4 + 5;
inline int read() {
char c = getchar();
int x = 0, f = 1;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = 0;
for (; c <= '9' && c >= '0'; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
return f ? x : -x;
}
inline int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<int> v[105];
long long dp[105][105];
int n, k;
void dfs(int p) {
dp[p][0] = dp[p][k + 1] = 1;
long long tmp[105];
for (int t = 0; t < v[p].size(); t++) {
if (dp[v[p][t]][0] == 0) {
memset(tmp, 0, sizeof(tmp));
int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct state {
char action;
int length;
state* prev;
int i;
int j;
};
const int MAX_N = 1000;
const int MAX_M = MAX_N;
char maze[MAX_N][MAX_M];
int shortestPath[MAX_N][MAX_M];
int directions[4][2] = {{1, 0}, {0, -1}, {0, 1}, {-1, 0}};
char directionsChar[4] = {'D'... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 400010;
inline long long read() {
long long s = 0, w = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + (ch ^ 48), ch =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
vector<long long int> a(n + 1);
for (long long int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n == 1) {
cout << "1 1\n0\n1 1\n0\n1 1\n" << (-1) * a[1] << "\n";
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long p, q, r;
long long dp[112345][3];
long long a[112345];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> p >> q >> r;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[i][0] = -1e18;
dp[i][1] = -1e18;
dp[i][2] = -... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int MOD = 1000000007;
long long n;
int solve() {
cin >> n;
map<pair<int, int>, bool> mp;
map<int, set<int>> ch;
long long ans = 0;
long long cur = 1, nxt = 1;
vector<pair<int, int>> v;
for (int i = 1; i < n; i++) {
v.push_back({i, i ... | 5 |
/**
Failing doesn’t give you a reason to give up,
as long as you believe.
- Seventh Hokage
(COPIED TEXT FROM BABUMOSHAI)
**/
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
//#include <ext/pb_ds/assoc_co... | 6 |
#include <bits/stdc++.h>
bool check(const char* s) {
if (!*s) return false;
if (*s == '0') return !*(s + 1);
while (*s) {
if (*s < '0') return false;
if ('9' < *s) return false;
++s;
}
return true;
}
int main() {
char s[100001] = "";
std::vector<std::string> r[2];
int e, k;
bool f;
std::... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double pi = 3.14159265358979;
const int maxn = 1e5 + 5;
const int maxm = 1e7 + 233;
const int mod = 998244353;
struct edge {
int to, nxt, w;
} edge[maxn << 1];
int tot, h... | 8 |
#include <bits/stdc++.h>
int a, b, r;
int main() {
scanf("%d%d%d", &a, &b, &r);
printf("%s\n", 2 * r > ((a) < (b) ? (a) : (b)) ? "Second" : "First");
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int N, n;
int main() {
while (~scanf("%d", &N)) {
n = N * N;
for (int i = 0; i < N; i++) {
for (int p = 1; p <= N / 2; p++) {
printf("%d %d ", i * (N / 2) + p, n - (i * (N / 2) + p) + 1);
}
printf("\n");
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string s[] = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM",
"SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"};
int main() {
int n;
scanf("%d", &n);
string ss;
int sol = 0;
for (int i = 0; i < n; i++) {
cin >> ss;
if (isalpha(s... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MOD = 1e9 + 9;
int a[MAXN];
multiset<int> b;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
b.insert(x);
}
for ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
vector<long long> v[100001];
bool compare(pair<long long, long long> x, pair<long long, long long> y) {
if (x.first < y.first) retur... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int stala = 1e6;
int n;
int getRow(char c) { return (c == '0' ? 3 : (c - '1') / 3); }
int getCol(char c) { return (c == '0' ? 1 : (c - '1') % 3); }
int col_min = INF, col_max = -INF;
int row_min = INF, row_max = -INF;
int main() {
ios::sync_with... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, a1, b1, a2, b2;
int main() {
cin >> a >> b >> a1 >> b1 >> a2 >> b2;
if (max(a1, a2) <= a && b1 + b2 <= b)
cout << "YES";
else if (max(b1, a2) <= a && a1 + b2 <= b)
cout << "YES";
else if (max(b1, b2) <= a && a1 + a2 <= b)
cout << "YES";
else ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int x, y, k;
long long add[1000000];
long long a[1000000];
long long b[1000000];
struct node {
int left, right;
int mid() { return (left + right) / 2; }
long long sum;
long long maxx;
} tree[1000000 << 2], point;
int father[1000000 << 2];
void update(int o, int l, i... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[200008];
int t, n, m, x, y, z[200008];
int main() {
for (scanf("%d", &t); t--; printf("\n")) {
for (scanf("%d%d", &n, &m), x = n + 1; --x; z[x] = 0, v[x].clear())
;
for (; m--; scanf("%d%d", &x, &y), v[x].push_back(y))
;
for (x = 0; x... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
inline long long read() {
long long res = 0, f_f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f_f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
res = (res << 3) + (res << 1) + ch - '0';
ch = get... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int maxn = 6e5 + 5;
char s[maxn];
int a[maxn], b[maxn], n, tot, m, p[maxn], c[maxn], cnt[26], st[maxn], top;
bool vis[maxn];
vector<pair<int, int> > ans, res;
void add(int x, int y) {
while (x <= n * 2) b[x] += y, x += x & (-x);
}
int qry(i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EO... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
long long c1, c2;
c1 = c2 = 0;
for (int i = n - 1; i >= 0; --i) {
if (i % 2 == 0)
b[i] = a[i] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int64_t inf = 2e18;
struct Point {
double first, second, z;
Point() {}
Point(double a) : first(a), second(a), z(a) {}
Point(double a, double b, double c) : first(a), second(b), z(c) {}
};
double dist(Point const& p1, Point const& p2) {
return sqrt((p1.first - p2.f... | 6 |
#include <bits/stdc++.h>
using namespace std;
char a[1000100], b[1000100];
int nextt[1000100];
int n;
int ok;
void getnext() {
int i = -1;
int j = 0;
nextt[0] = -1;
while (j < n) {
if (i == -1 || a[i] == a[j])
i++, j++, nextt[j] = i;
else
i = nextt[i];
}
}
void kmp() {
int i = 0, j = 0;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-8;
const int N = 1010;
struct point {
long double x, y;
point(long double x, long double y) : x(x), y(y) {}
point() : x(0), y(0) {}
};
point v[N];
bool eq(long double a, long double b) { return fabs(a - b) < EPS; }
long double sq(long double... | 5 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<int> occ[26];
int dupl[26];
int main() {
iostream::sync_with_stdio(0);
cin.tie(0);
string str;
cin >> str;
int n = str.size();
str += str;
for (int i = 0; i < n; i++) {
occ[str[i] - 'a'].emplace_back(i);
}
int win = 0;
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int g[100005];
bool used[100005];
int n;
int main() {
g[0] = 0;
g[1] = 0;
g[2] = 0;
scanf("%d", &n);
int ans = 0;
for (int m = 3; m <= max(n - 1, 3); m++) {
memset(used, false, sizeof used);
int ans = 0;
for (int k = 2; k * k <= 2 * m; k++) {
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int v[100000 + 5];
int main() {
int n, u;
cin >> n >> u;
int i, j, z, pas;
for (i = 0; i < n; i++) cin >> v[i];
double ans = -1.0;
for (i = 0; i < n; i++) {
for (z = -1, pas = (1 << 17); pas > 0; pas /= 2)
if (z + pas < n && v[z + pas] - v[i] <= u) z +... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct que {
int op, x, y;
} q[200010];
int n, bin[200010], cnt, id;
map<int, int> M;
int F[200010], cur, ml[200010], mr[200010], tot, seq[200010], vis[200010];
int gf(int x) { return (F[x] == x) ? x : (F[x] = gf(F[x])); }
vector<int> s[200010 << 2];
void find(int pos, in... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[1003], b[1003], i, m = 0, j;
cin >> n;
for (i = 0; i < n; ++i) {
cin >> a[i];
if (i > 0) a[i] |= a[i - 1];
}
for (i = 0; i < n; ++i) {
cin >> b[i];
if (i > 0) b[i] |= b[i - 1];
}
for (i = 0; i < n; ++i) {
m = max... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, r, j, k, m, y, x, v, a[3005], b[10], rez, h, i, cnt;
long long Abs(long long x) {
if (x < 0) return -x;
return x;
}
int main() {
cin >> x >> y;
long long min2, max2;
long long min1 = min2 = (long long)1e+18, max1 = max2 = -(long long)1e+18;
cin >... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct dsu {
int f[300005], l[300005], r[300005];
inline void reset(int n) {
for (int i = 1; i <= n; i++) f[i] = l[i] = r[i] = i;
}
inline int getf(int x) { return x != f[x] ? f[x] = getf(f[x]) : x; }
inline void merge(int x, int y) {
x = getf(x), y = getf... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
class TC {
public:
void solve() {
ll a, b;
cin >> a >> b;
ll two = 0, three = 0, five = 0;
ll aa = f(a, 5, five);
aa = f(aa, 3, three);
aa = f(aa, 2, two);
ll bb = f(b, 5, five, -1);
bb = f(bb, 3, three, -1);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int expo(long long int base, long long int exponent,
long long int mod) {
long long int ans = 1;
while (exponent != 0) {
if (exponent & 1) ans = (1LL * ans * base) % mod;
base = (1LL * base * base) % mod;
exponent >>= 1;
}
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100000 + 10;
vector<int> G[maxN];
int n, m, k, ind[maxN];
bool vis[maxN];
vector<int> ans;
void dfs(int u) {
vis[u] = true;
ans.push_back(u);
ind[u] = ans.size() - 1;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (vis[v] == fal... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int a, b;
void foo() {
if (a == 0 || b == 0) return;
if (a >= 2 * b) {
a -= (2 * b * (1 + (a - 2 * b) / (2 * b)));
foo();
return;
}
if (b >= 2 * a) {
b -= (2 * a * (1 + (b - 2 * a) / (2 * a)));
foo();
return;
}
return;
}
int mai... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, j;
cin >> n >> k;
i = n / k;
i++;
cout << k * i << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[2204], prefSum[2204];
int main() {
int n, k, i;
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> arr[i];
}
sort(arr + 1, arr + n + 1);
prefSum[0] = 0;
for (i = 1; i <= n; i++) prefSum[i] = arr[i] + prefSum[i - 1];
cout << prefSum[k] << endl;
re... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, sumk;
int a[N];
int cnt[N], k[N];
bool pred(int x);
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= m; ++i) scanf("%d", &k[i]);
sumk = accumulate(k + 1, k + m + 1, 0);
for (int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_LENGTH = (1 << (10 + 1));
int arr[MAX_LENGTH], total, n, dp[MAX_LENGTH];
int check(int x) {
if (x >= total) {
return 0;
}
if (dp[x] != -1) {
return dp[x];
}
dp[x] = arr[x] + max(check(x << 1), check((x << 1) + 1));
return dp[x];
}
int answe... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
vector<pair<int, int>> g[N], ans[N];
long long dist[N];
priority_queue<pair<int, int>> pq;
bool vis[N];
void dijkstra(int s) {
fill(dist, dist + N, 1LL << 61);
memset(vis, false, sizeof(vis));
dist[s] = 0;
pq.push({0, s});
while (!pq.empty()) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool vis[1009];
int ok[1009];
string v[1009];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> v[i];
memset(vis, 0, sizeof(vis));
memset(ok, -1, sizeof(ok));
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n - 1; ++j) {
if (v[... | 3 |
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const ... | 8 |
#include <iostream>
#include <vector>
#include <map>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;
void solve() {
map<ll,ll> dp;
dp[0] = 1;
ll offset = 0, sum = 0, ans = 1, n;
cin >> n;
vector<ll> b(n+1);
for(int i = 1; i <= n; ++i) {
cin >> b[i];
}
for(int i = 1; i <= n; ++i) {
ll save = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 100010;
int tot = 0;
long long a[N];
map<long long, int> mp;
long long basis[100];
vector<array<long long, 3> > ans;
void show_ans() {
printf("%d\n", (int)ans.size());
for (auto x : ans) {
printf("%lld %c %lld\n", x[0], (x[2... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[10000];
vector<int> ans;
int main() {
string s;
bool b = 0;
cin >> s;
int i, n = s.size();
for (i = 0; i < n - 1; i++) {
if ((!b) && s[i + 1] == 'a') a[i] = 1, b = 1;
if (b && s[i + 1] == 'b') a[i] = 1, b = 0;
}
if (b) a[i] = 1;
for (i = 0; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> arr;
string s;
cin >> s;
for (int i = 0; i != s.size(); i++) {
if (s[i] != '+') arr.push_back(s[i] - '0');
}
sort(arr.begin(), arr.end());
for (int i = 0; i != arr.size(); ++i) {
if (i) cout << "+";
cout << arr[i];
}
co... | 0 |
#include <bits/stdc++.h>
using namespace std;
string e[30];
int u[30][30];
vector<string> v;
vector<int> v2;
int f(int a, int b) {
if (u[v2[a]][v2[b]]) return u[v2[a]][v2[b]];
int minimum = min(v[a].length(), v[b].length());
for (int i = 0; i < minimum; i++)
if (v[a][i] != v[b][i]) return u[v2[a]][v2[b]] = i;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
for (int x1 = -(1 << 30), h1 = 0, x, h; cin >> x >> h; ++c, x1 = x, h1 = h) {
if (x1 + h1 >= x) --c, h1 = 0;
if (x - h > x1 + h1) h = 0;
}
cout << c << "\n";
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3e3 + 5;
int a[maxn], b[maxn];
long long dp[maxn][maxn];
void solve() {
int n;
cin >> n;
for (int i = 1; i < n + 1; i++) {
cin >> a[i];
a[i] -= i;
b[i] = a[i];
}
sort(b + 1, b + n + 1);
memset(dp, 0x3f, sizeo... | 7 |
#include <bits/stdc++.h>
#define pb push_back
#define er erase
#define in insert
#define s(a, x, y) sort(a.begin()+x, a.begin()+y);
#define r(a, x, y) reverse(a.begin()+x, a.begin()+y);
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ld long double
#define forn(i, a, b) for(int i=a; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) {
return (rng() % (y + 1 - x)) + x;
}
string inline to_string(char c) {
string second(1, c);
return second;
}
template <typename T>
inline T gcd(T a, T... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[400020];
int ans[400020];
int subsize[400020];
int thr;
int calc_size(int v, int par) {
subsize[v] = 1;
for (auto ch : g[v])
if (ch != par) subsize[v] += calc_size(ch, v);
return subsize[v];
}
int find_centroid(int v, int par) {
for (auto ch : g[v]... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long double PI = acosl(-1);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct point {
long double x, y;
point() {}
point(long double x, long double y) : x(x), y(y) {}
long double kampas() { return atan2l(... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.