solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long temp;
long long dp[100001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
long long a, b, x;
cin >> a;
cin >> b;
for (int i = 0; i < n; i++) {
cin >> x;
cout << (((x % b) * (a % b)) % b) / a << " "... | 3 |
#include <bits/stdc++.h>
using namespace std;
char buf[2048], *_s = buf + 2048;
inline char getc1(void) {
if (_s >= buf + 2048) {
fread(buf, 1, 2048, stdin);
_s = buf;
}
return *(_s++);
}
inline int readint() {
char t = getc1();
int n = 1, res = 0;
while (t != '-' && !isdigit(t)) t = getc1();
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long mod = 1e9 + 7;
int n;
long long value[MAXN];
vector<int> graph[MAXN];
long long pathSum, pathCnt;
long long currSum, currCnt;
bool isCentroid[MAXN];
int treeSize[MAXN];
long long answer = 0;
long long cnt[MAXN], sum[MAXN];
void DFSI... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, a[26] = {0}, b[100005];
string s, ans;
cin >> n;
cin >> s;
for (i = 0; i < s.length(); i++) {
a[s[i] - 'a']++;
}
j = 0;
for (i = 0; i < a['n' - 'a']; i++) {
b[j++] = 1;
}
for (i = 0; i < a['z' - 'a']; i++) {
b[j++] =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int n;
int a[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
long long res = 0;
for (int i = 0; i < n / 2; i++) {
res += (long long)(a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1])... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
int k = 0;
int s = 0;
int a[x];
for (int i = 0; i < x; i++) {
cin >> a[i];
if (a[i] < 0) {
k++;
}
s = s + a[i];
}
if (k == y) {
int m = 0;
for (int i = 0; i < x; i++) {
m = m + abs(a[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[k - 1] != s[0]) {
cout << s[k - 1] << endl;
} else {
if (s[k] == s[n - 1]) {
cout << s[0];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, dr, st, i, p;
int main() {
cin >> n >> m >> k;
if (n == 1)
cout << m;
else if (n == m)
cout << "1";
else {
p = m - n;
i = 1;
dr = k;
st = k;
while (p > 0) {
if (dr - st + 1 <= p) {
i++;
p -= dr - st + 1;... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, ans = "";
cin >> a >> b;
for (int i = 0; i < a.length(); i++) ans += (a[i] == b[i] ? '0' : '1');
cout << ans;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cou... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, k;
int x, y, z;
cin >> n;
while (n--) {
k = 0;
cin >> x >> y >> z;
cout << max(0, min(z + 1, (x + z + 1 - y) / 2)) << '\n';
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int adj[1007][1007];
int step[1007];
int n, m;
void BFS(int k) {
queue<int> q;
q.push(1);
step[1] = 1;
while (q.size()) {
int u = q.front();
q.pop();
for (int v = (1); v <= (n); ++v) {
if (adj[u][v] == k && !step[v]) {
step[v] = step[u] + 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int q;
int par[1000100][20];
int cnt[1000100];
int k1, k2, k3;
int lca(int a, int b) {
int aa = a, bb = b;
if (cnt[a] < cnt[b]) swap(a, b);
int d = cnt[a] - cnt[b];
for (int i = 0; d; i++, d >>= 1) {
if (d & 1) a = par[a][i];
}
for (int i = 19; i >= 0; i--) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int spf[1000001];
void sieve1() {
spf[1] = 1;
for (int i = 2; i < 1000001; i++) spf[i] = i;
for (int i = 4; i < 1000001; i += 2) spf[i] = 2;
for (int i = 3; i * i < 1000001; i++) {
if (spf[i] == i) {
for (int j = i * i; j < 1000001; j += i)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m, q, curcol, col[100010], depth[100010], val[100010], sum[100010],
par[20][100010], parr[100010];
bool vis[100010];
vector<int> g[100010];
int FIND(int pos) {
if (parr[pos] != pos) parr[pos] = FIND(parr[pos]);
return parr[pos];... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
int a[n + 5][m + 5];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = 0;
}
}
int num1 = 0, num2 = 0, num = n * m / 2, t = 1;... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
int x, y;
cin >> n >> m >> x >> y;
cout << x << " " << y << "\n";
cout << 1 << " " << y << "\n";
vector<pair<int, int>> v;
int z = 1;
for (int i = 1; i <= n; i++) {
vector<pair<int, int>> te;
for (int j = 1; j <= m; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
;
if (t == '-') neg = true, t = getchar();
if (t == EOF) return false;
for (; t <= '9' && t >= '0'; ... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
int x, y;
pt(int x = 0, int y = 0) : x(x), y(y) {}
} v[200100];
bool cmp(pt a, pt b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
int main() {
int n, k;
while (scanf("%d%d", &n, &k) == 2) {
for (int i = 0; i < (int)(n); i++) scanf("%d%... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct AC {
static const int MAX_N = 1e3 + 3;
int n;
int W[MAX_N][MAX_N];
vector<int> G[MAX_N];
vector<pair<int, int>> NG[MAX_N];
vector<tuple<int, int, int>> ans;
int root;
void add_edge(int u, int v, int w) {
G[u].emplace_back(v);
G[v].emplace_back... | 8 |
#include <bits/stdc++.h>
using namespace std;
int H, W;
int L[20], R[20];
int dp[20][2];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> H >> W;
W += 2;
int last = -1;
for (y = 0; y < (H); y++) {
cin >> s;
L[H - 1 - y] = R[H - 1 - y] = -1;
for (x = 0; x < (W); x++)
if (s[x] == '1'... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct sofa {
int x1, y1, x2, y2;
};
sofa arr[100005];
int lof[100005];
int rof[100005];
int tof[100005];
int bof[100005];
int main() {
int d;
int n, m;
cin >> d;
cin >> n >> m;
for (int i = 0; i < 1e5; i++) {
lof[i] = rof[i] = tof[i] = bof[i] = 0;
}
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a[3], cnt = 0;
for (long long i = 0; i < 3; i++) cin >> a[i];
long long meals = max(a[0], max(a[1], a[2]));
for (long long i = 0; i < 3; i++) {
if (a[i] == meals) continue;
if ((meals - 1) - a[i] > 0) cnt += (meals - 1) - a[i];
}
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
const int LOG = 20;
int n, m, len, tot;
int head[MAXN], root[MAXN], vis[MAXN], son[MAXN], size[MAXN], dep[MAXN],
f[MAXN][LOG], ans[MAXN], cnt[MAXN];
struct Edge {
int to, next;
} e[MAXN << 1];
struct Query {
int ... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int n, m, t;
int xl[100], yl[100], xr[100], yr[100], nt, area[100];
char s[1100][1100];
int lt[1100][1100];
int up[1100][1100];
int dw[1100][1100];
int p[1100][1100];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
bool used[1... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int maxn = (int)1e5 + 10;
int v[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
}
sort(v, v + n);
long long ans = 0;
int mod = 10007;
for (int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 10;
struct radio {
int x, r, f;
radio() { x = r = f = 0; }
bool operator<(const radio &other) const {
if (f != other.f) return f < other.f;
return x < other.x;
}
};
int n, k;
radio a[nmax];
int fen[nmax];
vector<int> val;
void fen_upda... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1550, INF = 0x3f3f3f3f, MAX_S = 1e7 + 200;
int n, start_pos, end_pos, head[MAX_N], current, dep[MAX_N], cur[MAX_N],
ptot = 1;
int ch[MAX_S][2], fail[MAX_S], tag[MAX_S], pos[MAX_N], fa[MAX_S];
bool mp[755][755];
char str[MAX_S];
struct edge {
int to, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
set<int> s[N];
int pfactor[N];
vector<int> fact(int n) {
vector<int> v;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
v.emplace_back(i);
if (n / i != i) {
v.emplace_back(n / i);
}
}
}
if (n != 1) v.empl... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[1000000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i < n + 1; i += 1) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int l = 1, r = n;
for (int i = n; i > 0; --i)
if (a[i] == a[r])
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, p[200001], base = 419, mod = 1e9 + 7;
string s;
vector<int> ch[26], sum[26];
int powlog(int a, int b) {
if (b == 0) return 1;
int ret = powlog(a, b / 2);
if (b % 2) return 1LL * ret * ret % mod * a % mod;
return 1LL * ret * ret % mod;
}
int main() {
ios_... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N;
char c[3000][3000];
int color[3000][3000];
int row[3000];
int col[3000];
int main() {
scanf("%d", &N);
for (int Ni = 0; Ni < N; Ni++) scanf("%s", c[Ni]);
for (int Ni = 0; Ni < N; Ni++)
for (int Nj = 0; Nj < N; Nj++) color[Ni][Nj] = c[Ni][Nj] - '0';
int cn... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int M = 100500;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
pair<int, int> p[M];
bool nw[M];
char c[N][N];
int n, m, k, col, ans, sz[M], u[N][N];
bool in(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); }
void ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, s;
cin >> s;
cin >> a >> b;
int A, B, A1 = 0, B1 = 0;
swap(a[0], a[1]);
if (a[0] == s[0]) A1 = 1000000007;
if (a[1] >= '6' && a[1] <= '9')
A = a[1] - '0';
else if (a[1] == 'T')
A = 10;
else if (a[1] == 'J')
A = 11;
e... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long MAXVAL = 1e12;
const int MAXN = 1e6;
const int MAXM = 4096;
const int MAXP = 78498;
const int MAXPP = 80070;
bool mark[MAXN + 1];
int pf[MAXP + 1];
long long pf_power[MAXPP + 1];
map<long long, int> rt;
map<long long, int> rem;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, t, a, b, da, db, i, k;
cin >> x >> t >> a >> b >> da >> db;
int pointsa[t + 1], bpoints[t + 1];
pointsa[t] = 0;
bpoints[t] = 0;
for (i = 0; i < t; i++) {
pointsa[i] = a - da * i;
bpoints[i] = b - db * i;
}
for (i = 0; i <= t; i++)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[5000], v[3][5000], a = 0, b = 0, c = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
if (arr[i] == 1) {
v[0][a] = i;
a++;
} else if (arr[i] == 2) {
v[1][b] = i;
b... | 0 |
#include <bits/stdc++.h>
int n, len = 0, w = 0;
std::string t;
char s[200];
std::map<std::string, int> mp;
int eval(int l, int r) {
for (int i = r, w = 0; i > l; i--)
if (w += (s[i] == ')'), w -= (s[i] == '('),
!w && (s[i] == '-' || s[i] == '+')) {
int L = eval(l, i - 1), R = eval(i + 1, r);
r... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &x, const T &y) {
if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
if (x > y) x = y;
}
const long long MAXN = (1 << 20);
long long n, m, a, d;
long long t[MAXN];
void read() {
cin >> n >> m >> a >> d... | 7 |
#include <bits/stdc++.h>
using namespace std;
int d, e, i, k, l, c, m, a[100], b[100], f, j, t, q, z, p, m1, m2, m3, m4;
int main(int argc, char *argv[]) {
cin >> d >> e;
while (e > 0) {
c = e % 10;
m++;
b[m] = c;
e = e / 10;
}
for (i = 1; i <= m; i++) {
if (b[i] == 4) m1++;
if (b[i] == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 2... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000010], A, B, n, l, t, m;
long long get(int x) { return A + B * (x - 1); }
long long getnum(int x) {
long long sum = 0;
sum = (get(l) * (x - l + 1) + (x - l + 1) * (x - l) * 0.5 * B);
return sum;
}
int main() {
while (~scanf("%I64d %I64d %I64d", &A, &B... | 5 |
#include <bits/stdc++.h>
using namespace std;
int const MAXn = 2e5 + 2;
int mat[4][4];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k;
cin >> k;
int i = 1;
while (i <= 300000) i *= 2;
i /= 2;
i--;
mat[1][1] = i;
mat[3][3] = i;
int y = (k ^ i);
mat[1][2] = mat[2][3] =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 330000;
const int MAXB = 20;
int a[MAXN], b[MAXB];
int f[MAXN][MAXB];
int main() {
int n, q;
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 0; i < 19; i++) b[i] = f[n + 1][i] = n + 1;
for (int i = n; i >= 1; i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, a[1001], kid[200001], k, l, sum, ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
sum = a[i] + a[j];... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long t, ans, med, tmp, n, m, k;
int main() {
cin >> n >> m >> k;
if (n > m) swap(n, m);
ans = min(((n * 2) + (m * 2)), n + m + k);
ans = min(ans, (n + n + k + k));
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, i, j, l, a[N], f[N][N];
int main() {
scanf("%d", &n);
memset(f, 0, sizeof(f));
for (i = 1; i <= n; i++) scanf("%d", &a[i]), f[i][i] = 1;
for (i = 2; i <= n; i++)
for (j = 1; i + j - 1 <= n; j++) {
f[j][i + j - 1] = f[j + 1][i + j ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int b[n];
for (int i = 0; i < n; i++) cin >> b[i];
int a[n];
a[0] = b[0];
int j = 0;
int c = a[0];
while (j < n - 1) {
a[j + 1] = b[j + 1] + c;
c = max(c, a[j + 1]);
j++;
}
for (int i = 0; i < n; i++) {
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int c = 0;
int c2 = 0;
cin >> str;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '0' || str[i] == '1') {
c++;
if (str[i] == '1') {
c = 0;
}
if (c == 7) {
cout << "YES" << endl;
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string Arr, Brr;
int larr, lbrr;
cin >> Arr >> Brr;
larr = Arr.size();
lbrr = Brr.size();
if (larr != lbrr)
cout << "NO" << endl;
else {
bool p = true;
for (int i = 0; i < larr; i++) {
if ((Arr[i] == 'a' || Arr[i] == 'e' || Arr[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
int p = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') p = -p;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar();
x = x * p;
}
const int ma... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, N;
while (cin >> A >> B >> N) {
int res;
bool flag = false;
for (int i = -1000; i <= 1000; i++) {
if (fabs((double)A * pow(double(i), N) - double(B)) < 1e-11) {
flag = true;
res = i;
break;
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
vector<int> cand;
int prime[1000005];
void SieveOfEratosthenes(int n) {
memset(prime, 0, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == 0) {
for (int i = p * p; i <= n; i += p) prime[i] = p;
}
}
}
long long power(long lon... | 4 |
#include <bits/stdc++.h>
void gen(int diff) {
for (int i = 0; i < 1000; i++) {
putchar('.');
}
putchar('\n');
for (int i = 0; i < 1000; i++) {
if (i % 2 == 0 && i / 2 < diff) {
putchar('X');
} else {
putchar('.');
}
}
putchar('\n');
for (int i = 0; i < 1000; i++) {
if (i ==... | 7 |
#include <bits/stdc++.h>
int main() {
using namespace std;
long long int sum = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int g;
cin >> g;
sum += g;
}
if (sum % n == 0) {
cout << n << endl;
} else {
cout << n - 1 << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 8;
char arr[8][8];
bool if_all_black() {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (arr[i][j] != 'B') return false;
}
}
return true;
}
int column_black() {
int cnt = 0;
for (int i = 0; i < N; ++i) {
bool bol = t... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
long long a, b;
scanf("%d", &tc);
for (int i = 1; i <= tc; i++) {
scanf("%lld %lld", &a, &b);
long long val = a * b;
long long cube_root = round(cbrt(val));
if (cube_root * cube_root * cube_root == val && a % cube_root == 0 &&
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pp(T v) {
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
cout << *it << ' ';
cout << endl;
}
template <class T>
void pp(T v, int n) {
for (int i = 0; i < (int)n; i++) cout << v[i] << ' ';
cout << endl;
}
const int INF... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dp[200001][5];
vector<vector<int>> g;
int dfs(int s, int p, int d) {
if (dp[s][d] == -1) {
int ans = 0;
if (d == 0 || d == 1) {
for (auto it : g[s]) {
if (it != p) ans += dfs(it, s, d + 1);
}
}
if (d == 2) {
int lans = 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, m, b, mode;
long long a[N], dp[N][N];
int main() {
scanf("%d %d %d %d", &n, &m, &b, &mode);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
for (int k = ... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define imax 0x3f3f3f3f
#define lmax 0x3f3f3f3f3f3f3f3f
void swap(ll* a, ll* b) {
int swapp = *a;
*a = *b;
*b = swapp;
}
ll max(ll a, ll b) {
if (a > b) return a;
return b;
}
ll min(ll a, ll b) {
if (a < b) return a;
return b... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = 1;
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
if (f) x = -x;
}
template <typename F>
inline void write(F x) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a;
cin >> n >> m >> a;
n = ((n % a) ? (1) : (0)) + n / a;
m = ((m % a) ? (1) : (0)) + m / a;
cout << m * n << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
long long lim;
long long M, A, B;
long long cur = 1, ans = 0;
bool vis[MAXN];
long long gcd(long long a, long long b) {
while (a % b) {
a %= b;
swap(a, b);
}
return b;
}
long long gsum(long long N, long long g) {
long long ans = N +... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
point() {}
point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
return a * a;
}
template <class T>
T power(T n, T p) {
T res = 1;
for (int i = 0; i < p; i++) res *= n;
return res;
}
template <class T>
double getdist... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
inline long long power(long long a, long long b) {
long long x = 1;
a = a % 1000000007ULL;
while (b) {
if (b & 1) x = (x * a) % 1000000007ULL;
a = (a * a) % 1000000007ULL;
b >>= 1;
}
return x;
}
inline long long inv(long long a) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void swap(int& a, int& b) {
int c = a;
a = b;
b = c;
}
int main() {
int n;
cin >> n;
int a[100];
int max = 0, min = 0, cmax = 0, cmin = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i == 0)
min = a[i];
else {
if (a[i] <= min) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
double h[N];
int sz[N];
int main() {
int n, t = 0;
scanf("%d", &n);
for (auto i = (1); i <= (n); ++i) {
int x;
scanf("%d", &x);
h[++t] = x;
sz[t] = 1;
while (t > 1 && h[t] <= h[t - 1]) {
h[t - 1] = (h[t] * sz[t] + h[t ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
int dp[1000];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == 'V' && s[i + 1] == 'K') {
count++;
dp[i] = 7;
dp[i + 1] = 7;
i = i + 1;
} else if (s[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int m) {
bool f = true;
if (m == 2) return f;
if (m == 1) return !f;
int i = 2;
while (i * i <= m) {
if (m % i++ == 0) {
f = false;
break;
}
}
return f;
}
void my_print(int n, int x, int y) {
for (int i = 1; i <= n; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int arr[300000][8];
int n, m;
int a, b;
void bin_search(int lb, int ub) {
int pos[256];
if (ub - lb < 2) {
return;
}
int next;
next = (lb + ub) / 2;
memset(pos, -1, sizeof(pos));
for (int i = 0; i < n; i++) {
int mask = 0;
for (int j = 0; j < m; j+... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const double pi = acos(-1.0), eps = 1e-6;
void File() {
freopen("D:\\in.txt", "r", stdin);
freopen("D:\\out.txt", "w", stdout);
}
template <class T>
inline void read(T &x) {
char c = getchar();
x = 0;
while (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n, b, c = 0;
cin >> n;
stack<long long> s;
map<long long, long long> ma;
queue<long long> q;
for (long long i = 0; i < n; i++) {
cin >> b;
q.push(b);
}
for (l... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 + 9e6;
const int inf = 0x3f3f3f;
vector<bool> dp[24];
int n;
int a[23];
vector<pair<int, int> > pre[23];
int ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long const MX = 90;
long long t, fib[MX];
bool used[MX];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
fib[0] = 1;
fib[1] = 2;
for (long long i = 2; i < MX; i++) fib[i] = fib[i - 1] + fib[i - 2];
while (t--) {
long... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, x, p[55], a[55][55];
int cnt[55], q;
bool s = 1;
void solve1() {
cin >> n;
for (int i = 1; i <= n; i++) {
q = 0;
for (int j = 1; j <= n; j++) {
cin >> x;
q = max(q, x);
}
if (q == n - 1) {
if (s) {
q = n;
s = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n;
long long s, cntv[30];
long long Pow(long long x, long long p) {
long long rnt = 1;
while (p) {
if (p & 1) rnt = rnt * x % MOD;
x = x * x % MOD;
p >>= 1;
}
return rnt;
}
long long Inv(long long x) {
return x == 1 ? 1 : I... | 7 |
#include <bits/stdc++.h>
using namespace std;
void da(int *a, int s, int e) {
for (int i = s; i < e; i++) cout << a[i] << " ";
}
void db(string s) { cout << s << '\n'; }
void cp(int *a, int *b, int n) {
for (int i = 0; i < n; i++) b[i] = a[i];
}
void de(int a) { cout << a << " <\n"; }
const long long N = 1e5 + 10, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[200000];
char n[128];
char str1[10], str2[10];
int j, m, len;
while (scanf("%d%d", &len, &m) != EOF) {
scanf("%s", str);
for (int i = 97; i <= 122; i++) {
n[i] = i;
}
for (int i = 1; i <= m; i++) {
scanf("%s%s", st... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long arr[k + 1];
long long c[k + 1];
memset(arr, 0, sizeof(arr));
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
arr[a]++;
}
for (int i = 1; i <= k; i++) cin >> c[i];
long long dea[k + 1];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int g_s[100100];
struct tagst {
int ty;
int tar;
int id;
};
struct tagin {
int t, s, f, id;
bool operator<(const tagin& aa) const { return t < aa.t; }
};
tagin gin[100100];
vector<tagst> g_v[100100];
int g_h;
long long g_ans[100100];
int indWait, iInEle, iReach, w... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 4;
struct Node {
int l, r, val;
Node* lc;
Node* rc;
Node(int l_, int r_) : l(... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int kMaxElement = 1e6;
vector<int> smallest_pf(kMaxElement);
void sieve_of_eratosthenes() {
for (int i = 1; i < kMaxElement; ++i) smallest_pf[i] = (i % 2 ? i : 2);
for (int i = 3; i * i < kMaxElement; i += 2) {
if (smallest_pf[i] != i) continue;
for (int j... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
cin >> test;
while (test--) {
long long n, k, ans = 0;
cin >> n >> k;
while (n) {
ans += (n % k);
if (n >= k) ans++;
n /= k;
}
cout << ans << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
cout << (n + 1) / 2 << "\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, p[16];
long long k;
long long ofmul(long long a, long long b) {
if (a * 1.0 * b > 4e18) {
return 3e18;
}
return a * b;
}
void generisi(vector<int> p, vector<long long>& a) {
set<long long> sk;
sk.insert(1);
long long last = -1;
while (last < 1.1e18)... | 8 |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int main() {
int q = 1;
cin >> q;
while (q--) {
int n;
cin >> n;
vector<int> qu(n, -1), ki(n, -1);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int j = 0; j < x; j++) {
int m;
cin ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, sum;
int main() {
cin >> a >> b;
for (int i = 1; i <= a; i++) {
cin >> n;
if (n > b)
sum += 2;
else
sum++;
}
cout << sum << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
long long int i, j, k, n, m, a, b, c, d, p, q, r, l, x, t = 1;
long long int sum, counted, ans = 0;
string s;
cin >> n;
while (n >= 100) {
n -= 100;
ans++;
}
while (n >= ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const char NL = '\n';
long long int mod = 1000000007;
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void read(vector<long long int> &a) {
for (auto &it : a) cin >> it;
}
struct ele {
long long int val;
long lon... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5050;
const int MOD = 1000000007;
int n, threshold;
short x[MAXN], y[MAXN], dist[MAXN][MAXN];
int mark[MAXN];
bool dfs(int pos, int color = 0) {
if (mark[pos] != -1) return mark[pos] == color;
mark[pos] = color;
for (register int i = (0); i < (int)(n)... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = -1;
long long n, DOS[60], S[60];
long long solve(long long n) {
if (!n) return 0;
int p = 0;
while (DOS[p + 1] <= n) p++;
long long k = DOS[p];
return DOS[p] + (p ? DOS[p - 1] * p : 0) + solve(n - k);
}
int main() {
DOS[0] = 1;
for (int i = (1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].first >> a[i].second;
}
if (n <= 3 || n % 2 == 1) {
cout << "NO\n";
return 0;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, mod = 1e9 + 7;
const int N = 100005;
int i, j, k, n, m, x, y, x2, y2, M;
pair<int, int> ST[4 * N], a[N], b[N];
vector<pair<int, int> > v[N], v2[N];
vector<pair<int, pair<int, int> > > blue;
vector<pair<pair<int, int>, int> > red;
vector<pair<pair<int, p... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
getline(cin, s);
int p = 0;
for (int i = 0; i < s.size(); i++) {
int t = (int)s[i];
int y = 0;
for (int j = 0; j < 8; j++) {
y *= 2;
y += t % 2;
t /= 2;
}
int u = y;
y = (p - y) % 256;
while (y < 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
const double Pi = acos(-1.0);
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int hh, mm, d;
char ch;
while (cin >> hh >> ch >> mm >> d) {
d += mm;
mm = d % 60;
hh += d / 60;
hh %= 24;
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
int v[105];
int main() {
int i, n;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &v[i]);
int l, r;
do {
l = r = -1;
for (i = 1; i < n; i++) {
if (l == -1) {
if (v[i] > v[i + 1]) {
l = i;
swap(v[i], v[i + 1]);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[100001], s[100001], n, d, b, ans;
int main() {
long long i, j, l, r, mid, s1, s2, t1, t2;
scanf("%I64d %I64d %I64d", &n, &d, &b);
for (i = 1; i <= n; i++) scanf("%I64d", &a[i]), s[i] = s[i - 1] + a[i];
l = 1;
r = n;
ans = n + 1;
while (l <= r) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
return x * x;
}
template <c... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.