solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, x = 0, count = 0;
cin >> n;
bool arrayval[n];
bool check = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> x;
if ((x == 1) || (x == 3)) {
check = false;
}
}
if (check == true) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> eea(int a, int b) {
if (b == 0) return make_pair(1, 0);
auto ret = eea(b, a % b);
return make_pair(ret.second, ret.first - a / b * ret.second);
}
struct Modint {
int val;
Modint(int nval = 0) { val = nval; }
Modint& operator+=(Modint r) {
val ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int ii, n, m, adj[510][510], deg[510], con[510][510], vst[510], mL[510], flag;
int Find(int u) {
int i, v;
for (i = 0; i < deg[u]; i++) {
v = adj[u][i];
if (ii == v) continue;
if (mL[v] == -1) return mL[v] = u, 1;
}
for (i = 0; i < deg[u]; i++) {
v =... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
const int M = 1e4 + 10;
int x[M], y[M];
int ans, k, n, m, ccnntt = 0;
map<int, int> ycq[M];
struct aa {
int u, v, w, next;
} edge[20 * M];
int pre[3 * M];
int dis[3 * M];
void add(int u, int v, int w) {
edge[ans].u = u;
edge... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int main() {
int n;
cin >> n;
char op[2];
int x, y, h, w;
int l, r;
l = 0;
r = 0;
while (n--) {
scanf("%s", op);
if (op[0] == '+') {
scanf("%d%d", &x, &y);
l ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct pers {
int count;
pers *l, *r;
pers(int val) {
this->l = NULL;
this->r = NULL;
this->count = val;
}
pers(pers *l, pers *r) {
this->l = l;
this->r = r;
if (this->l != NULL) this->count = l->count;
if (this->r != NULL) this->count ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000 + 7;
const double esp = 1e-13;
const long double PI = acos(-1.0);
long long nhan(long long x, long long y, long long m) {
long long ans = 0;
while (y) {
if (y % 2) ans = (ans + x) % m;
x = x * 2 % m;
y /= 2;
}
return ans;... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long md = 1000000007) {
long long res = 1;
x %= md;
while (y > 0) {
if (y & 1) res = (res * x) % md;
x = (x * x) % md;
y = y >> 1;
}
return res % md;
}
long long max1(long long a, long long b, long long c ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100, M = 1000, INF = (1 << 30) - 1;
int n, m, st0, td0;
struct side0 {
int x, y, g;
side0(int X = 0, int Y = 0, int G = 0) {
x = X;
y = Y;
g = G;
}
} a[M + 9];
void into() {
scanf("%d%d%d%d", &n, &m, &st0, &td0);
for (int i = 1; i <= m; +... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
map<char, vector<long long> > m;
for (long long i = 0; i < n; ++i) {
m[s[i]].push_back(i + 1);
}
long long k;
cin >> k;
while (k--) {
string t;
cin >> t;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
void debn(vector<int> a) {
for (auto v : a) cout << v << ' ';
cout << endl;
}
void debnn(vector<vector<int>> a) {
for (auto v : a) {
for (auto w : v) cout << w << ' ';
cout << endl;
}
}
long long powmod(long lon... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<char> > a(6, vector<char>(8));
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 8; j++) {
cin >> a[i][j];
if (a[i][j] == '.') {
if (i == 0 || i == 1) {
if (j == 0 || j == 1 || j == 6 || j == 7) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int LOGN = 20;
const long long oo = 1e18;
int n, m, q, a[N], b[N];
vector<pair<int, int> > g[N];
long long seg[4 * N], lazy[4 * N], best[N];
void push(int n, int s, int e) {
if (lazy[n]) {
seg[n] += lazy[n];
if (s != e) lazy[2 * n] += l... | 19 |
#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.0000000001;
using namespace std;
int B[100005][21];
int S[100005];
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout... | 16 |
#include <bits/stdc++.h>
inline int clz(int x) { return __builtin_clz(x); }
inline int clz(long long x) { return __builtin_clzll(x); }
inline int lg2(int x) { return !x ? -1 : 31 - clz(x); }
inline int lg2(long long x) { return !x ? -1 : 63 - clz(x); }
using namespace std;
const int M = 200000 + 10, mod = (int)1e9 + 7;... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class A>
istream& operator>>(istream& in, vector<A>& i) {
for (auto& x : i) in >> x;
return in;
};
template <class A, class B>
istream& operator>>(istream& in, pair<A, B>& i) {
in >> i.first >> i.second;
return in;
}
int main() {
int n, m;
cin >> n >> ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
long long int ans = 1;
cin >> n >> x;
for (int i = 0; i < n + x; i++) {
ans = ans * 2;
ans %= 998244353;
}
cout << ans << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, q;
cin >> n >> q;
while (q--) {
long long x, y;
scanf("%lld %lld", &x, &y);
long long lines = x - 1;
long long even =
(lines / 2 + lines % 2) * (n / 2 + n % 2) + (lines / 2) * (n / 2);
if (y % 2 == 0)
even +=... | 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);
}
struct point {
int x, y, col, ind;
};
bool cw(const point &a, const point &b, const point &c) {
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x ... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int n, x, ans, a[105], b[105], c[105], s1[105], s2[105], dp[105][10005];
int main(){
scanf("%d", &n);
for(int i=1; i<=n; ++i){
scanf("%d", &c[i]);
s1[i] = s1[i-1] + c[i];
}
for(int i=1, s=0; i<n; ++i) scanf("%d", &b[i]);
scanf("%*d%d", &x... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
vector<int> ideal(n);
for (int i = 0; i < n; i++) ideal[i] = i + 1;
int ctr = 0;
int oddIndex = 0;
while (ar... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, w, e, r, t;
scanf("%d%d%d", &q, &w, &e);
e--;
q *= 10;
for (r = 0; r < 10; r++)
if ((q + r) % w == 0) {
q += r;
break;
}
if (q % w != 0)
printf("-1");
else {
printf("%d", q);
for (; e; e--) printf("0");
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
printf("%d\n", n >= 31 ? m : m % (1 << n));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string str;
bool arr[123];
int main() {
int n;
cin >> n >> str;
for (int i = 0; i < n; i++)
if (str[i] == '*') arr[i + 1] = 1;
for (int i = 1; i <= n; i++) {
if (arr[i]) {
int c = 0;
for (int J = 1; J <= n; J++) {
c = 0;
int k = i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400;
int n, v, e;
long long sum = 0;
int a[N + 1], s[N + 1], fa[N + 1], b[N + 1];
vector<int> nei[N + 1];
int getFather(int i) {
if (fa[i] == -1) return i;
return fa[i] = getFather(fa[i]);
}
bool vis[N + 1];
bool mark[N + 1];
int currentVo;
vector<pair<int... | 17 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> clockwise(pair<int, int> st, int tymes, int row,
int col) {
long long prow = 0;
long long pcol = 0;
long long currow = 0;
long long curcol = 0;
prow = currow = st.first;
pcol = curcol = st.second;
... | 7 |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<ctime>
#include<cstring>
#include<map>
#include<queue>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
inline int read(){
int x=0,f=1;
char c=getc... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, first;
cin >> n >> first;
vector<int> a(n, 0);
map<int, int> all;
for (int(i) = (0); (i) < (int)(n); ++(i)) {
cin >> a[i];
}
long long res = 0;
for (int(i) = (0); (i) < (int)(n); ++(i)) {
int k = first ^ a[i];
if (all.count(k)... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
vector<int> g[MAXN + 1];
vector<int> game_grph[2 * MAXN + 10];
int seen[2 * MAXN + 10], cycle, father[2 * MAXN + 10];
void game_dfs(int node) {
seen[node] = 1;
for (auto it : game_grph[node])
if (seen[it] == 0) {
father[it] = node;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int abs(int a) {
if (a < 0) return -a;
return a;
}
bool vocal(char a) {
if (a == 'A' or a == 'E' or a == 'I' or a == 'O' or a == 'U' or a == 'Y')
return true;
return false;
}
int main() {
string s;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long int n, i, a[10004], m = 0, ans = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
m = max(a[i], m);
if (m <= i) {
ans++;
m = 0;
}
}
cout << ans;
ret... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[705][705], du[705], f[705][705];
long long ans, ans1;
int n, m, xc, yc, c1, c2;
int main() {
memset(a, 0, sizeof(a));
scanf("%d %d", &n, &m);
memset(du, 0, sizeof(du));
for (int i = 1; i <= m; i++) {
scanf("%d %d", &xc, &yc);
a[xc][yc] = 1;
a[yc][x... | 16 |
#include <bits/stdc++.h>
using namespace std;
int N;
int n;
int A[10240];
int B[10240];
int C[10240];
void init(int idx) {
if (idx > N) return;
B[idx] += A[idx];
B[idx * 2] += B[idx];
B[idx * 2 + 1] += B[idx];
init(idx * 2);
init(idx * 2 + 1);
C[idx] = B[idx];
C[idx] = max(C[idx], max(C[idx * 2], C[idx ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, a, b, ans;
cin >> t;
for (int z = 0; z < t; z++) {
cin >> a >> b;
ans = b + (a - 1) * 9;
cout << ans << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, d;
int a[100], x[100], y[100];
long long dist[100][100];
bool vis[100];
long long best[100];
bool solve(long long s) {
priority_queue<pair<long long, int> > q;
q.push(make_pair(s, 0));
memset(vis, 0, sizeof(vis));
memset(best, -1, sizeof(best));
while (!q.e... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, x, m, val, k1, k2, k3, b[30000], c[30000],
mod = 5237732522753;
string s, s1, s2;
long long dp[3000][3000];
unordered_map<long long, long long> mymap;
unordered_map<long long, long long>::iterator it;
int main() {
ios_base::sync_with_stdio(fal... | 12 |
#include <bits/stdc++.h>
using namespace std;
char a[100005], b[100005];
long long occ[2][2], ans;
int n;
int main() {
scanf("%d%s%s", &n, a, b);
for (int i = 0; i < n; i++) occ[a[i] - '0'][b[i] - '0']++;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
for (in... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, j, sum = 0, h, hu;
int a[5], b[5], w[5];
a[0] = 500;
a[1] = 1000;
a[2] = 1500;
a[3] = 2000;
a[4] = 2500;
for (i = 0; i < 5; i++) {
scanf("%d", &j);
b[i] = j;
}
for (i = 0; i < 5; i++) {
scanf("%d", &j);
w[i] = j;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long d = 2520, n;
scanf("%I64d", &n);
printf("%I64d", n / d);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int s[1001], temp[1001];
while (scanf("%d", &n) != EOF) {
scanf("%d", &s[0]);
temp[0] = 0;
for (int i = 1; i < n; i++) {
scanf("%d", &s[i]);
if (s[i] >= s[i - 1])
temp[i] = temp[i - 1] + 1;
else
temp[i]... | 3 |
#include <bits/stdc++.h>
int a2[1005][1005], a5[1005][1005], p2[1005][1005], p5[1005][1005],
f[1005][1005][2], n, t, al = -1, zx, zy;
char ans[2005];
bool zeo;
void fj(int x, int y, int k) {
if (!k) return;
while (k % 2 == 0) a2[x][y]++, k /= 2;
while (k % 5 == 0) a5[x][y]++, k /= 5;
}
void find(bool md) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<string, string> base;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string k, v;
cin >> k >> v;
base[v] = k;
if (!base[k].empty()) {
base[v] = base[k];
}
base.erase(k);
}
cout << base.size() << endl;
for (auto &kvp... | 3 |
#include <bits/stdc++.h>
using namespace std;
char c[100010];
int b[100];
int main() {
int n;
scanf("%d%s", &n, c + 1);
for (int i = 1; i <= n; ++i) {
if (c[i] == 'L') {
for (int j = 0; j <= 9; ++j)
if (!b[j]) {
b[j] = 1;
break;
}
} else if (c[i] == 'R') {
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double sum = 0;
double a[10000], b[10000];
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sum += b[i];
}
sum /= n;
sum += 5;
printf("%.3lf", sum);
return 0;
}
| 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans1, ans2;
vector<int> marker[1010], cap[1010];
int mx = -0x3f3f3f3f, mi = 0x3f3f3f3f;
void read() {
scanf("%d%d", &n, &m);
int c, d;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &c, &d);
marker[d].push_back(c);
mx = max(mx, d);
mi = min(mi,... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100];
int main() {
int n, i, w, b, res = 0;
cin >> n >> w >> b;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n / 2; i++) {
if (a[i] == 2 && a[n - 1 - i] == 2) {
res += 2 * (min(w, b));
}
if (a[i] == 0 && a[n - 1 - i] == 1) {... | 2 |
#include <bits/stdc++.h>
const int inf = (int)1e9;
using namespace std;
vector<pair<char, long long> > a, b;
int n, m;
long long d[800011];
vector<pair<char, long long> > c;
long long size = 1;
void kmp() {
for (int i = 1; i < size; i++) {
int j = d[i - 1];
while (j && c[i] != c[j]) {
j = d[j - 1];
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int q;
cin >> q;
while (q--) {
long long num;
cin >> num;
long long ct = 0;
int flag = 0;
while (num != 1) {
if (num % 2 == 0) {
num /= 2;
} else if (num %... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
int n, m;
scanf("%d %d", &n, &m);
priority_queue<long long, vector<long long>, greater<long long>> q;
for (int i = 0; i < m; i++) {
long long s, t;
scanf("%I64d%I64d", &s, &t);
q.push(s + t);
printf("%I64d\n",... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n];
int l = 0;
int m = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 0) l++;
}
for (int i = 0; i < n; i++) {
if (a[i] == 0) m++... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long MAX = 1e18;
bool comp(string s1, string s2) { return s1.size() < s2.size(); }
int main() {
long long n;
cin >> n;
if (n == 1) {
cout << "? " << 1 << " " << 1 << "\n";
string ans;
cin >> ans;
cout << "! " << ans;
return 0;
}
cout << "?... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string time;
cin >> time;
vector<int> hour, minute;
bool flag(0);
int minBase(2);
for (int p = 0; p < time.size(); p++) {
int c;
if (time[p] == ':') {
flag = 1;
continue;
} else if ('0' <= time[p] && time[p] <= '9') {
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ans[55];
int cnt[55];
int all;
int main() {
int b, n;
int v;
scanf("%d %d %d", &b, &v, &n);
all = (b * v);
v *= n;
for (int i = 1; i <= n; ++i) {
if (cnt[i] > all) {
puts("NO");
return 0;
}
while (cnt[i] + v <= all)... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct IT {
int d[100200];
void upd(int x, int k) {
if (x < 1) return;
for (; x < 100010; x += x & (-x)) d[x] += k;
}
int get(int x) {
int ans = 0;
for (; x > 0; x -= x & (-x)) ans += d[x];
return ans;
}
} it;
vector<pair<double, int> > a;
doub... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], lim[N], sum[N], ans;
void count(int l, int r) {
for (int i = (int)(1); i <= (int)(n); i++) lim[i] = sum[i];
int len = r - l + 1;
for (int i = (int)(1); i <= (int)(len / 2); i++)
if ((lim[a[r - i + 1]] -= 2) < 0)
return;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long read() {
long long s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[100007];
int main() {
ios_base::sync_with_stdio(0);
int s;
cin >> n >> s;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
if (n == 2) {
cout << setprecision(20) << fixed << (... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
int n, ct, top, ans, d[Maxn], pos[Maxn], sta[Maxn], far1[Maxn], far2[Maxn],
mini[Maxn], tmp[Maxn];
int lowbit(int x) { return x & -x; }
void add(int x, int y) {
for (int i = x; i <= ct; i += lowbit(i)) mini[i] = min(mini[i], y);
}
int ask(int ... | 22 |
#include <bits/stdc++.h>
using namespace std;
struct po {
int x;
int y;
int ans;
int tu;
po(void) {
x = 0;
y = 0;
ans = 3;
tu = 0;
}
po(int tx, int ty, int ta, int tt) {
x = tx;
y = ty;
ans = ta;
tu = tt;
}
};
char t[1010][1010];
int dp[1010][1010];
int turn[4][2] = {{1, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << ((n + 1) / 2) - 1;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
cin >> t;
while (t--) {
long long int n, W;
cin >> n >> W;
vector<pair<long long int, long long int> > v;
for (long long int i = 1; i <= n; i++) {
long long int val;
cin >> val;
v.push_back(make_pair(val, i));
}
... | 5 |
#define debug printf("-------------------------------\n");
#define debug2 printf("!!!!!!!!!!!!!!!!!!!!!!!\n");
#include<bits/stdc++.h>
#define lll __int128
#define ii inline
#define il inline
#define wln(x) write(x,'\n')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define MP make_pair
#define ... | 21 |
#include <bits/stdc++.h>
using namespace std;
vector<int> input;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int i, j, k, l, m, n, t;
cin >> t;
while (t--) {
input.clear();
cin >> n;
bool possible;
for (i = 0; i < n; i++) {
cin >> k;
input.push_back(k);
}
sort(... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2000010;
int prime[MAX_N], prime_n;
bool isn_prime[MAX_N + 1];
void sieve(int n) {
isn_prime[0] = isn_prime[1] = true;
for (int i = 2; i * i <= n; i++) {
if (isn_prime[i]) continue;
for (int j = i; i * j <= n; j++) isn_prime[i * j] = true;
}
... | 16 |
#include <bits/stdc++.h>
namespace ringo {
template <class T>
inline void read(T &x) {
x = 0;
register char c = getchar();
register bool f = 0;
while (!isdigit(c)) f ^= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
if (f) x = -x;
}
template <class T>
inline void print(T x)... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const int maxl = 21;
int tin[MAXN], tout[MAXN], depth[MAXN], up[MAXN][maxl];
int timer = 1;
vector<int> v[MAXN], adj[MAXN];
void dfs(int u, int p) {
tin[u] = timer++;
depth[u] = depth[p] + 1;
v[depth[u]].push_back(tin[u]);
up[u][0] = p;
f... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T POW(T b, T p) {
T r = 1;
while (p) {
if (p & 1) r = (r * b);
b = (b * b);
p >>= 1;
}
return r;
}
template <typename T>
T BigMod(T b, T p, T m) {
T r = 1;
while (p) {
if (p & 1) r = (r * b) % m;
b = (b * b) % m;
p >... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
vector<char> alphabet;
for (long long i = 0; i < 10; i++) {
alphabet.push_back(i + 48);
}
for (long long i = 0; i < 26; i++) {
alphabet.push_back(65 + i);
alphabet.push_back(97 + i);
}
long long t;
cin >> t;
while (t--) {
long... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, Q;
int val[N];
vector<int> G[N];
int vcnt;
namespace RST {
vector<int> T[N];
int dfn[N], low[N], timer = 0;
int stk[N], top = 0;
void tarjan(int x) {
dfn[x] = low[x] = ++timer, stk[++top] = x;
for (int i = 0; i < (int)G[x].size(); i++) {... | 24 |
#include <bits/stdc++.h>
char _;
using namespace std;
void PRINT(int x, int y) {
for (int i = y - 1; i >= 0; i--) {
cout << ((0u == (x & (1 << i))) ? 0u : 1u);
}
cout << endl;
}
int dp[30][1505] = {0}, l[1505], n, up = 'z' - 'a';
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int d[300005] = {0};
lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline 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 * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int a[1010][1010];
int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int maxn = 3e5 + 100;
const int maxm = 2e6 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
int t;
int n;
int a[maxn];
vector<int> v[maxn];
int dep[maxn], sz[maxn];
void dfs(int x, int fa) {
dep[x] = dep[fa] + 1;
sz[x] = 1;... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, d, i, lp, lst, io, ans, rao;
long long x[300002];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> a >> d;
for (i = 1; i <= m; i++) {
cin >> x[i];
}
lst = -1;
lp = 1;
for (i = 1; i <= m; i++) {
if (lst + d >=... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int b[n];
for (int i = 0; i < n; i++) {
cin >> b[i];
}
map<long long int, long long int> m;
long long int ma = 0;
for (int i = 0; i < n; i++) {
m[b[i] - i] += b[i];
}
for (auto i : m) {
ma = max(ma, i.s... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int prime = 999983;
const int prime1 = 10000007;
const int INF = 0x3f3f3f3f;
const int INFF = 1e9;
const double pi = 3.141592653589793;
const double inf = 1e18;
const double eps = 1e-8;
const int mod = 9937;
inline... | 9 |
#include <bits/stdc++.h>
namespace _ {
const int inf = 1e9 + 7;
namespace _in {
template <class T>
inline T read() {
char ch;
bool flag = 0;
T x = 0;
while (ch = getchar(), !isdigit(ch))
if (ch == '-') flag = 1;
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
return flag ? -x : x;
}
struct {
... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cout << 1;
cout << endl;
for (int i = 0; i < n - 1; i++) cout << 8;
cout << 9;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, x, y, a;
int main() {
cin >> t;
while (t--) {
cin >> n;
while (n--) {
cin >> a;
x += a;
y ^= a;
}
cout << "2\n" << y << " " << x + y << endl;
x = y = 0;
}
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s1;
cin >> s >> s1;
int n = s.length();
int m = s1.length();
int l = max(n, m);
if (s.length() != s1.length()) {
cout << max(n, m);
} else {
for (int i = 0; i < l; i++) {
if (s[i] != s1[i]) {
cout << max(n, m);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int na, ma, nb, mb, x, y;
int a[52][52], b[52][52];
string s;
cin >> na >> ma;
for (int i = 1; i <= na; i++) {
cin >> s;
for (int j = 1; j <= ma; ++j) {
if (s[j - 1] == '0') {
a[i][j] = 0;
} else if (s[j - 1] == '1') {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int qntd, qntf[100000], qnts[100000];
char in[200], *namef;
int main() {
int maior = 0, maiorfiles = 0;
map<pair<int, string>, int> mapa;
pair<int, string> aux;
int nextID = 10, atd, atf, incr = 3, qntsubs;
while (scanf("%s", in) == 1) {
qntsubs = 0;
for (... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
vector<pair<int, int> > uniforms;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
uniforms.push_back(make_pair(a, b));
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (uniforms[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int res[500050] = {0};
int res1[500050] = {0};
int read(int idx) {
int sum = 0;
while (idx > 0) {
sum += res[idx];
idx -= (idx & -idx);
}
return sum;
}
void update(int idx, int val, int N) {
while (idx <= N) {
res[idx] += val;
idx += (idx & -idx);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int N = 2e5 + 10;
const int M = 5e3 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const int mod3 = 1e9 + 9;
const int hash1 = 131;
const int hash2 = 13331;
st... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 12e4;
vector<int> ch[N], v;
int f[N], c[N], d[N], u[N];
void dfs_s(int x) {
for (int y : ch[x]) {
c[y] = c[x] + 1;
dfs_s(y);
}
}
bool cmp(int a, int b) { return u[a] < u[b]; }
int dfs_a(int x) {
int t = x;
sort(ch[x].begin(), ch[x].end(), cmp);... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string a, b;
cin >> a >> b;
int i = b.size() - 1;
int c = 0;
while (b[i] != '1') {
i--;
c++;
}
i = (a.size() - 1) - c;
int c2 = 0;
while (a[i] != '1') {
i--;
c2++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, l, r;
};
int n, m, sx, sy, l, r, ans = 1;
node off[4] = {{0, 1, 0, 1}, {1, 0, 0, 0}, {0, -1, 1, 0}, {-1, 0, 0, 0}};
char a[2005][2005];
node p[2005][2005];
int main() {
cin >> n >> m >> sx >> sy >> l >> r;
for (int i = 1; i <= n; i++) {
for... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long k, b, n, t, ans;
int main() {
scanf("%I64d%I64d%I64d%I64d", &k, &b, &n, &t);
long long tmp = 1ll;
ans = n;
while (t >= tmp && ans > 0ll) {
--ans;
tmp = tmp * k + b;
}
if (t >= tmp)
printf("0\n");
else
printf("%I64d\n", ans + 1);
ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long md = 1000000007;
long long bexp(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
long long r = bexp(a, b / 2);
r = r * r;
if (b % 2 == 0)
return r;
else
return r * a;
}
int main() {
ios_base::sync_with_stdio(false);
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, T[505][505], a[505];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 505; j++) T[i][j] = 505;
for (int i = 1; i <= n; i++) T[i][i] = 1;
for (int i = 1; i <= n - 1; i++)
... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio;
cin.tie(0);
cout.tie(0);
;
long long a, b;
cin >> a >> b;
a--;
b--;
long long aa = a, bb = b;
long long hour = 0, min = 0;
while (aa > 0) {
aa /= 7;
hour++;
}
while (bb > 0) {
bb /= 7;
min+... | 9 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int ar[1000005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, k, c = 0, f = 0, i, x;
cin >> n >> m >> k;
for (i = 0; i < m; i++) {
cin >> x;
mp[x] = 1;
}
int a = 1;
if (mp[1] == 1) {
cout << 1;
return... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int na, ma;
cin >> na >> ma;
int arr1[na][ma];
for (int i = 0; i < na; i++) {
string s;
cin >> s;
for (int j = 0; j < ma; j++) {
if (s[j] == '0')
arr1[i][j] = 0;
else
arr1[i][j] = 1;
}
}
int nb, mb;
cin ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[110], m[110], p[110], pr;
bool vis[110];
pair<int, int> dp[105][300010];
void Build_Primes() {
for (int i = 2; i < 60; i++) {
if (vis[i] == 0) {
for (int j = i; j < 60; j += i) vis[j] = 1;
p[pr++] = i;
}
}
for (int i = 2; i < 60; i++)
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
template <class A, class B>
pair<A, B> operator+(pair<A, B>& a, pair<A, B>& b) {
return {a.first + b.first, a.second + b.second};
}
template <class A, class B>
pair<A, B> operator-(pair<A, B>& a, pair<A, B>& b) {
return {a.first - b.f... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 168430090;
struct edge {
int v, next;
long long w;
} a[15000];
int start[1200], tot = 0;
inline void addedge(int u, int v, int w) {
a[tot].v = v;
a[tot].w = (long long)w;
a[tot].next = start[u];
start[u] = tot++;
}
int n, m;
long long g[1100][110... | 11 |
#include <bits/stdc++.h>
int a[5], b[5], n;
void Print1() {
printf("%d %d\n", a[3], b[2]);
printf("%d %d\n", a[2], b[2]);
printf("%d %d\n", a[3], b[1]);
printf("%d %d\n", a[0], b[1]);
printf("%d %d\n", a[1], b[3]);
printf("%d %d\n", a[2], b[3]);
printf("%d %d\n", a[1], b[2]);
printf("%d %d\n", a[1], b[1... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
void init() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int last_idx[N];
int main() {
init();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
memset(last_idx, -1, sizeof(int) * (n + 5));
int ... | 4 |
#include <bits/stdc++.h>
int main(void) {
double a[101], t[101];
int n, i, biaoji;
double vb, vs;
double x, y, min, minn, k;
while (scanf("%d%lf%lf", &n, &vb, &vs) != EOF) {
for (i = 1; i <= n; i++) scanf("%lf", &a[i]);
scanf("%lf%lf", &x, &y);
for (i = 1; i <= n; i++) t[i] = 0;
for (i = 2; i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x;
}
const int N = 100007;
struct node {
int num, x;
} a, b, c;
int operator<(node a, node b) { return a.num < b.num; }
int t[N]... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.