solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Ofast")
using namespace std;
signed main() {
string s1;
cin >> s1;
deque<char> d;
int sz = s1.size();
if (sz % 2 == 1) {
for (int i = 0; i < sz;) {
if (i == sz - 1) {
d.push_front(s1[sz - 1]);
sz--;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
char p[] = {"1000101021120100"};
int main() {
cin >> n;
if (!n) {
puts("1");
return 0;
}
int q = 0;
while (n) q += p[n % 16] - 48, n /= 16;
cout << q << "\n";
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long l, r;
vector<long long> edge[200005];
long long cnt[200005];
set<long long> s;
long long ans[4][200005];
signed main() {
memset(ans, -1, sizeof(ans));
for (long long i = 1; i < 200005; i++)
for (long long j = i; j < 200005; j += i) edge[j].... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
const int Len = 500000;
const long long l1 = 1LL;
bool f[Len + 5];
int A[N + 5], remain[Len + 5];
map<long long, int> facCount;
vector<int> E[Len + 5];
long long total;
int n, q;
void getPrime() {
for (int i = 1; i <= Len; ++i) {
E[i].clear();
... | 15 |
#include <bits/stdc++.h>
using namespace std;
class point {
public:
long long x, y;
point() {
x = 0;
y = 0;
}
point(long long _x, long long _y) {
x = _x;
y = _y;
}
~point() {}
};
class bhector {
public:
long long x, y;
bhector() {
x = 0;
y = 0;
}
bhector(point a, point b) {... | 14 |
#include <bits/stdc++.h>
int main() {
long long left(0), right(0), index(0);
scanf("%lld %lld %lld", &left, &right, &index);
int count = 1;
while (count++ < index) {
long long temp = left + right;
left = right;
right = temp;
}
printf("%lld\n", right);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = 10000 + 10, inf = 0x3f3f3f3f;
const long long P = 1e9 + 7;
int n, L, R, pre, cnt = 0, a[N];
char ans[N];
template <class t>
void rd(t &x) {
x = 0;
int w = 0;
char ch = 0;
while (!isdigit(ch)) w |= ch == '-', ch = getchar();
while (isdig... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b, n, m, i, j, k, s, t;
scanf("%d%d", &b, &k);
s = 0;
for (i = k - 1; i >= 0; i--) {
scanf("%d", &t);
if (t != 0) {
if (i != 0)
s += (b * t) % 2;
else
s += t % 2;
}
}
if (s % 2 == 0)
printf("even\n");
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, k;
set<int> G[N];
set<int> tar;
bool vis[N] = {0};
int bfs(int s) {
queue<int> q;
q.push(s);
vis[s] = 1;
vector<int> tmp;
tmp.clear();
int flag = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (set<int>::ite... | 16 |
#include <bits/stdc++.h>
using namespace std;
int fact[1000003];
void divisor() {
for (int i = 2; i < 1000003; i++) {
for (int j = i; j < 1000003; j += i) fact[j]++;
}
return;
}
int main() {
divisor();
int a, b, c, i, j, k;
while (scanf("%d %d %d", &a, &b, &c) != EOF) {
int ans = 0;
for (i = 1; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void slv() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> pos(n * m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int a;
cin >> a;
a--;
pos[a].second = j;
}
}
for (int j = 0; j < m; j++) {
for (int i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n, i, p, u, oc, lc;
int m[1001];
int left, right;
bool seek;
string moves = "";
cin >> n;
m[0] = 0;
left = n;
right = 0;
for (i = 1; i <= n; i++) {
cin >> m[i];
if ((i < left) && (m[i] > 0)) left = i;
if... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long m, k;
long long f[100][100][2];
long long calc(long long o) {
memset(f, 0, sizeof(f));
f[63][0][1] = 1;
for (int i = 62; i >= 0; i--)
for (int j = 0; j <= 63; j++) {
if (f[i + 1][j][0]) {
f[i][j][0] += f[i + 1][j][0];
f[i][j + 1][0]... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n = 0, k = 0, s = 0, sum = 1, step = 0;
cin >> n >> k >> s;
step = s / k;
if (k * (n - 1) < s || s < k) {
cout << "NO";
return 0;
}
cout << "YES" << endl;
int tek = 1;
for (int i = 0; i < k; ++i) {
if (i < s % k) {
su... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<int> v;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
int ans = v[0];
int r, x;
for (int i = 1; i < n; i++) {
if (k) {
while ((v[i] * i) > k) --v[i];
ans += v[i];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> adj[200111];
vector<int> arr[200111], cur[200111];
bool used[200111];
int pox[] = {0, 0, -1, 1};
int poy[] = {1, -1, 0, 0};
long long myrand() {
long long x = ((1LL * rand() * (1LL << 20) + rand()) % (1LL * n * m)) + 1;
return x;
}
bool check(int x... | 14 |
#include <bits/stdc++.h>
using namespace std;
int cases = 1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> v[i];
int maxi = 0;
vector<int> ase(n + 1,... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
struct node {
node *l, *r;
int sum, lnum, rnum, all;
node() {
l = r = NULL;
sum = lnum = rnum = all = 0;
}
};
struct RET {
int sum, lnum, rnum, all;
};
RET inv(const RET &a) {
RET b = a;
swap(b.lnum, b.rnum);
return b;
}... | 23 |
#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)1e5 + 10;
const long long INF = (long long)2242545357980376863;
const long double EPS = (long double)1e-8;
long long dp[MAXN][105];
long long dp2[MAXN][105]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
double t, x, s;
cin >> n >> t;
vector<pair<double, double> > v;
while (n--) {
cin >> x >> s;
pair<double, double> c(x - (s / 2), x + (s / 2));
v.push_back(c);
}
sort(v.begin(), v.end());
long long sum = 2;
double k, b;... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define ll long long int
void input() {return;}
template<typename T1, typename... T2>
void input(T1 & x, T2&... args){((cin >> x), input(args...));}
void wrt() { cout << endl; return;}
templa... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long inf = 2e18, mod = 1e9 + 7;
int n, x[maxn], y[maxn];
int solve(set<pair<int, int> >& srtX, set<pair<int, int> >& srtY) {
set<pair<int, int> >::iterator itx = srtX.begin(), ity = srtY.begin(), it,
t... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e4;
const long long INF = 1e9 + 1;
const long long MOD = 998244353;
const long double EPS = 1e-12;
const long double PI = acos(-1);
const unsigned long long PRIME = 31;
void bye() {
cout << "\n";
exit(0);
}
vector<vector<int>> g;
vector<bool> use... | 8 |
#include <bits/stdc++.h>
using namespace std;
int T[6];
int C[72][72] = {0}, R[72][72] = {0}, dis[72], n, u, v, w, s, t, m;
bool BFS(int s, int t) {
for (int i = 0; i < n; ++i) dis[i] = 1e9;
queue<int> q;
q.push(s);
dis[s] = 0;
while (!q.empty()) {
int s = q.front();
q.pop();
for (int i = 0; i < n... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int G = 1000 * 100 + 10;
vector<int> e[G], bnam[G], ans;
int h[G], up[G], st[G], mj[G], to[G], x, y;
void dfs(int v) {
up[v] = h[v];
st[y++] = v;
for (int i = 0; i < e[v].size(); i++) {
int u = e[v][i];
if (!h[u]) {
h[u] = h[v] + 1;
dfs(u);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int nxt() {
int res;
scanf("%d", &res);
return res;
}
inline void solve() {
int n = nxt();
int r = nxt();
long long avg = nxt();
int a[n];
int b[n];
int id[n];
long long su = 0;
for (int i = 0; i < n; ++i) {
a[i] = nxt();
b[i] = nxt();
id[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long dp[1002][2005][2][2];
int main() {
dp[1][1][0][0] = 1;
dp[1][1][1][1] = 1;
dp[1][2][0][1] = 1;
dp[1][2][1][0] = 1;
int n, k;
cin >> n >> k;
for (int i = 2; i <= n; i++) {
dp[i][1][0][0] = 1;
dp[i][1][1][1] = 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long XX = 1000000000000000000;
long long N, K;
long long D[55];
long long E[55];
int ans[55];
vector<int> perm;
int p[55];
bool chk[55];
int par(int x) {
if (x == p[x]) return x;
return p[x] = par(p[x]);
}
void unite(int a, int b) {
a = p[a];
b = p[b];
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<string, int> mp;
mp["void"] = 0;
mp["errtype"] = -1;
string cmd, s1, s2;
int x;
for (int i = 0; i < n; i++) {
x = 0;
cin >> cmd;
if (cmd == "typeof") {
cin >> s1;
int s, e;
for (s = 0;... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n;
set<pair<long long, long long> > gp[3005];
long long sz[3005];
long long parent[3005];
long long mx = 0;
pair<long long, long long> mxv = {0, 0};
map<pair<long long, long long>, long long> mp;
long long dfs(long long i, long long par) {
parent[i] = par;
sz[... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x;
}
const int MAXN = 250 ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-7;
const int maxn = 2e5 + 7;
vector<pair<int, long long> > e[maxn];
vector<pair<long long, int> > path;
long long a[maxn], dep[maxn], ans[maxn];
void dfs(int u) {
ans[u]++;
int p = lower_bo... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
return (b == 0 ? a : gcd(b, a % b));
}
const int MAXN = 300005;
const int INF = 1000000000;
const int N = 1000100;
int v[MAXN];
int acc[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
whi... | 13 |
#include <bits/stdc++.h>
using namespace std;
char formula[1000003];
int fcEval(char opchar, int fcA, int fcB) {
int fcRet = 0;
for (int apair = 0; apair < 4; apair++) {
if (((fcA >> apair) & 1) == 1) {
for (int bpair = 0; bpair < 4; bpair++) {
if (((fcB >> bpair) & 1) == 1) {
int rpair ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005 * 10;
const int MOD = 998244353;
const int G = 3;
const int GI = 332748118;
int add(int x, int y) {
x = x + y;
return x >= MOD ? x - MOD : x;
}
int mul(int x, int y) { return (long long)x * y % MOD; }
int dec(int x, int y) {
x = x - y;
return x ... | 23 |
#include <bits/stdc++.h>
using namespace std;
struct data {
long long int u, v;
int flag;
friend bool operator<(const struct data a, const struct data b) {
return a.v > b.v;
}
};
map<struct data, long long int> book;
void did(long long int u, long long int v, long long int add) {
while (u != v) {
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, gcount, u;
const int sz = 190, fsz = 300005;
int perm[fsz], c[fsz], rev[fsz], l[fsz], r[fsz], group[fsz], rvalue[fsz];
int cur_plus[fsz / sz + 1], cur_l[fsz / sz + 1], cur_r[fsz / sz + 1],
mvalue[fsz], pmax[fsz / sz + 1][2], cval[fsz / sz][2];
void init() {
for... | 21 |
#include <bits/stdc++.h>
using namespace std;
char tmp[10];
int n;
string f;
map<string, int> C;
map<string, string> M;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%s", tmp);
f = tmp;
set<string> S;
for (int i = 0; i < f.size(); i++)
for (int j = 1; i + j <= f.size(); j++) {
str... | 7 |
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define ll long long int
#include<bits/stdc++.h>
using namespace std;
void solve()
{
ll n;
cin>>n;
if(n<111)
{
if(n%11==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else if(n>1100)
cout<<"YES"<<endl;
else
{
for(int i=0;i<=1... | 6 |
using namespace std;
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define nl "\n"
#define forf(i,a,n) for(ll i=a;i<=n;i++)
#define forb(i,b,n) for(ll i=b;i>=n;i--)
#define pb push_back
#define vll vector<ll>
#define all(qw) qw.begin(),qw.end()
#define ... | 4 |
#include <bits/stdc++.h>
using namespace std;
namespace QoE_Library {
namespace QL_Bare_Minimum {
const double PI = 3.141592653589793238460;
const long double pi = 10000 * acos(-1.0L);
const long double E = 2.7182818284590452353;
const long double eps = 1e-10;
const int DX4[] = {0, 1, 0, -1};
const int DY4[] = {1, 0, -... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e6 + 20;
pair<pair<long long, long long>, long long> a[maxx];
int main() {
ios::sync_with_stdio(false);
long long t;
cin >> t;
for (int i = 0; i < t; i++) {
long long n;
cin >> n;
int m = 2 * n - 1;
for (int j = 0; j < m; j++) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long a[99];
int n;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
long long p, q, zi, mu;
while (~scanf("%I64d %I64d", &p, &q)) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
sc... | 9 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> colorRepFirst, colorRepSecond;
set<long long> colors;
long long n;
int main() {
scanf("%lld", &n);
for (int(i) = (1); i <= (int)(n); (i)++) {
pair<long long, long long> card;
scanf("%lld%lld", &card.first, &card.second);
+... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i, j, a, b;
vector<long long> v;
map<long long, long long> mp;
scanf("%lld %lld", &n, &k);
for (i = 0; i < n; i++) {
scanf("%lld", &a);
mp[a]++;
if (mp[a] == 1) v.push_back(a);
}
sort(v.begin(), v.end());
long long s ... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[2005];
long long vis[2005];
long long ans[2005];
struct DSU {
long long size;
vector<long long> id;
vector<long long> si;
DSU(long long x) {
size = x;
id.resize(x + 1);
si.resize(x + 1);
for (long long i = 0; i < x; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, k, i, j, t, l, r, ans, f[400005], astmp, p[400005], u, v, x;
int Find(int x) {
if (f[x] == 0) {
astmp = x;
return 0;
}
p[x] ^= Find(f[x]);
f[x] = astmp;
return p[x];
}
void uniot(int u, int v, int w) {
Find(u);
int x = astmp;
Find(v);
int y ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
int n;
bool ok = false;
long long s[N];
long long c[N];
long long l[N], r[N];
long long res;
long long tmp;
int main() {
ios ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(l, 0, sizeof(l));
memset(r, 0, sizeof(r));
cin >>... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar(), f = 0;
for (; c < 48 || c > 57; c = getchar())
if (!(c ^ 45)) f = 1;
for (; c >= 48 && c <= 57; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
f ? x = -x : 0;
}
int n, K, a[500005], ... | 21 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v, dp;
vector<int> vis, dep;
int dfs(int x) {
vis[x] = 1;
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
if (vis[y] == 0) {
dp[y][0] = x;
dep[y] = dep[x] + 1;
dfs(y);
}
}
return 0;
}
int lift(int x, int val... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int min_ = min(a, b);
int p = 1;
for (int i = 1; i <= min_; i++) {
p = p * i;
}
cout << p << '\n';
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[10][10];
for (int i = 0; i < 8; i++) scanf("%s", s[i]);
int flag = 1;
int x, y;
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
if (s[i][j] == 'W') {
flag = 0;
x = i;
y = j;
}
if (flag) {
pu... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct abc {
long long int c, x, y;
};
bool compare(abc a1, abc a2) {
if (a1.x == a2.x) return a1.y > a2.y;
return a1.x < a2.x;
}
const long long int mod = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, d, h[1000000], ans = 0, a[1000000];
int main() {
scanf("%d%d", &n, &d);
memset(h, 0, sizeof(h));
h[0] = 1;
int sum = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
for (int j = sum; j >= 0; j--)
if (h[j]) h[j + a[i]] = 1;
sum += a[i... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long int> v[60];
int M;
int exp(long long int a) {
int ret = 0;
while (a % 3ll == 0ll) {
ret++;
a /= 3ll;
}
if (ret > M) M = ret;
return ret;
}
int main() {
M = 0;
cin >> n;
long long int a;
for (int i = 0; i < n; i++) {
cin ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
struct Point {
int x, y;
Point(int _x = 0, int _y = 0) {
x = _x;
y = _y;
}
Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }
int operator^(const Point &b) const { return x * b.y - y * b.x; }
int operator*(... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <int SZ>
struct Dinic {
typedef long long F;
struct Edge {
int to, rev;
F flow, cap;
};
int N, s, t;
vector<Edge> adj[SZ];
typename vector<Edge>::iterator cur[SZ];
void addEdge(int u, int v, F cap) {
assert(cap >= 0);
Edge a{v, (int)ad... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e5 + 9;
int a[N];
int lf[N];
int rf[N];
int no[N];
vector<pair<int, int> > F[N];
int res1[N];
int iq[N];
int vv[N];
void solve(int l, int r) {
if (l >= r) return;
int mid = (l + r) / 2;
vector<pair<int, int> > tt;
for (int i = r; i > mid; i--) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ans = 0;
long long n, d, x, y;
cin >> n >> d;
cin >> y;
for (long long l = 0; l < n - 1; ++l) {
cin >> x;
long long s1 = y + d;
long long s2 = x - d;
if (s1 == s2) {
ans += 1;
} else if (s2 > s1) {
ans += 2;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100;
const int MAXSHIP = 100000;
const int MAXBASE = 100000;
const int MAXDEP = 1000;
const int MAXGN = 2 + MAXSHIP;
const int MAXGM = MAXSHIP + MAXDEP;
typedef struct MF {
int n, m;
int ghead... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
set<long long> s;
for (int i = 1; i <= n; i++) {
long long x;
scanf("%lld", &x);
s.insert(x);
}
if (s.size() == 1)
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <c... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
string d = "abacaba";
long long count = 0;
for (long long i = 0; i < n - 6; i++) {
long long flag = 0;
for (long long j = i; j < i + 7;... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline void prep() {
cin.tie(0);
cin.sync_with_stdio(0);
};
const int mod = (int)1e9 + 7;
const int MX = (int)2e5 + 10;
const int MAX_NODES = MX * 49;
struct Trie {
int sz;
int t[MAX_NODES][2], cnt[MAX_NODES][2];
Trie() {
memset(t, 0xff, sizeof t);
memset(... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, pos[maxn];
string s[maxn];
int main() {
ios::sync_with_stdio(false);
for (int i = 1; i < maxn; i++) pos[i] = -1;
int m = -1;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> s[i] >> t;
int len = s[i].length();
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int i, j, n, m;
cin >> n >> m;
for (i = 1;; i++) {
if (i % 6 == 0) {
if (2 * n > 3 * m)
n--;
else
m--;
} else if (i % 2 == 0)
n--;
else if (i % 3 == 0)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
ios::sync_with_stdio(false);
int n, m, i, t, k;
cin >> n >> m;
if (n - 1 <= m && m <= 2 * (n + 1)) {
if (m == n - 1) {
a[0] = -1;
a[m + 1] = -1;
t = n - 1;
} else if (m == n) {
a[m + 1] = -1;
t = n;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t ... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool prime[3000001];
bool prime_small[20000];
int divs = 3000000;
int n;
long long A, B, C, D;
long long mul(long long a, long long b) {
return (((a / 10000LL * b) % (1LL << 32) * 10000LL) % (1LL << 32) +
(a % 10000LL * b) % (1LL << 32)) %
(1LL << 32);
... | 17 |
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
map<pii, char> h;
set<pii> even, odd;
int main()
{
int N, M;
scanf("%d%d", &N, &M);
for(int i = 0; i < M; i++){
char op, c;
int u, v, k;
getchar();
scanf("%c", &op);
if(op == '+'){
scanf("%d%d %c", &u, &v, &c);
h[{u, v}] = c... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, m;
long long f[maxn], s[maxn], d[maxn];
signed main() {
cin.sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
f[1] = 1;
for (int i = 1; i <= n; ++i) {
d[i] = (d[i] + d[i - 1]) % m;
f[i] += (s[i - 1] ... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
vector<vector<int> > arr;
bool *used;
void dfs(int v, int day) {
used[v] = true;
int d = 0;
if (d == day) d++;
for (int i = 0; i < (int)g[v].size(); i++) {
if (used[g[v][i].first]) continue;
arr[d].push_back(g[v][i].second... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 5;
const long long SQRTN = 1003;
const long long LOGN = 22;
const double PI = acos(-1);
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const long long FMOD = 998244353;
const double eps = 1e-9;
void __print(long long x) { cerr << x; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 502;
int f[N][N][2];
int g[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> g[i];
}
for (int x = 0; x < n; ++x) {
for (int i = 1; i + x <= n; ++i) {
int j = i + x;
for (int k = 0; k < 2; ++k) {
int& ... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[100000][6];
bool pr[100000];
int b[6][6];
int d[6];
int n;
int res;
void rec(int x) {
if (x == n) {
++res;
return;
}
for (int i = (0); i < (((int)(a[d[x]][n - x]).size())); ++i) {
int g = a[d[x]][n - x][i];
bool good = true;
for (int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
const long long MAXN = 310;
long long N;
map<string, long long> mp;
vector<string> vect;
long long A[MAXN];
long long SZ[MAXN];
long long pt = 1;
map<long long, long long> T[MAXN * MAXN];
vector<long long> pos[MAXN * MAXN];
long long res;
void DFS... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
map<long long, bool> visted;
queue<long long> record[2];
vector<long long> ans;
int n, m;
long long getAns() {
long long tmp;
int num = 0;
int index = 0;
long long length = 0;
int ccnt = 1;
while (num < m) {
while (!record[index].e... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1000;
int N, M, K;
int a[NMAX + 2][NMAX + 2];
struct state {
int dad, sz;
int down;
};
state ds[NMAX + 2][NMAX + 2];
bool active[NMAX + 2][NMAX + 2];
int root(int col, int p) {
if (ds[p][col].dad != p) {
return ds[p][col].dad = root(col, ds[p][col... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
long long mod(long long a, long long mod_value = MOD) {
return (a >= 0) ? (a % MOD) : ((a % MOD) + MOD) % MOD;
}
long long mod_add(long long a, long long b, long long mod_value = MOD) {
return mod(mod(a, mod_value) + mod(b, mod_value)... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int ALPH = 26;
int N, vis[ALPH];
int T, ord[ALPH];
string S[MAXN];
vector<int> adj[ALPH];
void dfs(int v) {
vis[v] = 1;
for (int n : adj[v]) {
if (vis[n] == 1) {
cout << "Impossible\n";
exit(0);
} else if (!vis[n]) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, dp[1 << 23];
long long a[30];
int main() {
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < (1 << (n - 1)); i++) {
int mask = i | (1 << (n - 1));
dp[mask] = __builtin_popcount(mask);
}
for... | 14 |
#include <bits/stdc++.h>
int Abs(int x) {
if (x < 0) return -x;
return x;
}
int main() {
int i, n, m, k;
int s = -1;
int x;
int min1 = 0x7fffffff;
scanf("%d %d %d", &n, &m, &k);
for (i = 1; i <= n; i++) {
scanf("%d", &x);
if (x == 0) continue;
if (x <= k) s = i;
if (s != -1) {
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, p[N];
set<int> s[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
s[u].insert(v);
s[v].insert(u);
}
for (int op = 0; op < 300; ++op) {
for (int i = 1; i <= n;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 123, mod = (int)1e9 + 7, inf = (int)1e9;
const long long INF = (long long)1e18;
int n, d[N], ans[N];
int main() {
n = 1000000;
for (int i = 4; i <= n; i += 2) d[i] = 1;
for (int i = 3; i <= n; i += 2) {
if (!d[i]) {
if (i > 1000) con... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
long long int dp[100001];
long long int f(int n) {
if (dp[n] != -1) return dp[n];
long long int m = a[n];
m *= n;
m += f(n - 2);
dp[n] = max(f(n - 1), m);
return dp[n];
}
int main() {
ios::sync_with_stdio(false);
int n, x;
for (int i = 0; i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int find_min_kicks(char line[]);
int do_it(char line[]);
int count_marks(char line[]);
int main() {
int n = 0;
cin >> n;
char line[11];
cin.getline(line, 11);
for (int i = 0; i < n; i++) {
cin.getline(line, 11);
cout << do_it(line) << endl;
}
return 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int b[10];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
for (int i = 1; i <= 7; i++) {
cin >> b[i];
}
sort(b + 1, b + 7 + 1);
cout << b[1] << " " << b[2] << " " << b[7] - b[1] - b[2] << "\n";
}
retu... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline bool acompare(pair<int, pair<int, int> > a,
pair<int, pair<int, int> > b) {
if (a.first == b.first) return a.second.first > b.second.first;
return a.first < b.first;
}
inline bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, K = 203;
long long n, m, u, v, x, y, t, a, b, ans;
long long dp[MAXN][K];
long long dpt[K], cnt[K];
long long ... | 22 |
#include <bits/stdc++.h>
using namespace std;
void fastIO() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <typename T, typename U>
inline void mnze(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void mxze(T &x, U y) {
if (x < y) x = y;
}
void _scan(int &x)... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
while (n--) {
string fak = "0000", tmp;
vector<string> ve;
cin >> tmp;
int k = 0;
for (int i = 0; i <= tmp.length(); i++) {
if (i == tmp.length() || tmp[i] == ':') {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans[100010], l[100010], x, s, p;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) scanf("%d", &l[i]);
s = l[m];
x = m - 1;
while (s + x < n && x >= 1) {
s += l[x];
x--;
}
p = s + x - n;
if (x == 0 && s < n) {
printf("-1\... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<long long, long long>> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i].first;
cin >> arr[i].second;
}
sort(arr.begin(), arr.end());
long long ctr;
ctr = arr[0].second;
for (int i = 1; i < n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string input;
int tampung = 1;
cin >> input;
for (int i = 1; i < input.length(); i++) {
if (input[i] != '1')
tampung += stoi(input.substr(i, 1));
else {
tampung += 10;
i++;
}
}
cout << tampung;
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define MOD 1000000007
#define all(x) x.begin(), x.end()
#define sze(x) (int) x.... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long binpow(long long a, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
int main() {
cin >> n >> m;
long long ans = binpow(3, n);
ans = (ans + m - 1) % m;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int lazy[4 * N], tree[4 * N];
int arr[N];
int m, ind, type, val;
void upd(int id, int lo, int hi, int l, int r, int val) {
if (l > hi or r < lo) return;
if (l <= lo and r >= hi) {
lazy[id] += val;
return;
}
int mid = (lo + hi) >> 1;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, K = 23, mod = 1e9 + 7;
int n, t, u, v, k, ans, C[K][K], dp[N][K][K];
vector<int> g[N];
void dfs(int x, int par) {
dp[x][0][0] = 1;
for (int i = 0; i < g[x].size(); i++)
if (g[x][i] != par) {
dfs(g[x][i], x);
for (int i = 0; i < k + 1; ... | 17 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 3500;
const double eps = 1e-8;
double a[N][N], ans[N];
int n, m, t, id[N << 1];
void pivot(int l, int e) {
swap(id[e], id[n + l]);
double r = a[l][e];
a[l][e] = 1;
for (int j = 0; j <= n; ++j) a[l][j] /= r;
for (int i = 0; i <= m... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int grundy[N];
int mex(set<int> &st) {
int ret = 0;
while (st.count(ret)) ret++;
return ret;
}
int calc(int x) { return x * (x + 1) / 2; }
int solve(int n) {
if (grundy[n] != -1) return grundy[n];
set<int> st;
for (int i = 2... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.