solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long int n;
string s, t;
vector<long long int> ans;
long long int a[200];
int main() {
cin >> n;
cin >> s >> t;
for (auto j : s) a[j]++;
for (auto j : t) a[j]--;
if (*max_element(a, a + 200) != 0 || *min_element(a, a + 200) != 0)
return cout << -1 << '\n'... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dir1[8] = {1, 0, 0, -1, -1, 1, -1, 1};
int dir2[8] = {0, -1, 1, 0, -1, 1, 1, -1};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, m;
cin >> n >> m;
string str;
cin >> str;
int cnt = 0;
for (int i = 0; i < str.size() - 1; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int a[N];
int cur = 0, cl[N], t[N];
bool del[N];
int main() {
int n;
scanf("%d", &n);
int ng_p = 0, neg = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] < 0) neg ^= 1;
}
for (int i = 1; i <= n; i++) {
if (a[i] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long sz = 1e6 + 10;
long long car[sz], n, m;
struct info {
long long id, gap;
};
struct cmp1 {
const bool operator()(const info &a, const info &b) {
if (a.gap == b.gap) return a.id < b.id;
return a.gap > b.gap;
}
};
struct cmp2 {
const bool operat... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
char c[N];
char s[N];
char t[N];
long long net[N], suf[N], sux[N], sua[N];
long long p[N];
signed main() {
ios::sync_with_stdio(false);
cin >> (c + 1);
long long n = strlen(c + 1);
for (long long i = 1; i <= n; ++i) {
s[i * 2 - 1] =... | 20 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
int ppl, k, l, water, c, d, lem, salt, wneed, sneed;
int main() {
cin >> ppl >> k >> l >> c >> d >> salt >> wneed >> sneed;
water = k * l;
lem = c * d;
cout << min(min(water / wneed, lem), salt / sneed) / ppl << endl;
re... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
map<int, int> mp;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (int j = 0; j < str.length(); j++) {
... | 0 |
#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 = 1... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p;
int q;
int l;
int r;
cin >> p >> q >> l >> r;
int X[p][2];
int Z[q][2];
for (int i = 0; i < p; i++) cin >> X[i][0] >> X[i][1];
for (int i = 0; i < q; i++) cin >> Z[i][0] >> Z[i][1];
long int t[10000];
for (int i = 0; i < 1000; i++) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const int N = 100010;
int low[5 * N], high[5 * N], Min[5 * N];
void Creat(int l, int r, int p) {
low[p] = l, high[p] = r;
if (l == r) {
scanf("%d", &Min[p]);
return;
}
int mid = (l + r) >> 1;
Creat(l, mid, 2 * p);
Creat(mid + ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
char s[N][N];
int n, m;
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
bool visit[N][N];
queue<int> q;
pair<int, int> nodes[N * N], stk[2][N * N];
int d[N][N];
bool in(int first, int second) {
return first >= 0 && first < n && second >= 0 && second < m &&... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const int N = 2000 + 7;
const int M = 22;
const int multipleTest = 0;
int n, r;
int x[N];
double y[N];
int id[N];
double sqr(double a) { return a * a; }
double giao(int i, int j) {
if (x[j] - r > x[i] + r ||... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, p, t;
set<int> s[100010];
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a >> b;
s[a].insert(b);
s[b].insert(a);
}
for (p = 1; p <= n; p++)
if (s[p].size() < n - 1) break;
if (p == n + 1) {
cout << "NO" << end... | 10 |
#include <bits/stdc++.h>
using namespace std;
int N, S, A[100005], B[100005], C[100005];
long long Ans;
inline bool check(int T) {
for (int i = 1; i <= N; i++)
if ((i < S || i > T) && (N - i + 1 < S || N - i + 1 > T) &&
A[i] != A[N - i + 1])
return 0;
for (int i = 1; i <= N; i++) C[i] = 0;
for (... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class U, class T>
void Max(U &first, T second) {
if (first < second) first = second;
}
template <class U, class T>
void Min(U &first, T second) {
if (first > second) first = second;
}
template <class T>
void add(int &a, T b) {
a = (a + b) % 998244353;
}
inli... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[110000];
vector<int> ag[110000];
stack<int> s;
int n, m, x, y, h, u[110000], v[110000], num[110000], sum[110000];
void link(int x, int y) {
g[x].push_back(y);
ag[y].push_back(x);
}
void dfs(int x) {
v[x] = 1;
for (int i = 0; i < g[x].size(); i++)
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T max3(T a, T b, T c) {
return max(a, max(b, c));
}
long long n;
long long const N = 2 * 1e5 + 2;
vector<long long> temp;
vector<vector<long long>> count1(N, vector<long long>(7, 0));
long long checkforbest() {
long long count = 0;
long long sum = 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f * 2;
int a[505];
int n;
long long work(int x) {
long long sum = 0;
for (int i = 0; i < n; i++) {
if (a[i] % x == 0 || (a[i] / x + a[i] % x >= x - 1))
sum += a[i] / x + (a[i] % x != 0);
else
return ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n;
long long int k = 2000000000;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long int sum = 0;
for (int i = n - 1; i >= 0; i--) {
k ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int c[100005][4], col[100005];
vector<int> v[100005];
void dfs1(int gfc, int fc, int p, int no) {
int co;
for (int i = 1; i <= 3; i++) {
if (i != gfc && i != fc) {
co = i;
break;
}
}
col[no] = co;
for (int i = 0; i < v[no].size(); i++) {
if... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 5e5;
const long long int mod = 1e9 + 7;
long long int power[MAX + 1];
long long int c[MAX + 1];
set<long long int> s;
vector<long long int> g[MAX + 1];
map<long long int, vector<long long int>> adj[MAX + 1];
map<long long int, bool> vis[MAX + 1];
m... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool vis[200005];
map<int, int> mp;
int main() {
int h, m, n;
scanf("%d %d %d", &h, &m, &n);
long long ans = 0;
for (int i = 0; i < n; i++) {
char ch;
int idx;
scanf(" %c %d", &ch, &idx);
if (ch == '+') {
int val;
scanf("%d", &val);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
void check(vector<long long>& a) {
for (long long i = 0; i <= a.size() - 1; i++) {
printf("%I64d", a[i]);
printf(" ");
}
printf("\n");
}
void check(long long a[], long long n) {
for (long long i = 0; i <= n - 1; i++) {
printf("%I64d", a[i]);
printf("... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9;
const long long oo64 = 1e18;
const long long MAXSIZE = oo + 7;
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
srand(time(NULL));
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vect... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
set<int> si;
for (int i = 0; i < n; i++) {
if (arr[i] % k == 0) {
if (si.find(arr[i] / k) == si.end()) si.insert(arr[i]);
} else
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long k, m;
long long mod = 1e9 + 7;
vector<long long> ar;
vector<long long> graph[200005];
vector<pair<long long, long long> > travel;
int D[200005], tin[200005], tout[200005];
vector<pair<long long, long long> > stree[4 * 200005];
int tag[200005 + 1];
int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int head[200000 * 3], top = 0, num = 1;
struct node {
int to;
int next;
} edge[200000 * 3];
int a[200000 * 3];
long long bit[3][200000 * 3];
long long s[4][200000 * 3];
void add(int from, int to) {
edge[top].to = to;
edge[top].next = head[from];
head[from] = top++... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mp;
int A[5010];
int X[5010], Y[5010], Z[5010];
int ans[5010][5010];
int p[5010], q[5010];
int cnt;
int n;
void check(int x) {
for (int i = 0; i < n; i++) {
int pos = A[i] ^ x;
if (pos >= n) return;
p[pos] = i;
q[i] = pos;
}
if... | 12 |
#include <bits/stdc++.h>
using namespace std;
void cal() {
long long no1, no2;
cin >> no1 >> no2;
if (no1 == 1 || no1 == 2) {
cout << 1 << "\n";
} else {
int count = 2;
for (int i = 2; i <= no1; i++) {
count += no2;
if (count >= no1) {
cout << i << "\n";
break;
}
... | 0 |
#include <bits/stdc++.h>
int main() {
int n, i, j, k = 0, count = 0;
scanf("%d", &n);
j = n;
for (i = 1; i <= j; i++) {
k = k + i;
n = n - k;
if (n >= 0)
count++;
else
break;
}
printf("%d", count);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
const int M = 100005;
const int mod = (int)1e9 + 7;
int dp[M];
bool flag = 0;
int to[N], num[N], vis[N], t;
void dfs(int u, int f) {
vis[u] = 0;
num[u] += num[f];
if (to[u]) {
t -= num[u];
if (t < 0) flag = 0;
dfs(to[u], u);
}
to[u] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 2e9 + 7;
const int N = 3000200;
long long a[N];
long long sum, cnt;
int main() {
ios_base::sync_with_stdio(0);
int n, z = 0, k = 0, d = 0, t = 0;
cin >> n;
k = n;
sum = 2;
while (sum % 4 != 0) {
n = k;
k++;
sum = 0;
while (n > 0) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void fldsmdfr() {}
int main() {
fldsmdfr();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t;
t = 1;
while (t--) {
int n, i, j, k, ans = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
const long long INF = 1000000000 + 9;
const long double EPS = 1e-9;
const long double PI = acos(-1);
char s1[MAXN], s2[MAXN];
int k4, k7, len;
void Input() {
ifstream in("INPUT.TXT");
cin >> s1;
cin >> s2;
in.close();
}
void Solution() ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0LL) return b;
if (b == 0LL) return a;
return gcd(b, a % b);
}
long long modx(long long base, long long ex) {
long long ans = 1LL, val = base;
while (ex > 0LL) {
if (ex & 1LL) ans = (ans * val) % 1000000007LL;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e11;
int N;
long long L[600005];
long long R[600005];
struct SplayTree {
int par[600005], ch[600005][2], root, tot1, sz[600005];
long long key[600005], add[600005], sum[600005], m[600005];
int s[600005], tot2;
long long ar[600005];
void Upda... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
string s;
cin >> s;
int fl = 1;
for (int i = 0; (i + p) < n; i++) {
if (s[i] == '1') {
if (s[i] == '0') {
break;
}
if (s[i + p] == '.') {
s[i + p] = '0';
break;
}
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int MaxVal = int(1e6);
long long tree[int(1e6 + 6)][2];
long long read(int idx, int r) {
long long sum = 0;
while (idx > 0) {
sum += tree[idx][r];
idx -= (idx & -idx);
}
return sum;
}
void update(int idx, int val, int r) {
while (idx <= MaxVal) {
tree[... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
ll n, m;
cin >> n >> m;
string s[50];
bool check[50];
for (ll i = 0; i < n; i++) {
cin >> s[i];
check[i] = true;
}
vector<vector<ll> > c;
for (ll i = 0; i < m; i++) {
vector<ll> temp;
c.push_back(temp);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 10;
int H, W, dis[MAXN][MAXN], vis[MAXN][MAXN], dcnt;
char str[MAXN][MAXN];
void work(int sx, int sy) {
dcnt++;
int cx = sx, cy = sy;
vector<int> vec;
bool mod = false;
int rec = 0;
while (1) {
vec.push_back(cx * W + cy);
vis[cx][... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
int n = 0, ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
return n;
}
const int MAX_N = 1000 + 3;
int n, a[MAX_N], b[MAX_N];
bool vis[MAX_N];
int main() {
n = readInt();
int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
static void redirect(int argc, const char **argv) {
ios::sync_with_stdio(false);
cin.t... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y) {
long long ans = 1;
x = x % mod;
while (y > 0) {
if (y & 1) ans = (ans * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ss[200002][2], ys[200002];
int n, c, fh, i, gs, gss, t, m, j, k;
bool ed[200002];
inline void read(int &x) {
c = getchar();
fh = 1;
while ((c < 48) || (c > 57)) {
if (c == '-') {
c = getchar();
fh = -1;
break;
}
c = getchar();
}
x... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct adat {
int os = -1, mely = 1;
bool egyezik = false;
};
struct update {
int ind;
adat d;
};
const int maxn = (int)2e5;
adat csop[2 * maxn];
update upd[4 * maxn];
int veg = 0;
int n, m;
int ki[maxn + 1];
vector<pair<int, int>> v;
int Os(int a) {
if (csop[a].o... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int _ = 1e6 + 7, P = 1e9 + 7, IV6 = (P + 1) / 6;
long long val[4], N, pw[1000003][4];
int main() {
cin >> N;
pw[0][0] = 1;
val[0] = N % P * (N % P + 1) % P * (N % P + 2) % P;
val[1] = (-3 * N - 2) % P;
val[2] = -3 * N % P;
val[3] = 2;
for (int i = 1; 1ll... | 21 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.);
template <class T>
inline T sq(T x) {
return x * x;
}
bool endsWith(string a, string b) {
if (a.length() < b.length()) return false;
return a.substr(a.length() - b.length()) == b;
}
void solve() {
string endings[... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
long long ans;
map<int, long long> mp;
pair<int, int> dig[M * 2];
int sz[M], mx[M], A[M];
int head[M], nxt[M << 1], to[M << 1], V[M << 1], tot;
int NE, Mx, root, num, m, n;
bool mk[M];
inline void Add(int x, int y, int z) {
nxt[++tot] = head[x];
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int row[] = {0, 1, 0, -1};
int col[] = {1, 0, -1, 0};
const long long N = 1e6 + 10;
const long long M = 1e18 + 7;
const long long H = 1e9 + 7;
const long long base = 131;
long long logx(long long a, long long bs) { return log(a) / log(bs); }
long long Max(long long a, long ... | 8 |
#include <bits/stdc++.h>
int n, m, l, r, a, b;
int main() {
scanf("%d %d", &n, &m);
for (int h = 1; h <= n; h++) {
scanf("%d", &l);
if (l < 0)
a++;
else
b++;
}
for (int h = 0; h < m; h++) {
scanf("%d %d", &l, &r);
int to = r - l + 1;
if (to % 2 == 0 && a >= to / 2 && b >= to ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[123][123];
int main() {
int n, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> a[i][j];
for (int i = 1; i <= n; i++) {
sum += a[i][i];
sum += a[i][n - i + 1];
sum += a[i][n / 2 + 1];
sum += a[n / 2 + 1][i... | 0 |
#include <bits/stdc++.h>
int main() {
long long t, a, b, n, m, k;
scanf("%lld", &t);
while (t > 0) {
t--;
scanf("%lld%lld%lld%lld", &a, &b, &n, &m);
if (a > b) {
k = a;
a = b;
b = k;
}
if (a < m) {
printf("No\n");
continue;
}
if (a + b < n + m) {
pri... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool arr[8][8];
memset(arr, true, sizeof(arr));
string a, b;
cin >> a >> b;
int row, col, row2, col2;
col = a[0] - 97;
row = a[1] - 49;
for (int i = 0; i < 8; i++) {
arr[row][i] = false;
}
for (int i = 0; i < 8; i++) {
arr[i][col] = ... | 4 |
#include <bits/stdc++.h>
int a[100010], b[100010], f[100010];
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < n; i++) scanf("%d", &b[i]);
for (i = 0; i < n; i++) f[a[i]] = b[i];
for (i = 1; i <= n; i++) printf("%d ", f[i]);
puts("");
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 4e3 + 123;
int dx[8] = {1, 0, 0, -1, 1, -1, 1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
cout << (n - 2) * (n - 2);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
return x * f;
}
void print(long long x) {
if (x < 0) x = -x, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int k;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int dp[400005];
long long solve(long long a, long long b) {
for (int i = (int)0; i <= (int)400000; i++) dp[i] = 1000000;
dp[a] = 0;
for (int i = a; i >= 0; i--) {
dp[i] = min(dp[i], d... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
bool dp1[5001][5001] = {};
int dp2[5001][5001] = {};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++) {
dp1[i][i] = 1;
dp2[i][i] = 1;
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, k, ans, a, b, c;
char s[5];
int main() {
scanf("%d", &n);
x = 0;
y = 1023;
while (n--) {
scanf("%s", s);
scanf("%d", &k);
if (s[0] == '|') x |= k, y |= k;
if (s[0] == '^') x ^= k, y ^= k;
if (s[0] == '&') x &= k, y &= k;
}
a = x ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
const long double EPS = 1e-12;
int lazy[200005][55];
int tree[200005][55];
int n, k;
int a[35005];
map<int, int> ma;
int pre[35005];
int dp[55][35005];
void build(int v, int left, int right, int id... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long numberDigits(long long n) {
long long count = 0;
while (n != 0) {
n /= 10L;
count++;
}
return count;
}
int main() {
long long n;
cin >> n;
long long digits = numberDigits(n);
long long cur = 1;
long long count = 0;
for (long long i = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, l, r;
cin >> t;
while (t--) {
cin >> l >> r;
if (2 * l > r) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[25];
bool visited[25];
bool dfs(int val, int pos);
int main() {
int i, j, k;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
memset(visited, false, sizeof(visited));
for (i = 0; i < n; i++) {
for (j = i - 1; j >= 0; j--)... | 15 |
#include <bits/stdc++.h>
using namespace std;
char s[200001];
void CopyArray(int n, int s[], int t[]) {
for (int i = 0; i <= n; ++i) {
t[i] = s[i];
}
}
int suffixArray[200001], posInSuffixArray[200001], lcpArray[200001],
clas[200001], order[200001], cnt[200001], temp[200001], lg[200001],
lcpTable[18][20... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 1; i < n; ++i) cin >> a[i];
vector<int> vis;
vis.push_back(1);
for (int i = 1; i < n; ++i) {
vis.push_back(i + a[i])... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 25;
long long i, j, k, l, m, n, o, q, r, s, t, u, v, w, x, y, z, cnt[(1 << 20)],
hbit[(1 << 20)];
double dp[(1 << 20)], sum[(1 << 20)], p[df];
int main() {
{
scanf("%lld%lld", &n, &k);
s = (1 << n) - 1;
for (long long i ... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void fileio(const char* in, const char* out) {
freopen(in, "r", stdin);
freopen(out, "w", stdout);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vecto... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
const int mo = 998244353;
const int N = (1 << 20) + 10;
const int maxn = (1 << 20) + 10;
int fexp(int a, int n) {
int res = 1;
for (; n; n >>= 1, a = 1ll * a * a % P)
if (n & 1) res = 1ll * res * a % P;
return res;
}
struct da {
int n, w... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long N, M, K;
int p[400000];
map<long long, int> mpN, mpM, mpK;
vector<long long> prime, v;
void dfs(map<long long, int>::iterator it, long long ret) {
if (it == mpN.end()) {
v.push_back(ret);
return;
}
long long k = 1;
dfs(next(it), ret);
int siz = i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int _next[1000001], behind[1000001], front[1000001], ans[1000001];
inline int getint() {
int n = 0, negflag = 0;
char c = getchar();
while (!(c >= '0' && c <= '9')) {
if (c == '-') negflag = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = (n << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[500];
long long c[501][501];
long long dp[2][501][501];
int main() {
int n, m, mod, x = 0, y = 0, i, j, k;
scanf("%d %d %d", &n, &m, &mod);
for (i = 0; i < m; i++) {
char s[501];
scanf("%s", s);
for (j = 0; j < n; j++) {
if (s[j] == '1') a[j]++... | 13 |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
//const int mod = 1e9 + 7;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string first, second, word;
cin >> first >> second >> word;
string answer = "";
for (char c : word) {
if (c > 47 && c < 58) {
answer += c;
continue;
}
bool isupper = c < 91;
int low = c;
if (isupper) low = c + 32;
for... | 0 |
#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;
long long n, m, k;
long long s[MAXN];
long long ult[MAXN];
int main() {
scanf("%lld", &... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool d[1 << 19] = {};
int sz[15] = {3, 4, 5, 4, 3, 3, 4, 5, 4, 3, 3, 4, 5, 4, 3};
int pos[15][5] = {
{0, 1, 2, -1, -1}, {3, 4, 5, 6, -1}, {7, 8, 9, 10, 11},
{12, 13, 14, 15, -1}, {16, 17, 18, -1, -1}, {0, 3, 7, -1, -1},
{1, 4, 8, 12, -1}, {2, 5, 9, 13,... | 12 |
#include <bits/stdc++.h>
using namespace std;
int visited[1000];
int cnt = 0;
void DFS(int k, int y, int x) {
int cell = x + 10 * y + 100 * k;
if (visited[cell] == -1 && 0 <= x && x < 10 && 0 <= y && y < 10 && 0 <= k &&
k < 10) {
cnt++;
visited[cell] = 1;
DFS(k + 1, y, x), DFS(k, y + 1, x), DFS(k,... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long Inf = 1e18;
const int N = 3e5 + 10;
const int mod = 0;
const int blo = 547;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
wh... | 24 |
#include <bits/stdc++.h>
using namespace std;
int N, n, m, K, i, j, k, x, y, ansx, ansy;
long long sum[2005][2005], now, ans;
char ch;
void read(int &x) {
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
;
for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int main() {
scan... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const int mod = 1000003;
long long f[maxn + 10];
void init() {
f[0] = 1;
for (int i = 1; i <= maxn; i++) {
f[i] = (long long)f[i - 1] * i % mod;
}
}
long long pow_mod(long long a, long long b) {
long long ans = 1;
a %= mod;
while (b... | 10 |
#include <bits/stdc++.h>
char ch;
bool fs;
void re(int& x) {
while (ch = getchar(), ch < 33)
;
if (ch == '-')
fs = 1, x = 0;
else
fs = 0, x = ch - 48;
while (ch = getchar(), ch > 33) x = x * 10 + ch - 48;
if (fs) x = -x;
}
using namespace std;
const int mod = 1000000007;
int n, m, fac[1000001], an... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
int main() {
cin >> n >> k;
cin >> s;
if (n - k < k - 1) {
for (int i = k - 1; i < n; i++) {
cout << "PRINT " << s[i] << "\n";
if (i + 1 < n) cout << "RIGHT\n";
}
for (int i = n - 1; i > k - 2; i--)
if (i - 1 >= 0) cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int Q;
cin >> Q;
vector<long long> shift(64, 0);
for (int qq = 0; qq < Q; ++qq) {
int type;
long long x;
cin >> type;
cin >> x;
int level = 64 - __builtin_clzll(x);
if (typ... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double PI = 2 * acos(0.0);
const double EPS = 1e-8;
const int INF = 1000000000;
int n;
map<int, int> q;
int d[100001];
int getf(int n) {
if (q.find(n) != q.end()) return q[n];
set<int> w;
for (int k = 2; (k * (k + 1)) /... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int K = 1e5 + 7;
const int mod = 1e9 + 7;
int n, m, q, f[K], rl[K];
map<string, int> hs;
string sa, sb;
int fd(int x) {
if (f[x] == x) return x;
int fa = f[x];
f[x] = fd(f[x]);
rl[x] = (rl[x] + rl[fa]) % 2... | 12 |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T, n;
signed main() {
scanf("%lld", &T);
while (T--) {
scanf("%lld", &n);
if (n % 2050) {
puts("-1");
} else {
n = n / 2050;
int ans = 0;
while (n) {
... | 0 |
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) +... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-18;
struct node {
double x;
int flag;
} q[350000];
bool cmp(node a, node b) { return a.x > b.x; }
int cnt;
long long cntzero1, cntzero2;
int r[350000], w[350000];
int fir[350000], las[350000];
long long fsum1[350000], fsum2[350000], lsum1[350000], ... | 19 |
#include <bits/stdc++.h>
using namespace std;
string c, d;
string z(int i, int j, int k, int l) {
string r;
r += c[i];
r += c[j];
r += c[k];
r += c[l];
return r;
}
string rotar() {
if (c[0] == 'X') return c;
if (c[1] == 'X') {
swap(c[1], c[0]);
return c;
}
if (c[2] == 'X') {
swap(c[2], c... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, w, h, m;
cin >> n >> m;
long long int a[n];
long long int ans = -1, count = 1, temp = 10000000000, f = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
temp = min(t... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
long long judge(vector<int> a) {
int ans = 0;
int len = a.size() / 2;
for (int i = 0; i < len; i++) {
ans += a[2 * i + 1] - a[2 * i];
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
a.resize(2 * n... | 7 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int l;
int r;
int id;
} TV;
bool compare(TV a, TV b) { return (a.l < b.l); }
bool compare2(TV a, TV b) { return (a.r < b.r); }
int main() {
int n, i, temp, count;
scanf("%d", &n);
TV a[200001];
for (i = 0; i < n; i++) scanf("%d %d", &a[i].l, &... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long k, n, w, sum, i;
int main() {
cin >> n;
cout << n / 2520 << endl;
}
| 3 |
#include <bits/stdc++.h>
int r, g, b, s, min, a[4], i;
int main() {
scanf("%d %d %d", &r, &g, &b);
a[0] = r;
a[1] = g;
a[2] = b;
min = 1000000001;
for (i = 0; i < 3; i++) {
if (min > a[i]) {
min = a[i];
}
}
r = r - min;
g = g - min;
b = b - min;
s = r / 3 + g / 3 + b / 3 + min;
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, K;
vector<int> vect;
int res;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> K;
res = n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
vect.push_back(a);
}
sort(vect.begin(), vect.end());
int L = 0;
int R =... | 4 |
#include <bits/stdc++.h>
using namespace std;
double w, h, a, s = 0, x[5], y[5];
const double pi = 3.1415926535;
vector<pair<double, pair<double, double> > > ans;
void intersect(double x1, double y1, double x2, double y2, double x3, double y3,
double x4, double y4) {
double k = (y3 - y4) / (x3 - x4), b... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 0;
bool tab[11];
bool ans = 1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int l, r;
cin >> l >> r;
int ans;
for (int i = l; i <= r; i++) {
ans = 0;
for (int i = 0; i <= 10; i++) tab[i] = 0;
int x = i;
wh... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, q, ans;
const long long N = 3e5 + 5;
long long arr[N];
void add(long long pos, long long factor) {
long long x = arr[pos] * factor;
if (arr[pos] > arr[pos + 1] && arr[pos] > arr[pos - 1]) {
ans += x;
} else if (arr[pos] < arr[pos + 1] && arr[pos] < ar... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> AdjList[maxn];
vector<int> trade[maxn];
int ans[maxn];
int deg[maxn];
bool ok[maxn];
queue<int> q;
int res = 0;
int n;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i < n; i++... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long a[maxn], b[maxn], sum1, sum2, ans1, ans2;
int main() {
int N, M;
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) scanf("%lld", &a[i]), sum1 += a[i];
for (int i = 1; i <= M; i++) scanf("%lld", &b[i]), sum2 += b[i];
ans1 = sum2... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.