solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 2e5 + 10;
const long long inf = 1e9 + 100;
const double eps = 1;
int n, h[N], l[N], r[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> h[i];
l[1] = 1;
for (int i = 2; i <= n; i++) {
l[i] = min(h[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
int f[5], t[5];
int main() {
int n;
scanf("%d", &n);
int sum = 0;
for (int i = 0; i < n; ++i) {
int foo;
scanf("%d", &foo);
f[foo]++;
sum += foo;
}
int ans = inf;
for (int _4 = 0; _4 * 4 <= sum; ++_4) {
int _3 = sum... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long a[MAXN], ans[MAXN];
int main(void) {
int n, m, k;
cin >> n >> m >> k;
long long l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
a[l]++;
ans[l] += x;
a[r]--;
ans[r + 1] -= x + r - l;
}
long long o... | 8 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int size = 2e5 + 9;
const ll mod = 1e9 + 7;
ll a[size];
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int t = 1;
// cin >> t;
scanf("%d", &... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exponent, long long mod) {
long long ans = 1;
while (exponent) {
if (exponent & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
exponent /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long mask = 2 * 2 * 2 * 3 * 3 * 5 * 7 * 11 * 13;
long long a, b;
long long k;
bool us[mask];
long long ans = 0;
long long step(long long p, long long c) {
long long m = p - 1;
for (int i = 2; i <= k; ++i)
if (p - (p % i) >= c) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct Mat {
static long long MOD;
long long a[2][2];
};
const Mat FIB = {{{1, 1}, {1, 0}}};
const Mat SUM = {{{3, -1}, {0, 1}}};
long long Mat::MOD;
Mat operator*(const Mat& lhs, const Mat& rhs) {
Mat ret;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++... | 18 |
#include <bits/stdc++.h>
int a[1000 + 1][1000 + 1];
int origr[1000 + 1], origc[1000 + 1];
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
int main() {
int i, j;
int n, m, k;
int x, y;
char c;
scanf("%d %d %d", &n, &m, &k);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++) scanf("%d", &a... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long b, d, s, mn, mx, ans = 0;
cin >> b >> d >> s;
mn = min(b, d);
mn = min(mn, s);
b -= mn;
d -= mn;
s -= mn;
mx = max(b, d);
mx = max(mx, s);
if ((mx == b) && (mx != 0)) {
b--;
ans = (b - s) + (b - d);
}
if ((mx == d) && (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 32 * 50010;
const int INF = 0x3f3f3f3f;
int main() {
set<int> s;
int n, x;
cin >> n;
while (n--) {
cin >> x;
s.insert(x);
}
for (;;) {
x = *s.rbegin();
while (x) {
x /= 2;
if (!s.count(x)) bre... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[300000];
long long int m[31][2], x, r;
void s(int d, vector<int> v) {
if (d < 0 or !v.size()) return;
int c[2] = {0, 0};
vector<int> p[2];
for (int i : v) {
int b = !!((1 << d) & a[i]);
c[b]++;
p[b].push_back(i);
m[d][b] += c[!b];
}
s(d - 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int winner;
int remains;
};
void answer(node* tree, int* ans, int s, int e, int current) {
if (s == e) {
ans[s - 1] = tree[current].winner;
return;
}
int mid = (s + e) / 2;
answer(tree, ans, s, mid, 2 * current);
answer(tree, ans, mid + 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e3 + 7;
const int MOD = 1e9 + 7;
int n;
int dp[34][2][2][2];
int sum[34][2][2][2];
int x, y, k;
int dfs(int pos, int limx, int limy, int limk, int &t) {
if (pos == -1) return 1;
int &st = sum[pos][limx][limy][limk];
if (~dp[p... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int MX = 100005;
int n, m, x, c[MX];
int dp[1 << 20][22];
int sum[1 << 20][22];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
for (in... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct ppp {
string a, b;
void read() { cin >> a >> b; }
} ori[40];
int n, m;
map<string, int> ma;
queue<string> que;
int main() {
while (cin >> n >> m) {
ma.clear();
for (int i = 1; i <= m; i++) ori[i].read();
que.push("a");
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
for (int j = 1; j <= n; j++) {
for (int i = 0; i < n / 2; i++) {
cout << j + i * n << " ";
}
int i;
for (i = 1; i < n / 2; i++) {
cout << n * n - (n / 2 - i) * n - j + 1 << " ";
}
cout << n * n - (n / 2 -... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
struct comp {
bool operator()(string a, string b) { return a > b; }
};
int main() {
ios_base::sync_with_stdio(false);
int n;
string s;
priority_queue<string, vector<string>, comp> p... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, cost[100001];
vector<int> links[100001];
bool visited[100001] = {0};
long long answer = 0;
int mincost;
void dfs(int in) {
if (!visited[in]) {
visited[in] = true;
mincost = min(mincost, cost[in]);
for (int i : links[in]) dfs(i);
}
}
int main() {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[500010];
void rd(int &x) {
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
}
int main() {
rd(n);
for (int i = 1; i <= n; ++i) rd(a[i]);
so... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(0));
struct Node {
vector<Node *> go;
Node() { go.assign(26, nullptr); };
};
const int MAXN = 300005;
char c[MAXN];
const int r = 10;
int a[MAXN];
Node *roots[MAXN];
int num = 0;
int dif[MAXN];
int add[MAXN];
int sz[MAXN];
Node *reroot(Node *v, char t) ... | 16 |
#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 fpow(long long a, long long b, long long mod) {
long long res = 1ll;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
vector<ll> a(N), ans(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
ll ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 100 * 3 + 10;
int a[MAXN];
int cnt[MAXN];
long long int mod = 1000 * 1000 * 1000 + 7;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, q;
cin >> n >> q;
a[0] = 1;
a[n + 1] = 1;
for (int i = 1; i <= n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int c, p, id, sol;
} a[1005];
struct node1 {
int r, id;
} b[1005];
int r[1005];
bool cmp(node x, node y) {
if (x.p == y.p) return x.c < y.c;
return x.p > y.p;
}
bool cmp1(node1 x, node1 y) { return x.r < y.r; }
int main() {
int n, k;
scanf("%d", &n... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
long long n, a, b, c, w, ans[N];
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> w;
ans[i] = (w * a % b) / a;
}
for (int i = 1; i < n; i++) cout << ans[i] << " ";
cout << ans[n] << endl;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c;
cin >> a >> b >> c;
if (c != 0) {
if (c > 0) {
if (b > a) {
long long int n = (b - a) / c;
if (c * n == b - a)
cout << "YES";
else
cout << "NO";
} else if (b < a) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 2) {
cout << 2;
} else {
cout << 1;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
vector<T> &operator--(vector<T> &v) {
for (auto &i : v) --i;
return v;
}
template <typename T>
vector<T> &operator++(vector<T> &v) {
for (auto &i : v) ++i;
return v;
}
template <typename T>
istream ... | 24 |
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ll long long
#define PII pair<int,int>
#define iter set<int>::iterator
#define sz(x) (int)(x.size())
#define pb push_back
#define mk make_pair
#define rd (rand())
#define gc getchar()
//#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 0.000000001;
const double pi = 3.141592653589;
const long long mod = 1000000007;
long long gcd(long long a, long long b) {
if (a > b) swap(a, b);
while (a != 0 && b != 0) {
b %= a;
swap(a, b);
}
return a + b;
}
long long poww(long lon... | 8 |
#include <bits/stdc++.h>
int N, M, i, j, Ans = 1000000, E;
char s[60][60];
int d[2550], f[2550], son[2550], Q[100000];
int ed[10050], cost[10050], next[10050];
void Spfa(int x) {
int i, j, k, l, r, Max = 0;
memset(d, 33, sizeof(d));
memset(f, 0, sizeof(f));
f[x] = 1, Q[1] = x, d[x] = 1;
for (l = 0, r = 1; l <... | 18 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, b, p;
cin >> n >> b >> p;
long long x = (n - 1) * (2 * b + 1);
long long y = n * p;
cout << x << " " << y << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fastio();
int i, a, b, t, n, l, r, x;
cin >> t;
while (t--) {
cin >> n;
int a[n + 5];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> v;
for (i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int b[1000005];
int main() {
int n, i;
bool c = true;
vector<int> vt;
cin >> n;
for (i = 0; i < n; i++) {
int v;
cin >> v;
if (b[v] == 0 && v <= n) {
b[v] = 44;
a[i] = v;
}
}
for (i = 1; i <= n; i++) {
if (b[i] =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000000 + 7;
long long fact[10001], tcaf[10001];
long long delta[2001][2001];
long long well[2001][2001], cyl[2001];
long long deg(long long x, int d) {
if (d == 0) {
return 1;
}
long long y = deg(x, d / 2);
y *= y;
y %= P;
if (d % 2) ... | 16 |
#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 1;
const long long MOD = 1e9 + 7;
vector<int> euler, g[MAX], g1[MAX];
bool v[MAX], v1[MAX];
int cnt = 0;
void dfs(int cur) {
v[cur] = true;
for (int nxt : g[cur]) {
if (!v[nxt]) {
dfs(nxt);
}
}
euler.push_back(cur);
}
void dfs1(in... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int Max = 1e5 + 10;
long long dp[Max][2];
vector<int> N[Max];
void DFS(int v) {
long long left[2] = {0, 1};
long long bad[3] = {1, 0, 1};
for (int u : N[v]) {
DFS(u);
long long tmpl[2] = {0, 0};
long long tmpb[3] = {0, 0, 0};... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
while (n % 3 == 0) {
n /= 3;
}
cout << ((n / 3) + 1) << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
short H[1 << 17];
int W;
struct DSU {
short *C, *X, *Y;
int gc(int a) { return C[a] = (a == C[a] ? a : gc(C[a])); }
bool con(int a, int b) {
if (gc(a) == gc(b)) return 0;
X[gc(a)] = mi... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, i = 0, t = 0, d = 0, ans1 = 0, ans2 = 0;
cin >> n;
int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] % 2 == 0) {
t++;
ans1 = i + 1;
} else if (arr[i] % 2 == 1) {
d++;
ans2 = i + 1;
}
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, c = 0, maxi = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
c = c + 1;
} else {
if (c > maxi) {
maxi = c;
}
c = 0;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void rd(T& x) {
int f = 0, c;
while (!isdigit(c = getchar())) f ^= !(c ^ 45);
x = (c & 15);
while (isdigit(c = getchar())) x = x * 10 + (c & 15);
if (f) x = -x;
}
template <typename T>
void pt(T x, int c = -1) {
if (x < 0) putchar('-'), x =... | 18 |
#include <bits/stdc++.h>
using namespace std;
int r[25][6] = {
{0, 0, 0, 0, 0, 0}, {1, 2, 3, 4, 5, 6}, {1, 2, 4, 5, 6, 3},
{1, 2, 5, 6, 3, 4}, {1, 2, 6, 3, 4, 5}, {2, 1, 5, 4, 3, 6},
{2, 1, 4, 3, 6, 5}, {2, 1, 3, 6, 5, 4}, {2, 1, 6, 5, 4, 3},
{5, 3, 1, 4, 2, 6}, {5, 3, 4, 2, 6, 1}, {5, 3, 2, 6, 1, 4},
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 500005;
long long a[maxn], sum[maxn], b[maxn], k, n, sum1[maxn], rr, qq[maxn];
inline long long read() {
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
printf("%d\n", ((a + b) % n + n - 1) % n + 1);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
const int mod = 1e9 + 7;
int a[500005], freq[10000005], pot[500005], qtd[10000005];
bool flag[10000005], bad[10000005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
int root = sqrt(a[i]), x = ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
long long n, m, k;
vector<int> data;
cin >> n >> m >> k;
for (int i = 0; i < (int)(n); ++i) {
int d;
cin >> d;
data.push_back(d);
}
if (n == 1) {
cout << min<long long>(data[0], m * k);
return 0;
}
if ((... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, a[123456], f, ans;
int mm[323456];
int main() {
scanf("%d", &n);
printf("%d ", 1);
f = n - 1;
m = 1;
for (int i = 0; i < n; i++) {
scanf("%d", &k);
k--;
m++;
mm[k] = 1;
if (k == f) {
for (int j = f; j >= 0; j--) {
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 0x7fffffff;
long long p[N];
vector<long long> v[N];
int main() {
long long a[50];
a[0] = 1;
for (int i = 1; i < 32; i++) a[i] = a[i - 1] * 2;
int n;
scanf("%d", &n);
set<long long> s;
for (int i = 0; i < n; i++) {
sca... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long d = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120;
d = d * 120 * d;
cout << d;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
struct BigNumber {
int s[maxn], siz;
int &operator[](int x) { return s[x]; }
} A, B[maxn];
char str[maxn];
int n, m, c[maxn], g[maxn], ss[maxn];
int f[maxn][maxn], sa[maxn][maxn];
void get(BigNumber &A) {
scanf("%s", str);
while (str[A.siz]) +... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, cnt = 0;
cin >> n >> m;
while (1) {
if (m % 3 == 0 && (m / 3) % n == 0) {
m /= 3;
cnt++;
} else if (m % 2 == 0 && (m / 2) % n == 0) {
m /= 2;
cnt++;
} else if (m == n)
break;
else {
cout << -1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum = sum + arr[i] * (i + 1);
}
cout << sum;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int t, n, m, k, h[110];
template <class T>
inline void read(T &x) {
x = 0;
char ch = getchar(), w = 0;
while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = w ? -x : x;
return;
}
int ma... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5;
const int MOD = 1e9 + 7;
struct node_t {
int sum;
int sum2;
int lazy;
node_t operator+(const node_t &other) const {
node_t ans;
ans.sum = (this->sum + other.sum) % MOD;
ans.sum2 = (this->sum2 + other.sum2) % MOD;
ans.lazy = 0;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c;
cin >> r >> c;
char s[r + 1][c + 1];
int flag = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) cin >> s[i][j];
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if ((j != c) && s[i][j] == 'S' &... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = 80;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
struct edge {
int go, cost, f, c;
};
int edges;
int a[N + 2][N + 2], num[N + 2][N + 2];
int first[... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> dp(300005, 0);
long long int x = INT_MIN;
int k = 0;
long long int t_sort(vector<long long int> list[], vector<long long int> &arr,
int parent, int idex, int flag) {
dp[idex] = arr[idex];
for (int i = 0; i < list[idex].size(); ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int len = 3e5 + 10;
const double pi = acos(-1.0);
const long long mod = 998244353;
const int inf = 0x3f3f3f3f;
const int maxn = 1e9 + 5;
long long a[len];
long long sum[len];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool visited[100005];
bool lvl[100005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, p;
cin >> n;
for (int i = 2; i <= n; i++) {
cin >> p;
adj[p].push_back(i);
adj[i].push_back(p);
}
int maxl = 0;
queue<p... | 7 |
#include <bits/stdc++.h>
using namespace std;
int tt = 0, N, sum[3][2501][51] = {0};
long long curr, ans = 0, dp[51][51][51][3] = {0}, comb[51][51][51], fact[51];
vector<int> inp[3];
vector<pair<long long, long long> > optisum[3][2501];
long long mod = 1000000007LL;
int main() {
int i, j, k, m, t, g, first, second, z... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, now = 1;
void solve(int m) {
if (m == 1) {
printf("%d\n", now);
return;
}
if (m == 2) {
printf("%d %d\n", now, 2 * now);
return;
}
if (m == 3) {
printf("%d %d %d\n", now, now, 3 * now);
return;
}
for (int i = 0; i < (m + 1) / 2; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 12;
const long long Inf = 1e18 + 12;
template <typename T>
void alert(const T& t) {
cout << t << endl;
exit(0);
}
const int MOD = 1e9 + 7;
int main() {
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n, k;
cin >> ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
char c;
bool ok = false;
vector<int> calc, v;
int l = 0, remind = 0, up = 0, stay = 0;
void gg() {
for (int i = 0; i < v.size(); ++i) cout << v[i];
if (remind == 1) return;
cout << '.';
for (int i = 0; i < calc.size(); ++i) {
if (calc[i] == -1) break;
... | 9 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int mod = 998244353;
ll fpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
ll inv(ll x) { return fpow(x, mod - 2); }
ll C(ll n, ll m) {
if (n < m) return ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long mod = 1e9 + 7;
int T;
int main() {
std::ios::sync_with_stdio(0);
;
cin >> T;
while (T--) {
long long n, k, d1, d2;
cin >> n >> k >> d1 >> d2;
long long h = n - k;
long long t = h;
long long a, b, c;
b = 0;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct noder {
long long a, b, id;
} num[100050];
int cmp(noder a, noder b) { return a.a > b.a; }
int main() {
long long n, i;
scanf("%lld", &n);
for (i = 0; i < n; i++) {
scanf("%lld", &num[i].a);
num[i].id = i + 1;
}
for (i = 0; i < n; i++) scanf("%lld... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int kd, x, y, z;
node() {}
node(int _kd, int _x, int _y, int _z) { kd = _kd, x = _x, y = _y, z = _z; }
} r[150];
int n, m, q;
long long f[13][1 << 13];
bool ok(int m1, int rt, int m2, int ch) {
for (int i = 1; i <= m + q; i++) {
int x = r[i].x, y =... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(0);
int i;
cin >> i;
string s;
cin >> s;
string rv;
rv.push_back(s[0]);
vector<bool> vowels(26, false);
vowels['a' - 'a'] = true;
vowels['e' - 'a'] = true;
vowels['i' - 'a'] = true;
vowels['o' -... | 0 |
#include <bits/stdc++.h>
using namespace std;
int T, H = 0, i;
int main() {
cin >> T;
int A[T];
for (i = 0; i < T; i++) {
cin >> A[i];
}
sort(A, A + T);
for (i = 1; i < T; i++) {
while (A[i] <= A[i - 1]) {
A[i]++;
H++;
}
}
cout << H << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout << std::setprecision(8) << std::fixed;
int n, i, ans = 0;
double s = 0, a[111], p;
p = 40.0 / 9.0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
sort(a, a + n... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a[105];
int p, z, sum;
cin >> t;
while (t--) {
cin >> n;
z = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] == 0) z++;
}
if ((sum + z) == 0) z++;
cout << z << endl;
}
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie();
long long n;
cin >> n;
int res = 0;
bool x = false;
while (true) {
bool flag = false;
long long k;
for (long long i = 1; i < n; i++) {
k = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long me(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string a, b, r;
cin >> a >> b;
vector<char> v;
v.assign(a.begin(), a.end());
sort(v.begin(), v.end());
int i;
for (i = 0; i != v.size() && v[i] == '0'; ++i)
;
if (i != v.size()) swap(v[0], v[i]);
r.append(v.begin(), v.end());
if (r =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, i, n, b[102], temp = 0, tpos, pos, min1 = INT_MAX, j, c;
cin >> a;
for (i = 0; i < a; i++) {
cin >> b[i];
}
for (i = 0; i < a; i++) {
for (j = 0; j < b[i]; j++) {
cin >> c;
temp += c;
tpos = b[i];
}
temp = temp... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int flags[26] = {0};
string s;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j <= s.size(); j++) {
char ch = s[j];
int c = (int)ch - 97;
flag... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (long long)((1e5) + 100);
long long cuberoot(long long x) {
long long lo = 1, hi = min(2000000ll, x);
while (hi - lo > 1) {
long long mid = (lo + hi) / 2;
if (mid * mid * mid < x) {
lo = mid;
} else
hi = mid;
}
if (hi *... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100004];
int main() {
int n, k, i, cnt = 0, zero;
char s[100];
scanf("%d%d", &n, &k);
for (i = 0; i <= n; i++) {
scanf("%s", s);
if (i == 0) zero = s[0] == '?';
if (s[0] != '?') cnt++;
a[i] = s[0] != '?' ? atoi(s) : 0;
}
if (k == 0) {
p... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct Tree {
int n;
vector<vector<int>> g;
vector<int> sz, pa, depth, sta, fin, tour;
int tim;
Tree(int _n) : n(_n), g(n), sz(n), pa(n, -1), depth(n), sta(n), fin(n) {
tour.reserve(n);
input();
tim = 0;
basic_dfs(0);
build_lca();
}
int L;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
set<long long> s;
for (long long i = 0; i < n * 2; ++i) s.insert(i);
vector<pair<long long, long long>> p;
for (long long i = 0; i < k; ++i) {
long long x, y;
cin >> x >> y;
if (x > y) swap(x, y);
p.p... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
map<int, vector<int>> kit;
for (int i = 0; i < n; i++) {
kit[a[i]].push_... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using piii = pair<int, pii>;
using plll = pair<ll, pll>;
using pib = pair<int, bool>;
using pdi = pair<double, int>;
using pid = pair<int, doubl... | 10 |
#include <bits/stdc++.h>
using namespace std;
int i, n, x, y, z, a, b, c, q;
int main() {
cin >> x >> y >> z >> a >> b >> c;
if (x != 0 && a != 0) {
q = x;
x = x * a * -1;
y = y * a * -1;
z = z * a * -1;
a = a * q;
b = b * q;
c = c * q;
x += a;
y += b;
z += c;
} else if (!(... | 12 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mod = 1e9 + 7;
const int NN = (1 << 7);
char gchar() {
static char tbuf1[1000], *tmp_st = tbuf1, *tmp_ed = tbuf1;
if (tmp_st == tmp_ed) {
int len = fread(tbuf1, 1, 1000, stdin);
if (len == 0) return -1;
tmp_ed = tbuf1 + len;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
static int n, ch;
n = 0, ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
return n;
}
const int MAX_N = 100 + 3;
vector<pair<int, int> > G[MAX_N];
int n, deg[MAX_N], fa[MAX_N], i... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int max_m = 1e5 + 10;
pair<int, int> ans[max_m];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m, v, tot = 0;
cin >> n >> m >> v;
if (m > n - 1 + (n - 2) * (n - 3) / 2 || m < n - 1) {
cout << -1 << endl;
return 0;
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e6 + 10;
const int mod = 1e9 + 7;
const long long int inf = 1LL << 62;
int dx4[] = {0, 0, -1, 1};
int dy4[] = {1, -1, 0, 0};
int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
int main() {
string str, ans;
long long int n, k;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> a;
for (int i = 0; i < (int)n; i++) {
long long x;
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
if (n & 1) {
cout << a[n / 2];
} else {
cout << a[n / 2 - 1];
}
return 0;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
char num[200005];
int n;
int len;
int mod_num(char num[], int n) {
int mod = 0;
for (int i = 0; i < len; i++) {
mod = (mod * 10 + (num[i] - '0')) % n;
}
return mod;
}
long long fastpow(long long base, long long power) {
long long ret = 1;
for (; power; power... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string hate = "I hate";
string love = "I love";
int n;
cin >> n;
if (n == 1) {
cout << hate << " it" << endl;
exit(0);
}
if (n == 2) {
cout << hate << " that " << love << " it" << endl;
exit(0);
}
for (int i = 1; i < n; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10005];
int b[10005];
long long s = 0;
long long r = 0;
int main() {
cin >> n;
cin >> a[1] >> b[1];
if (a[1] == b[1]) s--;
r = 2;
for (int i = 2; i <= n; i++) {
cin >> a[r] >> b[r];
if (a[r] == a[r - 1] && b[r] == b[r - 1]) continue;
if (a... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s;
cin >> s;
int n = s.length();
vector<vector<int>> cnt(n + 1, vector<int>(26));
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) {
cnt[i][j] = c... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct my {
int t, x, i;
};
bool comp(my a, my b) { return a.x < b.x; }
int n, m, now = 0, ans[100011], l;
my a[100011];
int main() {
cin >> n >> m;
while (1) {
int i = 0, ma1 = now, ma2 = 0;
while (i < m && cin >> a[i].t >> a[i].x) {
a[i].i = l;
m... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n, i, j, sum, pos;
string second;
cin >> n;
cin >> second;
sum = 0;
for (i = 0; i < n; i++) {
sum += (second[i] - '0');
... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isPalin(int l, int r, const string &s) {
for (int i = l, j = r; i < j; i++, j--) {
if (s[i] != s[j]) return false;
}
return true;
}
int main() {
string s;
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s;
int ans = -1;
for (int i = 0, j = s.size(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int A[19000] = {0};
int main() {
int a;
cin >> a;
A[0] = 1;
for (int i = 1; i < a; i++) A[i] = A[i - 1] + 6 + 6 * (2 * i - 1);
cout << A[a - 1] << endl;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int t;
vector<double> compoundprob;
double answers[5000][5000];
vector<double> prob;
vector<int> limReagent;
double calcprob(int songindex, int transturn) {
if (compoundprob[songindex] != -1.0 && transturn == limReagent[songindex] - 2)
return compoundprob[songi... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
long long cnt = 0, aux = n;
while (aux != 0) {
cnt += aux % 10 == 0;
if (aux % 10 != 0) break;
aux /= 10;
}
if (cnt >= k)
cout << n << "\n";
else {
long lo... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.