solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
const int maxn = 1 << 18, mod = 998244353, proot = 3, base = (mod - 1) / maxn,
inv2 = mod + 1 >> 1;
int w[maxn], rw[maxn];
inline int pow_mod(int x, int n) {
int y = 1;
while (n) {
if (n & 1) {
y = 1ll * y * x % mod;
}
x = 1ll * x * x % mod;
n >>= 1;
}
re... | 11 |
#include <bits/stdc++.h>
#pragma GCC target("sse4.2")
using namespace std;
bool home = 1;
signed realMain();
signed main() {
home = 0;
if (home) {
freopen("tony_stark", "r", stdin);
} else {
ios::sync_with_stdio(0);
cin.tie(0);
}
realMain();
}
const long long B = 61;
const long long N = (long long... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
return x * neg;
}
inline void print(int x) {
if (x < 0) {
putchar('-'... | 4 |
#include <bits/stdc++.h>
const double PI = 2 * acos(0.0);
const long long MOD = 1000000007;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
;
long long int n, i, j, index = 0, l, b_size = 0, c_size = 0, flag = 1,
cnt = 0;
string a, b, c;
cin >> a;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
struct P {
int st, len;
bool operator<(const P &A) const {
if (len != A.len) return len < A.len;
return st < A.st;
}
};
struct P2 {
int st, len;
bool operator<(const P2 &A) const { return st < A.st; }
};
int main() {
int... | 6 |
#include <bits/stdc++.h>
using namespace std;
double ans(0);
int n, m;
double qp(double x, int y) {
double s = 1;
while (y > 0) {
if (y % 2 == 1) s = s * x;
y = y >> 1;
x = x * x;
}
return s;
}
int main() {
scanf("%d%d", &m, &n);
double mm = m;
for (int i = m; i; --i) {
ans += i * (qp(i / ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long BIG = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000;
long long c[100][100];
long long m;
int k;
long long get(long long a) {
long long val = 0;
int cur = 0;
for (int i = 62; ~i; --i)
if (a & (1ll << i)) {
if (k >= cur) val += c[i][k - cur];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
void dem() {
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
priority_queue<int> p;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long dp[12];
signed main() {
long long n;
cin >> n;
for (long long i = 1; i <= 9; i++) {
dp[i] = -100000000000000000;
}
for (long long ii = 1; ii <= n; ii++) {
long long cnt;
cin >> cnt;
vector<long long> a[4];
for (long long i = 1; i <= c... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], sum[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int xx = 0;
for (int i = n - 1; i >= 0; i--) {
xx = max(xx, a[i] + 1);
sum[i] = xx;
xx--;
}
long long int ans = 0, cnt = 0;
for (int i... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
double PI = acos(-1);
struct base {
double a, b;
base(double _a = 0.0, double _b = 0.0) : a(_a), b(_b) {}
const base operator+(c... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> graf[2000010];
int gle[2000010];
int P[2000010];
int pod[2000010];
int odl_1;
void dfs(int v) {
pod[v] = 1;
for (auto x : graf[v]) {
if (pod[x] == 0) {
P[x] = v;
gle[x] = gle[v] + 1;
dfs(x);
pod[v] += pod[x];
}
}
}
vo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, sm, mx, mn, res, n;
int a, b;
void read() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> a >> b;
}
void solve() {
i = a;
j = b;
while (i) {
mx = max(mx, i % 10);
i /= 10;
}
while (j) {
mx = max(mx, j % 10);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
node *left, *right;
node() {
left = NULL;
right = NULL;
}
} * root;
void insert(long long int num) {
node *current = root;
for (int i = 63; i >= 0; i--) {
bool bit = num & (1LL << i);
if (bit) {
if (current->right == NULL) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
long long int a, i, j;
map<long long int, long long int> m;
map<long long int, long long int>::iterator o;
cin >> n;
while (n != 0) {
long long int x;
cin >> x;
if (m.find(x) !=... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp &x) {
x = 0;
char c = getchar();
int f = 0;
for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
;
for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
;
if (f) x = -x;
}
const int ... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long long n;
vector<string> a(105);
vector<long long> b(105, 0), c(105, 0);
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a[i];
for (long long j = 0; j < n; j++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 10, cut = 700;
int n, m, k, cnt[mx], lv, x[mx], y[mx], dead[mx];
vector<pair<int, int> > adj[mx];
vector<int> res;
void er(int a, int b) {
auto it = lower_bound(adj[a].begin(), adj[a].end(), make_pair(b, 0));
if (it->second) return;
it->second = 1... | 7 |
#include <bits/stdc++.h>
const int N = 1010;
long long n, m, q, a[N][N], fr[N][N];
int cnt(long long x) {
int res = 0;
while (x) {
if (x & 1) res++;
x >>= 1;
}
return res;
}
long long sum(long long x, long long y) {
if (!x || !y) return 0;
long long res = 0, x_ = (x + n - 1) / n, y_ = (y + m - 1) / ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct comp {
bool operator()(const int& lhs, const int& rhs) const {
return (lhs % 10) > (rhs % 10);
}
};
int main() {
int numSkills, numImpr;
cin >> numSkills >> numImpr;
multiset<int, comp> skills;
for (int i = 0; i < numSkills; i++) {
int temp;
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int val[210000];
vector<int> wt[210000];
vector<int> dp[210000];
vector<pair<int, int> > adj[210000];
int n, k;
pair<int, int> totwt[210000][2];
int full[210000];
pair<int, int> notfull[210000][2];
int state[210000];
int rec(int v, int p, int goal);
void upd(int follow_idx,... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2345, mod = 998244353;
void add(int& x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
int mul(int x, int y) { return (long long)x * y % mod; }
int n, a[N], b[N], pa[N], pb[N], binom[N][N], s[N][N], fac[N], f[N], g[N], h[N],
result[N], new_result... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int v, w;
node(){};
node(int v_, int w_) : v(v_), w(w_){};
};
int n, m;
list<node> G[200007];
stack<int> S;
int color[200007] = {0};
int C[200007] = {0};
long long W[200007] = {0}, D[200007] = {0};
bool vis[200007] = {0};
long long f[200007][2] = {0}, g[... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
if (n & 1) {
int l = a[n / 2];
cout << a[n / 2] << ' ';
for (int i = 1; i <= n / 2; i++) {
... | 2 |
#include <bits/stdc++.h>
int main() {
int i, j, arr[3][3];
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) scanf("%d", &arr[i][j]);
arr[0][0] =
(arr[0][1] + arr[0][2] + arr[1][2] + arr[2][1] - arr[1][0] - arr[2][0]) /
2;
arr[1][1] =
(-arr[0][1] + arr[0][2] + arr[1][2] - arr[2][1] + arr[1][... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
string D[100], L, l, C;
int R[100];
int main() {
for (int i = 0; i < 100; ++i) {
R[i] = 0;
}
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> D[i];
for (int j = 0; j < D[i].size(); ++j) {
D[i][j] = tolower(D[i][j]);
}
}
cin >> L;
cin... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T poww(T b, T p) {
long long a = 1;
while (p) {
if (p & 1) {
a = (a * b);
}
p >>= 1;
b = (b * b);
}
return a;
}
template <class T>
inline T poww2(T b, int p) {
T a = 1;
while (p) {
if (p & 1) {
a = (a * b... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> cost(n);
for (int i = 0; i < n; i++) {
cin >> cost[i];
}
vector<string> str(n);
vector<string> str2(n);
for (int i = 0; i < n; i++) {
cin >> str[i];
str2[i] = str[i];
reverse(str2[i].begin(), st... | 4 |
#include <bits/stdc++.h>
using namespace std;
int k[26], t[26];
int main() {
int n, l = 0;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < s.length() && l < n; i++) {
if (!k[s[i]]) {
k[s[i]] = 1;
t[l++] = i;
}
}
if (l == n)
cout << "YES";
else {
cout << "NO";
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int Read() {
char c;
while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
;
bool neg = (c == '-');
int ret = (neg ? 0 : c - 48);
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
return neg ? -ret : ret;
}
const double pi = acos(-1);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long phi(long long n) {
long long res = 1;
for (long long i = 2; i * i <= n; i++)
if (n % i == 0) {
long long p = i;
n /= i;
res *= p - 1;
while (n % i == 0) n /= i, res *= p;
}
if (n > 1) res *= n - 1;
return res;
}
int main() {... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5, M = 1e5 + 5;
int n, m, ans[N], L[M], R[M];
vector<int> vec[N];
struct segment_tree_2D
{
struct node { int mn, ls, rs; } o[N * 300];
int rt[N << 2], tot;
void modify(int l, int r, int &u, int ml, int mr, int v)
{
if(!u) { u = ++tot; o[u].mn = INT... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, m;
cin >> n >> m;
map<string, string> ipName;
for (int i = 0; i < n; i++) {
string name, ip;
cin >> name >> ip;
ipName[ip] = name;
}
while (m--) {
string s1, ip;... | 0 |
#include <bits/stdc++.h>
using namespace std;
char ch[200000];
int n;
int main() {
scanf("%s", ch);
n = strlen(ch);
for (int i = 0; i < n; ++i)
if (ch[i] != 'A' && ch[i] != 'H' && ch[i] != 'I' && ch[i] != 'M' &&
ch[i] != 'O' && ch[i] != 'T' && ch[i] != 'U' && ch[i] != 'V' &&
ch[i] != 'W' && ch... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long one = 1;
long long mp[] = {0, 2, 3, 1};
long long solve(long long n) {
if (n < 4) return n;
long long _n = n;
n -= 4;
long long a, b, c;
for (int i = 2;; i += 2) {
long long can = 3 * (one << i);
if (n < can) {
a = (one << i) | (n / 3... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a = 1;
cin >> n;
int ans;
for (int i = 1; i < 1000; i++) {
ans = i * n + 1;
for (int j = 2; j <= sqrt(ans); j++) {
if (ans % j == 0) {
cout << i;
return 0;
}
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int n, a[200005]... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ans[10] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};
long long opt = 1;
int n, m;
long long k = 1000000007;
int main() {
scanf("%d%d", &n, &m);
opt = ans[m];
long long p = n - m, b = n - m;
while (p) {
if (p & 1) opt *= b;
opt %= k;
b *= b;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, x[1000], y[1000], a[1000], ans[1000], col[200010],
used[200010];
bool can = 0;
vector<int> pos[200010];
void update() {
for (i = 0; i <= 200010; i++) used[i] = col[i];
}
void clear() {
for (i = 0; i <= 200010; i++) used[i] = 0;
}
int myabs(long... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
if (n == 1 || m == 1)
cout << "YES" << endl;
else if (n == 2 && m == 2)
cout << "YES" << endl;
else
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int X[100], Y[100];
int ok(int x1, int y1, int x2, int y2) {
if (x1 > a || x2 > a || y1 > b || y2 > b) return 0;
if (x1 + x2 > a && y1 + y2 > b) return 0;
return 1;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int p[maxn][10];
int n;
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 5; j++) cin >> p[i][j];
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
if (i == j) continue;
int a = 0, b = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt = 0, cnt2 = 0;
for (int k = 0; k < s.size(); k++) {
if (s[k] != s[k + 1]) {
cnt++;
cnt2 = 0;
} else {
cnt2++;
}
if (cnt2 == 5) {
cnt++;
cnt2 = 0;
}
}
cout << cnt;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
long long cnt = 0;
while (a != 0 && b != 0) {
if (a < b) {
swap(a, b);
}
cnt += ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int w[102][102];
int a[102];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
int d;
cin >> d;
w[i][i] = 1;
if (i + d <= n) w[i][i + d] = w[i + d][i] = 1;
if (i - d > 0) w[i][i - d] = w[i - d]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = 4 * atan(1);
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int nCase = 0;
int dcmp(double x) {
if (fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
}
template <class T>
inline bool read(T& n) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void gmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (a > b) a = b;
}
int n, m, sym, id, lot[1000010], L[200010], R[200010];
struct SEGMENT {
int len, st, pos;
} cur;
struct cmp {
bool operator()(co... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long get(long long num, long long cnt) {
long long val = num / cnt;
long long rem = num % cnt;
long long ans = ((val + 1) * (val + 1) * rem);
ans = ans + ((cnt - rem) * val * val);
return ans;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
struct plakat {
int v;
int s;
char c;
};
bool operator<(const plakat& lhs, const plakat& rhs) {
return (lhs.c) < (rhs.c);
}
bool operator>(const plakat& lhs, const plakat& rhs) {
return (lhs.c) > (rhs.c);
}
int poskusi(vector<pl... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<string> A;
string S;
int main() {
int M, N;
cin >> M >> N;
for (int i = 0; i < M; i++) {
cin >> S;
A.push_back(S);
}
int Ans = 1;
for (int i = 0; i < M; i++) {
bool Flag = true, T;
for (int j = 0; j < N; j++)
if (A[i][j] != '.') {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int sum, suf, pre, max;
} Node;
int toint(const string &s) {
stringstream ss;
ss << s;
int x;
ss >> x;
return x;
}
const int MAXN = 3010;
const int UP = 31;
const long long int mod = 1e9 + 7;
const long long int highest = 1e18;
const double pi =... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool prime[100005];
std::vector<int> vg[100005];
int main() {
std::ios::sync_with_stdio(0);
int dp[100005];
memset(dp, 0, sizeof(dp));
int n, k, m;
cin >> n >> k >> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
dp[x % m]++;
vg[x % m].push_bac... | 2 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
int tot = 0, yo = 0, ti = 0;
bool is = true;
for (int i = 0; i < n; i++) {
tot += arr[i];
if (tot > 350 && tot <= 710) ti += tot - 350;
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int a[2005];
long long int dp[2005][4015];
long long int moves[2005][3];
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, x, y;
cin >> a >> b;
if (a >= b) {
x = b;
y = (a - b) / 2;
} else {
x = a;
y = (b - a) / 2;
}
cout << x << " " << y << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 1e5 + 5, mod = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
string x;
cin >> x;
int dif = 0;
sort(((x).begin()), ((x).end()));
for (int i = 1; i < ((int)((x).size())); ++i) {
if (x[i] !=... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Treap {
int size, key, auxkey, val;
Treap *lf, *rg;
Treap(int _size, int _key, int _auxkey, int _val, Treap *_lf, Treap *_rg) {
size = _size;
key = _key;
auxkey = _auxkey;
val = _val;
lf = _lf;
rg = _rg;
}
};
Treap *nil = new Treap(0, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int sign(double x) { return (x > eps) - (x < -eps); }
struct Point {
double x, y;
Point(double _x = 0, double _y = 0) { x = _x, y = _y; }
Point operator+(const Point &a) { return Point(x + a.x, y + a.y); }
Point... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e15;
const int N = 1e5 + 6;
int n, a[N], vis[N];
char s[N];
int main() {
memset(vis, 0, sizeof(vis));
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int pos = 1;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
struct pii {
int name, first, second;
} q[N];
int n, m, k, ans[N], a[N], t[4 * N], adr[N], age[N], grp[N], u[N], v[N], r[N],
per[N], tmp[N], f[N];
bool by_r(int x, int y) { return r[x] < r[y]; }
bool by_second_r(pii x, pii y) { return r[x.second... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (int i = 0; i < v.size(); ++i) {
os << v[i];
if (i != v.size() - 1) os << ", ";
}
os << "]\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 45;
int n, m;
char G[maxn][maxn];
int sg[maxn][maxn][maxn][maxn][2];
int SG(int x0, int x1, int y0, int y1, int d) {
int &g = sg[x0][x1][y0][y1][d];
if (g != -1) return g;
char s[maxn * 2 + 1];
memset(s, 0, sizeof(s));
for (int y = 0; y < n; ++y) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, l[100001];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> k;
l[k] = l[k - 1] + 1;
a = max(a, l[k]);
}
cout << n - a << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
bool fixed_pos[N];
int left_dis[N], right_dis[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, k;
string s;
cin >> n >> k >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == s[(i - 1 + n) % n] || s[i] == s[(i + 1) % n])
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
long long n, m, a[N], tr[N * 4], Mi[N * 4];
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s1, s2;
cin >> s1;
cin >> s2;
int size = s1.size() - 1;
int it = size;
while (s1[it] == 'z') {
s1[it] = 'a';
--it;
}
s1[it] += 1;
if (s1 != s2) {
cout << s1;
} else {
cout << "No such string";
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> k;
int min = 50;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
if (a < min) {
min = a;
}
k.push_back(a);
}
int suma = 0;
for (auto &i : k) {
if (i == min) {
suma++;
}
}
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, p;
long long h[100005], a[100005];
bool isPossible(long long v) {
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
greater<pair<long long, int> > >
fila;
long long foo[n];
for (int i = 0; i < n; i++) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ns = 0;
int nh = 0;
for (int i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
if (b == "soft") {
ns++;
} else {
nh++;
}
}
int k = 0;
while (k * k < (ns + nh) || (k * k + 1) / 2 < max(ns, nh)) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int d, n;
cin >> d >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
long long int ans = 0;
for (long long int i = 0; i < n - 1; i++) {
an... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const double eps = 1e-8;
int dcmp(double d) { return d < -eps ? -1 : d > eps; }
struct Point {
double x, y;
Point() {}
Point(double _x, double _y) : x(_x), y(_y) {}
void input() { scanf("%lf %lf", &x, &y); }
in... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long arr[60];
int pos[60];
void func(int st, int l, int r, long long m) {
if (l == r) {
pos[l] = st;
return;
}
int n = r - l + 1;
if (m <= arr[n - 1]) {
pos[l] = st;
func(st + 1, l + 1, r, m);
} else {
pos[r] = st;
func(st + 1, l, r - ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int nn = 2e6 + 8;
const int Max = 2e6;
const long long mod = 1e9 + 7;
long long e[nn];
long long fac[nn];
long long x, y;
long long Pow(long long a, long long x) {
if (x == 0) return 1;
long long d = Pow(a, x >> 1);
d = (d * d) % mod;
if (x & 1) return (d * a)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans = 0;
string s;
void change(int h) {
int c1;
if (h < n - 1) {
c1 = s[h + 1] - 'A';
} else {
c1 = s[h - 1] - 'A';
}
int c = s[h] - 'A';
for (int i = 0; i < k; i++) {
if (i != c && i != c1) {
s[h] = char('A' + i);
}
}
}
int mai... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p, x, y;
cin >> p >> x >> y;
for (int s = y;; s++) {
if (s % 50 != x % 50) {
continue;
}
bool me = false;
int i = s / 50 % 475;
for (int j = 0; j < 25; j++) {
i = (i * 96 + 42) % 475;
if (i + 26 == p) {
me... | 2 |
#include <bits/stdc++.h>
using namespace std;
int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int mark[1000005], arr[1000005];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N];
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
if (!a[i])
for (int j = i + i; j <= n; j += i) a[j] = i;
a[i] = i - a[i] + 1;
}
int ans = n;
for (int i = a[n]; i <= n; i++) ans = min(ans, a[i]);
cout ... | 4 |
#include <bits/stdc++.h>
int getbit(long long x, int y) { return (x >> y) & 1; }
long long getoff(long long x, int y) { return x ^ ((1ll) << y); }
using namespace std;
int n, res, a[1010], b[1010][9], c[1010][9], f[1010][256];
void dp(int kc) {
for (int i = 0; i <= n; ++i)
for (int mask = 1; mask < 256; ++mask) f... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int c[N], rr[N], ans[N];
struct node {
int l, r;
int id;
bool operator<(const node& a) const { return l == a.l ? r < a.r : l > a.l; }
} seg[N];
void add(int i) {
while (i < N) c[i]++, i += (i) & (-i);
}
int sum(int i) {
int ans = 0;
while ... | 5 |
#include <bits/stdc++.h>
int bsf(int x) { return __builtin_ctz(x); }
int bsr(int x) { return 31 - __builtin_clz(x); }
using namespace std;
const double pi = 3.14159265358979323846;
const int inf = (int)2e+9 + 2;
const int mod = (int)1e+9 + 7;
const double eps = 1e-8;
const int N = 100000;
int n, m, k;
void solve() {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
long long t, n, f[N], dp1[N], dp2[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
f[1] = 1;
f[2] = 2;
for (int i = 3; i <= 91; i++) {
f[i] = f[i - 1] + f[i - 2];
}
cin >> t;
while (t--) {
cin >> n;
int... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
pair<int, int> a[1010];
int n, m, p[1010];
double dp[1010];
double cal(int i, int j) { return sqrt(abs(a[j].first - a[i].first - m) + 0.); }
bool func(double t) {
dp[0] = 0;
for (int i = 1; i <= n; i++) dp[i] = 100... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
struct node {
int x, y;
} e[maxn * 2];
struct node2 {
int u, v, next;
} edge[maxn * 2];
map<pair<int, int>, int> ma;
vector<int> vv[maxn];
vector<int> v2;
queue<int> q;
int head[maxn], cnt, vis[maxn], deg[maxn], k;
void add(int x, int y) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
string s, A = "", B = "";
cin >> n;
cin >> s;
if (n & 1) {
for (int i = 1; i < n; i++)
if (i & 1)
A = s[i] + A;
else
B = B + s[i];
cout << A + s[0] + B << endl;
} el... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string get() {
char ch[1000000];
scanf("%s", ch);
return ch;
}
template <class P, class Q>
inline P smin(P &a, Q b) {
if (b < a) a = b;
return a;
}
template <class P, class Q>
inline P smax(P &... | 7 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int y, p;
cin >> p >> y;
for (long long int i = y; i > p; i--) {
long long int cnt = 0;
for (long long int j = 2; j <= p; j++) {
if (j * j > i) break;
if (i % j == 0) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-10;
double EQ(double a, double b) { return abs(a - b) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
template <class T>
string IntToString(T num) {
string res;
stringstream ss;
ss << num;
return ss.str();
}
long long StringToInt(s... | 3 |
#include <bits/stdc++.h>
using namespace std;
int tot;
const int M = 1e6 + 6;
vector<int> g1[M], g2[M];
int vis[M];
void dfs1(int u) {
vis[u] = 1;
tot++;
for (int i = 0; i <= g1[u].size() - 1; ++i) {
int v = g1[u][i];
if (!vis[v]) dfs1(v);
}
}
void dfs2(int u) {
vis[u] = 1;
tot++;
for (int i = 0; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
const int inf = 1e9;
void fail() {
cout << "NO" << endl;
exit(0);
}
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(12);
cin.tie(nullptr);
int n;
cin >> n;
vector<... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... | 11 |
#include <bits/stdc++.h>
using namespace std;
int Rand(int M) { return (((long long)rand()) * rand() + 3 * rand()) % M + 1; }
bool vis[1000000];
int getIndex(int M) {
int x;
while (1) {
x = Rand(M);
if (vis[x]) continue;
vis[x] = 1;
return x;
}
return -1;
}
int main() {
srand(time(NULL));
in... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
const int M = 10;
const int D = 300;
int pr[10] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
vector<vector<char> > mp;
vector<char> cur(M);
int fp[N];
int calc(vector<char> &v) {
int res = 1;
for (auto x : v) res *= x + 1;
return res;
}
void gen(int i, int... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
string s;
cin >> n;
while (n--) {
cin >> s;
a = 0;
b = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
int minimum = min(a, b);
if (minimum % 2 ... | 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
vector<int> pos[3];
const int MAX = 100005;
const int inf = 1e9 + 9;
bool zajete1[MAX], zajete2[MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret) {
char c;
int sgn;
T bit = 0.1;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && c != '.' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0... | 5 |
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <random>
#include <cmath>
#include <deque>
#include <unordered_map>
#include... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5;
long long a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long m;
cin >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a + 1, a + n + 1, greater... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k, res, div;
cin >> n >> k;
div = (n + 1) / 2;
if (k > div) {
k = k - div;
res = 2 * k;
} else {
res = 2 * k - 1;
}
cout << res;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long p, x, y, cur;
long long check(long long s) {
s = (s / 50) % 475;
long long n = 25;
while (n) {
s = (s * 96 + 42) % 475;
if (s + 26 == p) {
return 1;
}
n--;
}
return 0;
}
int main() {
cin >> p >> x >> y;
for (int i = x; i >= y; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 2000005, maxm = 29;
const double eps = 1e-9;
const double pi = acos(-1.0);
int cs(int x) {
int r = 0;
if (x <= 0) return 1;
while (x > 0) {
x /= 7;
++r;
}
return r;
}
int n, m, k, k1, k2;
int r = 0;
int sx... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.