solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long a, b;
cin >> a >> b;
long long ans = 0;
while (1) {
if (a == 1 || b == 1) break;
long long x = a / b;
ans = ans + x;
a = a - b * x;
ans = ans + b / a;
b = b % a;
}
ans = ans + ((a == 1) ? b : a);
cout << ans <... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
if (!y) return 1;
long long t = power(x, y >> 1, p);
t = t * t % p;
if (y & 1) t = t * x % p;
return t;
}
long long rev(long long x, long long p) { return power(x, p - 2, p); }
long long ex_power(long long x... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-14;
struct edge {
int v, nxt;
} e[300001];
vector<int> gen[300001];
int head[300001], cnt, fz[300001], rt, sum, n, m, id[300001], dfn[300001], tot,
low[300001], low1[300001], rk[300001], used[100001];
bool vis[300001], al[300001], flag = 0, inter... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1000;
const int mx = 100000;
long long num[maxn];
long long len;
int m, n;
struct Op {
int type;
int l, c;
};
Op ops[maxn];
int main() {
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &ops[i].type);
if (ops[i].type == 1)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int vis[256];
vector<int> v;
int n, k;
void debug() {
for (int i = 0; i < 15; i++) cout << vis[i] << " ";
cout << endl;
}
int main() {
while (cin >> n >> k) {
memset(vis, -1, sizeof(vis));
v.clear();
for (int i = 0; i < n; i++) {
int x;
cin >> ... | 9 |
#include <bits/stdc++.h>
struct ty {
int s, t, anti, len;
} kk[30], k[30], tmp;
int n, top, e;
int l[10], r[10];
int seq[1010];
void check(int c) {
int i;
for (i = 1; i <= top; ++i)
if (k[i].anti && k[i].s != k[i].t) return;
for (i = 1; i < top; ++i)
if (seq[k[i].t] + 1 != seq[k[i + 1].s]) return;
pri... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
char str[1000011];
long long Hashes[1000011];
long long BASE[10000011];
bool YES[1000011];
long long GetHash(int L, int R) {
long long ans =
(Hashes[R] - (Hashes[L - 1] * BASE[R - L + 1]) % 1000000009LL);
if (ans < 0)
return ans + 1000000009LL;
els... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
int n, k;
double l, vb, vs;
int go(double ini) {
double t = 0;
t += ini / vb;
double est = ini;
for (int a ... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void gao(int dep, int val) {
if (val != 0) v.push_back(val);
if (dep == 9) return;
gao(dep + 1, val * 10 + 4);
gao(dep + 1, val * 10 + 7);
}
int pl, pr, vl, vr, k;
double gao() {
double add = 0.0, ct = 0.0;
int i;
for (i = 0; i < v.size(); ++i) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long double v1, v2, l;
const long double eps = 1e-13;
bool check(long double m) {
long double pos = 0;
int left = n;
while (left > 0 && fabs(pos - l) > eps) {
long double dist = l - pos;
if (fabs(dist - m * v1) <= eps) return 1;
if (dist < m * v1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, c, ar[100009] = {}, arr[100009], ans[100009], i, x, j,
la[100009];
scanf("%lld", &n), scanf("%lld", &m), scanf("%lld", &c);
for (i = 1; i <= n; i++) scanf("%lld", &arr[i]);
for (i = 1; i <= m; i++) {
scan... | 4 |
#include <bits/stdc++.h>
const int maxn = 1000007;
const long long mod = 1e9 + 7;
int main() {
long long clr[4];
long long ans = -1;
for (int i = 0; i < 3; i++) {
std::cin >> clr[i];
ans += clr[i];
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j || (clr[i] + clr[j] &... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 1e6 + 9;
long long dp[1009][1009];
long long y[N];
int x, m;
bool ans = 0;
long long f(int index, int modo, int good) {
if (good && !modo) return 1;
if (index > x) return 0;
if (dp[index][modo] != -1) return dp[index][mod... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T a) {
for (auto x : a) cout << x << ' ';
cout << '\n';
}
void solve() {
long long n;
cin >> n;
long long ans1 = 1, ans2 = n - 1;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
ans1 = n / i;
ans2 = n -... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long ceil(long long a, long long b) {
long long s;
if (a % b == 0) {
s = a / b;
} else {
s = (a / b) + 1;
}
return s;
}
long long sumdigit(long long n) {
lon... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int w, h, k;
cin >> w >> h >> k;
int count = 0;
while (k) {
count += 2 * (w + (h - 2));
w -= 4;
h -= 4;
k--;
}
cout << count;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, d;
scanf("%d %d", &k, &d);
if (d == 0) {
if (k > 1) {
printf("No solution\n");
} else {
printf("0\n");
}
return 0;
}
printf("%d", d);
for (int i = 1; i < k; ++i) {
printf("0");
}
printf("\n");
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int maxi = -1;
int A[1000];
int tot = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
tot += A[i];
}
for (int b = 0; b <= 100; b++) {
int cur = 0;
for (int i = -100; i <= 100; i++) {
int ind = b + i *... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long nod(long long a, long long b) {
while (a != 0 && b != 0) {
if (a > b) {
a %= b;
} else {
b %= a;
}
}
return a + b;
}
signed main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long l = nod(x, y);
x /= l;
y /= l;
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int hibit(long long x) {
for (int i = 63; i >= 0; i--)
if (x & (1LL << i)) return i;
assert(false);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long x;
cin >> x;
vector<pair<int, long long>> base;
int len = hibit(x);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a, b[26], cnt, ch;
int c[24] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int d[24] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m... | 4 |
#include <bits/stdc++.h>
using namespace std;
__attribute__((constructor)) static void fast_cin() {
ios_base::sync_with_stdio(false);
cin.tie(0);
}
using ll = int64_t;
using ull = uint64_t;
using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;
template <typename T, typename R>
istream &operator>>(istream &fin, pai... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long qpow(long long x, long long y) {
long long s = 1;
while (y) {
if (y & 1) s = s * x % mod;
x = x * x % mod;
y >>= 1;
}
return s;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> t(10, false);
void init(int n) {
while (n) {
t[n % 10] = true;
n /= 10;
}
}
bool common(int i) {
while (i) {
if (t[i % 10]) return true;
i /= 10;
}
return false;
}
int main() {
int n;
cin >> n;
init(n);
int res = 0;
int i;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[3844], w[3844], ans;
void dfs(int x) {
while (!v[x].empty()) {
int y = v[x].back();
v[x].pop_back();
dfs(y);
}
ans.push_back(x);
}
int main() {
int n;
cin >> n;
map<char, int> mp;
for (int i = 0; i < 26; i++) {
mp['a' + i] = i;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int maxm = 1e6 + 5;
struct edge {
int u, v, next;
} E[maxm];
int head[maxn];
int tot = -1;
void addedge(int u, int v) {
E[++tot].u = u;
E[tot].v = v;
E[tot].next = head[u];
head[u] = tot;
}
int vis[maxn], fa[maxn], isnleaf[maxn];
in... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int sum;
Node *lch, *rch;
Node() {
lch = rch = NULL;
sum = 0;
}
};
inline Node *duplicate(Node *x) {
Node *ret = new Node();
if (x) {
ret->sum = x->sum;
ret->lch = x->lch;
ret->rch = x->rch;
}
return ret;
}
void modify(Node ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
struct input {
int value;
char button;
int id;
bool operator<(struct input tmp) const {
return id < tmp.id || (id == tmp.id && value > tmp.value);
}
} all[200005];
long long ans = 0;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[1000000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
? EOF
: *p1++;
}
template <typename T>
inline T frd(T x) {
int f = 1;
char ch = gc();
for (;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int T;
vector<int> v[2][1505050];
string s[1505050];
string sx[1505050];
int calc(int p, int x1, int y1, int x2, int y2) {
x1 = max(0, x1);
y1 = max(0, y1);
x2 = min(N - 1, x2);
y2 = min(M - 1, y2);
int sum = v[p][x2][y2];
if (x1) sum -= v[p][x1 - 1][y... | 14 |
#include <bits/stdc++.h>
using namespace std;
int used[1000007];
int winner[1000007];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
int n;
cin >> n;
int A[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
used[A[i]]++;
}
int xam = -7;
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool can(char c, int *a) {
for (long long i = 0; i < int(c); i++) {
if (a[i] > 0) return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
stack<char> t1;
string u;
int a[256] = {0};
for (long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
int main() {
long long int t;
cin >> t;
while (t--) {
long double a, b;
cin >> a >> b;
long double ans;
if (b == 0) {
cout << 1 << "\n";
continue;
}
if (a < 4 * b)
ans = (a / 8 + b) / (2 * b);
... | 10 |
#include <bits/stdc++.h>
struct point {
int coo;
int num;
} p[110];
bool cmp(point x, point y) { return x.coo < y.coo; }
int main() {
int n, m, l, r, ans[110];
scanf("%d %d ", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &p[i].coo);
p[i].num = i;
}
while (m--) {
scanf("%d %d", &l, &r);
... | 8 |
#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << (#x) << " = " << x << endl;
#defin... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
long long n, m, k, t;
int main() {
cin >> t;
while (t--) {
cin >> n;
int res = 0;
bool flag = true;
while (n != 1) {
if (n % 2 == 0)
n = n / 2;
else if (n % 3 == 0)
n = (n / ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int index = ceil((float)k / 2);
vector<vector<int>> v(index, vector<int>(26, 0));
for (int i = 0; i < index; i++) {
int num = 0;
for ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> oneLoc, cnt;
long long update(vector<int> &counts, int k, int multiplier) {
long long ways = 0;
for (int i = 0; i <= n; i++) {
int ind = k * cnt[i] - i + n;
ways += counts[ind];
counts[ind] += multiplier;
}
return ways;
}
long long sol... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long clc[100] = {0};
struct wid {
wid() {
n = 0;
w = h = s = b = 0;
t = 0;
nn = 0;
}
long long w, h;
long long s, b;
string name;
long long n;
long long t;
long long child[100];
long long nn;
void pack(long long k) { child[nn++] = k;... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int testcase;
cin >> testcase;
while (testcase--) {
int n, m, ele;
cin >> n;
map<int, int> make_pair;
for (int i = 0; i < n; i++) {
cin >> ele;
make_pair[ele]++;
}
un... | 4 |
#include <bits/stdc++.h>
int sort(const void *a, const void *b) { return (*(int *)b - *(int *)a); }
int main() {
int n, p;
scanf("%d%d", &n, &p);
int com[n];
for (int i = 0; i < n; i++) {
scanf("%d", &com[i]);
}
qsort(com, n, 4, sort);
printf("%d", com[p - 1]);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline void invi(vector<int> &a) {
for (int i = 0; i < a.size(); i++) scanf("%d", &a[i]);
}
inline void outvi(vector<int> &a) {
for (int i = 0; i < a.size(); i++) printf("%d ", a[i]);
printf("\n");
}
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
invi... | 1 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long powmod(long long a, long long b) {
long long res = 1;
if (a >= mod) a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
if (res >= mod) res %= mod;
a = a * a;
if (a >= mod) a %= mod;
}
return res;
}
long long gcd(l... | 15 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > kol;
int tab[5 * 100 * 1000 + 5], pocz[5 * 100 * 1000 + 5], kon[5 * 100 * 1000 + 5];
bool czy[5 * 100 * 1000 + 5];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
for (int z = 1, n, zer, pa... | 25 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;
long long mod = 1000000009;
const long long INF = mod * mod;
const double eps = 1e-12;
const double pi = acosl(-1.0);
long long mod_pow(long long x, long long n, long long m = mod) {
long long res = 1;
while (n) {... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, h, x0 = 0, temp, x1 = 0;
cin >> n >> h;
temp = h * h / n;
x1 = sqrt(temp);
printf("%.12llf", x1);
for (int i = 0; i < n - 2; i++) {
x0 = x1;
x1 = sqrt(temp + x0 * x0);
printf(" %.12llf", x1);
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long f[55][55], res;
string s;
bool made() {
int x = int(s[0]) - int('0');
for (int i = 1; i < n; i++) {
int y = int(s[i]) - int('0');
if ((x + y) % 2 == 0) {
if (x + y != 2 * y) return false;
continue;
}
if ((x + y + 1) / 2 != y ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int res = 0;
if (a + b <= c) res += c - (a + b) + 1;
if (a + c <= b) res += b - (a + c) + 1;
if (b + c <= a) res += a - (b + c) + 1;
cout << res;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, x, f[6] = {0};
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x;
for (int t = 1; t <= 4; ++t)
f[t] = max(f[t - 1], f[t] + (x - 1 != (t & 1)));
}
cout << f[4];
cout << flush;
r... | 10 |
#include <bits/stdc++.h>
using namespace std;
string calc(long long n) {
string str;
while (n) {
if (n & 1)
str = '1' + str;
else
str = '0' + str;
n /= 10;
}
while (str.size() < 18) str = '0' + str;
return str;
}
int main() {
unordered_map<string, long long> pattern;
long long t, i... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp1, mp2;
map<long long int, long long int>::iterator it;
int main() {
ios_base::sync_with_stdio(false);
long long int n, p1, p2, x, y, result = 0;
cin >> n;
for (p1 = 0; p1 < n; p1++) {
cin >> x >> y;
mp1[x + y]++;
mp2[... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
} else {
return gcd(b % a, a);
}
}
int main() {
int n, occ, root, last;
cin >> n;
cin >> root;
cout << root << endl;
occ = n;
last = root;
vector<int> visited(n + 1);
visited[roo... | 14 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[40];
int main() {
string s;
int k;
cin >> s >> k;
for (int i = 0; i < 40; i++) a[i].second = i;
for (int i = 0; i < s.length(); i++) a[s[i] - 'a'].first++;
sort(a, a + ('z' - 'a') + 1);
for (int i = 0; i < 'z' - 'a' + 1; i++)
if (a[i].firs... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 88;
const int INF = 1e9 + 7;
int n, a[maxn], cnt;
int dp[maxn][maxn * maxn][maxn];
int b[maxn];
int getwei(int x, int y, int l) { return max(l + x - y, b[x]); }
int ans[maxn * maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long MOD = 1e+9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const long long MAXN = 1e+5 + 7;
vector<long long> adj[MAXN];
lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long par[101];
vector<int> vec;
int main() {
int q;
scanf("%d", &q);
while (q--) {
int t;
long long x, k;
scanf("%d %lld", &t, &x);
if (t == 1) {
scanf("%lld", &k);
int d = 0;
long long node = 1;
while (node * 2 <= x) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int add(long long int x, long long int y) {
x += y;
while (x >= 1000000007) x -= 1000000007;
while (x < 0) x += 1000000007;
return x;
}
long long int mul(long long int x, long long int y) {
return (x * 1ll * y) % 1000000007;
}
long long int binpow(long l... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long n, h, x[N];
pair<long long, long long> p[N];
int main() {
cin >> n >> h;
for (int i = 0; i < n; i++) {
cin >> x[i];
p[i] = make_pair(x[i], i);
}
sort(x, x + n);
sort(p, p + n);
long long best = ((long long)1) << 60;
long... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
void fastIO() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
fastIO();
int n, k;
long long x, nm;
cin >> n >> k >> x;
char sign = '+';
int signP = 0, signM = 0, signZ = 0... | 12 |
#include <bits/stdc++.h>
using namespace std;
int64_t n, k, m, r[200005], p[100005], a, b, c;
vector<int> ans;
char s[105][105];
int count(int x, int y) {
int c = 0;
for (int i = x; i <= x + 1; i++)
for (int j = y; j <= y + 1; j++) c += (s[i][j] == '1' ? 1 : 0);
return c;
}
void solve(int x, int y) {
if (co... | 7 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
const int MAXN = 1e5 + 50;
long long a[MAXN], b[MAXN], d... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
ll mod = 1e9 + 7;
ll mode = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t, n, m, i, j, k, d;
cin >> t;
while (t--) {
cin >> n >> m;
char a[n][m];
fo... | 12 |
#include <bits/stdc++.h>
int main() {
int r, d, n, i, r1, r2, sum = 0, x, y;
double dis, dis1, dis2;
scanf("%d %d", &r, &d);
r1 = r;
r2 = r - d;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d %d %d", &x, &y, &r);
dis2 = sqrt(x * x + y * y) - r;
dis1 = sqrt(x * x + y * y) + r;
if (r1... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int a[200000 + 50];
int cnt[200000 + 50];
vector<pair<long long, long long> > v;
bool vis[200000 + 50];
vector<long long> seg[800000 + 50];
void build(int node, int l, int r) {
if (l == r) {
seg[node].push_back(a[l]);
return;
}
int mid = (l + r) / 2;... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> t;
void build(int v, int l, int r) {
if (l + 1 == r) {
t[v] = 1;
} else {
int m = (l + r) / 2;
build(2 * v + 1, l, m);
build(2 * v + 2, m, r);
t[v] = t[2 * v + 1] + t[2 * v + 2];
}
}
int sum(int v, int l, int r, int a, int b) {
if (l ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, k, arr[300001], cnt[1000001 * 2];
int mi = 1000001, mx = 0;
bool check(int mid) {
if (mid == 6) cout << "";
;
int tot = 0;
int ind = 0;
k = min(k, mid - 1);
while (ind <= mx) {
tot += cnt[ind + k] - cnt[max(0, ind - 1)];
if (tot == 2) cout << "";
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p[20][5];
int ans[20];
int anscnt;
int main() {
scanf("%d", &n);
if (n > 11) {
printf("0\n");
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
scanf("%d", &(p[i][j]));
}
}
for (int i = 0; i < n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const long long inf = 1000000000000000ll;
struct node {
int l, r;
long long x, lazy;
} t[maxn << 2];
int n, m, tot, v, u, indexx;
int in[maxn], out[maxn];
struct edge {
int v, next;
} e[maxn << 1];
int h[maxn], num, pos[maxn], c[maxn];
vecto... | 21 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 1e9;
int main() {
int n, i;
scanf("%d", &n);
if (n < 4)
printf("NO\n");
else {
printf("YES\n");
printf("2 * 4 = 8\n");
if (n & 1) {
printf("3 - 1 = 2\n");
printf("5 - 2 = 3\n");
printf("3 * 8... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
const int N = 3e5 + 7;
const int M = -1;
map<string, int> g;
vector<pair<int, int> > z;
vector<int> e[N];
int no, p[N], rd[N];
int id(string x) {
for (int i = 0; i < (x.length()); ... | 16 |
#include <bits/stdc++.h>
using namespace std;
string str[1100][11];
static int diff[1100][1100];
static int dist[11020];
int vis[1100] = {0};
int parent[1100];
vector<pair<long long int, long long int> > answer;
long long int sum = 0;
long long int n, m, w, k;
void add_to_tree(int curnode) {
vis[curnode] = 1;
sum +... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans[1000], temp, i, j;
fill(ans, ans + 1000, 0);
char s[1000];
cin >> n;
cin >> s;
for (i = 0; i < n; i++) {
ans[i] = 1;
temp = 1;
for (j = i; j < n; j++) {
if (s[j] == 'R')
break;
else if (s[j] == 'L')
... | 10 |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T>
ostream& prnt(ostream& out, T v) {
out << v.size() << '\n';
for (auto e : v) out << e << ' ';
return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> v) {
return prnt(out, v);
}
template <cla... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e4 + 7;
const int INF = 2e9 + 11;
int n, m, s, t, par[NMAX], fup[NMAX], tin[NMAX], es[NMAX], ec[NMAX], vis[NMAX],
par2[NMAX];
vector<int> G[NMAX], res;
map<pair<int, int>, int> Bridge;
int ans = INF;
void Bfs() {
queue<int> Q;
Q.push(s);
vis[s] =... | 18 |
#include <bits/stdc++.h>
int n, m;
double ans;
int main() {
while (scanf("%d %d", &n, &m) == 2) {
if (n == 1) {
puts("1.000000000000000000");
continue;
}
ans = 0.0;
for (int i = 1; i <= std::min(m, n); ++i) {
std::vector<int> p, q;
for (int j = 0; j < i; ++j) {
p.push_b... | 13 |
#include <bits/stdc++.h>
using namespace std;
char s[3000005];
const long long mod = 1e9 + 7;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
scanf("%s", s);
long long len = strlen(s);
int pos = 0;
while (len < n) {
int t = len;
for (int i = 1; i < s[... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ansh[1005][1005], ansl[1005][1005];
int temp[1005];
int num[1005][1005];
int maxh[1005], maxl[1005];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &num[i][j]);
for (int i = 1; i <= n; i++... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, c = 0;
int main() {
scanf("%d%d", &n, &k);
while (n--) {
int d[10], u;
fill(d, d + 10, 0);
scanf("%d", &u);
while (u > 0) {
++d[u % 10];
u /= 10;
}
bool ok = 1;
for (int i = k; i >= 0; --i) {
if (d[i] == 0) ok = 0;... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long dx4[4] = {0, 1, 0, -1};
long long dy4[4] = {1, 0, -1, 0};
long long dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
long long dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
double r1 = -1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt[11];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
cnt[x]++;
}
long long ans = 0;
for (int i = 1; i <= m; i++) ans += 1LL * cnt[i] * (n - cnt[i]);
cout << ans / 2 << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int tc;
cin >> tc;
while (tc--) {
long long int n, t;
cin >> n >> t;
vector<int> nums(n);
for (int &num : nums) cin >> num;
set<long long int> s1, s0;
int count1 = 0, count0 = 0;
for (int i = 0; i < n; i++) {
lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, c, x, y;
int ans = 0;
void bs(int l, int r) {
int m;
while (l <= r) {
m = (l + r) / 2;
long long s = 0;
for (int i = y; i <= y + m && i <= n; ++i) {
long long v = (i - y) - m;
long long le = max(1LL, x + v);
long long ri = min((long ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, x, y, z, l, k[2005], ans, a[2005], r;
vector<int> g[2005];
vector<int> b;
set<pair<int, int> > q;
int main() {
cin >> n >> m;
l = n / m;
for (i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] <= m) {
k[a[i]]++;
g[a[i]].push_back(i);... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18;
int round(int n, int m) {
long double k = (m * 1.0) / (n * 1.0);
k *= 100.0;
int res = (int)(k + 0.5);
return res;
}
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
queue<int> q;
for (int i = 1; i <= n... | 8 |
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo dp[501*501];
llo dp2[501*501];
llo dp3[501*501];
llo mi;
llo n;
llo mod;
llo ee(llo aa,llo bb){
if(bb==0){
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1010;
int dp[N][N][2];
int bits[N];
int t, k;
long long dfs(int len, int pos, int num, bool mark) {
int maxx;
long long sum;
if (!len) {
if (num == 1) {
return true;
} else {
return false;
}
}
if (!mar... | 17 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
char ibuf[(1 << 18)], *iS, *iT, obuf[(1 << 18)],
*oS = obuf, *oT = oS + (1 << 18) - 1, c, qu[55];
int f, qr;
inline void flush(void) {
fwrite(obuf, 1, oS - obuf, stdout);
oS = obuf;
return;
}
inline char getch(void) {
return (iS == iT ? (iT = (iS ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int F[4444][4444];
int b[4444];
int main() {
int n = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
int ans = 1;
for (int i = n - 1; i > 0; i--) {
int t = 0;
for (int j = n; j > i; j--) {
F[i][j] = 2;
if (t) F[i][j] = max(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, l, p1 = 0, p2 = 0, c11 = 0, c10 = 0, c01 = 0;
string s, t;
cin >> l;
l = 2 * l;
cin >> s >> t;
s = " " + s;
t = " " + t;
for (i = 1; i <= l; i++) {
if (s[i] == '1' && t[i] == '1') c11++;
if (s[i] == '1' && t[i] == '0'... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INFI = (1LL << 31) - 1;
const long long INFL = (1LL << 62);
const double eps = 1e-7;
const long double pi = acos(-1.0);
const int MAXN = 10001;
struct houses {
houses(int a, int b, int c, int d) : H(a), R(b), G(c), S(d) {}
int H, R, G, S;
};
struct cmp {
boo... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long d[3000], n, p[3000];
int main() {
cin >> n;
for (int i = 0, _n = (int)(n); i < _n; i++) cin >> p[i + 1];
d[1] = 0;
for (int i = (int)(1), _n = (int)(n + 1); i < _n; i++)
d[i + 1] = (d[i] + 2 + d[i] - d[p[i]] + 1000000007ll) % 1000000007ll;
cout << d[... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> son[10010];
long long cnt[10010];
int main(int argc, char const *argv[]) {
memset(cnt, 0, sizeof(cnt));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) son[i].clear();
for (int i = 0; i < n - 1; i++) {
int u, v;
scanf("%d%d", &u, &v);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int i, j, n, m, a, b, c = 0;
cin >> n;
for (int i = 0; i <= n - 1; i++) {
cin >> a;
if (a % 2) c++;
}
if (c != 0)
cout << "First";
else
cout << "Second";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int comb[445][445];
int dp[445][445];
int pow(int a, int b, int m) {
a %= m;
int r = 1;
while (b) {
if (b & 1) r = (1LL * r * a) % m;
a = (1LL * a * a) % m;
b >>= 1;
}
return r;
}
int powK[445];
int powK1[445];
int main(int argc, ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXL = 1005, P = 1000000007;
int digit[MAXL], lucky[10], LIMIT, LEN;
long long dp[MAXL][MAXL], Pow10[MAXL], topMod[MAXL];
char str[MAXL];
long long rec(int pos, int dist, int bound) {
if (pos == -1) return 0;
if (!bound && dp[pos][dist] != -1) return dp[pos][d... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 755;
int N, Q, arr[maxn];
long long res[maxn];
inline bool works(long long mid, int t) {
priority_queue<int> q;
for (int i = 1; i <= N; i++) {
mid += arr[i];
q.push(-arr[i]);
if (mid < 0) {
mid += q.top();
q.pop();
t--;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 20) + 100;
queue<int> q;
char s[30], t[30];
int msk[N], dis[N], pos[N], n, m, k, a[30], ans, l, r, tmp[30];
int get(char s[]) {
for (int i = 1; i <= k; i++) tmp[a[i]] = s[i] - '0';
int msk = 0;
for (int i = 1; i <= k; i++) msk = (msk << 1) | tmp[i]... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300030, mod = 998244353;
inline int read() {
int x = 0, f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int T, n, a... | 18 |
#include <bits/stdc++.h>
using namespace std;
bool isprime[400];
int primes[400];
int sz;
inline void precompute() {
for (int i = 2; i * i < 400; i++) {
if (!isprime[i])
for (int j = i * i; j < 400; j += i) isprime[j] = 1;
}
for (int i = 2; i < 400; i++)
if (!isprime[i]) primes[sz++] = i;
}
int X[10... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.