solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int k = 0;
for (int i = 0; i < s.length(); i++) {
bool u = true;
bool y = true;
for (int j = 0; j < 7; j++) {
u *= (s[i + j] == '1');
y *= (s[i + j] == '0');
}
if (u || y) {
cout << "YES";
... | 1 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int maxn = 1e5 + 33, mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dp[maxn], p[maxn], x[maxn], y[maxn], t[maxn];
void solve() {
int r, n;
cin >> r >> n;
x[0] = 1, y[0] = 1, t[0] = 0;
for (int i ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
int n, p, k;
int a[MAX_N], sum[MAX_N];
int main() {
int T;
scanf("%d", &T);
a[0] = 0;
while (T--) {
scanf("%d", &n), scanf("%d", &p), scanf("%d", &k);
for (register int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s1, s2;
int z[3100][3100];
bool dead = false;
bool alive[3100];
int p[3100];
int a[3100];
void add(int a, int b) {
if (a == b) b--;
if (s2.find(make_pair(a, b)) == s2.end()) s2.insert(make_pair(a, b));
}
void add2(int a, int b, int v) {
if (a < 0)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b, k;
cin >> b >> k;
int a[k], cnt = 0;
for (int i = 0; i < k; i++) {
cin >> a[i];
if (a[i] % 2 == 1) {
cnt++;
}
}
if ((b % 2 == 1 && cnt % 2 == 1) || (b % 2 == 0 && a[k - 1] % 2 != 0)) {
cout << "odd" << endl;
} else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double inf = 1e60;
double dis[1200];
int vis[1200];
int st[1200];
double a, b;
struct point {
double x;
double y;
};
struct line {
point p[2];
};
line keng[1200];
double sqr(double x) { return x * x; }
double dist(line& a, line& b) {
double z = 0;
return sqr... | 14 |
#include <bits/stdc++.h>
using namespace std;
int k, n, m;
int arr[100005];
vector<pair<int, int> > v[100005][2];
pair<int, int> as[100005];
vector<int> res;
long long mul[100005], pre[100005];
inline bool cmp(int a, int b) {
if (pre[a] == 0 && pre[b] == 0)
return mul[a] > mul[b];
else if (pre[a] && pre[b])
... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<int> t[1 << 21];
int lz[1 << 21];
vector<int> get(vector<int> s) {
vector<int> ans;
int sz = s.size();
for (int k = 0; !s.empty() && k < 30; ++k) {
int cnt = -1;
for (int i = 0; i < sz; ++i)
if ((s[i] >> k) & 1) cnt = i;
if (cnt != -1) {
... | 21 |
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100005];
bool vis[100005];
set<int> A, B;
bool dfs(int x, bool st) {
vis[x] = true;
if (!st) {
A.insert(x);
} else {
B.insert(x);
}
int i, ans = 1;
for (i = 0; i < graph[x].size(); i++) {
int s = graph[x][i];
if (!vis[s]) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)(1 * 1e6 + 10);
void ggg() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string st, cp;
cin >> st;
cp = st;
int cnt = 0, total = 0;
for (int i = 0; i < n; i++) {
int tmp = 0;
for (int j = 0; j < n - 1; j++) {
if (st[j] == 'R' && st[j + 1] == 'L') {
tmp++;
swap(st[j... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll x, y, n;
map<ll, bool> pq;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int ts;
cin >> ts;
while (ts--) {
cin >> n;
if (ts == 0) {
ts = 0;
}
ll ans = 0;
pq.clear();
while (n % 6 == 0 && n != 1)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
scanf("%d", &x);
vector<int> luck;
for (int i = 1; i <= 9; i++) {
for (int j = 0; j <= i; j++) {
int four = i - j;
int seven = j;
string s;
while (four--) s += "4";
while (seven--) s += "7";
do {
lu... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100100];
int dep[100100];
int c = 0;
void dfs(int v, int p) {
c++;
dep[v] = c;
for (int i = 0; i < G[v].size(); i++) {
if (G[v][i] == p) continue;
dfs(G[v][i], v);
}
c--;
}
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N - 1;... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000001], cnt[1000001];
vector<int> crr;
int ans[25][25];
int cnt1[1000001], cnt2[1000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a, b;
cin >> n;
for (int i = 0; i < n * n; i++) {
cin >> arr[i];
cnt[arr[i]]+... | 9 |
#include <bits/stdc++.h>
using namespace std;
int x[1000][4];
int p[1000];
vector<bitset<2001> > aug;
int num(char c) {
if (c == 'R')
return 1;
else if (c == 'Y')
return 2;
else if (c == 'B')
return 3;
else
return 0;
}
const int N = 2001;
int gauss(vector<bitset<N> > a, int n, int m, bitset<N>& ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> v;
if (n == 1) {
cout << 1;
return 0;
}
v.push_back(1);
v.push_back(n);
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int p;
int q;
bool operator<(const node& m) const { return p < m.p; }
};
vector<node> ll;
vector<node> rr;
int main() {
int x, a, sum, n, k, flag = 0;
node aha;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &x, &a);
if (x ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int PRIME = 999983;
const int MOD = 10007;
const int MULTI = 1000000007;
const double EPS = 1e-9;
class Matrix {
public:
int n, m;
long long a[32][32];
Matrix(int n, int m) : n(n), m(m) { memset(a, 0, sizeof(a)); }
Matrix qpow(int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t[100000];
int v[100000];
double calculateBest(double t0, double v, double a, double d) {
if (d < v * v / 2 / a) {
return t0 + sqrt(2 * d / a);
}
return t0 + v / a + (d - v * v / 2 / a) / v;
}
int main() {
int n, a, d;
scanf("%d%d%d", &n, &a, &d);
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int siz;
cin >> siz;
stack<string> stk;
for (int i = 0; i < siz; i++) {
string s;
cin >> s;
stk.push(s);
}
map<string, bool> mpp;
while (!stk.empty()) {
if (mpp[stk.top()] == false) {
cout << stk.top() << "\n";
mpp[stk.... | 4 |
#include <bits/stdc++.h>
int main() {
long long n;
scanf("%I64d", &n);
long long a[n];
long long i, j;
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
long long count = 0;
long long less = 0;
long long more = 0;
for (i = 1; i < n; i++) {
for (j = 0; j < i; j++) {
if (a[j] < a[i]) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q, a, u, v, ans, w;
cin >> q;
map<long long, long long> m;
while (q--) {
cin >> a >> u >> v;
if (a == 1) {
cin >> w;
while (u != v) {
if (u < v) swap(u, v);
m[u] += w;
u = u / 2;
}
} else {... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int t = 0;
pair<int, int> l[maxn], a[maxn];
void superset(int c, int r) {
int k = (r + c) / 2;
for (int i = c; i < r; i++) {
a[t].first = l[k].first;
a[t].second = l[i].second;
t++;
}
if (r - c > 1) {
superset(c, k);
su... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct SAM_node {
int minlen, maxlen, slink;
int trans[4];
inline void reset(int _minlen, int _maxlen, int _slink, int *_trans) {
minlen = _minlen, maxlen = _maxlen, slink = _slink;
for (int i = 0; i < 4; i++) trans[i] = _trans[i];
return;
}
};
struct ma... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans, i, a;
int main() {
cin >> n;
for (i = 0; i <= n; i++) {
cin >> a;
cin >> a;
}
cout << (n - 4) / 2;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int f[110][3000];
int i, j, k, n, t;
const int modx = 1000000007;
char s[200];
int sum;
int main() {
f[0][0] = 1;
for (i = 0; i <= 100; i++)
for (j = 0; j <= 3000; j++) {
if (f[i][j] > 0) {
for (k = 1; k <= 26; k++)
f[i + 1][j + k] = (f[i + 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ones = 0, zeros = 0;
cin >> n;
char arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == '0') {
zeros++;
} else if (arr[i] == '1') {
ones++;
}
}
cout << abs(ones - zeros) << endl;
}
| 1 |
#include <bits/stdc++.h>
int num[2][15], pos0, pos1;
bool used[7];
int f(int x, int pos, int flag) {
if (pos < 0) {
if (x == 0) return f(1, pos1, 1);
return 1;
}
int ret = 0;
if (flag == 0) {
for (int i = 0; i < 7; i++) {
if (!used[i]) {
used[i] = true;
ret += f(x, pos - 1, 0);... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ara[150100], on[150100];
vector<int> vc;
int main() {
int i, j, k, l, n, q, r, s;
map<int, int> m;
scanf("%d %d %d", &n, &k, &q);
for (i = 0; i <= n; i++) on[i] = 0;
for (i = 1; i <= n; i++) scanf("%d", &ara[i]);
for (i = 0; i < q; i++) {
scanf("%d %d", ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n & 1)
cout << 0;
else
cout << (1 << (n / 2));
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int num;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int n, m, xi, yi, xf, yf;
char maze[507][507];
bool vis[507][507];
bool ok(int x, int y) { return x < n && x >= 0 && y >= 0 && y < m; }
void dfs(int x, int y) {
if (x >= n || y >= m) return;
vis[x][y] = 1;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j;
unordered_map<int, int> mapper;
int start = 1, end;
vector<int> a;
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i++) {
int banyakMain, durasi;
scanf("%d %d", &banyakMain, &durasi);
int selisih = (banyakMain * durasi);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
int a[5], flag, i, L, R, n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for (cin >> s, n = s.size(), i = 0; i < n; ++i) a[s[i] - 'a']++;
if (s[0] != 'a' || s[n - 1] != 'c')
flag = false;
else {
for (L = 0; s[L] == 'a'; L++)
;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, q, i, r;
cin >> n >> m;
q = n / m;
int arr[m];
for (int i = 0; i < m; ++i) {
arr[i] = q;
}
r = n % m;
if (r > 0) {
for (r, i = m... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Movie {
int r, l;
} mov[55];
int main() {
int n, x;
int sr = 1;
int sl = 1;
int totle = 0;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> mov[i].r >> mov[i].l;
totle += (mov[i].r - sl) / x;
sl = mov[i].l + 1;
}
cout << mov[n - 1].l ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, t, i;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n;
if (n % 4 == 0 || n % 4 == 2) cout << n * 4 + 1 << endl;
if (n % 4 == 1) cout << n * 2 + 1 << endl;
if (n % 4 == 3) cout << n + 1 << endl;
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
struct treap {
int val, fix, siz;
long long sum[5];
treap *lc, *rc;
} * tot, *I;
void update(treap *&x) {
if (!x) return;
treap *lc = x->lc ? x->lc : I;
treap *rc = x->rc ? x->rc : I;
x->siz = lc->siz + rc->siz + 1;
int j = lc->si... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 210;
int mp[N][N], x[N * N], y[N * N], z[N * N];
struct P {
int x, y;
P() {}
P(int x, int y) : x(x), y(y) {}
bool operator<(const P &a) const {
if (a.x != x)
return x < a.x;
else
return y < a.y;
}
} p[N... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1000000 + 5;
int N;
string edges;
vector<int> chains;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
cin >> edges;
N = edges.size();
int pos;
for (int i = 0; i < N; ++i)
if (edges[i] != edges[0]) {
pos = i;
break;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx2,avx,fma")
vector<vector<int> > g;
vector<int> a;
vector<int> c;
vector<bool> vis;
vector<vector<int> > order;
vector<int> s;
void dfs(int r) {
vis[r] = 1;
s[r] = 1;
int... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1073741824;
const int M = INF;
const double RRR = 180.0 / PI;
int main() {
int n;
cin >> n;
string str;
vector<string> buf;
int k = -1;
int r = 0;
for (int i = 0; i < n; i++) {
cin >... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(T a, int n) {
for (int i = 0; i < n; ++i) cout << a[i] << ' ';
cout << endl;
}
template <class T>
void show(T a, int r, int l) {
for (int i = 0; i < r; ++i) show(a[i], l);
cout << endl;
}
const int N = 310;
const int M = 5000;
const int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(double &x, double &y) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, i, j, k, u;
cin >> n;
vector<pair<int, int> > vect;
for (i = 1; i <= n; i++) {
scanf("%d", &x);
vect.push_back(make_pair(x, i));
}
sort(vect.begin(), vect.end());
int l, r, flag = 0;
l = vect[n - 1].second;
r = l;
for (i = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t, n, to[200001];
int caled[200001];
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> to[i];
memset(caled, 0, sizeof(caled));
for (int i = 1; i <= n; i++) {
if (caled[i]) continue;
int p = i, cnt = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<tuple<int, int, int>, long long int> memoa;
map<tuple<int, int, int>, int> memoc;
int cw(int i, int j, int k) {
if (memoc[tuple<int, int, int>(i, j, k)] != 0)
return memoc[tuple<int, int, int>(i, j, k)];
printf("2 %d %d %d\n", i, j, k);
fflush(stdout);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, S = 1 << 23;
int tot, cnt, n, dfn[N], out[N], f[S], rk[N], ans[N], sum[N], dep[N], head[N],
to[N], ne[N], w[N], size[N], son[N], g[N][23];
char t[11];
void add(int x, int y, int z) {
to[++tot] = y;
w[tot] = z;
ne[tot] = head[x];
head[x] =... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int dx[3] = {-1, 0, 1};
const int dy[3] = {-1, -1, -1};
const int INF = 1e9 + 9;
int n;
int x[maxn], y[maxn], cnt[maxn];
map<pair<int, int>, int> id;
set<int> s;
inline void upd(int i, int d) {
if (!cnt[i]) s.erase(i);
cnt[i] += d;
if (... | 13 |
#include <bits/stdc++.h>
using namespace std;
set<pair<long long, long long> > s;
int main() {
ios_base::sync_with_stdio(false);
long long p;
cin >> p;
for (long long j = 2; j <= 1442249; j++) {
long long i = j - 1;
long long x = (i * i) + (3 * i);
x = x / 2;
x = x + 1;
long long y = (i * i)... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Complex {
double x, y;
Complex() {}
Complex(double a, double b) : x(a), y(b) {}
Complex operator+(Complex b) { return Complex(x + b.x, y + b.y); }
Complex operator-(Complex b) { return Complex(x - b.x, y - b.y); }
Complex operator*(Complex b) {
return... | 27 |
#include <bits/stdc++.h>
using namespace std;
int const N = 10;
int r, c, n, k;
int a[20][20];
int main() {
cin >> r >> c >> n >> k;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
a[i][j] = 0;
}
}
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
a... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = int((s).size()), u = 0;
for (int i = 0; i < int(n); i++)
if (s[i] == '1') u++;
int k = 0;
while (k < n && s[k] != '2') {
if (s[k] == '0') cout << 0;
k++;
}
... | 6 |
#include <bits/stdc++.h>
long long p[8][3];
long long op[8][3];
bool found = false;
bool cross(long long u[3], long long v[3]) {
return (u[0] * v[0] + u[1] * v[1] + u[2] * v[2] == 0);
}
bool notIn(long long u[3], long long p[8][3]) {
for (int i = 0; i < 8; i++) {
if (p[i][0] == u[0] && p[i][1] == u[1] && p[i][2... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
int s, m;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s >> m;
cout << (60 - m) + (23 - s) * 60 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
const int INF = 1e9 + 7;
int a[7], b[maxn], id[maxn];
struct note {
int diff, pos;
} p[maxn * 6];
bool cmp(note x, note y) { return x.diff < y.diff; }
int main() {
int n;
for (int i = 1; i <= 6; ++i) scanf("%d", &a[i]);
scanf("%d", &n);
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = -1;
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
unordered_map<int, int> m1;
unordered_map<int, int> m2;
for (int i = 0; i < n; i++) {
if (m2.find(a[i]) == m2.end()) {
m1[1]++;
m2[a[i]] = 1;
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
int mai... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long lmax = LONG_LONG_MAX;
const int imax = INT_MAX;
const int mod = 1000000007;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n / 4; i++) cout << "abcd";
if (n % 4 == 1) cout << 'a';
if (n % 4 == 2) cou... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mo, l[1000001], yu = 0, la = 0, C[5005], a[5005], f[2][5005];
int dp[5005][5005], g[2][5005];
int gcd(int o, int p) { return (!p) ? o : gcd(p, o % p); }
int mi(int o, int p) {
if (!p) return 1;
if (!o) return 0;
int u = 1;
while (p > 0) {
if (p & 1) u ... | 18 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b;
cin >> a >> b;
if (a == b)
cout << 0 << endl;
else if ((a > b && (a - b) % 2 == 0) || (a < b && (a - b) % 2 != 0))
cout << 1 << endl;
else
cout << 2 << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
ci... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long m... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
os << "{" << p.first << ", " << p.second << "}";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
os << "[";
int i = 0;
for (typename vect... | 9 |
#include<bits/stdc++.h>
#define ll long long int
#define me9 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==1)
cout<<0<<"\n";
else if(n%2==0)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int k;
cin >> k;
int n = 26;
int w[n];
for (int i = 0; i < n; i++) {
cin >> w[i];
}
int max = *max_element(w, w + n);
int l = s.length();
int score = 0;
for (int i = 0; i < l; i++) {
for (int j = 0; j < 26; j+... | 2 |
#include <bits/stdc++.h>
using namespace std;
void Sieve(int *prime, int n) {
for (int i = 0; i < n; i++) {
prime[i] = 0;
}
for (int i = 2; i < n; i++) {
prime[i] = 1;
}
for (int i = 4; i < n; i += 2) {
prime[i] = 0;
}
for (int i = 3; i < n; i++) {
if (prime[i] == 1) {
for (int j = i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
char s[11000];
int nu[11000];
int sum[10];
int Min;
int mind;
int Minus[10];
int mr[10];
string str[10];
string anss;
int work(int i) {
for (int j = 0; j < 10; j++) Minus[j] = 0;
int ans = 0;
int l = i - 1, r = i + 1;
int kk = k - sum[i];
while (kk > 0) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long ppow(long long a, long long n) {
long long ans = 1;
while (n) {
if (n & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return ans;
}
int main() {
long long n, h;
cin >> h >> n;
int step = 0;
n--;
l... | 9 |
#include <bits/stdc++.h>
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
char mp[20][20];
int bMap[20][20];
int isGo[20][20];
int Tx, Ty;
int Sx, Sy;
int n, m;
int L;
struct node {
int map[20][20];
int hx, hy;
int move;
bool canGo(int x, int y) {
if (isGo[x][y] >= 20) return false;
if (x < 0 || x ... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class... U>
void pr(T&& a, U&&... b) {
cout << forward<T>(a);
(int[]){(cout << forward<U>(b), 0)...};
}
template <class T, class... U>
void re(T&& a, U&&... b) {
cin >> forward<T>(a);
(int[]){(cin >> forward<U>(b), 0)...};
}
const int MAXN = 2e5;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int solve() {
int n;
string a, b;
cin >> n >> a >> b;
int sa, sb, ss;
sa = sb = ss = 0;
for (int i = 0; i < n; i++) {
sa += a[i] - '0';
sb += b[i] - '0';
if (a[i] != b[i]) ss++;
}
if (sa != sb && sa + sb != n + 1) return -... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265359;
const long long MOD = (long long)998244353ll;
const long long MAXN = (long long)2e5 + 10;
const long long INF = (long long)9223372036854775;
const long double EPS = (long double)1e-8;
long long a[MAXN], dp[MAXN], s[MAXN];
int main() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n;
set<int, greater<int>> y;
set<int, greater<int>>::iterator itr;
for (int i = 0; i < n; i++) {
cin >> k;
y.insert(k);
}
k = 1;
while (true) {
itr = ... | 11 |
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
struct segtree{
int n; vector<int> t, lz;
segtree(int m): n(m),t(m<<2),lz(m<<2,-1) {}
void propa(int n,int s,int e){
if(~lz[n]){
if(s<e){
lz[n<<1] = lz[n];
lz[n<<1|1] = lz[n];
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, M = 120, mod = 1e9 + 7;
inline void mul_add(long long &x, const long long &y, const long long &z) {
x = (x + y * z % mod) % mod;
}
inline void reduce(long long &x) { x += x >> 31 & mod; }
long long u[M], v[M], w[M], A[M], B[M], fac[N], n, m, ans;
ve... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long c, d, x1, y1, x2, y2;
c = abs(a) + abs(b);
x1 = 0;
y1 = c;
x2 = c;
y2 = 0;
if (a < 0) {
x2 *= -1;
}
if (b < 0) {
y1 *= -1;
}
if (x1 < x2) {
cout << x1 << " " << y1 << " " << x2 << " ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 3 << endl;
return 0;
}
if (n == 2) {
cout << 63 << endl;
return 0;
}
if (n == 3) {
cout << 9933 << endl;
return 0;
}
if (n == 4) {
cout << 11213343 << endl;
return 0;
}
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (1LL << 30) - 1;
const long long int LINF = (1LL << 62) - 1;
const int BASE = 7;
int N, M, A, B;
int solution;
int st[20];
int used[20];
int convert(int i, int j) {
int nr = 0;
for (int k = i; k < j; k++) nr = nr * BASE + st[k];
return nr;
}
void print... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vect;
const long long mod = 1000000000 + 7;
long long exp(long long a, long long n) {
if (n == 0) return 1;
long long p = exp(a, n / 2);
if (n % 2 == 0)
return (p * p) % mod;
else
return (((p * p) % mod) * a) % mod;
}
void factorize(long lo... | 9 |
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+50;
int t;
string s;
int cnt[maxn];
int main()
{
cin>>t;
while(t--)
{
cin>>s;
int cur=5e5+10;
for(int i=0;i<s.size();i++)
{
if(s[i]=='0')
{
cur--;
cnt[cur]++;
}
else
{
cnt[cur]++;
cur++;
}
}
cur=5e5+10;
wh... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int N, M, K, dir, rem;
string state;
int main() {
cin >> N >> M >> K;
string s;
cin >> s >> s >> state;
if (s == "head")
dir = 0;
else
dir = 1;
if (M < K) {
if (dir == 0) {
rem = K - 1;
} ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
int n, s, cos;
while (~scanf("%d%d", &n, &s)) {
s *= 100;
int flag = 0, a, b, ans = 0;
while (n--) {
scanf("%d%d", &a, &b);
cos = a * 100 + b;
for (int j... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 7;
int a[maxn];
signed main () {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
map<int,int>mp;
mp.clear();
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += mp[a[i]]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000 + 9;
int n, m, cnt;
long long Ans;
int Dx[Maxn], Dy[Maxn], cx[Maxn], cy[Maxn];
char s[Maxn];
inline void calc_x() {
for (int i = 1; i <= n; i++)
if (Dx[i]) {
int tmp = Dx[i];
for (int j = i + 1; j <= n && Dx[j] && Dx[j] < Dx[j - 1]; j... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <class T>
T power(T a, T b) {
T result = 1;
while (b > 0) {
if (b & 1) result = result * a;
a = a * a;
b >>= 1;
}
return result;
}
template <clas... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
scanf("%d", &a);
for (long long i = 1; i <= a; ++i) {
if (i == 1)
printf("2\n");
else
printf("%I64d\n", i * (i + 1) * (i + 1) - (i - 1));
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, n;
cin >> n >> a >> b;
if (a * b >= 6 * n) {
cout << a * b << endl << a << " " << b << endl;
} else {
int flag = 0;
if (a > b) {
flag = 1;
swap(a, b);
}
long long ans = 1e18, ansa, ansb;
for (long long... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, s, a[2010], f[2010], g[2010], p[2010], pre[2010], tot;
bool cw[2010];
pair<int, int> sec[2010];
bool cmp(int x, int y) { return (a[x] > a[y]) || (a[x] == a[y] && x < y); }
int dis(int x, int y) { return min(abs(x - y), n - abs(x - y)); }
int cwdis(int x, int y) { ret... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
return x < y ? (x = y, 1) : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
return x > y ? (x = y, 1) : 0;
}
const int N = 2e5 + 1;
int n;
long long dp[N][3][2][2], a[N];
int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' || c ... | 12 |
#include <bits/stdc++.h>
using namespace std;
string ans = "";
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if ((s[i] - '0') % 8 == 0) {
cout << "YES" << endl << s[i] - '0';
return 0;
}
}
for (int i = 0; i < s.size(); i++)
for (int j = i + 1; j < s.size(); j++)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, count = 1, j = -1, flag = 0;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 1 && flag == 0) {
j = i;
flag = 1;
}
}
if (j == -1) {
cout << 0;
} else
while (j < n) {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t, u;
cin >> s;
set<int> idxs;
int n = s.length(), a[100010], idx_min = n - 1;
a[n - 1] = n - 1;
char curr_min = s[n - 1];
for (int i = n - 2; i >= (int)0; i--) {
if (curr_min >= s[i]) {
curr_min = s[i];
idx_min = i;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int h[100005];
bool test(int a) {
int energy = 0;
for (int i = 0; i < n; i++) {
energy += a - h[i];
a = h[i];
if (energy < 0) return true;
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n;... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T zz) {
return zz < 0 ? -zz : zz;
}
template <typename T>
inline T sqr(T zz) {
return zz * zz;
}
const int N = 200500;
const int L = 20;
int n, m, q;
int a[N];
int p[N], rp[N];
int pos[N];
int nx[L][N];
int dp[N];
int tr[4 * N];
void b... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int read() {
int x = 0, f = 1;
char ch;
ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] < i + 1)
ans += i + 1 - a[i];
else if (a[i] > i + 1)
ans += a[i] - (i + 1);
}
cou... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[100];
int main() {
long long w, m, i;
cin >> w >> m;
for (i = 0; i <= 63; i++) {
a[i] = m % w;
m /= w;
}
for (i = 0; i <= 63; i++) {
a[i + 1] += a[i] / w;
a[i] %= w;
if (a[i] <= 1) {
continue;
} else if (a[i] == w - 1) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
struct bian {
int from, to;
} eg[N << 1];
int front[N], num;
void add(int x, int y) {
eg[++num].to = y;
eg[num].from = front[x];
front[x] = num;
}
int siz[N];
int root;
long long ans;
void dfs1(int o, int from) {
siz[o] = 1;
int sf... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, y1, x2, y2, a, b;
cin >> x1 >> y1 >> x2 >> y2 >> a >> b;
if (abs(x1 - x2) % a || abs(y1 - y2) % b ||
((abs(x1 - x2) / a - abs(y1 - y2) / b) % 2))
cout << "NO";
else
cout << "YES";
return 0;
}
| 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.