solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, m;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long int> v;
long long int ans = 0;
for (int i = 0; i < n; i++) {
if (i == 0 && a[i] ==... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include<bits/stdc++.h>
using namespace std;
bool check(int x,int y,int z)
{
if((x>=y&&y>=z)||(x<=y&&y<=z))
return true;
else
return false;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n+10];
for(int i=1;i<=n;i++)
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int h[maxn], preMax[maxn], suffMin[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
preMax[0] = 0;
suffMin[n + 1] = 1e9 + 10;
for (int i = 1; i <= n; i++) {
preMax[i] = max(preMax[i - 1],... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, x, y;
cin >> l >> x >> y;
if ((x == l / 2 + 1 && y == l / 2 + 1) || (x == l / 2 && y == l / 2) ||
(x == l / 2 + 1 && y == l / 2) || (x == l / 2 && y == l / 2 + 1))
cout << "NO" << endl;
else
cout << "YES" << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &ret) {
ret = 0;
bool ok = 0, u = 0;
for (;;) {
int c = getchar();
if (c >= '0' && c <= '9')
ret = (ret << 3) + (ret << 1) + c - '0', ok = 1;
else if (c == '-')
u = 1;
else if (ok) {
if (u) ret *= -1;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int T;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--) {
double d;
cin >> d;
if (!d)
cout << "Y " << 0 << " " << 0 << '\n';
else if (d < 4)
cout << "N" << '\n';
else {
double denta =... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g1[111111], g2[111111], dfn, g3[111111];
int N, M, C[111111], gcnt, gnum, P[111111];
int ans, S[111111], chk;
void dfs(int node) {
int i;
C[node] = 1;
for (i = 0; i < g1[node].size(); i++)
if (!C[g1[node][i]]) dfs(g1[node][i]);
dfn.push_back(node);
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using vi = vector<int>;
char s[5000];
int main() {
scanf("%s", s);
int n = strlen(s);
vector<char> a;
a.clear();
int l = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||... | 7 |
#include <bits/stdc++.h>
using namespace std;
set<int> s[105], t[105];
int main() {
int n;
int pr = 0;
int i;
int t = 0;
int ma = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
pr = pr - (x - t);
if (pr < 0) pr = 0;
if (y + pr > ma) ma = y + pr;
t = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int val[500005], lazy[500005], data[500005], size[500005];
int lc[500005], rc[500005], fa[500005];
void Add(int t, int ret) {
val[t] += ret;
lazy[t] += ret;
data[t] += ret;
}
void down(int t) {
if (lazy[t]) {
if (lc[t]) Add(lc[t], lazy[t]);
if (rc[t]) Add(rc... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000")
#pragma warning(disable : 6031)
#pragma warning(disable : 4244)
#pragma warning(disable : 26451)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int finished = 0;
const int sz = 501;
char maze[sz][sz];
bool vtd[sz][sz];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
struct point {
int x, y;
};
void init() {
for (int i = 0; i < n; i++) {
scanf("%s", &maze[i]);
}
}
void dfs(point a) {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnl(7319);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, x;
cin >> n;
for (; n--;) {
cin >> x;
cout << x - (x + 1) % 2 << " ";
}
return 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
vector<string> v;
char s[1500];
int main() {
gets(s);
int l = strlen(s);
string cur = "";
int i;
for (i = 0; i < l; ++i) {
if (s[i] == ',') {
if (cur != "") v.push_back(cur);
v.push_back(",");
cur =... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, primes[] = {2, 3, 5, 7, 11, 13, 17, 19}, counters[20];
long long max_val;
set<long long> result;
void rec(int step, int limit, long long num) {
if (step == limit) {
if (num != 1) {
result.insert(num);
if (result.size() > n) {
result.erase(re... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int b[N];
int ans;
int n, m, k;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
;
int a = 1;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
bool vk = 1;
bool vn = 1;
for (int i = 0; i < n; ++i) {
if (b[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int i, cnt, low;
int main() {
for (i = 1; i <= 3; i++) scanf("%d", &a[i]);
for (i = 1; i <= 3; i++) {
scanf("%d", &b[i]);
a[i] -= b[i];
if (a[i] > 0)
cnt += a[i] / 2;
else
low += a[i];
}
if (cnt + low >= 0)
printf("Y... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a[100100], u[100100];
bool w[100100];
int main() {
scanf("%d", &n);
if (n & 1) {
puts("-1");
return 0;
}
for (i = 0; i < n; i++) a[i] = (i * 2 + int(i * 2 < n)) % n;
for (k = 0; k < n; k++)
if (!u[k]) {
m++;
for (i = k, j... | 20 |
#include <bits/stdc++.h>
using namespace std;
set<int> row[100005], col[100005], rowRev[100005], colRev[100005];
int main() {
long long n, m, k, x, y;
cin >> n >> m >> k;
bool no = 0;
for (int i = 1; i <= n; i++) {
row[i].insert(m + 1);
rowRev[i].insert(0);
}
for (int i = 1; i <= m; i++) {
col[i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
long long int dp[1000001];
int main() {
ios::sync_with_stdio(false);
dp[1] = 1;
dp[2] = 2;
cin >> n;
for (int i = 3; i <= n; ++i) {
dp[i] = dp[i - 1] + 1;
dp[i] += dp[i - 2];
dp[i] = dp[i] % 1000000007;
}
cout << (dp[n] + dp[n -... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int n, a[200009];
cin >> t;
while (t--) {
cin >> n;
map<int, int> dp, dp2;
dp[0] = n + 1;
dp2[0] = n;
int deficit = 0;
for (int i = 1; i <= 2 * n; i++) {
cin >> a[i];
if (a[i] == 1)
deficit++;
els... | 9 |
#include <bits/stdc++.h>
using namespace std;
int c[5010], n, x[5010], y[5010], top, d[5010], sta[5010], t;
struct DOT {
int x, y;
DOT(int _x = 0, int _y = 0) { x = _x, y = _y; }
} a[5010];
DOT operator-(DOT a, DOT b) { return DOT(a.x - b.x, a.y - b.y); }
int ctime(DOT a, DOT b) { return a.x * b.y - a.y * b.x; }
bo... | 24 |
#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
ios::sync_with_stdio(0);
run();
}
long long const lots = 777777777;
int ways[110000][4][4];
int seg[1 << 18][2];
int psh[1 << 18][2];
int ans[1 << 18];
unsigned char val[1 << 17];
long long n, m;
void pull(long long i, long long x, long long mor... | 16 |
#include <bits/stdc++.h>
using namespace std;
char s[50050], ans[2650];
int num[30];
int f[2650][2650];
int n, len;
int search(int l, int r) {
if (r < l) return 0;
if (f[l][r]) return f[l][r];
if (l == r) return f[l][r] = 1;
if (s[l] == s[r]) return f[l][r] = search(l + 1, r - 1) + 2;
return f[l][r] = max(sea... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long power(long long x, long long y, long long p) {
long long res = 1;
x %= p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
r... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, a[100], fa[100], id[100], S[100], cnt[40000], dp[100][40000],
c[200][200];
bool not_mn[100];
int find(int a) { return fa[a] == a ? a : fa[a] = find(fa[a]); }
void merge(int u, int v) {
int fu = find(u), fv = find(v);
if (fu == fv) ret... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4005, maxm = 70, oo = 1e9;
int f[maxn][maxm][maxm], vis[maxn][maxm][maxm];
int a[maxn], s[maxn];
int n, i;
void update(int &F, int x) { F = max(F, x); }
void solve(int l, int k, int d) {
if (vis[l][k][d]) return;
vis[l][k][d] = 1;
int &F = f[l][k][d];... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int Mod = 1e9 + 7;
struct Edge {
int u, v;
long long x;
bool operator<(const Edge& B) const { return x < B.x; }
} E[N];
vector<int> G[N];
long long A[N];
int Pow2[N], ver[N << 1];
int n, m, k;
int col[N];
bool DFS(int o) {
for (int v : ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000005;
int pos[105];
int main() {
int n, m, k;
int ans = 0;
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i <= k; i++) {
int x;
scanf("%d", &x);
pos[x] = i;
}
for (int i = 1; i <= n; i++)
for (int i = 1; i <= m; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 7;
const int mod = 1000000007;
int n, a[maxn];
long long dp[maxn][maxn], fac[maxn];
long long quick_pow(long long a, long long b) {
long long sum = 1;
while (b) {
if (b & 1) sum = (sum * a) % mod;
b /= 2;
a = (a * a) % mod;
}
retur... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int main() {
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> arr[i];
int na, ans = 0;
for (int i = 1; i <= n; i++) {
cin >> na;
if (na) ans += arr[i], arr[i] = 0;
arr[i] +=... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
long long n, k, a[N], to[N], vis[N], tot[N], top, belong, du[N], pos;
inline long long read() {
long long ret = 0, ff = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int inf = 1e9;
bool isprime(long long x) {
for (long long i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
void solve() {
long long n, k;
cin >> n >> k;
long long val = n - k;
long long val2... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (100000 + 5) * 2;
struct nood {
long long x;
int p;
} s[maxn], st[maxn];
bool cmp(nood a, nood b) { return a.x > b.x; }
bool cmp1(nood a, nood b) { return a.x < b.x; }
bool cmp2(nood a, nood b) { return a.p < b.p; }
int main() {
int m;
cin >> m;
f... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, u, v;
vector<int> adjlist[1005];
int shortestpath[1005][1005];
int ans = 0;
bool connected(int a, int b) {
bool connected = false;
if (a == b) return true;
for (int v : adjlist[a]) {
if (v == b) connected = true;
}
return connected;
}
void bfs(... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
for (int i = 0; i < n; i++) {
cin >> b[i];
b[i]--;
}
int ind1[n]... | 13 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> x, y;
void init() {
x['1'] = 1;
y['1'] = 1;
x['2'] = 1;
y['2'] = 2;
x['3'] = 1;
y['3'] = 3;
x['4'] = 2;
y['4'] = 1;
x['5'] = 2;
y['5'] = 2;
x['6'] = 2;
y['6'] = 3;
x['7'] = 3;
y['7'] = 1;
x['8'] = 3;
y['8'] = 2;
x['9'] = 3;
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
const long double Eps = 1e-9;
int dx[9] = {0, 1, -1, 0, 0, 1, 1,... | 12 |
#include <bits/stdc++.h>
using namespace std;
string str;
int cal() {
int res = 0;
for (int i = 0; i < str.size() - 1; i++)
if (str[i] == 'V' && str[i + 1] == 'K') res++;
return res;
}
int main() {
while (cin >> str) {
int ans = cal();
char pre;
for (int i = 0; i < str.size(); i++) {
if (i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
template <class T>
void out(const vector<T> &a) {
cout << "array: ";
for (int i = 0; i < (int)a.size(); i++) cout << a[i] << " ";
cout << endl;
cout.flush();
}
void binprint(int mask, int n) {
int i;
string s = "";
do {
s += (... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 4e5 + 5;
pair<int, int> a[M];
int countt[M];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int tot = 0;
for (int l, r, i = 1; i <= n; i++) {
scanf("%d%d", &l, &r);
a[tot++] = make_pair(l, -i);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, k, x, dy, y;
void p(int x, int y) { printf("%d %d\n", x, y); }
int main() {
scanf("%d%d", &n, &k);
if (k == 3) {
if (n == 3) {
printf("0 0\n0 1\n1 0\n");
return 0;
}
if (n == 4) {
printf("0 0\n0 100\n100 0\n1 1\n");
return 0;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5005;
const int MAX1 = 200005;
const int LOGMAX = 25;
const double eps = 1e-11;
const int oo = 1e9 + 7;
const long long mod = 987654321;
int n, p;
vector<int> g[1005];
int cas;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cin >> cas;
while (c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int h[101];
queue<int> q;
int main() {
ios_base::sync_with_stdio(false);
int n, k, temp, ans = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> temp;
h[temp]++;
}
if (h[k] == n) {
cout << "0";
return 0;
}
if (n == 1) {
cout << k - t... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long x, y;
float k;
int main() {
cin >> x >> y;
k = sqrt(x * x + y * y);
if (ceil(k) > k) {
int z = (int)(ceil(k));
if (x * y > 0 == (z & 1))
cout << "black";
else
cout << "white";
} else
cout << "black";
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans, sum, tmp;
int MAX, MIN;
int main() {
long long a, b, x1, y1, x2, y2;
cin >> a >> b >> x1 >> y1 >> x2 >> y2;
long long dx, dy;
dx = abs((x1 + y1) / (2 * a) - (x2 + y2) / (2 * a));
if ((x1 + y1) * (x2 + y2) < 0) dx++;
dy = abs((x1 - y1) / (2 * b... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[6][26];
a[0][0] = '+';
a[5][0] = '+';
for (int i = 1; i < 26; i++) {
a[0][i] = '-';
a[5][i] = '-';
}
a[0][25] = '+';
a[5][25] = '+';
for (int i = 1; i < 5; i++) {
a[i][0] = '|';
a[i][25] = '|';
}
a[1][24] = 'D';
a[2]... | 3 |
#include <iostream>
using namespace std;
int T;
int n;
int main() {
cin>>T;
while (T--) {
cin>>n;
int cnt = 0;
while (n) {
n >>= 1; cnt++;
}
n = 1; cnt--;
while (cnt--) {
n <<= 1;
}
cout<<n-1<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
int dist[5][1005][1005];
int n, m;
int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
inline bool ok(int x, int y) {
if (x < 0) return false;
if (y < 0) return false;
if (x >= n) return false;
if (y >= m) return false;
if (a[x][y] == '#') return... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string x;
while (cin >> n >> x) {
vector<int> all;
for (int i(1); i <= n; i++) {
if (n % i == 0) all.push_back(i);
}
for (int i(0); i < all.size(); i++) {
for (int j(0); j < all[i] / 2; j++) {
swap(x[j], x[all[i]... | 1 |
#include <bits/stdc++.h>
int main() {
long long s, x;
int p1, p2, i, judge = 0;
scanf("%lld%lld", &s, &x);
if ((s - x) % 2 != 0)
printf("0\n");
else {
long long ans = 1;
if (s == x) judge = 1;
int flag = 1;
s = (s - x) / 2;
for (i = 0; i < 60; i++) {
p1 = (s >> i) & 1;
p2 =... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int MAX(long long int a, long long int b) { return a > b ? a : b; }
long long int MIN(long long int a, long long int b) { return a < b ? a : b; }
int main() {
long long int m, n, i, j;
scanf("%lld", &n), scanf("%lld", &m);
long long int min_ans, max_ans;
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, d;
scanf("%d %d %d", &n, &a, &d);
double previous = 0;
while (n--) {
int t, v;
scanf("%d %d", &t, &v);
double next = 0;
double ti = v * 1.0 / a;
double di = a * ti * ti / 2.0;
if (di - d > 1e-9)
next = sqrt(d * 2.... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long x = 0, y = 0;
long long t = n * 2;
while (t--) {
long long xx, yy;
cin >> xx >> yy;
x += xx;
y += yy;
}
cout << x / n << " " << y / n << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
struct hull {
map<int, int> points;
long long area;
inline hull() {
points.clear();
area = 0;
}
inline map<int, int>::iterator prev(map<int, int>::iterator it) {
return it == points.begin() ? it : --it;
}
inline map<int, int>::iterator next(map<int... | 19 |
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e6 + 10;
constexpr int LG = 20;
constexpr int MOD = 1e9 + 7;
constexpr int MOD2 = 1e9 + 9;
int n, k, p[N], sz, cnt[N], mx;
bitset<N> foo;
bool mark[N];
void dfs(int v) {
mark[v] = true;
sz++;
if (!mark[p[v]]) dfs(p[v]);
}
int main() {
ios_base::sy... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, Q, x, y, u, v, kk, cnt, rt, f[200005][257];
int a[200005], father[200005], depth[200005], top[200005], head[200005],
ls[2000... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e2;
const double EPS = 1e-9;
const int INF = 1e9;
const double PI = acos(-1);
int n;
int ar[N + 5][5];
int sqr(int a) { return a * a; }
int dot(int idxi, int idxa, int idxb) {
int ans = 0;
for (int i = 0; i < 5; ++i) {
ans += ... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
vector<string> univ;
long long int n, m;
string second[100];
void awesome(string s) {
if (s.size() >= m) {
univ.push_back(s);
return;
}
long long int i;
for (i = 97; i <= 122; i++) {
char ch = i;
string str = s + ch;
awesome(str... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
if (a < 0) return GCD(-a, b);
if (b < 0) return GCD(a, -b);
return ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
bool v[maxn];
vector<int> a, b;
vector<pair<int, int> > ans;
int main() {
int n, m, k, x;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= k; i++) {
scanf("%d", &x);
v[x] = 1;
}
if (k == n) {
printf("-1\n");
return 0;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1000100;
struct Node {
int lf, rg;
int res;
Node *l, *r;
Node() { lf = rg = res = 0; }
Node(char ch) {
lf = (ch == '(');
rg = (ch == ')');
res = 0;
}
};
Node* comb(Node* b, Node* c, Node* a = new Node()) {
int add = min(b->lf, c->rg);... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, cnt, head[100010], maxcol, maxsum, size[100010];
long long ans, dp[100010][21][3], f[21][3];
template <class T>
bool checkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
template <class T>
bool checkmin(T &x, T y) {
return x > y ? x = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int k;
cin >> n >> k;
vector<int> d;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
d.push_back(x);
}
int q;
int p;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> p;
int t1 = 0;
int t2 = 0;
int f = 0;
int... | 11 |
#include <bits/stdc++.h>
using namespace std;
int s;
int a[2 * 100000 + 2], p[2 * 100000 + 2], d[2 * 100000 + 2];
int f(int n, int m) {
if (n == s) {
return s;
}
if (p[n] == a[n])
return f(d[n], m);
else {
if (a[n] - p[n] > m) {
p[n] += m;
m = 0;
return n;
} else {
m -= (... | 10 |
#include <bits/stdc++.h>
long long a[400060] = {0}, b[450], n, m = 0, j, k, l, i, t, r, x, y, z, q;
int main() {
scanf("%lld", &n);
scanf("%lld", &x);
for (i = 2; i <= n; i++) {
scanf("%lld", &y);
if (x == y) {
x = x;
} else {
if (x < y) {
q = x;
x = y;
y = q;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, sum = 0;
scanf(" %d", &n);
for (int i = 1; i <= n; i++) {
scanf(" %d", &x);
sum += i * x;
}
printf("%d\n", sum);
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
if (n % 2 == 0)
cout << n / 2 << "\n";
else
cout << (-(n + 1)) / 2 << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, t;
cin >> n >> t;
if (n == 1 && t == 10) {
cout << -1;
return 0;
}
if (t == 10) {
cout << 1;
for (int i = 1; i <= n - 1; i++) {
cout << 0;
}
return ... | 2 |
#include <bits/stdc++.h>
using ll = int64_t;
const int MAX = 1e5;
int32_t main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
int n, k;
std::cin >> n >> k;
std::vector<int> number_count(MAX + 1), favorite_count(MAX + 1), h(k + 1);
int lim = k * n;
for (int i = 0; i < lim; i++) {
int x;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> ma;
long long int pre[100009], k;
int tree[100009], n;
void update(int idx, int val) {
while (idx <= n) {
tree[idx] += val;
idx += (idx & -idx);
}
}
int sum(int idx) {
int val = 0;
while (idx > 0) {
val += tree[idx];
idx -= (idx... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long b[300], pow2[300];
int main() {
pow2[0] = 1;
for (int i = 1; i <= 35; i++) {
b[i] = b[i - 1] * 4 + 1;
pow2[i] = pow2[i - 1] * 2;
}
int T;
scanf("%d", &T);
for (int t = 1; t <= T; t++) {
int n;
long long k, sum = 0;
bool yesans = 0;
... | 12 |
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <queue>
#... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
struct node {
long long x, y;
} a[MAXN];
bool cmp(const node& a, const node& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
int main() {
int n;
long long x1, x2, k, b;
scanf("%d%I64d%I64d", &n, &x1, &x2);
for (int i = 0; i < n; ++... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(228);
const int maxn = 2e5;
pair<int, int> a[maxn];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i].first;
a[i].second = i;
}
sort(a, a + n);
reverse(a, a + n);
vector<int> ve;
long long ans = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
char vowel[] = {'a', 'e', 'i', 'o', 'u'};
int check(char s) {
for (int i = 0; i < 5; i++) {
if (vowel[i] == s) return 1;
}
return 0;
}
int main() {
string s;
cin >> s;
if (!check(s[s.size() - 1]) && s[s.size() - 1] != 'n') {
printf("NO\n");
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct name {
long long a, b;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long i, n, m, x, y, l, r, L, R, j, coun;
cin >> n >> m >> x >> y;
long long b[m];
name a[n];
for (i = 0; i < n; i++) {
cin >> a[i].a;
a[i].b = -1;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const int M = 998244353;
int n, a[N];
long long fac[N], inv[N], f[N], ans;
long long pow_mod(long long a, int b) {
long long ans = 1;
a = a % M;
while (b) {
if (b & 1) ans = ans * a % M;
a = a * a % M;
b >>= 1;
}
return ans % M;
}
v... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &i : a) cin >> i;
map<int, int> sums;
vector<int> pos(2 * k + 2, 0);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
ostream &operator<<(ostream &os, const ... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void mul(T &a, T &b, int k) {
T c(k * k, 0);
for (int i = 0; i < k; ++i)
for (int j = 0; j < k; ++j) {
for (int t = 0; t < k; ++t)
c[i * k + j] =
(c[i * k + j] + a[i * k + t] * b[t * k + j]) % (998244353 - 1);
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 10;
char s[maxN], t[maxN];
int cs[26], ct[26];
int chk() {
memset(cs, 0, sizeof(cs));
for (int i = 0; s[i]; i++) cs[s[i] - 'a']++;
memset(ct, 0, sizeof(ct));
for (int i = 0; t[i]; i++) ct[t[i] - 'a']++;
for (int i = 0; i < 26; i++)
if (c... | 6 |
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 998244353
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
#define fast_io ios_base::sync_... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int SIZEN = 2010;
char mp[SIZEN][SIZEN] = {0};
int N, M;
int r, s;
int x, y;
bool vis[SIZEN][SIZEN] = {0};
struct Node {
int x, y, l, r;
Node(int _, int __, int ___, int ____) {
x = _;
y = __;
l = ___;
r = ____;
}
Node() { ; }
};
deque<Node> q;... | 10 |
#include <bits/stdc++.h>
int n, a[30], b[30], c[30], d[30];
bool dfs(int dep, int limit) {
if (a[dep] == n) {
printf("%d\n", dep - 1);
for (int i = 1; i < dep; i++) {
printf("lea e%cx, [", 'a' + i);
if (c[i] != 0) {
printf("e%cx + ", 'a' + b[i] - 1);
if (d[i] == 0)
printf... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x = 0;
bool f = 0;
char c;
for (; (c = getchar()) < '0' || c > '9'; f = c == '-')
;
for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';
x = (x << 3) + (x << 1) + c - '0')
;
return f ? -x : x;
}
struct dom {
int l, r, y;
}... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1640005;
struct pi {
int x, y, r;
} pp[maxn / 20];
double dis(int x1, int y1) {
double xx = x1;
double yy = y1;
return sqrt(xx * xx + yy * yy);
}
struct ppi {
double y;
int id;
} p1[maxn];
int be(double x, double y) {
if (x > y) return 1;
if... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
m = (a[n - 1] - a[0]) / 2;
cout << a[0] + m << endl;
}
| 0 |
#include <bits/stdc++.h>
int main() {
int a, x;
scanf("%d", &a);
for (int i = 0; i < a; i++) {
scanf("%d", &x);
printf("%d\n", (x % 7) ? (x / 7 + 1) : (x / 7));
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct Matrix {
long long data[2][2];
long long &operator()(int x, int y) { return data[x][y]; }
};
Matrix Multiply(Matrix &a, Matrix &b) {
Matrix c;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
c(i, j) = 0;
for (int k = 0; k < 2; ++k)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int l, k = 1;
cin >> l;
string s, temp, temp2, ans;
cin >> s;
ans = s;
int ch = min_element(s.begin(), s.end()) - s.begin();
for (int i = 0; i < l; i++) {
if (s[i] != s[ch]) continue;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], nxt[N][31] = {0};
int maxx[N][20];
int Log2[N];
int GetMaxx(int l, int r) {
int len = Log2[r - l + 1];
return max(maxx[l][len], maxx[r - (1 << len) + 1][len]);
}
int Solve(int start, int l, int r, int val) {
while (l <= r) {
int m... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
int c = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int j = 0;
while (a[j] <= k && j < n) {
c++;
j++;
}
int m = n - 1;
while (a[m] <= k && m >= j) {
c++;
m--;
}
cout << c << en... | 0 |
#include <bits/stdc++.h>
const int inf = 1e9;
namespace Flow {
const int maxn = 3e4;
const int maxm = 3e4;
int hd[maxn], dis[maxn], pre[maxn], preE[maxn], inq[maxn], tl = 0, MinCost = 0,
MaxFlow = 0, s, t;
struct edge {
int v, w, c, nxt, rev;
} E[maxm << 1];
... | 21 |
#include <bits/stdc++.h>
using namespace std;
complex<double> p[1000];
complex<double> u, v;
complex<double> v1, v2;
int n;
double a1, b1, c1;
double a2, b2, c2;
double det, XX1, YY1;
double l[1000];
double uu[1000];
void check() {
p[n + 1] = p[1];
p[0] = p[n];
for (int i = 1; i <= n; ++i) {
complex<double> v... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 100000 + 5;
int a[maxn];
bool vis[maxn];
int ret[maxn];
int pnt[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++)
if (!vis[i]) {
for... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, flag = 0, q, r;
cin >> n;
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> p;
m[i + 1] = p;
}
for (int i = 1; i <= n; i++) {
p = m[i];
q = m[p];
r = m[q];
if (r == i) {
flag = 1;
break;
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, k, win, tot, sm, a[200001], sz[200001];
vector<int> G[200001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> sz[i];
G[a[i]].push_back(i);
}
cin >> q;
while (q--) {
ve... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.