solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to;
};
const long long LINF = 123123123123123123;
const int INF = 1231231234;
const int MOD = 998244353;
const long double EPS = 1e-9;
const int MAXN = 100000;
const int MAXV = 200;
int dp[MAXN + 5][MAXV + 5][3];
int prefixUp[MAXV + 5][3], prefixDown[MAX... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt = 0;
if (s.size() % 2 == 0) {
cout << (s.size() / 2) << endl;
} else {
if (s.size() == 1)
cout << 0 << endl;
else {
for (int i = 1; i < s.size(); i++) {
if (s[i] == '1') cnt++;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1000005], s[1000005];
inline int qs(int x, int y) {
if (x > y) return 0;
return s[y] - s[x - 1];
}
inline bool calc1() {
for (int i = 1; i <= n - k + 1; i++) {
int r = qs(1, i - 1) + qs(i + k, n);
if (!r || r + k == n) return 1;
}
return 0;... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int pref, suf, pref_neg, suf_pos, ans, cant;
Node() {}
void init(long long v) {
if (v < 0) {
pref = 0;
suf = 0;
pref_neg = 1;
suf_pos = 0;
ans = 1;
cant = 1;
} else if (v > 0) {
pref = 0;
suf = 0;
... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int w = 0, f = 1;
char c = ' ';
while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
return w * f;
}
struct node {
int a, b;
} t[105];
bool cmp(node x, node y) {
if (x.b ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
void fact_init(int n, int md);
long long exp(long long taban, long long us, long long md);
long long ebob(long long a, long long b);
long long ekok(long long a, long long b);
long long komb(int a, int b, int md);
long lon... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int pre[300100], use[300100], ok[300100], ok1[300100], m, a, b;
vector<int> v[300100], ans, c;
int kAns = 1e9, snode = -1, gg = -1;
void dfs(int k) {
use[k] = 1;
c.push_back(k);
for (auto i : v[k])
if (!use[i]) dfs(i);
}
bool is_complete() {
for (auto ... | 18 |
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr static int mod = 1e9 + 7;
constexpr static int inf = (1 << 30) - 1;
constexpr static Int infll = (1LL << 61) - 1;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
string ask(Int p, Int q) {
cout <<... | 12 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:264777216")
long long getPhi(int a) {
char s[30];
sprintf(s, "%d", a);
long long res = 0;
for (int i = 0; s[i]; ++i) {
res = res * 10 + 9 - (s[i] - '0');
}
return res;
}
long long che(int L, int R) {
long long r = 0;
for (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
const int N = 40;
long long n, m, a[N];
int main() {
ios::sync_with_stdio(false);
cin.ti... | 10 |
#include <bits/stdc++.h>
using namespace std;
double const eps = 1e-10;
int sgn(double x) { return x < -eps ? -1 : x < eps ? 0 : 1; }
double a, b, c;
void solve(double x1, double y1, double x2, double y2) {
int sign = 1;
a = y2 - y1;
if (a < 0) {
sign = -1;
a = -a;
}
b = sign * (x1 - x2);
c = sign *... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
pair<int, int> s[N];
vector<int> v[N];
int a[N], vis[N];
int edge = 0, p = 0;
void dfs(int x) {
vis[x] = 1;
p++;
edge += a[x];
for (int i = 0; i < v[x].size(); i++) {
int next = v[x][i];
if (vis[next] == 0) {
dfs(next);
}
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
string a;
string word[1100000];
string digit[1100000];
vector<string> v[1000000];
int num[1100000];
int len;
int cnt;
int st = 0;
int maxdepth;
void dfs(int depth) {
if (depth > maxdepth) maxdepth = depth;
st++;
v[depth].push_back(word[st]);
int t = num[st];
for (... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> pos1[maxn], cnt1[maxn];
int a[maxn], b[maxn], que[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t, n, x, y, mis, cn1, cn2;
cin >> t;
while (t--) {
cin >> n >> x >> y;
for (int i = 1; i <= n + 1; i++)... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e9 + 7;
void solve() {
long long int n, x, y;
cin >> n >> x >> y;
vector<long long int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
long long int flagl = 0;
long long int flagr = 0;
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a;
int f(int st) {
int r = 0;
for (int i = 0; i < n; ++i)
if (a[i] != st + i * k) ++r;
return r;
}
int main() {
cin >> n >> k;
a.resize(n);
int r = -1;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (r < a[i]) r = a[i];
}
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, b, c, d;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
cin >> a >> b >> c >> d;
if (n <= 4) {
cout << -1;
return 0;
}
if (k < n + 1) {
cout << -1;
return 0;
}
cout << a << " " << c << " ";
for (int i = 1; i <= n... | 8 |
#include <bits/stdc++.h>
using namespace std;
int adj[509][509];
int f[509][509], h[509][509];
int n, m, ans;
int main() {
cin >> n >> m;
ans = -(1 << 25);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> adj[i][j];
h[i][j] = adj[i][j];
}
for (int i = 1; i <= n; i++)
for ... | 11 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
struct custom_hash;
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0, -1};
const int dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1, -1};
struct custom_hash {
size_t operator()(uint64_t x) cons... | 5 |
#include <bits/stdc++.h>
using namespace std;
int f[200050], g[200050];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (; t != 0; t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> f[i];
for (int i = 1; i <= n; i++) {
if (g[i] == t) {
cou... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[100000 + 7];
int n, k;
while (3 == scanf("%d %d %s", &n, &k, s)) {
int d, r;
string ans;
for (int i = 0; i < n; i++) {
if (k == 0) {
ans += s[i];
continue;
}
if (s[i] <= 109) {
r = 122 - s[i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int a, b;
while (t--) {
cin >> a >> b;
int flag = abs(a - b);
int ans = flag / 5;
flag %= 5;
ans += flag / 2;
flag %= 2;
ans += flag;
cout << ans << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
return a * b / gcd(a, b);
}
const int N = 1e5 + 10;
int a[N], n, cntr;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long M;
template <int DEG>
void cp(long long a[DEG][DEG], long long b[DEG][DEG]) {
memcpy(b, a, sizeof(long long) * DEG * DEG);
}
template <int DEG>
void mul(long long a[DEG][DEG], long long b[DEG][DEG], long long c[DEG][DEG]) {
long long t[DEG][DEG] = {};
for (i... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
const int inf = 0x3f3f3f3f;
int rnk[maxn], ans[10100][maxn], n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &rnk[i]);
int cc = 0;
while (1) {
int cnt = 0, minn = inf, num = 0;
for (int i = 1; i <= n; i++) minn... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool cmp1(const pair<pair<long long, long long>, long long> &a,
const pair<pair<long long, long long>, long long> &b) {
return a.second > b.second || (a.second == b.second && a.first < b.first);
}
bool cmp2(const pair<pair<long long, long long>, long long> &a,
... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[100005];
bool vis[100005];
bool dfs(int u, int fa) {
vis[u] = 1;
int i, v, tot = 0;
for (i = 0; i < vec[u].size(); i++) {
if (vis[v = vec[u][i]])
if (v == fa)
continue;
else
return false;
tot++;
if (!dfs(v, u)) r... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
x = 0;
int op = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') op = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= op;
}
template <typename Tp... | 24 |
#include <bits/stdc++.h>
using namespace std;
int head[100001], nxt[100001 << 1], ver[100001 << 1], tot;
int n;
inline void addedge(int a, int b) {
nxt[++tot] = head[a];
ver[tot] = b;
head[a] = tot;
nxt[++tot] = head[b];
ver[tot] = a;
head[b] = tot;
}
double a[100001];
inline void init() {
scanf("%d", &n)... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long M = 21;
const long long maxn = 5e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f3f3f3f3f;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 3;
int n, p[N], c[N];
pair<int, int> pp[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
assert(scanf("%d%d", &x, &y) == 2);
x--, y--;
p[x] = y;
p[y] = x;
pp[i] = make_pair(x, y);
}
memset(c, -1, s... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
a -= b;
if (a < 0) a += md;
}
inline int mul(int a, int b) { return (int)((long long)a * b % md); }
inline int power(int a, long long b) {
i... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int k;
cin >> str >> k;
int n = str.length();
int i = 0;
while (k && i < n) {
char big = str[i];
int idx = i;
for (int j = i + 1; j < n && j - i <= k; j++)
if (str[j] > big) {
big = str[j];
idx = j;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v[1200];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k, p, in;
cin >> n >> k;
for (long long i = 1; i <= n; i++) {
in = i + 1;
for (long long j = 1; j <= k; j++) {
p = in % n;
if (p == 0) p = n;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
struct no {
long long k, b;
};
long long f(long long x, no y) { return x * y.k + y.b; }
vector<no> v[500010];
vector<int> id[500010], vc[500010];
long long k[500010], b[500010], tg[500010];
int dfn[500010], sz[500010], p[500010], va[500010], vb[500... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double r, x, y, X, Y;
scanf("%lf%lf%lf%lf%lf", &r, &x, &y, &X, &Y);
printf("%d\n", (int)ceil(hypot(x - X, y - Y) / 2 / r));
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void ff() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void in_out_txt() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
ff();
int n, m;
cin >> n >> m;
pair<long... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long T;
cin >> T;
while (T--) {
long long n;
cin >> n;
std::vector<long long> v(n);
long long sum = 0;
for (auto &i : v) {
cin >> i;
... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int NMAX = 100000;
const int VALMAX = 100000;
const int BUCKSZ = 320;
const int NUMBUCKS = NMAX / BUCKSZ;
int N, M;
int belong[NMAX + 5];
int A[NMAX + 5];
struct DSU {
int T[VALMAX + 5];
int W[VALMAX + 5];
void init() {
memset(T... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
bool odd = 0;
if (n & 1) {
n--;
odd = 1;
}
long long mn, mx;
if (n) {
mn = n / 2;
mx = 500000000;
long long cur = 500000000 - 1;
long long nn = n;
while (nn -= 2 > 0) {
mx += cur;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n, m, tot, ans;
int mx[maxn], mn[maxn], fir[maxn];
struct edge {
int a, b, l, r;
} p[maxn << 1];
queue<int> q;
vector<int> v[maxn];
inline void add(int a, int b, int c, int d) {
p[++tot].a = a, p[tot].b = b, p[tot].l = c + ((c ^ a) & 1),
... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX_N = 1e5 + 10, inf = 1e16, mod = 998244353;
long long int dp[600][600] = {};
int32_t main() {
long long int n, k;
cin >> n >> k;
dp[0][0] = 1;
for (long long int i = 0; i <= n; i++) {
for (long long int j = 1; j <= n; j++) {
if (j > ... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct E {
int v, i;
bool operator<(const E &t) const { return v > t.v; }
};
int n;
E a[100001];
E b[100001];
bool s[100001];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].v);
s[i] = 0;
a[i].i = i;
}
for (int i = 0; i ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k, l, s_k, s_all, r, arr[1005];
memset(arr, 0, sizeof(arr));
cin >> n >> k >> l >> r >> s_all >> s_k;
for (i = 0; i < n; i++) arr[i] = r;
int sum = k * r;
while (sum != s_k) {
for (i = 0; i < k; i++) {
if (sum > s_k) {
ar... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int ind = -1, z = 0, o = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
z++;
else if (s[i] == '1')
o++;
else {
ind = i;
break;
}
}
for (int i = 0; i < z; i++) cout << 0;
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 2;
vector<pair<int, int> > graph[10000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int i, j, n, m, v[10000];
cin >> n >> m;
for (i = 1; i <= n; ++i) cin >> v[i];
for (i = 0; i < m; ++i) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-5;
const long double EPS2 = 1e-12;
const long double PI = acos(-1);
int mod = (int)998244353;
const int MOD7 = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const int inf = 1e9;
mt19937 rnd(time(0));
const long long kekmod = 179179... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t, n, i, nr, st, sp, si, val;
char ch;
vector<int> ans;
int a[100005];
int b[100005];
void upd(int r) {
nr++;
swap(sp, si);
si += r;
}
int fval(int i) {
int ans;
if (nr % 2 == 0) {
ans = sp - si + i;
ans = a[ans];
} else {
ans = si - sp - i + 1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int sx, sy;
char graph[1508][1508];
int chgx[4] = {0, 0, 1, -1};
int chgy[4] = {1, -1, 0, 0};
struct node {
int x, y;
};
node vis[1508][1508];
bool vis2[1508][1508];
bool bfs(int x, int y) {
node u, v;
u.x = x;
u.y = y;
vis[x][y].x = x;
vis[x][y].y = y... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long fact(int a) {
long long res = 1;
for (int i = 2; i <= a; i++) res = (res * i) % 998244353;
return res;
}
int main() {
long long n;
cin >> n;
vector<vector<int> > rels;
vector<int> tmp;
rels.assign(n, tmp);
for (int i = 1; i < n; i++) {
long l... | 11 |
#include <bits/stdc++.h>
const int mod = 998244353;
inline void add(int &x, const int y) {(x += y) >= mod && (x -= mod);}
inline int Add(int x, const int y) {return add(x, y), x;}
inline void sub(int &x, const int y) {(x -= y) < 0 && (x += mod);}
inline int Sub(int x, const int y) {return sub(x, y), x;}
inline void mul... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n & 1)
cout << "black" << endl;
else
cout << "white 1 2" << endl;
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a[12] = {"C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "B", "H"};
int i = 0;
string x, y, z;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void EE(int a, int b, int& x, int& y) {
if (a % b == 0) {
x = 0;
y = 1;
return;
}
EE(b, a % b, x, y);
int temp = x;
x = y;
y = temp - y * (a / b);
}
int inverse(int a, int m) {
int x, y;
EE(a, m, x, y);
if (x < 0) x ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &n) {
T w = 1;
n = 0;
char ch = getchar();
while (!isdigit(ch) && ch != EOF) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch) && ch != EOF) {
n = (n << 1) + (n << 3) + (ch ^ 48);
ch = getchar(... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long int Maxn3 = 1e3 + 10;
const long long int Maxn4 = 1e4 + 10;
const long long int Maxn5 = 1e5 + 10;
const long long int Maxn6 = 1e6 + 10;
const long long int Maxn7 = 1e7 + 10;
const long long int Maxn8 = 1e8 + 10;
const long long int Maxn9 = 1e9 + 10;
const lo... | 8 |
#include <bits/stdc++.h>
inline int random(int x) {
if (RAND_MAX == 32767)
return (rand() << 15 ^ rand()) % x;
else
return rand() % x;
}
using namespace std;
const int N = 2002;
const char lc = 'a', hc = 'z';
int ggwp[N * 2], len[N * 2], to[N * 2][hc - lc + 1];
int cnt[N * 2];
void sufau(char *s, int n, int... | 9 |
#include <bits/stdc++.h>
const int ntf = 998244353;
long long frc[1000003], fic[1000003];
inline long long _inv(long long x) {
long long r = 1;
int v = ntf - 2;
while (v) {
(v & 1) && (r = r * x % ntf), x = x * x % ntf, v >>= 1;
}
return r;
}
int n;
long long ans;
long long f[1000003];
int main() {
scan... | 25 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <array>
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 998244... | 22 |
#include <bits/stdc++.h>
using namespace std;
char s1[1000005];
char s2[1000005];
int main() {
gets(s1);
gets(s2);
int len1 = strlen(s1);
int len2 = strlen(s2);
if (len1 != len2) {
cout << "NO" << endl;
} else {
int ans1 = 0;
int ans2 = 0;
for (int i = 0; i < len1; i++) {
if (s1[i] == ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
pair<long long, long long> a[100006];
vector<pair<long long, long long> > v;
long long premax[100006], premin[100006], suffmax[100006], suffmin[100006];
inline bool compare(pair<long long, long long> uu,
pair<long long, long long> vv) {
return u... | 21 |
#include <bits/stdc++.h>
using namespace std;
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
template <typename T = int>
inline T nxt() {
char c = nc();
T x = 0;
int f = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans, i, m;
cin >> n >> m;
for (i = (n + 1) / 2; i <= n; i++) {
if (i % m == 0) {
cout << i << endl;
return 0;
}
}
cout << "-1" << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
bool check(const string& s) {
if (s.empty()) return false;
bool flag = true;
for (int i = 0; i < s.size(); ++i)
if (!isdigit(s[i])) {
flag = false;
break;
}
if (flag && (s.size() == 1 || (s.size() > 1 && s[0] != '0'))) re... | 8 |
#include <bits/stdc++.h>
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
int main() {
int n;
cin >> n;
vector<vector<int> > e(n), d(n, vector<int>(2));
for (int i = 0; i < n; ++i) {
int u = in() - 1, v = in() - 1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 4e18;
const long long mod = 1e9 + 7;
const long long nax = 0;
long long n, h, arr[1005];
bool cek(long long idx) {
vector<long long> v;
for (int i = 0; i <= idx; ++i) {
v.push_back(arr[i]);
}
sort(v.rbegin(), v.rend());
long long total = ... | 5 |
#include <bits/stdc++.h>
const double pi = acos(-1.0);
int main() {
int n, r, v;
scanf("%d%d%d", &n, &r, &v);
double c = 2 * pi * r;
double t = c / v;
int s, f;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &s, &f);
double cnt = (f - s) / c;
int ccnt = (int)cnt;
double ti = t * ccnt;
doub... | 17 |
// Problem: F. Unusual Matrix
// Contest: Codeforces - Codeforces Round #697 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1475/F
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t=0; char ch=getchar(); int f=1;
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=2010;
const ll INF=1e18;
int ... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
vector<int> z(n);
int j = 0;
int i;
for (i = 0; i < ceil(n / 2.0); i++) {
z[j] = v[i];
j += 2;
}
j = 1;
for (; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, vis[404040], V, VV, kk;
pair<int, int> rr[404040];
vector<int> v[404040], vv[404040], xx;
map<pair<int, int>, int> xh;
void dfs(int x, int y) {
if (vis[x] == 2) {
return;
}
if (y != 0) {
vv[x].push_back(y);
}
if (vis[x] == 1) {
return;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 20, K = 17;
const int mod = 1e9 + 9;
vector<int> election[3011];
int it[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int e, val;
scanf("%d%d", &e, &val);
election[e - 1].push_back(val);
}
int mx = 0;
for... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-all-loops")
using namespace std;
template <typename Type>
void Get_Val(Type &Ret) {
Ret = 0;
char ch;
bool Neg(false);
while (ch = getchar(), (ch > '9' ||... | 23 |
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int N = 100228;
ll f[N];
ll g[N];
int n;
ll split(int n, int x) {
if (x == 0) {
assert(n == 0);
return 0;
}
int y = n / x;
int b = n % x;
return f[y] * (x - b) + f[y + 1] * b;
}
void c... | 16 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > Set;
int ans[610000], c[610000], n, k;
long long Ans;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
for (int i = 1; i <= min(n, k); i++) Set.insert(make_pair(-c[i], i));
for (int i = k + 1; i <= n + k; i++)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, x;
cin >> n >> m;
vector<int> v(n), v1;
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < m; i++) {
cin >> x;
for (int j = 0; j < n; j++) {
if (x == v[j]) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, q, t[156789], s[156789], a[10], cur = 0;
int main() {
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) cin >> t[i];
for (int i = 1; i <= n; i++) s[i] = 0;
while (q--) {
int x, y;
cin >> x >> y;
if (x == 1) {
if (cur < k) {
cur++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
int a[30];
scanf("%d %d", &n, &k);
if (k == 1) {
printf("%d\n", n);
return 0;
}
int cnt = 0;
for (int i = 2; i <= n; i++) {
if (n % i == 0) {
cnt++;
a[cnt] = i;
n /= i;
i--;
if (cnt == k - 1) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int cnt2 = 0;
int mini = 1000;
for (int i = 0; i <= 100; i++) {
int save = 0;
int cnt = 0;
for (int j = 0; j < n; j++) {
int d = abs(arr[j] - i);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long tam1, tam0;
int a[201000];
int b[201000];
int c[201000];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == 0) {
b[i] = b[i - 1] + 1;
c[i] = c[i - 1];
} else {
b[i] = b[i - 1];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.fi... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
string s;
cin >> n >> k >> s;
if ((int)(s).size() == 1 && k >= 1)
cout << 0 << '\n';
else {
int i = 0;
while (k > 0 && i < n) {
if (i == 0 && s[i] != '1') {
s[i] = '1';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[52 * 52];
char s[52][52];
int a[52][52], num[52][52], C[52 * 52], d[52 * 52];
bool vis[52 * 52];
int N, M, n;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
bool in(int x, int y) { return x >= 0 && x < N && y >= 0 && y < M; }
void dfs(int x, int y, int id, in... | 18 |
#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int dp[1000010];
int main() {
int i, j, n, top = 0;
scanf("%s", s + 1);
for (i = 1; s[i] == 'F'; i++) top++;
for (i; s[i]; i++)
if (s[i] == 'F') {
top++;
if (i - top > dp[top - 1])
dp[top] = i - top;
else
dp[top... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n - 2; i++) {
if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') {
int j = i + 3;
s[i] = '*';
s[i + 1] = '*';
s[i + 2] = '*';
while (j < n - 1 && s[j] == 'g... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct cmd {
int y, z, k;
};
unordered_map<bitset<256>, int> achieve;
unordered_map<bitset<256>, cmd> action;
string to_bs(bitset<256> mask) {
string ans;
for (int i = 0; i < (int)(64); i++) ans.push_back('0' + mask[i]);
return ans;
}
int main() {
ios_base::sync_w... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, swap;
cin >> m >> n;
if ((m > n) || m == n) {
if (m % 2 == 0) {
cout << (m / 2) * n;
} else {
cout << ((m / 2) * n) + (n / 2);
}
} else {
swap = n;
n = m;
m = swap;
if (m % 2 == 0) {
cout << (m / 2... | 0 |
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
int a[N], b[N], pre[N], suf[N], len[N][2];
vector<int> up, down;
int get_l(vector<int> &v, int x){
int p = lower_bound(v.begin(... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, s, st, cnt, a[200005], b[200005];
int main() {
int i, j, k;
cin >> n;
j = -1;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (j == -1 && a[i] != 0) j = st = i;
}
for (i = 0; i < n; i++) {
scanf("%d", &b[i]);
if (b[i] == a[j]) k = i;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;
const int N = 24;
const int MAX = 1 << N;
int f[MAX];
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
in... | 19 |
#include <bits/stdc++.h>
int main() {
printf("2000\n");
for (int i = 1; i <= 1000; ++i) printf("%d 1 %d 2\n", i, i);
for (int i = 1000; i >= 1; --i) printf("%d 1 %d 2\n", i, i);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, n, ans = 0, sum, sqSum;
cin >> n;
long long arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
for (i = 0, j = n - 1; i < j; i++, j--) {
sum = arr[i] + arr[j];
sqSum = sum * sum;
ans += sqSum;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
int n = 0;
std::cin >> n;
if (n < 3 || n > 100000) return 1;
std::vector<int> v;
std::copy_n(std::istream_iterator<int>(std::cin), n, std::back_inserter(v));
std::so... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 0) {
cout << 1 << endl;
return 0;
}
int a = (abs(1 - n)) % 4;
if (a == 0)
cout << 8 << endl;
else if (a == 3)
cout << 6 << endl;
else if (a == 2)
cout << 2 << endl;
else if (a == 1)
cout << 4 <... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, w, x, c, m;
cin >> a >> b >> w >> x >> c;
if (c <= a)
cout << 0 << endl;
else {
m = (a * w - c * w + b) / (x - w);
if (abs(m * (x - w)) < abs(a * w - c * w + b)) m++;
cout << m << endl;
}
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
long long int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
long long int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool q[31][400][400][8];
bool e[400][400];
long long int n;
long long int a[31];
void fill(long long int p, long long int x, long long int y, long long int d) {
if (q[p][... | 11 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
int grid[4010][4010];
int dp[810][4010];
int pre[4010][4010];
int ans;
int rect(int x, int y) {
if (x == 0) {
return pre[y][y];
} else {
return pre[y][y] - pre[x - 1][y] - pre[y][x - 1] + pre[x - 1][x - 1];
}
}
void solve(int i, int l, int r, int opt... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
char c[11][11][1001];
int ted[1001][1001], mted[1001], nted[1001];
int n, m, k, w;
int d(int x, int y) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (c[i][j][x] != c[i][j][y]) ted[x][y] += w;
if (ted[x][y] < mted[... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a;
cin >> t;
while (t--) {
cin >> a;
cout << a / 2 << endl;
}
return 0;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.