solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const long long inf = 0x3f3f3f3f;
int n, a, b, c, d, st, len;
int t[maxn], q[maxn];
long long sum = 0, minn = inf;
long long rating = 0;
int main() {
scanf("%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &st, &len);
for (int i = 1; i <= n; i++) scanf("%... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long k;
cin >> n >> k;
vector<vector<vector<long long>>> dp(
n, vector<vector<long long>>(2, vector<long long>(2 * n + 1, 0)));
vector<int> cor(n);
for (... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const long long MOD = 1000000007;
long long ABS(long long a) {
if (a < 0)
return a * (-1);
else
return a;
}
long long binpow(long long a, l... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a1[100500], a2[100500];
int f[100500];
int n, m;
int used2[100500], used1[100500];
void dfs1(int v) {
if (used1[v]) return;
used1[v] = 1;
for (int i = 0; i < a1[v].size(); i++)
if (f[a1[v][i]] != 1) dfs1(a1[v][i]);
}
void dfs2(int v) {
if (used2[v]) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void numgen(vector<string> &v, string &s) {
if (s.length() == 4) {
v.push_back(s);
return;
}
int p1 = s[0] - '0';
int p2 = -1, p3 = -1;
if (s.length() >= 2) {
p2 = s[1] - '0';
}
if (s.length() == 3) {
p3 = s[2] - '0';
}
for (int i = 0; i <=... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int NM = 2e5 + 10;
int p[NM], s[NM], a[NM], b[NM];
bool used[NM];
int main() {
int n, m;
scanf("%d %d", &n, &m);
unordered_map<int, vector<int>> mp;
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
mp[p[i]].push_back(i);
}
for (int i = 1; i <= m;... | 13 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
n -= 43500;
puts(n > 0 ? (n > 2000 ? "3" : "2") : "1");
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
bool prime[1000];
void Siev(int x) {
memset(prime, true, sizeof(prime));
for (int i = 2; i * i <= x; i++) {
if (prime[i] == true) {
for (int j = i * 2; j <= x; j += i) prime[j] = false;
}
}
}
int main() {
int n, m;
cin >> n >> m;
int flag = 0;
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int v[100000], c[100000], l[100000], r[100000];
int parent[100000], value[100000];
int main() {
int n, pos = 0;
cin >> n;
for (int i = 0; i < n; ++i) cin >> v[i] >> c[i] >> l[i] >> r[i];
map<pair<int, int>, pair<int, int> > hash;
map<pair<int, int>, pair<int, int>... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long prime = 41;
int toInt(char c) {
if (c >= 'a' && c <= 'z') {
return c - 'a' + 1;
}
if (c >= '0' && c <= '9') {
return 29 + c - '0';
}
return 28;
}
vector<long long> revPrime;
vector<long long> getHash(string &kek)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int const N = 5e5 + 10, oo = 1e9;
int mod = oo + 7;
long long const OO = 1e18;
int n, q;
int aa[N], bb[N];
long long cum[N], an[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> aa[i];
cin >> q;
for (int i = 0; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long c, d;
cin >> c >> d;
long long a = 0, b = 0;
if (c == 0 && d == 0) {
cout << "0" << endl;
} else if (c == d) {
cout << "1" << endl;
} else if (abs(c - d) % 2 == 0) {
cout <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
const long long mod = 1e9 + 7;
long long fact[maxn + 5], inv[maxn + 5], x[maxn + 5], y[maxn + 5],
sum[maxn + 5];
void init() {
fact[0] = 1;
for (long long i = 1; i <= maxn; i++) fact[i] = (fact[i - 1] * i) % mod;
inv[1] = 1;
for (long long... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <typename T>
struct modular {
constexpr modular() : val(0) {}
constexpr modular(const modular<T>& _m) : val(_m.val) {}
template <typename U>
constexpr modular(const U& _r = U()) {
val = -MOD <= _r && _r < MOD ? _r : _r % MOD;... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char ch[3], ma[3];
int store = 0;
cin >> ch;
for (int i = 0; i < 5; i++) {
cin >> ma;
if (ch[0] == ma[0] || ch[0] == ma[1] || ch[1] == ma[0] || ch[1] == ma[1]) {
store = 1;
}
}
if (store == 1)
cout << "YES" << endl;
else
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, sum = 0, count = 0, num[10] = {0};
string n;
cin >> k >> n;
for (int i = 0; i < n.size(); i++)
sum += int(n[i]) - 48, num[int(n[i]) - 48]++;
if (sum >= k)
cout << 0;
else
for (int i = 0; i < 10; i++)
for (int j = 0; j < num[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
bool ans = true;
int arr[n + 100];
int mini = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> arr[i];
mini = min(arr[i], mini);
}
long long res = 0;
if (ans || n == 1) {
for (int i = 0; i < n; i++) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, a[1007];
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
int f = 0, ans = 0, d = 1, n = 0;
while (f != N) {
if (a[n] != -1 && a[n] <= f) {
a[n] = -1;
++f;
}
if (f != N && (n + d < 0 || n + d > N - 1)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
int n;
int p[MAXN], l[MAXN];
pair<int, int> f[MAXN];
struct node {
int who, cost;
node() {}
node(int who, int cost) : who(who), cost(cost) {}
} dp[MAXN][20];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &p[i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int am0[70][70];
long double am[70][70];
struct P {
long double p;
long double e;
int i;
P(long double pp, long double ee, int ii) {
p = pp;
e = ee;
i = ii;
}
};
vector<P> sav[70];
vector<P> sev[70];
int main() {
cout << s... | 13 |
#include <bits/stdc++.h>
using namespace std;
int* tbl = new int[1000000];
int* atb = new int[1000000];
void ct(int cl, int cr, int ci) {
tbl[ci] = 0;
atb[ci] = 0;
if (cl == cr) {
return;
}
int cm = (cl + cr) / 2;
ct(cl, cm, ci * 2);
ct(cm + 1, cr, ci * 2 + 1);
}
void ut(int cl, int cr, int ci, int sp... | 14 |
#include <bits/stdc++.h>
const double eps = 1e-8;
const long long INF = 1e18;
const double pie = acos(-1.0);
using namespace std;
long long fun[100005], mad[100005];
long long s1[100005], s2[100005];
long long ans;
bool cmp(int x, int y) { return x > y; }
int main() {
long long n, d, m, a;
long long l1 = 0, l2 = 0;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
string s;
cin >> s;
transform(s.begin(), s.end(), s.begin(), ::tolower);
for (int i = 0; i < s.size(); i++) {
if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i' &... | 2 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << H << ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char home[30], away[30], team[90], card[90];
int faults, dem[2][100], timefault[90], player[100], pos[200], len = 0;
cin.get(home, 30, '\n');
cin.get();
cin.get(away, 30, '\n');
cin >> faults;
for (int i = 0; i < faults; i++) {
cin >> timefaul... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000;
const int oo = 998244353;
int n, m;
string s;
string t;
int dp[maxn + 1][maxn + 1];
int caldp(int x, int y) {
if (dp[x][y] != -1) return dp[x][y];
if (x == y) {
if (t[x] == s[1] or x > m)
dp[x][y] = 1;
else
dp[x][y] = 0;
re... | 14 |
#include <bits/stdc++.h>
using namespace std;
const char* fi = "loco2.inp";
const char* fo = "loco2.out";
const int maxn = 1e5 + 2;
int n, a[maxn], dem[maxn];
void nhap() {
cin >> n;
for (int i = (1); i <= (n); i++) cin >> a[i];
}
int cal(int x) {
return x == 0 ? 0 : (x % 2 == 0 ? cal(x / 2) : cal(x / 2) + 1);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
bool sub = false;
int j = 0;
if (t.size() < s.size()) {
for (int i = 0; i < s.size(); i++) {
if (s[i] == t[j]) {
j++;
}
if (j == t.size()) {
sub = true;
break;
}
}
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long sum[200000 + 10];
map<long long, int> mp;
int main() {
mp.clear();
int n;
cin >> n;
long double ans = 0, x;
for (int i = 1; i <= n; i++) {
cin >> x;
ans += x * (i - 1) - (long double)(sum[i - 1]);
if (mp[x - 1]) ans -= (long double)(mp[x - 1]... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct bignum {
int m[201];
bignum() { memset(m, 0, sizeof(m)); }
bignum &operator=(const int a) {
memset(m, 0, sizeof(m));
m[0] = a;
for (int i = 0; i < 201; i++) {
if (m[i] >= 1000) {
m[i + 1] += m[i] / 1000;
m[i] %= 1000;
} e... | 12 |
#include <bits/stdc++.h>
const int N = 105, MOD = 1000000007;
using namespace std;
int a[N][N], b[N][N];
int main() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) b[i][j] = 1;
}
int m, n;
cin >> m >> n;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2100;
int A[N], B[N];
int n;
const int SZ = N * 10 * 10 * 10 * 10;
int mem[SZ];
int go(int x, int pos, vector<int> elev) {
int ADD1 = 0;
int ADD2 = 0;
for (int i = 0; i < (4); i++)
if (elev[i] == pos) elev[i] = 0, ADD1++;
if (x == n) {
int ok =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, x, y, s, c;
cin >> x >> y;
c = (x * x) + (y * y);
s = sqrt(c);
if ((x >= 0 && y >= 0) || (x < 0 && y < 0)) {
if (x == 0 || y == 0 || s * s == c)
printf("black");
else if (s % 2 == 0)
printf("black");
else
printf("w... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, a, b;
int main() {
cin >> t;
while (t--) {
cin >> n >> m >> a >> b;
if (n * a != m * b)
cout << "NO\n";
else {
cout << "YES\n";
int g[55][55] = {0};
int s = 0;
for (int i = 0; i < n; ++i) {
for (int j = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
const int N = 24, NN = 1 << N;
int a[N];
long long b1, b2, d[NN];
int f[NN];
bool visited[NN];
int s[NN];
int bit[N];
int main() {
int TT = 1;
for (int tt = 1; tt <= TT; ++tt) {
int i, j;
memset(f, 0, sizeof(f));
b1 = b2 = -1;
i... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool v[105];
int i, a, ans = 0, j, n;
int main() {
cin >> n >> a;
for (i = 1; i <= n; ++i) cin >> v[i];
ans = (int)v[a];
for (j = 1; a - j >= 1 || a + j <= n; ++j) {
bool oks = (a - j >= 1 && v[a - j] == 1);
bool okd = (a + j <= n && v[a + j] == 1);
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, p, edges, x;
scanf("%d", &t);
while (t--) {
cin >> n >> p;
x = (2 * n) + p;
edges = 0;
for (int i = 1; i <= n && edges < x; i++) {
for (int j = i + 1; j <= n && edges < x; j++) {
printf("%d %d\n", i, j);
edg... | 7 |
#include <bits/stdc++.h>
int main() {
int a[100005];
int i, n, k, min, m, j, num;
while (scanf("%d%d", &n, &k) != EOF) {
min = 999999999;
num = 0;
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= k; i++) {
num = 0;
for (j = i; j <= n;) {
num += a[j];
j += k... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, x;
int a[100005];
int main() {
cin >> n >> x;
if (n == 0)
printf("YES\n");
else {
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
}
if (sum + n - 1 == x)
printf("YES\n");
else
printf("NO\... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1919810;
int n, t, a[N], s[114];
long long f[N], fac[N], kkr;
int main() {
fac[0] = 1;
f[0] = f[1] = 1;
for (int i = 1; i <= 1919800; i++) fac[i] = fac[i - 1] * i % mod;
for (int i = 2; i <= 1919800; i++)
f[i] = (f[i - 1] +... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
char c1 = 65, c2 = 65, c3 = 65;
int i = 0;
if (s.size() < 3) {
cout << "NO\n" << endl;
return 0;
}
while (i < s.size() - 2) {
c1 = s[i];
c2 = s[i + 1];
c3 = s[i + 2];
if (c1 + c2 + c3 == 198 && c1 != c2)... | 1 |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long dp[500000][3];
long long sum[500000][3];
long long lg[500000][3];
long long cnt[500000][3];
int D[500000];
long long pw(int b, int p) {
if (p == 0) return 1;
long long ans = pw(b, p / 2);
ans *= ans;
ans %= 1000000007ll;
if (p % 2) ans *= b;
ans %= 100... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> adj[107];
bool mark[107];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int nLoop = 0;
queue<int> q;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void checkmin(T &t, T x) {
if (x < t) t = x;
}
template <class T>
void checkmax(T &t, T x) {
if (x > t) t = x;
}
const int N = 105555;
int n, m, h;
int w[N];
int v[N];
long long max_h[N];
int ind[N];
vector<int> vec;
bool cmp(int i, int j) {
if (w[i... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 101;
const long long INF = 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long> st(n);
st[0] = 1;
for (int i = 0; i < n; ++i) {
st[i + 1] = st[i] * 10 % MOD;
}
for (lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[3];
int cnt1 = 1, cnt2 = 0, n;
vector<int> vec, v1, v2;
while (true) {
scanf("%s", s);
if (s[0] == '+')
++cnt1, vec.push_back(1);
else if (s[0] == '-')
++cnt2, vec.push_back(-1);
else if (s[0] == '=') {
scanf("%d... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, q;
long long a[maxn];
struct node {
long long l, r, lm, rm;
long long sum;
} ans[maxn * 4];
long long ls(long long x) { return x << 1; }
long long rs(long long x) { return x << 1 | 1; }
void pushup(long long x, long long l, long long r)... | 14 |
#include <bits/stdc++.h>
int main() {
char arr[205], res[1000];
int i, j, len, flag = 1, k = 0;
scanf("%s", arr);
len = strlen(arr);
if (arr[0] == '@' || arr[len - 1] == '@')
printf("No solution");
else {
for (i = j = 0; i < len; i++) {
res[j++] = arr[i];
if (arr[i] == '@') k = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long a[40] = {
1, 2, 4, 8, 16, 32,
64, 128, 256, 512, 1024, 2048,
4096, 8092, 16184, 32368, 64736, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
void solve() {
long long int n, k;
cin >> n >> k;
long long int p[n];
for (int i = 0; i < n; i++) cin >> p[i];
long long int maxi = 0, num = 1;
for (int i = 0; i < k; i++) {
maxi += n - i;
}
vector<long long int> dis;
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long get() {
long long x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const long long N = 405;
long long P, A[N], I... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, l = 0;
cin >> n >> m;
l = n * m;
cout << l / 2;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e18 + 7;
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long n, k;
cin >> n >> k;
string s;
cin >> s;
long long ans = 0;
if (s.length() == 1 && k > 0) {
s[0] = '0';
cout << s << endl;
return ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int tt = 0; tt < (t); tt++) {
int a, b, c;
cin >> a >> b >> c;
if (a + b == c || a + c == b || b + c == a || (a == b && c % 2 == 0) ||
(a == c && b % 2 == 0) || (b == c && ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
char a[N][N];
int p[N];
string s;
int n, m, sx, sy, ex, ey, ans;
void Follow() {
int len, i, x, y;
x = sx;
y = sy;
len = s.size();
for (i = 0; i < len; i++) {
if ((s[i] - '0') == p[0]) x--;
if ((s[i] - '0') == p[1]) x++;
if ((s[i] - ... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int n, maxn[100005], ans, num;
unsigned long long LtoR1[100005], LtoR2[100005], RtoL1[100005], RtoL2[100005],
mul1[100005], mul2[100005], pos[100005];
pair<int, int> ans1, ans2, ans3;
void init(unsigned long long LtoR[], unsigned long long RtoL[],
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
long long a[N];
long long k;
int n;
long long eval(long long int d) {
long long ret = 0;
for (int i = 1; i <= n; i++) {
ret += ((a[i] + d - 1LL) / d);
}
ret = ret * d;
return ret;
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 1, 1, -1, -1, 0, 0};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
map<int, vector<pair<int, int> > > allowed;
bool valid(int r, int c) {
if (r <= 10e9 && c <= 10e9 && r >= 0 && c >= 0)
for (auto v : allowed[r]) {
if (c >= v.first && c <= v.second) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000 + 123];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int ta;
scanf("%d", &ta);
a[i] = ta + 0ll;
}
for (int i = 0; i < n - 1; ++i) {
int j;
for (j = 0; j <= 20; ++j)
if ((i + (1 << j)) >= n) break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> B;
vector<pair<int, int>> V;
int a, b, c, d, q, ans;
int main() {
cin >> a >> c;
for (int i = 0; i < a; i++) {
cin >> b;
V.push_back({b, i});
}
sort(V.begin(), V.end());
for (int i = 0; i < a; i++) {
if (ans + V[i].first < c + 1) ans += V[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
char a[251];
int main() {
cin >> n >> a;
int m = strlen(a);
a[m] = '0';
for (int i = 0; i <= m; i++) {
if (a[i] == '1' && a[i + 1] == '0') {
ans++;
printf("%d", ans);
ans = 0;
i++;
continue;
} else if (a[i] == '0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char S[int(1e5 + 5)];
set<pair<int, int> > Set;
int main() {
scanf("%s", S + 1);
n = strlen(S + 1);
scanf("%d", &m);
while (m--) {
char s[2];
cin >> s;
Set.insert(make_pair(s[0], s[1]));
Set.insert(make_pair(s[1], s[0]));
}
for (au... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
string s[105];
char a, b, c;
bool cek;
bool hori() {
if (m % 3 != 0) {
return false;
}
a = s[1][0];
b = s[1][m / 3];
c = s[1][2 * m / 3];
if (a == b or a == c or b == c) return false;
for (long long i = 1; i <= n; i++)
for (long long j ... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int cnt;
int n;
string t, ss;
bool ok;
void dfs(int p, string s) {
if (cnt >= 2) return;
if (p >= n) {
cnt++;
return;
}
if (s[p] != '?') {
dfs(p + 1, s);
return;
}
bool a = 1, b = 1, c = 1;
if (s[p - 1] == 'C' || s[p + 1] == 'C') a = 0;
if (s... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
double a[18][18], f[1 << 18];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%lf", &a[i][j]);
f[(1 << n) - 1] = 1;
for (int i = (1 << n) - 1; i; i--)
for (int u = 0; u < n; u++)
if (i & (1 << u))
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2007;
int a[N], b[N], c[N], d[N];
int patl[N * N], patr[N * N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
c[a[i]] = i;
}
for (int i = 1; i <= n; ++i) {
scanf("%d", &b[i]);
d[b[i]] = i;
}
vect... | 15 |
#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 main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
read:
while (n--) {
string s1, s2;
cin ... | 4 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { return '\'' + string(1, c) + '\''; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int n;
struct Node {
int x, i;
Node(int x = -1, int i = -1) : x(x), i(i) {}
bool operator<(const Node &node) const { return x < node.x; }
} nodes[maxn];
int a[maxn];
int d[maxn];
int cnt[maxn];
int main() {
ios::sync_with_stdio(false);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
string s;
int m;
int ans[1100];
int solve(int i, int diff, int last) {
if ((i > 0 && diff <= 0) || diff > 10) {
return 0;
}
if (i == m) {
cout << "YES" << endl;
for (int j = 0; j < m; j++) {
cout << ans[j] << " ";
}
return 1;
}
for (int j... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[4], i, c = 0;
for (i = 0; i < 4; i++) {
cin >> a[i];
}
sort(a, a + 4);
for (i = 0; i < 4; i++) {
if (a[i] == a[i + 1]) c++;
}
cout << c << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b, long long m) {
long long res = 1;
a = a % m;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long binpow(long long a, long long b) {
long long res = 1;
while (b >... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, A;
int mx, l, r;
long long K, B;
set<long long> p;
void cl() {
r = min(r, A - 1);
if (l > r) l = r = 0;
if (K > 0) {
long long qx = A - B;
while (!p.empty()) {
set<long long>::iterator ga = p.lower_bound(qx);
if (ga != ... | 24 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
void tostring(pair<A, B> p) {
cerr << "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <class A>
void tostring(A v) {
int f = 1;
string r = "{";
for (auto& x : v) {
if (!f) {
r += ", ";
}
f = 0;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct Path {
int x;
int y;
int z;
bool operator<(Path const &a) const {
if (x != a.x)
return x < a.x;
else if (y != a.y)
return y < a.y;
else
return z < a.z;
}
};
set<Path> invalid;
int const nmax = 3000;
int dist[1 + nmax][1 + nmax]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double x;
double ans = 0;
cin >> x;
for (int i = 1; i <= x; i++) {
ans += (double)1 / i;
}
cout << ans << "\n";
}
| 2 |
#include <bits/stdc++.h>
const int maxn = 200007;
int low[maxn], high[maxn], val[maxn], n;
void update(int bit[], int k, int c) {
for (; k <= n; k += -k & k) {
bit[k] += c;
}
}
int sum(int bit[], int k) {
int ret = 0;
for (; k; k -= -k & k) {
ret += bit[k];
}
return ret;
}
int main() {
int k, a, b... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
out << "(" << obj.first << "," << obj.second << ")";
return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
typename map<T, T1>::cons... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 7;
vector<int> edg[MAXN];
int niche[MAXN];
map<int, int> mp[MAXN];
void dfs(int u, int p) {
for (int v : edg[u]) {
if (v == p) continue;
dfs(v, u);
niche[u] = max(niche[u], 1 + niche[v]);
mp[u][niche[v] + 1]++;
}
}
int ans[MAXN];
i... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct rings {
int a, b, h;
rings(int aa, int bb, int hh) {
a = aa;
b = bb;
h = hh;
}
};
vector<rings> ara;
int n;
long long int segTree[4 * 100105];
void merge_node(int nd) {
segTree[nd] = max(segTree[nd + nd], segTree[nd + nd + 1]);
}
void build(int s,... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[5001][5001];
vector<int> p, e;
ll solve(int i, int j){
if(i >= p.size()){ // no person left, return 0
return 0;
}
if(j >= e.size()){
return 1e18;
}
if(dp[i][j] != -1){
return dp[i][j];
}
// we h... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;
std::vector<int> g[MX];
int init[MX], goal[MX];
vector<int> res;
void dfs(int x, int par, int lvl, vector<int> flipped) {
init[x] ^= flipped[lvl];
if (init[x] != goal[x]) {
flipped[lvl] ^= true;
init[x]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 300333, inf = 1000111222;
int t, n, a[max_n], ans[max_n];
vector<int> all[max_n];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
all[i + 1].push_back(-1);
}
for (int i = 0; i < n; ++i) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ar[n + 1];
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
int cnt = 0;
while (1) {
bool flag = true;
for (int i = 1; i <= n; i++) {
if (ar[i] != i) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int a[N];
int inverse[N];
vector<int> g[N];
int dp[N];
bool solve(int start) {
if (dp[start] != -1) return dp[start];
bool possible = false;
for (int i = 0; i < g[start].size(); i++) {
int neighbor = g[start][i];
possible = possib... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _print(T a) {
cerr << a;
}
template <class T>
void _print(vector<T> v) {
cerr << "[";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);... | 0 |
#include <bits/stdc++.h>
const int MAXN = 150000 + 5;
using namespace std;
int a[MAXN];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
int ans = 1;
if (a[1] > 1) --a[1];
for (int i = 2, last = a[1]; i <= n; ++i) {
if (a[i] - 1 > last) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int A, int B) {
if (!B) return A;
return gcd(B, A % B);
}
long long int dp[200005];
int lf[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
string s;
cin >> n >> k >> s;
int nearest = -1;
for (int i = n - 1; i >= ... | 13 |
#include <bits/stdc++.h>
int main() {
int i, j, n, t = 1;
char s[105], s1[35];
scanf("%d", &n);
for (i = 0; i <= n; i++) scanf("%c", &s[i]);
if (n < 26)
printf("NO");
else {
for (i = 1; i <= n; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = s[i] + 32;
}
}
s1[1] = s[1];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MAXN = 1010;
char a[MAXN][MAXN];
int u[MAXN][MAXN];
int l1, l2, k, f, n, m;
int x, xx, yy, y;
bool is_in(int x, int y) {
return ((x < 1 || x > n || y < 1 || y > m) ? 0 : 1);
}
queue<pair<int, int> > q;
void dfs(int x, int y, int t) {
if (!is_in(... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 1e9;
int n, m, v[maxn], l[maxn], ans[maxn], r[maxn], p[maxn];
char c;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> c;
v[i] = c - 'a';
}
vector<int> k;
for (int i = 0; i < 3; i++) k.push_back(i)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100007];
int dp[100007];
int used[100007];
void input();
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
void input() {
scanf("%d", &n);
int i;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, K, Q;
int A[100005];
long long PartialR[100005], PartialL[100005], ans;
int B[100005], bl, coord, FreqR[200005], FreqL[200005], T[200005];
long long Coord[200005], Aux[200005], Res[200005];
const int limit = 320;
pair<pair<int, int>, int> Query[100005];
void Read() {... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
const int MAX_N = 3... | 20 |
#include <bits/stdc++.h>
using namespace std;
int a[16][2048];
int n, m;
pair<int, int> w[2048];
int b[12][12];
int f[1 << 12];
int f2[1 << 12];
int p[12][1 << 12];
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
scanf("%d%d", &n, &m);
memset(a, 0, sizeof(a));
for (int i = 0, ThxDem = n; i < Thx... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ta, tb, k;
scanf("%d%d%d%d%d", &n, &m, &ta, &tb, &k);
vector<int> a(n), b(m);
for (int &t : a) scanf("%d", &t);
for (int &t : b) scanf("%d", &t);
if (k >= min(n, m)) {
puts("-1");
return 0;
}
int i = 0, j = 0;
int ans = 0;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3000;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long n, k, dp[maxN][maxN], sum[maxN][maxN], s[maxN], ans;
char c;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> c;
s[i] = c;
}
sum[0][0] = dp[0][0] = 1;
for (int i... | 17 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
char s[112], chat[100][112];
int us[100], n, m;
string P[101];
vector<int> no[100];
bool vis[100][101];
bool go(int j) {
if (j == m) return true;
if (j && us[j] == us[j - 1]) return false;
if (!j && us[j] || j && us[j] && us[j] != us[j - 1]) retur... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.