solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
bool arr[26];
string ip;
string op;
cin >> ip;
op = "YES";
if (ip[0] != 'a') {
cout << "NO" << endl;
exit(0);
} else {
int maxi = 'a';
for (int i = 1; i < ip.length(); i++) {
if (ip[i] > maxi + 1) {
op = "NO";
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
char buf[1 << 23], *p1 = buf, *p2 = buf;
set<pair<int, int> > s;
vector<pair<int, int> > cg[N];
set<pair<int, int> >::iterator a, b;
long long n, k, nm[N], ans, sum, cnt, lp, lq, lg, gg;
long long read() {
long long res = 0, fl = 0;
char a =
... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
int i, j, k;
int m, n;
int tc;
int x[3];
k = -INF;
for (i = 0; i < 3; ++i) {
scanf("%d", x + i);
x[i] = (x[i] + 1) >> 1;
k = max(k, 3 * (x[i] - 1) + i + 30);
}
printf("%d\n", k);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
char a[101][101], b[101][101], c[101][101];
int check(int n) {
int i, j, k;
for (k = 1; k <= 4; k++) {
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
c[i][j] = a[n + 1 - j][i];
}
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) a[... | 6 |
#include <bits/stdc++.h>
using namespace std;
int GetNumber() {
char c;
while (c = getchar(), c < '0' || c > '9')
;
int X = c - 48;
while (c = getchar(), c >= '0' && c <= '9') X = X * 10 + c - 48;
return X;
}
double K[2097152], Delta[2097152];
void Add(int P, int Left, int Right, int L, int R, double X, d... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((long double)a) / b); }
int faltu;
const int mod = 1e9 + 7;
const long long inf = 4e18;
const long long ninf = -inf;
const int imax = 2e9 + 100;
const int maxn = 1e6 + 100;
int n, m;
vecto... | 22 |
#include <bits/stdc++.h>
using namespace std;
inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; }
const int N = 100500, inf = 1e9 * 2;
const long long MOD = 1e9 + 7ll, INF = 1e18;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
int m, l[N], r[N];
string s;
vecto... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, u[14], v[14], a[110], b[110], c[110], g[14][14];
long long dp[20][10010];
bool in(int x, int s) { return (1 << x) & s; }
long long dfs(long long x, long long S) {
if (dp[x][S] != -1) return dp[x][S];
dp[x][S] = 0;
int s = S ^ (1 << x), p;
for (p = 0; p ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010, P = 998244353;
int n, m, ans;
int fac[maxn], inv[maxn], a[maxn], l[maxn], r[maxn], f[2][maxn][maxn];
int C(int n, int m) {
if (n < m) return 0;
return (long long)fac[n] * inv[m] % P * inv[n - m] % P;
}
int main() {
fac[0] = inv[0] = inv[1] = 1;
... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long inf = 1e12;
int t[N];
int n, q;
void upd(int pos, int val) {
for (; pos < n; pos |= (pos + 1)) {
t[pos] += val;
}
}
int get(int r) {
int ans = 0;
for (; r >= 0; r = (r & (r + 1)) - 1) {
ans += t[r];
}
return ans;
}
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int inline ABS(int a) {
if (a > 0)
return a;
else
return -a;
}
int GCD(int a, int b) {
if (!a) return b;
return GCD(b % a, a);
}
int a[222];
double ans[222];
int main() {
int b, n;
cin >> n >> b;
for (int i = 0; i < n; i++) cin >> a[i];
int mx = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T GCD(T a, T b) {
if (a < 0) return GCD(-a, b);
if (b < 0) return GCD(a, -b);
return (b == 0) ? a : GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
if (a < 0) return LCM(-a, b);
if (b < 0) return LCM(a, -b);
return a * (b /... | 6 |
#include <bits/stdc++.h>
using namespace std;
int MAX_LCA = 20;
void deep(int v, const vector<vector<int>>& edges, vector<int>& tin,
vector<int>& tout, vector<int>& h, vector<vector<int>>& max,
vector<vector<int>>& p) {
static int t = 1;
tin[v] = t++;
for (int i = 0; i < edges[v].size(); i++) ... | 20 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:216000000")
using namespace std;
const long long MAX = 100000000LL * 100000000LL;
const long long MIN = numeric_limits<long long>::min();
const double PI = 3.14159265358979;
const long long MOD = 1000000007LL;
template <class T>
ostream& operator<<(ostream& out, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int N = 250;
int x[N];
bool solvetype() {
double sum = 0;
for (int i = (0); i < (N); ++i) sum += x[i];
double avg = sum / N;
double sumsq = 0;
for (int i = (0); i < (N); ++i) sums... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, m, i;
cin >> t;
while (t--) {
long long int term, ans = 0, sum = 0, temp;
cin >> n >> m;
term = (n - (n % m)) / m;
if (m % 10 == 0)
ans = 0;
else if (m % 5 == 0) {
if (term & 1)
ans = ((term + 1)... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool solve(int test) {
long long n, x, y;
cin >> n >> x >> y;
long long p = y - n + 1;
if (p <= 0) {
cout << "-1";
return 0;
}
long long ans = p * p + n - 1;
if (ans < x)
cout << "-1" << endl;
else {
cout << p << endl;
for (int i = 0; i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010], b[200010], c[200010];
int pos1 = 0, ans = 0;
bool satify(int num) {
for (int i = num + 1; i <= n; ++i) {
if (b[i] != 12345678 && b[i] <= i - num) return false;
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) sc... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x = 0;
register bool f = 0;
register char ch = getchar();
while (!isdigit(ch)) {
f ^= !(ch ^ '-');
ch = getchar();
}
while (isdigit(ch)) {
x = (x + (x << 2) << 1) + (ch ^ '0');
ch = getchar();
}
return f ? -x ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXV = 1e6 + 10;
char s[10];
int N, A, B;
bool C1[MAXV], C2[MAXV];
int v[MAXV], X[MAXV], Y[MAXV];
void DFS1(int H) {
if (v[H] == 1) {
DFS1(X[H]);
C1[H] = !C1[X[H]];
} else if (v[H] == 2) {
DFS1(X[H]);
DFS1(Y[H]);
C1[H] = C1[X[H]] && C1[Y[H]... | 12 |
#include <bits/stdc++.h>
using namespace std;
class Team {
public:
int point, get, lost;
string name;
Team() { point = get = lost = 0; }
bool operator<(const Team &t) const {
if (point != t.point) return point > t.point;
if (get - lost != t.get - t.lost) return get - lost > t.get - t.lost;
if (get ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int cur = 0;
vector<vector<int> > v;
int nw = 1;
while (cur != n) {
vector<int> yo{nw * k, (nw + 1) * k, (nw + 2) * k, (nw + 4) * k};
v.push_back(yo);
n... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int n, x, y;
int sol(long long int l, long long int r, long long int a) {
if (l == r) return 3;
long long int mid = (l + r) / 2;
long long int shots = mid / y + mid / x;
if (shots == a) {
long long int first = y * (mid / y);
long long int second = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
std::vector<long long int> v[200009];
long long int cnt, ans;
std::vector<long long int> v2 = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
void solve(long long int val, vector<long long int> v1) {
if (val == 1)... | 12 |
#include <bits/stdc++.h>
using namespace std;
char s[100];
int main() {
scanf("%s", s);
int res = 0;
for (int i = 1; i < 7; i++) {
if (i + 1 < 7 && s[i] == '1' && s[i + 1] == '0') {
res += 10;
i++;
} else {
res += s[i] - '0';
}
}
printf("%d\n", res + 1);
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a[10000];
long long n, m, k;
cin >> n >> m >> k;
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
if (n % 2 == 0) {
cout << 0 << endl;
return 0;
}
long long inf = 10000000;
long long v = inf;
for (long long i = 0; i <... | 10 |
#include <bits/stdc++.h>
using namespace std;
int arr[200008];
vector<int> tree[200008];
bool vis[200008];
void dfs(int root) {
vis[root] = 1;
for (int i = 0; i < tree[root].size(); i++) {
if (!vis[tree[root][i]]) dfs(tree[root][i]);
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int N, M, arr[maxn], cnt[maxn], res;
vector<int> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
cin >> arr[i];
if (arr[i] <= M) cnt[arr[i]]++;
}
for (int i = M; i >= 1; i--)
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int one = 0, zero = 0, n;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
zero++;
else
one++;
}
if (zero != one) {
cout << 1 << endl << s;
} else {
cout << 2 << endl << s[0] << " ";
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = (1 << 18) + 10, mod = 998244353;
long long rd() {
long long x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch ^ 48);
ch =... | 23 |
#include <bits/stdc++.h>
using namespace std;
int arr[10];
int main() {
long long int a;
cin >> a;
string c[4];
for (int i = 0; i < 4; i++) {
cin >> c[i];
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (c[i][j] != '.') arr[c[i][j] - '0']++;
}
}
for (int i = 0; i < 10;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
const double pi = acos(-1.0);
const int maxp = 1010;
int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
inline double sqr(double x) { return x * x; }
struct Point {
double... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long p;
long long pow2(long long y) {
if (!y) return 1LL;
long long res = pow2(y / 2);
res *= res;
res %= (p - 1);
if (y % 2) res *= 2, res %= (p - 1);
return res;
}
long long power(long long x, long long y) {
if (!y) return x ? 1LL : 0LL;
long long res... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 22;
const long long M = 1e18 + 2;
int T, n, m;
long long a[105][105];
long long dp[105][105], ans;
void ck(long long x) {
;
if (a[1][1] < x) return;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {... | 14 |
#include <bits/stdc++.h>
using namespace std;
int arrayy[368][2];
int main() {
memset(arrayy, 0, sizeof(arrayy));
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char c;
int x, y;
cin >> c >> x >> y;
if (c == 'M')
for (int j = x; j <= y; j++) arrayy[j][0]++;
else
for (int j = x; j... | 3 |
#include <bits/stdc++.h>
int n1, k1, n2, k2;
int main() {
while (std::cin >> n1 >> n2 >> k1 >> k2) {
int i = 1;
while (n1 > 0 && n2 > 0) {
if (i % 2) {
n1 -= 1;
} else {
n2 -= 1;
}
++i;
}
if (n1 <= 0) {
std::cout << "Second\n";
} else {
std::cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
long a, b, n, i, j, f[200];
long long ans = 0;
string s1, s2;
int main() {
cin >> a >> b >> s1 >> s2;
n = s2.length();
for (i = 0; i < n; i++)
for (j = 0; j < s1.length(); j++)
if (s1[j] == s2[(i + f[i]) % n]) f[i]++;
for (i = 0; i < a; i++) ans += f[ans %... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;
void solve(long long tc) {
long long n;
cin >> n;
long long... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long qpow(long long a, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
n >>= 1;
}
return res;
}
char s[1000005];
int n, m, len, Next[1000005], mark[1000005], p[1000005];
void init() {
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long h[200001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, m, g[123] = {0}, c = 0, x, v[123] = {0};
for (long long i = 0; i <= 200000; i++) h[i] = 0;
cin >> n >... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long readll() {
long long x = 0;
bool ok = 0;
char c = getchar();
while (c < 48 or c > 57) ok |= (c == '-'), c = getchar();
while (c > 47 and c < 58) x = (x << 3) + (x << 1) + c - 48, c = getchar();
if (ok) x = -x;
return x;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 1e5 + 5;
const int maxm = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long md0 = 1e9 + 7;
const long long md1 = 1e9 + 9;
const int base = 131;
int pw0[maxm], pw1[maxm];
int has0[maxn], has1[maxn];
map<long long, int> mp;
c... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, m;
int deg[MAXN];
vector<pair<int, int>> graph[MAXN];
int up[MAXN], visit[MAXN], vtime;
vector<tuple<int, int, int>> stk;
int bcc_cnt;
set<int> bccverts[MAXN];
vector<int> bccedges[MAXN];
void dfs(int nod, int par_edge) {
up[nod] = visit[no... | 16 |
#include <bits/stdc++.h>
int a[105], b[105];
int n, k, x, ans = 0;
int Ins(int pos) {
int l, r, num, flag, now;
num = 0;
l = pos;
r = pos + 1;
if (a[l] == x && a[r] == x) {
num += 2;
l = pos - 1;
r = pos + 2;
} else
return 0;
do {
flag = 0;
if (a[l] != a[r])
break;
else
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
vector<int> e[MAXN];
int path[MAXN];
int nroot;
void DFS(int x, int p) {
(void)0;
vector<int> tmp;
for (int t : e[x]) {
if (t == p) continue;
DFS(t, x);
(void)0;
tmp.push_back(path[t]);
}
if (((int)(tmp).size()) == 0) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int k;
cin >> k;
int n = s.length(), l = (n + k) / 2;
while (l > 0) {
for (int i = n + k - l * 2, j; i >= 0; i--) {
for (j = 0; j < l; j++)
if (!(i + l + j >= n || s[i + j] == s[i + l + j])) break;
if (j >... | 7 |
#include <bits/stdc++.h>
using namespace std;
char buf[1000010];
int TIM = 1, SZ = 0, P = 0;
int tok[2000010];
unsigned long long code[2000010];
unsigned long long HC;
int type;
bool nextToken() {
if (!buf[P]) return false;
int E = P, L, R;
HC = 0;
while (buf[E] != '>') ++E;
if (buf[P + 1] == '/') {
type ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int N, K, d;
void read() { scanf("%d %d %d", &N, &K, &d); }
long long dp[128][2];
long long rec(int n, int done) {
if (n < 0) return 0;
if (n == 0) return done;
if (dp[n][done] != -1) return dp[n][done];
long long ans = 0;
for (int i = 1; i <= min(K, n); i++)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m = 0, kol[26], x, y, k = 0;
cin >> n >> m >> x >> y;
pair<int, int> r[n];
int a[n], b[m];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0, j = 0; i < n && j < m;) {
if (b[j] >= a[i] - x ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], id[100005], vis[100005];
int f[100005], st[100005], t;
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
int i, j, k, n;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", a + i);
id[i] = i;
}
sort(id + 1, id + n + 1, cmp);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
long long c[4][n + 1];
for (long long i = 1; i <= 3; i++)
for (long long j = 1; j <= n; j++) cin >> c[i][j];
vector<long long> g[n + 1];
for (long long i = 1; i < n; i++) {
long long u, v;
cin >> u >> v;
g[u... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int main() {
long long i, j, k, m, n;
cin >> n;
long long x, res = 0;
for (x = 1; x < n; x = x * 2) {
long long z = (n - 1 - x) / (2 * x);
z++;
z = z * x;
res = res + z;
}
cout << res << "\n";
return 0;
}... | 11 |
#include <bits/stdc++.h>
int main() {
int n, a[100], i, j, b[100];
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
int k = 1, o = 0, c = 1, t;
for (i = 0; i < n - 1; i++) {
for (j = k; j < n; j++) {
if (a[i] == a[j]) c++;
}
k++;
if (c > 1) {
b[o] = c;
c = 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b;
cin >> n >> b;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int odd = 0, even = 0;
vector<int> v;
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0)
even++;
else
odd++;
if (odd == even && i < n - 1) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
char Map[MAXN][MAXN];
int n;
bool check() {
for (int i = 0; i < n; i++) {
int j;
for (j = 0; j < n; j++) {
if (Map[i][j] == '.') break;
}
if (j == n) return false;
for (j = 0; j < n; j++) {
if (Map[j][i] == '.') break;... | 7 |
#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar();
bool flag = false;
while (!isdigit(c)) {
if (c == '-') flag = true;
c = getchar();
}
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
if (flag) x = -x;
}
using namespace std;
int n, K, R, pto... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
int a[100010], b[100010];
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
sort(a + 1, a + n + 1);
for (int i = n; i >= 2; i--) a[i] = a[i - 1];
a[1] = 1;
bool dif = 0;
for (long... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long m, h1, a1, x1, y1, h2, a2, x2, y2;
scanf("%lld", &m);
scanf("%lld%lld", &h1, &a1);
scanf("%lld%lld", &x1, &y1);
scanf("%lld%lld", &h2, &a2);
scanf("%lld%lld", &x2, &y2);
long long i;
long long st1, st2, len1, len2;
st1 = st2 = len1 =... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 1123456;
int n, m, k;
long long s[MAXN];
long long mnL[MAXN], mnR[MAXN], mxL[MAXN], mxR[MAXN];
sta... | 11 |
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now... | 23 |
#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);
}
struct Fraction {
long long p, q;
Fraction(long long p) : p(p), q(1) {}
Fraction(long long p, long long q) : p(p), q(q) { relax(); }
void relax() {
assert(q != 0);
if (q ... | 17 |
#include <bits/stdc++.h>
short int mas[1000002], mas1[1000002];
int main() {
long long n;
scanf("%I64d", &n);
int m[1002], max = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &m[i]);
++mas[m[i]];
if (max < mas[m[i]]) max = mas[m[i]];
}
for (int i = 0; i < n; ++i) {
++mas1[m[i]];
if (max =... | 2 |
#include <bits/stdc++.h>
const long base = 14012001;
const long long MM = 1ll * 1000000007 * 1000000007;
using namespace std;
int BIT(int i, long long x) { return (x & (1 << i)); }
long long ONBIT(int i, long long x) { return (x | (1 << i)); }
long long OFFBIT(int i, long long x) { return (x & ~(1 << i)); }
long long F... | 10 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
long long a1[9];
long long a2[9];
char kalimat[100005];
int main() {
long long sisa1, sisa2, a, b, temp, kelompok, jum, i;
scanf("%lld", &a);
getchar();
if (a <= 4) {
if (a == 4) {
cout << "12" << endl;
} else if (a == 3) {
cout... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, n, m, j, k;
int main() {
cin >> n >> k;
for (j = 1; j < n + 1; j++) {
if (j < k + 1) {
cout << 2 * j << " " << 2 * j - 1 << " ";
} else {
cout << 2 * j - 1 << " " << 2 * j << " ";
}
}
}
| 6 |
#include <bits/stdc++.h>
int main(void) {
int n, d, songs = 0, x, time, i, jokes;
scanf("%d%d", &n, &d);
for (i = 0; i < n; i++) {
scanf("%d", &x);
songs += x;
}
time = songs + (n - 1) * 10;
if (time > d)
printf("-1\n");
else {
jokes = d - songs;
printf("%d\n", jokes / 5);
}
return... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<string> vec(1001);
int up[1001][1001], down[1001][1001], lef[1001][1001], righ[1001][1001];
int arr[1001][1001], brr[1001][1001], ans[1001][1001];
int n, m;
int find_min(int row, int col) {
return min(min(up[row][col], down[row][col]),
min(lef[row][col... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, x, temp = 0, cnt = 0;
cin >> n >> x;
vector<int> arr(n);
for (i = 0; i < n; ++i) cin >> arr[i];
for (i = 0; i < x; ++i)
if (find(arr.begin(), arr.end(), i) == arr.end()) {
temp++;
}
if (find(arr.begin(), arr.end(), x) != arr.... | 2 |
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
bool v = 0;
cin >> n;
int x[n];
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n - 1; ++j) {
if (v) break;
if (max(x[i], x[i + 1]) < max(x[j], x[j + 1]) &&
mi... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int n;
scanf("%d", &n);
return n;
}
inline void out(int n) { printf("%d ", n); }
struct triple {
public:
int x;
int y;
int a;
};
int main() {
int n = in();
string s;
cin >> s;
for (int i = 0; i < n - 1; i++) {
if (s[i] > s[i + 1]) ... | 4 |
#include <bits/stdc++.h>
int main() {
long long a, b, c;
std::cin >> a >> b >> c;
long long ans = 2 * c;
if (a == b) {
ans += (2 * a);
} else {
ans += (std::min(a, b) * 2) + 1;
}
std::cout << ans << '\n';
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long cache[2001][2001][2];
long long dp(long long pos, long long sum, int prev) {
if (pos == 0) return 0;
long long &ans = cache[pos][sum][prev];
if (ans != -1) return ans;
ans = 0;
if (sum == 0) {
ans += dp(pos - 1, sum + 1, prev ^ 1);
ans %= 1000000... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int B = 2000;
int n, m, a[N], bl[N], bll[N], blr[N], cnt[N / B + 5][N];
list<int> lst[N / B + 5];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
for (int i = 1, l = 1, r; l <= n; l = r + 1, ++i) {
r = mi... | 19 |
#include <bits/stdc++.h>
using namespace std;
char getc() {
char c = getchar();
while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
c = getchar();
return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
int x = 0, f = 1;
char c = getchar();
while (c... | 21 |
#include <bits/stdc++.h>
using namespace std;
int a[200001], now = 1;
vector<int> s;
void wk(int x) {
s.push_back(x);
while (!s.empty() && s.back() == now) s.pop_back(), now++;
}
int main() {
int n, k;
cin >> n >> k;
s.push_back(n + 1);
for (int x = 1; x <= k; x++) cin >> a[x], wk(a[x]);
for (int x = k + ... | 12 |
#include <bits/stdc++.h>
using namespace std;
char st[100005][2][55];
int n, f[100005][2], p[100005], len[100005][2];
bool cmp(int x, int u, int y, int v) {
int i, lon = min(len[x][u], len[y][v]);
for (i = 0; i <= lon; i++)
if (st[x][u][i] != st[y][v][i]) break;
return st[x][u][i] > st[y][v][i];
}
int main() ... | 6 |
#include <bits/stdc++.h>
using namespace std;
pair<int, long double> forwards[109];
pair<int, long double> backwards[109];
vector<int> adj[109];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
int a[26] = {0};
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
int m = s[i][0] - 'a';
a[m]++;
}
int c = 0;
for (int i = 0; i < 26; i++) {
if (a[i] != 0) {
if (a[i] % 2 ==... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
cout << a << endl;
for (int i = 0; i < a; i++) {
cout << "1 ";
}
cout << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
int n;
cin >> n;
int l = 1, r = 0;
map<int, int> mp;
while (n--) {
char c;
int x;
cin >> c >> x;
if (c == 'L') {
l--;
mp[x] = l;
} else if (c == 'R') {
r++;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
while (cin >> n) {
while (n % 3 == 0) n /= 3;
cout << (n / 3) + 1 << endl;
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans = (1 << 23) - 1;
bitset<25> a;
struct mat {
bitset<25> d[25];
} S;
void dfs(int t, int p, mat x) {
if (t == n + 1) {
int g = 0;
for (int i = 1; i <= n; ++i)
if (x.d[i] != a) g = 1;
if (!g)
if (__builtin_popcount(p) < __builtin_popco... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
while (l <= r) {
int x = l;
if (2 * x <= r) {
cout << x << " " << 2 * x << endl;
break;
} else {
continue;
}
l++;
}
}
return ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
int count = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
count++;
}
}
if (n... | 1 |
#include <bits/stdc++.h>
int n, lp, tmp, i;
std::vector<bool> vis(300005);
int main() {
scanf("%d", &n);
lp = n;
printf("1 ");
for (i = 2; i < n + 2; ++i) {
scanf("%d", &tmp);
vis[tmp] = 1;
while (vis[lp]) lp--;
printf("%d ", i - n + lp);
}
}
| 7 |
#include <bits/stdc++.h>
int n, m, z = 1, w, ans, f3, f11, flag = 1;
int main() {
scanf("%d%d", &m, &n), f3 = m % n == 1, f11 = m % n == n - 1;
for (int i = 2; i <= n; i++)
if (n % i == 0) {
int c = 0, cnt = -1, x = 1, y = m;
while (n % i == 0) cnt++, n /= i, x *= i;
while (y % i == 0) c++, y ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
int n;
cin >> n;
long long res = 0;
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> arr[i];
for (int j = 0; j <= 31; j++) {
res += mp[(int)((1LL << j) - arr[i])];
}
mp[arr[i]]++;
}
cout << res << endl;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 100002;
const long long INF = (1LLU << 62) - 1;
int n, k;
int v[NMAX];
int stk[NMAX];
pair<long long, long long> f[NMAX];
vector<pair<long long, long long> > inttree[4 * NMAX];
bool check(pair<long long, long long> a, pair<long long, long long> b,
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], i;
int st = 0;
int en = n - 1, countt = 0, ma = INT_MIN;
for (i = 0; i < n; i++) {
cin >> a[i];
}
int prev = INT_MIN;
string s = "", s1 = "", s2;
while (st != en) {
if (a[st] > prev || a[en] > prev) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[10];
double re = 0;
double xx;
int n, k;
void dfs(int k) {
if (k == 0) {
int cnt = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j < i; j++) {
if (a[j] > a[i]) cnt++;
}
re += cnt * xx;
return;
}
for (int i = 0; i <= n; i++) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long maxn = 5e5 + 50, N = 2e6 + 10, SQRT = 300, base = 607583,
mod = 1e9 + 7, INF = 1e18 + 1, lg = 25;
const long double eps = 1e-4;
struct node {
long long mx, id;
node() { mx = -INF; }
};
node seg[4 * maxn];
lon... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100000];
int p[100000];
int vist[100000] = {};
void dfs(int v) {
vist[v] = 1;
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
if (!vist[u]) {
p[u] = v;
dfs(u);
}
}
}
int main() {
int n, r1, r2, m;
int v;
scanf("%d%d... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, z;
cin >> n >> m >> z;
vector<int> art(z / n);
int ans = 0;
for (int i = 0; i < z / n; i++) art[i] = (i + 1) * n;
for (int i = 0; i < z / m; i++)
ans += (binary_search(art.begin(), art.end(), (i + 1) * m) ? 1 : 0);
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool vis[N];
int col[N];
vector<vector<int> > g;
int cmp[N], cc;
void dfs(int u, int c) {
vis[u] = true;
cmp[u] = c;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (col[v] == col[u] && !vis[v]) dfs(v, c);
}
}
int main() {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-2;
const double PI = acos(0.0) * 2.0;
typedef struct p {
double first, second;
};
bool operator<(const p &a, const p &b) {
if (abs(a.first - b.first) < EPS) {
if (abs(a.second - b.second) < EPS) {
return 0;
} else
return a.secon... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long xor1_n(long long n) {
switch (n % 4) {
case 0:
return n;
case 1:
return 1;
case 2:
return n + 1;
}
return 0;
}
long long ncr(long long n, long long r) {
long long res = 1;
if (r > n - r) r = n ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, A, cf, cm;
long long m;
long long sum[N];
struct node {
long long v;
int id;
} a[N];
bool cmp1(node a, node b) { return a.v < b.v; }
bool cmp2(node a, node b) { return a.id < b.id; }
int work(int v) {
int l = 1, r = n;
int ans = n... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.