solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n;
int m;
pair<int, int> seg[N];
int main() {
int mn = 1e9;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &seg[i].first, &seg[i].second);
mn = min(mn, seg[i].second - seg[i].first);
}
printf("%d\n", mn + 1);... | 9 |
#include <bits/stdc++.h>
long long int snc = 0, syc = 0;
int main() {
int n, a;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
if (a == 1)
syc++;
else
snc += syc;
}
printf("%lli\n", snc);
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 123;
int m[N], phi[N], cnt[N];
vector<long long> ps;
bool mark[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
long long ans1 = 0, ans2 = 0, ans3 = 0;
cin >> n;
for (int i = 2; i <= n / 2; i++)
if (!mark[i]) {
cnt[... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, k, ans[2 * 100000 + 5];
char s[2 * 100000 + 5];
int main() {
scanf("%d%d%d%d%s", &n, &a, &b, &k, s + 1);
int cnt = 0, bt = 0;
for (int i = 1; i <= n; ++i) {
if (s[i] == '0')
++cnt;
else
cnt = 0;
if (cnt == b) ans[++bt] = i, cnt = 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int a[400000] = {0};
int main() {
string s;
cin >> s;
long long int i;
long long int m;
scanf("%lld", &m);
while (m--) {
long long int b;
scanf("%lld", &b);
b--;
a[b] = 1 - a[b];
}
string ans;
long long int j = s.size() - 1;
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int n, m, p, a[maxn], b[maxn];
struct T {
void ins(int x) {
int &t = f[x];
s -= abs(t);
++t;
s += abs(t);
}
void del(int x) {
int &t = f[x];
s -= abs(t);
--t;
s += abs(t);
}
bool check() { return s == 0;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int a[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cin >> a[i][j];
}
int b[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9;
int n, m, x, y, a[N], b[N];
vector<int> ans[2];
int main() {
cin >> n >> m >> x >> y;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
sort(a, a + n);... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c;
do c = getchar(), f = c == '-' ? -1 : f;
while (!isdigit(c));
do x = (x << 3) + (x << 1) + c - '0', c = getchar();
while (isdigit(c));
return x * f;
}
int n, m, q, k, ans, t;
int a[10000020], b[10000020], v[1000002... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b) {
a += b;
if (a >= 998244353) return a - 998244353;
return a;
}
long long mul(long long a, long long b) {
a *= b;
if (a >= 998244353) return a % 998244353;
return a;
}
long long power(long long x, long long y) {
if (y ==... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 20;
const int maxn = 2e5 + 20;
const int mod = 998244353;
int cnt, head[maxn], pos[maxn];
double Max(double a, double b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
in... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
long long a[100007];
cin >> n >> x;
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
long long time = 0;
long long i;
for (i = 0; i < n; i++) {
time += a[i] * x;
if (x > 1) x--;
}
cout << time;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int p[N], c[N];
vector<int> v[N];
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p[i] >> c[i];
v[p[i]].push_back(c[i]);
}
for (int i = 1; i <= m; i++) {
sort(v[i].begin(), v[i].end());
reverse(v[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int Lpow(long long int a, long long int b) {
long long int ans = 1;
while (b > 0) {
if (b % 2) ans = (ans * a);
a = (a * a);
b = b / 2;
}
return ans;
}
long long int gcd(long long int a, long long int b) {
if (a % b == 0)
return b;
else... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool eq(string s1, string s2) {
if (s1 == s2)
return true;
else if (s1.length() % 2 == 0 && s2.length() % 2 == 0) {
int h = s1.length() / 2;
if ((eq(s1.substr(0, h), s2.substr(h, h)) &&
eq(s1.substr(h, h), s2.substr(0, h))) ||
(eq(s1.substr(... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long i1, i2, t1, t2, t3, l1;
long long n, ans;
bool b[200];
vector<long long> a;
int main() {
cin >> n;
for (i1 = 0; i1 < n; i1++) {
cin >> t1;
a.push_back(t1);
}
sort(a.begin(), a.end());
for (i1 = 0; i1 < n; i1++) {
if (b[i1]) continue;
b[i1... | 0 |
#include<set>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define md (l+r>>1)
#define ls (now<<1)
#define ll long long
#define rs (now<<1|1)
#define cht 1000000007
#define F(i,j,n)for(int i=j;i<=n;i++)
#define D(i,j,n)for(int i=j;i>=n;i--)
using namespace std;
ll read(){ll ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string shift;
cin >> shift;
string message;
cin >> message;
string result;
string keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./";
for (char& c : message) {
int index = keyboard.find(c);
result += shift.compare("L") == 0 ? keyboard.at(index + ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, Q = 1e4 + 5, NM = 21;
int n, m, q;
long long t, vec[NM], adj[NM][NM], vectmp[NM], tmp[2][NM][NM];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool cat[NM];
long long T = 1;
struct event {
int tp, x, y;
long long t;
} e[Q];
inline bool in... | 16 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x;
scanf("%d", &x);
return x;
}
int readln() {
int x;
scanf("%d\n", &x);
return x;
}
const int MAX_N = int(1e6) + 6;
bool ok[MAX_N];
int main() {
memset(ok, (true), sizeof(ok));
ok[1] = false;
for (long long i = 2; i < MAX_N; ++i)
if (... | 0 |
#include <bits/stdc++.h>
int main(void) {
int a, b, i, c, y, z, j;
char str[3000][11], arr[3000][11], full[3000][11];
scanf("%d%d", &a, &b);
for (i = 0; i < b; i++) scanf("%s%s", &str[i], &arr[i]);
for (i = 0; i < a; i++) scanf("%s", &full[i]);
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, b;
int cnt = 0, count = 0, i;
cin >> s >> b;
for (i = 0; i < b.size(); i++) {
if (s[i] != b[i]) cnt = (cnt + 1) & 1;
}
if (!(cnt & 1)) count++;
for (i = 0; i < s.... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string B;
cin >> B;
int cnt = 0;
for (int i = 0; i < N; ++i) {
if (B[i] == '>') break;
++cnt;
}
for (int i = N - 1; i >= 0; --i) {
if (B[i] == '<') break;
++cnt;
}
cout << cnt << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int T, n, k, x, ans;
int cnt, p[110000];
char s[110000];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k);
scanf("%s", s + 1);
cnt = 0;
ans = 0;
x = 0;
for (int i = 1; i <= n; i++)
if (s[i] == 'W') {
if (x) p[++cnt]... | 6 |
#include <bits/stdc++.h>
using namespace std;
int read();
int M(int x) { return x >= 1000000007 ? x - 1000000007 : x; }
const int lim = 1 << 16;
int n;
char s[502];
map<char, int> trans;
int f[502][70004], g[9][70004];
void init() {
trans['A'] = 1, trans['B'] = 2, trans['C'] = 3, trans['D'] = 4;
trans['a'] = 5, tra... | 22 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
int n, m, i, t = 0, mx, mn1, mn2, mn3;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
t += a[i];
}
sort(a, a + n);
mx = a[n - 1] + m;
mn2 = a[n - 1];
mn1 = ceil(((double)t + m) / n);
if (mn1 < mn2)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200005;
vector<int> graf[MAX_N];
int litery[26];
bool odw[MAX_N];
string s;
void dfs(int v) {
odw[v] = true;
char litera = s[v];
int ASC = litera - 'a';
litery[ASC]++;
for (int i = 0; i < graf[v].size(); i++) {
int u = graf[v][i];
if (!od... | 7 |
#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 2000005;
using namespace std;
long long a[MAXN];
long long sum[MAXN], cnt[MAXN];
long long f[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, i, j, x, y, N = 2e6 ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
string s = "";
for (int i = 1; i <= k; i++) {
stringstream ss;
ss << i;
s = s + ss.str();
}
cout << s[k - 1] << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = (int)1e5 + 228;
using namespace std;
int n, x[N], y[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
if (n & 1) {
cout... | 10 |
#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
int i;
for (i = 0; i < rep; i++) p[i] = val;
}
signed long long GETi() {
signed long long i;
scanf("%lld", &i);
return i;
}
int N, K;
double Y[301][301];
double S[301][301];
void solve() {
int f, i, j, k, l, x, y;
cin... | 17 |
#include <bits/stdc++.h>
int main(int argc, char **argv) {
int a, b, t_a, t_b, m, m2, sum = 0, h;
std::string s;
std::cin >> a >> t_a;
std::cin >> b >> t_b;
std::cin >> s;
h = std::stoi(s.substr(0, 2));
m = std::stoi(s.substr(3, 2));
h -= 5;
m += h * 60;
m2 = m + t_a;
for (int i = 0;; ++i) {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k = 1, n, m, a, i, j = 1;
bool t = true;
char c, h;
cin >> c;
while (cin >> h) {
if (h == c)
if (k != 5)
k++;
else {
k = 1;
j++;
}
else {
k = 1;
j++;
c = h;
}
}
cout << j;... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int sq(long long int x) { return x * x; }
void minimize(long long int &a, long long int b) { a = min(a, b); }
long long int sol = 1000000000000000000LL;
long long int s1, s2;
void check(long long int &a1, long long int a) {
for (; sq(a1) <= a and a1 <= s1; a1++)... | 12 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, sl;
cin >> n;
vector<float> v;
map<float, long long> mp;
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
sl = s.length();
vector<char> n1, n2, n3;
long l... | 6 |
#include <bits/stdc++.h>
int ls, lt;
char s[500005], t[500005];
int fail[500005];
int main() {
scanf("%s", s);
scanf(" %s", t);
ls = strlen(s);
lt = strlen(t);
int x1, y1, x2, y2;
x1 = y1 = x2 = y2 = 0;
for (int i = 0; i < ls; i++) {
if (s[i] == '1')
x1++;
else
y1++;
}
for (int i =... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, uz[100005], nr;
vector<pair<int, int> > ans;
vector<int> H;
int main() {
cin >> n;
for (int i = 3; i <= n; i++) {
H.clear();
if (uz[i] || i % 2 == 0) continue;
for (int j = i; j <= n; j += i) {
if (uz[j]) continue;
uz[j] = 1;
H.push_... | 17 |
#include <bits/stdc++.h>
using namespace std;
int L[100010];
long long power(long long a, long long b, long long mod) {
if (b == 0) return 1;
long long x = power(a, b / 2, mod);
if (b % 2 == 0)
return (x * x) % mod;
else
return (((a * x) % mod) * x) % mod;
}
bool doit(int v, vector<vector<int> >& edges,... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct Gas {
int x, p;
bool operator<(const Gas& g) const { return x < g.x; }
};
int d, n, m;
vector<Gas> gs;
vector<int> nxt;
bool read() {
if (scanf("%d%d%d", &d, &n, &m) < 3) {
return false;
}
gs.resize(m);
for (int i = 0; i < (int)m; ++i) {
scanf("%d... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long n, x, m;
cin >> n >> x >> m;
int mn = x, mx = x, l, r;
while (m--) {
cin >> l >> r;
if (mn <= r && mx >= l) {
if (l < mn) mn = l;
if (r > mx) mx = r;
}
}
cout <<... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int M = 105;
int a[M];
int main() {
int n, v, i, j, k;
while (~scanf("%d%d", &n, &v)) {
int mx = 0;
k = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
k += a[i];
mx = max(mx, a[i]);
}
if (k - mx > v)
puts("NO");
el... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct E {
int id, x, type;
bool operator<(E a) const {
if (x != a.x) return x < a.x;
return type < a.type;
}
} e[900005];
int ans[300005];
int Num[300005];
int c[1000005];
void add(int x, int a) {
while (x <= 1000000) {
c[x] += a;
x += x & (-x);
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
const int inf = 0x3f3f3f3f;
int n, m, T;
int f[N][N];
short nxt[N][N];
vector<pair<int, int> > a[N];
bool vis[N];
void dfs(int x) {
if (vis[x]) return;
vis[x] = 1;
for (auto it : a[x]) {
dfs(it.first);
for (int i = 2; i <= n; ++i) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans, a[111];
bool f = true;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 0, d; i < n; ++i) {
cin >> d;
++a[d];
}
while (f) {
f = false;
for (int i = k - 1; i > 0; --i) {
if (a[i]) {
f = true;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int tab[52][52];
int kolumna[52];
int wiersz[52];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t) {
t--;
int height, width, liczbakol, liczbarze, liczbazapkol = 0;
cin >> height >> width >> liczbarze >> ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int cnt[32];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
int oddcnt = 0;
int nonzerocnt = 0;
int ni = -1;
for (int i = 0; i < n; ++i) {
cin >> cnt[i];... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct fenwickTree {
long long n, logn;
vector<long long> tree;
fenwickTree(long long _n)
: n(_n + 5), logn((long long)(ceil(log2(_n)))), tree(_n + 5, 0) {}
void add(long long p, long long x) {
while (p < n) {
tree[p] += x;
p += p & (-p);
}... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010, mod = 1000000007;
int f[N];
int n, k;
int sum[N];
int dp(int x) {
int &v = f[x];
if (v != -1) return v;
if (x < k) return v = 1;
return v = (dp(x - 1) + dp(x - k)) % mod;
}
int main() {
while (scanf("%d%d", &n, &k) != EOF) {
int l, r;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long y, b;
long long total_y, total_b;
long long y1, g1, b1;
long long ans;
cin >> y >> b;
cin >> y1 >> g1 >> b1;
total_y = y - (y1 * 2 + g1);
total_b = b - (b1 * 3 + g1);
if (total_y < 0 && total_b < 0)
cout << abs(total_y) + abs(tot... | 0 |
#include <bits/stdc++.h>
using namespace std;
void Solve() {
int X, Y;
cin >> X >> Y;
if (X > Y)
cout << X - 1 << ' ' << Y;
else
cout << Y - 1 << ' ' << X;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
Solve();
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 1e9;
int n, m, ans = inf;
vector<int> v, v1;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
int z;
cin >> z;
v.push_back(z);
}
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int catat[100005];
int RA[200010], SA[200010], LCP[200010], *FC, *SC, step;
char S[200010], Q[200010];
bool cmp(int a, int b) {
if (step == -1 || FC[a] != FC[b]) return FC[a] < FC[b];
return FC[a + (1 << step)] < FC[b + (1 << step)];
}
void suffix_array(char *s, int n) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const long long int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
bool as[100010];
int main() {
int n;
long long sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
for (int i = n - 1; i >= 0; i--) {
if (sum > 0) {
sum -= a[i];
as[i] = 1;
} else {
sum += a[... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, T;
int d[5005][5005];
int pre[5005][5005];
bool visited[5005];
vector<vector<pair<int, int> > > v(5005);
void dp(int x) {
if (visited[x]) return;
visited[x] = 1;
if (x == 1) {
d[x][1] = 0;
return;
}
for (auto it = v[x].begin(); it != v[x].end(); ... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> z[3];
long long ch[3];
int n;
void solve(long long, int);
void gen(long long x, int y, int cnt) {
if (x == 0) {
solve(y, cnt + 1);
return;
}
if (x >= 10) {
z[cnt].push_back(2);
gen(x / 100, y + x % 100, cnt);
z[cnt].pop_back()... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool upper(char a) { return a >= 'A' && a <= 'Z'; }
bool lower(char a) { return a >= 'a' && a <= 'a'; }
void ProblemB() {
int n;
char s[210];
set<char> m;
int c = 0;
int best = 0;
cin >> n >> s;
for (int i = 0; i < n; ++i) {
if (upper(s[i])) {
if (c ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int seed = 131;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
long long n, m;
long long MIN;
struct node {
long long id, cost;
node() {}
node(long long id, long long cost) : id(id), cost(cost) {}
};
bool cmp(node a, node b) { return a.cost < b.cost; }
vecto... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, solA, solB = 10000000000;
vector<long long int> TA, TB;
void play(long long int mid) {
long long int sc1 = upper_bound(TA.begin(), TA.end(), mid) - TA.begin();
long long int sc2 = upper_bound(TB.begin(), TB.end(), mid) - TB.begin();
sc1 = sc1 * 2 +... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1000 * 100 + 10, T = 5;
int n;
string s, t1 = "2016", t2 = "2017";
struct Node {
int dp[T][T];
Node() {
for (int i = 0; i < T; i++)
for (int j = 0; j < T; j++) dp[i][j] = (i ^ j ? N + 10 : 0);
}
void init(char c) {
for (int i = 0; i <... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int nstart = 10;
const int maxn = 100100;
int n;
int a[maxn];
int v[maxn];
vector<int> pos[maxn];
int B[maxn];
void update(int i, int d) {
i += nstart;
while (i < maxn) B[i] += d, i += i & -i;
}
int query(int i) {
int r = 0;
i += nstart;
while (i > 0) r += B... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
int arr[n][2];
for (int i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
int sorted[n][2];
for (int i = 0, k = 0; i < n; i++) {
int mn = 1000000, smn = 1000000, in;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[200010];
void dfs(int curr, int currmax, int a, int b, int n) {
if (dp[curr] > 0) {
return;
}
if (curr > currmax) {
currmax = curr;
}
dp[curr] = currmax;
if (curr > b) {
dfs(curr - b, currmax, a, b, n);
}
if (curr < 2 * n - a) {
dfs(cu... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 2000000000;
const long long BIG = 1446803456761533460LL;
const long long int maxn = 80;
const long long int maxk = 110;
long long int n, k;
long long int dp[maxn][maxn];
map<string, long long int> M;
long long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
long long ma = LLONG_MIN, mi = LLONG_MAX;
for (long long i = 1; i <= cbrt(n); i++) {
if (n % i == 0) {
long long m = n / i;
for (long long j = i; j <= sqrt(m); j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, k;
cin >> n >> k;
vector<long long int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
;
sort(v.begin(), v.end());
vector<long long int> p(10, 0);
p[0] = 1;
for (int i = 1; i <= 9; i++) {
p[i] = p[i - 1] * 10;
}
long... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, first, second;
scanf("%I64d%I64d%I64d", &n, &first, &second);
long long l, r;
l = first - n + 1;
r = second - n + 1;
if (l < 0) l = 0;
if (r <= 0)
printf("-1\n");
else {
l = (long long)ceil(sqrt((double)first - n + 1));
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> factorize(int n) {
vector<int> res;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res.push_back(i);
n /= i;
}
}
if (n != 1) {
res.push_back(n);
}
return res;
}
long long int multiple(long long int a, long long int b,... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<int> G[maxn];
bool mark[maxn];
int H[maxn];
int main() {
int n;
while (scanf("%d", &n) == 1) {
queue<int> Q[2];
int num = 0;
memset(mark, false, sizeof(mark));
for (int i = 1; i <= n; i++) {
scanf("%d", &H[i]);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
string n;
cin >> n;
long long ans = -1;
long long len = n.length();
for (long long i = 1; i < 1000000; i++) {
if (i * i > 2 * 1000000000) break;
long long pos = len - 1;
long... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int main() {
int t;
cin >> t;
while (t--) {
int x, y, a, b;
cin >> x >> y >> a >> b;
int z = (y - x) % (a + b);
if (z == 0)
cout << (y - x) / (a + b) << endl;
else
cout << "-1\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long res = 1;
cin >> n;
for (int p = 2; (long long)p * p <= n; p++) {
if (n % p == 0) {
int ex = 0;
while (n % p == 0) {
n /= p;
ex++;
}
res = res * (ex + 1);
}
}
if (n > 1) res = res... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, t = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') t = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return s * t;
}
const int N = (1 <<... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, cnt = 0;
scanf("%d %d", &n, &m);
int a[n];
int b[m];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d", &b[i]);
}
for (int i = 0, j = 0; i < n; i++) {
while (b[j] < a[i] && j < m... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000004];
bool ase[5 * 1000004][2];
int ans[5 * 1000004][2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ase[a[i]][0] = 1;
ans[a[i]][0] = a[i];
}
int cur = 1, last = 0;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int N = 1e6 + 4;
inline int FIX(int a) { return (a % Mod + Mod) % Mod; }
int lcp[5000 + 5][5000 + 5], dp[5000 + 5][5000 + 5];
void cal(const string &x) {
int L = ((int)x.length());
for (int i = L - 1; i >= 0; i--) {
for (int j = i + 1;... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a;
if (n > m) {
a = m;
} else {
a = n;
}
if (a % 2 == 0) {
cout << "Malvika";
} else {
cout << "Akshat";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> V[303030];
vector<int> K;
int P[303030], D[303030];
bool chk[303030];
int n, m, k, l;
void PATH(int p) {
printf("PATH\n");
vector<int> X;
for (; p; p = P[p]) X.push_back(p);
printf("%d\n", (int)X.size());
for (int &t : X) printf("%d ", t);
printf("\n... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[5002];
int b[5003], arr[5003], ans1[5006];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << flush << "? " << 0 << " " << i << '\n';
int w;
cin >> w;
if (w == -1) {
return 0;
}
a[0].push_back(w);
}
for ... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger &operator,(const T &v) {
cerr << v << " ";
return *this;
}
} dbg;
inline long long gcd(long long a, long long b) {
a = ((a) < 0 ? -(a) : (a));
b = ((b) < 0 ? -(b) : (b));
while (b) {
a = a % b;
swa... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x, y, k, ans, s;
int t;
cin >> t;
while (t--) {
ans = 0;
cin >> x >> y >> k;
ans += k;
s = k * y + k - 1;
ans += ceil((long double)s / (x - 1));
cout << ans << "\n";
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, K, f[100100], a[100100], nxt[100100], lst[100100], dp[35100][60],
seg[351000], lazy[351000], sum;
void Lazy(int p) {
seg[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
void build(int i, int p = 1, int st = 0, int en = n ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100007];
vector<int> v[100007];
int ans = 0;
void dfs(int vertex, int lst, int br) {
if (a[vertex] == 1) {
br++;
} else {
br = 0;
}
int i;
int sz = v[vertex].size();
if (sz == 1 && lst != -1) {
if (br <= k) {
ans++;
}
re... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
int n, m, t[MAXN + 1];
stack<int> a, b;
bool ok = true;
void mov() {
int x = a.top();
a.pop();
t[x] = -t[x];
b.push(x);
}
void go() {
while (!b.empty()) {
if (a.empty()) {
ok = false;
break;
}
if (t[a.top()] == -t[b.to... | 13 |
#include <bits/stdc++.h>
char s[3000 + 5];
int u[3000 + 5];
bool check(char c) {
return c >= 'a' && c <= 'z' && c != 'a' && c != 'e' && c != 'i' && c != 'o' &&
c != 'u';
}
int main() {
scanf("%s", s + 1);
for (int i = 1; s[i]; ++i)
if (check(s[i]) && check(s[i + 1]) && check(s[i + 2]) &&
(s[i... | 7 |
#include<bits/stdc++.h>
using namespace std;
const int maxn=7;
const int maxm=20005;
const int INF=0x3f3f3f3f;
int n,m,ini,ans;
int a[maxn],b[maxn],c[maxn],pw[maxn],dp[maxm],ndp[maxn][maxm][maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int i=0;i<m;i++)scanf("%d",&b[i]);
pw[m]=... | 24 |
#include <bits/stdc++.h>
using namespace std;
string str, str2;
long long n, m, t, k, j;
void printVec(string desc, vector<map<char, long long>> vec) {
cout << desc << ":" << endl;
for (long long x = 0; x < vec.size(); x++) {
for (auto y = vec[x].begin(); y != vec[x].end(); y++) {
cout << "Letra: " << y->... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const int N = 2e5 + 7;
vector<int> b;
int a[N];
int n, m, h;
int seg[N * 4];
int laz[N * 4];
void spl(int v) {
for (int u = (v * 2); u <= (v * 2 + 1); u++) {
seg[u] += laz[v];
laz[u] += laz[v];
}
laz[v] = 0;
}
void add(int l, int r, int ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int LIM = 200, INF = 1e+9;
const double PI = 3.1415926535, EPS = 1e-7;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T>
T gcd(T a, T b) {
return a == 0 ? b : gcd(b % a, a);
}
int n, m;
int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3... | 12 |
#include <bits/stdc++.h>
const int pi = acos(-1);
using namespace std;
int n, a, b, k, f;
map<pair<string, string>, bool> vis;
map<pair<string, string>, int> m;
string to, from, prv;
vector<pair<string, string> > u;
int main() {
cin >> n >> a >> b >> k >> f;
for (int i = 0; i < n; i++) {
int cost = 0;
cin >... | 10 |
#include <bits/stdc++.h>
using namespace std;
set<int> S;
map<int, int> M;
vector<int> V;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, x;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> x;
if (M[x] == 0) M[x] = i;
S.insert(x);
}
if (S.size() < k)
cout << "NO\n";
else ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const double EPS = 1e-9;
template <class T>
void _db(const char* dbStr, T e) {
cout << dbStr << " = " << e << endl;
}
template <class T, class... L>
void _db(const char* dbStr, T e, L... r) {
while (*dbStr != ',') cout << *dbStr++;
cout << " = " <<... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 105;
int n;
int m;
int g[MAX_N][MAX_N];
long long d[MAX_N][MAX_N];
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) g[i][j] = (i != j) * 987654321;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
... | 11 |
#include <bits/stdc++.h>
int main() {
int i, j1, j2, n, k, q;
static int cc[500];
static char dp[500][500 + 1][500 + 1];
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++) scanf("%d", &cc[i]);
dp[0][0][0] = dp[0][cc[0]][cc[0]] = dp[0][0][cc[0]] = 1;
for (i = 1; i < n; i++)
for (j1 = 0; j1 <= k; j1++)
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int c[maxn];
string a[maxn];
int main() {
int n, k;
cin >> n >> k;
cin.ignore();
for (__typeof((n)-1) i = (0); i <= (n)-1; ++i) {
cin >> a[i];
c[a[i].size()]++;
}
string s;
cin >> s;
int a1 = 0, a2 = 0;
int m = s.size();
int... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> used;
vector<int> d;
vector<vector<int>> g;
int cnt[1000000];
int t = 0;
void dfs(int v, int p) {
d[v] = d[p] + 1;
for (auto &u : g[v]) {
dfs(u, v);
}
}
signed main() {
int n;
cin >> n;
g.resize(n + 1);
d.resize(n + 1);
used.resize(n, false)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int pos(int x) { return 1 + ((x - 1) % n); }
int main() {
cin >> n;
if ((n / 2) & 1) {
cout << "! -1" << endl;
return 0;
}
pair<int, int> p1, p2, p3;
p1.first = 1;
p2.first = n / 2;
int s11, s12, s21, s22;
cout << "? " << p1.first << endl;
c... | 12 |
#include <bits/stdc++.h>
using namespace std;
int arr[200000];
vector<vector<int> > v;
int vis[200000];
int ans = 0;
int m;
void dfs(int n, int c) {
if (arr[n])
c += 1;
else
c = 0;
if (c > m) return;
vis[n] = 1;
int f = 0;
for (int i = 0; i < v[n].size(); i++) {
if (!vis[v[n][i]]) {
f = 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, i, a, ma;
long long s;
vector<long long> v;
map<long long, int> m;
int main() {
scanf("%d", &n);
s = 0;
v.push_back(s);
ma = 1;
for (i = 0; i < n; i++) {
scanf("%d", &a);
s += a;
if (m[s] == 0) {
m[s] = v.size();
v.push_back(1);
... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.