solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 10;
long long depth[MAXN], ans = 0;
int fa[MAXN];
int getfa(int x) {
if (fa[x] == x) return x;
int ret = fa[x];
fa[x] = getfa(fa[x]);
depth[x] += depth[ret];
return fa[x];
}
int m;
int main() {
scanf("%d"... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5001;
int n, prior[MAXN], t[MAXN], p[MAXN], cap[MAXN];
int a, b, c, cnt;
pair<int, int> d[MAXN];
vector<pair<int, int> > E[MAXN];
void dfs(int v) {
d[v].second = v;
for (int i = 0; i < E[v].size(); i++) {
int to = E[v][i].first;
if (to == p[v]) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int canBe[100000];
int isHere[100000];
bool pre[100000];
vector<int> history;
char com[100000];
int x[100000];
bool allExcept[100000];
int cntHere = 0;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
canBe[i] = 1;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline void read(int &x) {
char c = nc(), b = 1;
for (; !(c >= '0' && c <= '9')... | 23 |
#include <bits/stdc++.h>
using namespace std;
#define vt vector
#define vi vector<int>
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define sz(x) (int) x.size()
#define len(s) (int) s.length()
#define all(c) c.begin(), c.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
template<typename T>
v... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> T;
map<int, int>::iterator it;
vector<int> V;
vector<int> vect;
vector<int> temp;
int funcion(int a, int b) { return a > b; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, x, ans, i, j;
cin >> n;
for (i = 0; i < n; i++) {
cin >... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int minv = 0x3f3f3f3f;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
minv = min(minv, a[i]);
}
if (minv != 1) {
printf("1\n");
} else
printf("-1\n");
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int gl, gr, bl, br;
cin >> gl >> gr >> bl >> br;
if ((bl >= gr - 1 && bl <= gr * 2 + 2) ||
(br >= gl - 1 && br <= gl * 2 + 2)) {
cout << "YES";
} else
cout << "NO";
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
int vf[2 * N], urm[2 * N], lst[N], nr, dt[N], ds[N], q[N], a[N][N];
void adauga(int x, int y) {
vf[++nr] = y;
urm[nr] = lst[x];
lst[x] = nr;
}
int main() {
int n, m, x, y, s, t;
cin >> n >> m >> s >> t;
for (int i = 1; i <= m; i++) {
cin ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long a[5002], pre[5002];
int glob_d1, glob_d2;
long long max_subarray(int start, int finish) {
long long cur_max = (-1) * 100000000000000, max_so_far = 0;
int prev = start, last = start, len = 0;
for (int i = start; i <= finish; i++) {
if (cur_max < 0) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int>> v;
priority_queue<int, vector<int>, greater<int>> pq;
long long int sm = 0;
void add(int x) {
pq.push(x);
sm += x;
if (pq.size() <= k) {
return;
} else {
while (pq.size() > k) {
sm -= pq.top();
pq.pop();
}
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double dinf = 1e40;
const int maxc = 1e6;
const int LEFT = 1;
const int RIGHT = 2;
double time_to_intersect(double ray_pos, double person_pos, double ray_speed,
double person_speed, bool left) {
double t1 = abs((ray_pos - person_pos) / (ray_... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, dem[30];
char a[100005];
int main() {
cin >> n;
cin >> a + 1;
bool ok = false;
for (int i = 1; i <= n; i++) {
if (dem[a[i] - 'a']) ok = true;
dem[a[i] - 'a']++;
}
if (ok || n == 1)
cout << "YES";
else
cout << "NO";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
int n;
cin >> n;
long long factorials[n + 1];
factorials[0] = 1;
for (int i = 1; i <= n; ++i) {
factorials[i] = (factorials[i - 1] * i) % MOD;
}
long long reversefactorials[n + 1];
reversefactorials[n] = 1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int n = 1e5 + 5;
int Q, a, b, N;
int main() {
cin >> Q;
for (int q = 0; q < Q; ++q) {
string s;
cin >> a >> b >> s;
N = s.size();
bool pos = true;
int cZ = 0;
int c = 0;
int lS = 0;
for (int i = 0; i <= N; ++i) {
if (i < N && ... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
long long binpow(long long a, long long b) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(vector<T> a) {
int n = a.size();
for (long long i = 0; i < n; ++i) {
cout << a[i] << (i == n - 1 ? "\n" : " ");
}
}
int sum_vector(vector<int> v) { return accumulate(v.begin(), v.end(), 0); }
void sort_vector(vector<int> &v) { sort(v.... | 16 |
#include <bits/stdc++.h>
using namespace std;
int TC, N, mxb, t, Xn;
int B[100010];
vector<int> X;
map<int, int> dx;
vector<vector<int> > prec;
int la[5010];
pair<int, int> dp[2][5010];
int main() {
scanf("%d %d %d %d", &TC, &N, &mxb, &t);
while (TC--) {
X.clear();
dx.clear();
for (int i = 0; i < N; i++... | 18 |
#include<bits/stdc++.h>
using namespace std;
#include<cstring>
#include<vector>
typedef long long int ll;
typedef long double ld;
typedef double db;
int main()
{ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll n;cin>>n;
ll a[2*n],c[2*n],x=0,y=0,ct=0,d=0,dt=0,w=0,z=0;
for(ll ... | 4 |
#include <bits/stdc++.h>
inline void inp(long long int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
n = n * sign;
}
using namespace st... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
cin >> x;
}
template <class H, class... T>
void read(H& h, T&... t) {
read(h);
read(t...);
}
template <class A>
void read(A* x, int size) {
for (int i = (0); (1) > 0 ? i < (size) : i > (size); i += (1)) read(x[i]);
}
template <cl... | 15 |
#include <bits/stdc++.h>
long long S, d[55 * 55];
int n, cnt, a[55][55], b[55][55], e[55][55], c[55], res[55];
typedef int arr[55][55], arr1[55];
arr tmp[55];
void mul1(arr1 &res, arr &a) {
memset(c, 0, sizeof(c));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) c[i] = (a[i][j] * res[j] + c[i]) & 1;
m... | 19 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll B = 50;
ll dp[2][B + 1][B + B + 1];
ll solve(ll sum, ll bits, ll dmax, ll emax) {
ll lastbit = 1;
while ((1LL << lastbit) <= sum) ++lastbit;
if (sum > (1LL << (dmax + 1)) + (1LL << (emax + 1LL)) - 2LL) return 0LL;
for (int b = 0; b... | 24 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline long long toll(string s) {
long long v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream ... | 13 |
#include <bits/stdc++.h>
using namespace std;
char s[10];
int main() {
scanf("%s", s);
int n = strlen(s);
int now = n - 1;
while (s[now] == '0') --now;
for (int i = 0; i <= now; ++i)
if (s[i] != s[now - i]) {
puts("NO");
exit(0);
}
puts("YES");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int data = 0, w = 1;
char ch = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (ch >= '0' && ch <= '9')
data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
ret... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int Next[maxn], ex[maxn];
void GETNext(char *str) {
int i = 0, j, po, len = strlen(str);
Next[0] = len;
while (str[i] == str[i + 1] && i + 1 < len) i++;
Next[1] = i;
po = 1;
for (i = 2; i < len; i++) {
if (Next[i - po] + i < Next[p... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
string s;
cin >> s;
int numIntervals = n / p + (n % p ? 1 : 0);
set<int> contentCandidates[p];
for (int i = 0; i < p; ++i) {
for (int k = 0; k < numIntervals; ++k) {
int coord = i + k * p;
if (coord < n) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, d[13][13], res;
void minimize(int &x, int y) { x = x > y ? y : x; }
void maximize(int &x, int y) { x = x < y ? y : x; }
int main(void) {
scanf("%d", &n);
n >= 1 ? scanf("%d", &d[1][1]) : 0;
n >= 2 ? scanf("%d", &d[1][2]) : 0;
n >= 3 ? scanf("%d", &d[1][3]) : ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n);
vector<int> pre(n);
int mn = INT_MAX;
for (int i = 0; i < n; i++) {
int x;
cin >> v[i] >> x;
mn = min(mn, x);
pre[i] = mn;
}
int sum = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
n *= 2;
cout << fixed << setprecision(9)
<< 1.0L / tan(3.141592653589793238462643383279502884L / n) << "\n";
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)998244353;
const long long maxn = (long long)1e5 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max() - 1;
const long long INF = numeric_limits<long long>::max() - 1;
void solve() {
long long n, k, d;
map<long long, l... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long StringToNumber(string &s) {
stringstream ss(s);
long long result;
return ss >> result ? result : 0;
}
int main() {
long long max = 0;
bool thereIsMax = false;
string s;
cin >> s;
for (unsigned int i = 1; i < s.length(); i++) {
for (unsigned int... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
map<int, int> mp;
vector<int> vs;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (mp[a[... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, ans1 = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int x, ans = 0;
cin >> x;
while (x > 0) {
int digit = x % 10;
if (digit == 4 || digit == 7) {
ans++;
}
x /= 10;
}
if (ans <= k) {
an... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 8010, mod = 1e9 + 7, inf = 1e9 + 10;
bool adj[maxn][maxn];
int dg[maxn], arr[maxn];
long long ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie();
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (n /... | 27 |
#include <bits/stdc++.h>
using namespace std;
int n, k, e, head[100010], r[100005], f1[100005], f2[100005], len;
vector<int> vec;
struct Edge {
int to, cost, next;
} edge[200010];
void addedge(int a, int b, int c) {
edge[e].to = b;
edge[e].cost = c;
edge[e].next = head[a];
head[a] = e++;
}
void dfs1(int u, in... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inv = numeric_limits<int>::max();
const int minv = numeric_limits<int>::min();
const int max_n = 100010;
const int clim = 1000010;
int n;
pair<int, int> v[max_n];
double res = 0.0;
double c[2 * clim + 1][2];
int csz[2 * clim + 1];
int miny, maxy;
void markoff(int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int table[26] = {0, 0, 1, 1, 5, 1, 21,
1, 85, 73, 341, 89, 1365, 1,
5461, 4681, 21845, 1, 87381, 1, 349525,
299593, 1398101, 178481, 5592405, 1082401};
int... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double inf = ~0u >> 2;
char s[1010][12][12];
int fa[1010], sw[1010][1010];
vector<int> ed[1010];
struct node {
int x, y, w;
} p[1010 * 1010];
int n, m;
bool vis[1010];
int find(int x) {
if (x != fa[x]) {
f... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void fileio(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const long long INF = 4e18;
inline long long read() {
long long x = 0;
bool flag = 1;
char c = getchar();
while (... | 11 |
#include <bits/stdc++.h>
using namespace std;
int x[1005][6];
int vis[1005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 5; j++) scanf("%d", &x[i][j]);
if (n > 11) {
printf("0\n");
return 0;
}
int num = 0;
for (int i = 1; i <= n; i++) {
int flag =... | 9 |
#include <bits/stdc++.h>
const int MAX = 1e3 + 11;
using namespace std;
const double eps = 0.000001;
const int N = 8;
vector<int64_t> A[N];
static inline int64_t dot(const vector<int64_t> &a, const vector<int64_t> &b) {
int64_t res = 0;
for (int i = 0; i < (int((a).size())); ++i) {
res += a[i] * b[i];
}
ret... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 998244353;
double eps = 1e-12;
void solve() {
long long a, b;
cin >> a >> b;
if (a == b) {
cout << 0 << en... | 0 |
#include <algorithm>
#include <iostream>
#include <cstring>
#include <math.h>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iomanip>
#define fi first
#define se second
#define pb push_back
#define si(s) s.size()
#define all(a) a.begin(), a.end()
using namespace std;
typed... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int a[100005];
int mark[100005];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) a[i] = i + 1;
if (k == 1) {
for (int i = 0; i < n; ++i) co... | 4 |
#include <bits/stdc++.h>
const int MAXN = 3010;
struct edge {
int v;
edge *nxt;
edge() {
v = 0;
nxt = NULL;
}
} * head[MAXN];
inline void adde(int u, int v) {
edge *p = new edge;
p->v = v;
p->nxt = head[u];
head[u] = p;
}
struct ask {
int s, t, k, id;
ask() {}
ask(int s, int t, int k, int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 100;
const int INF = 1e9;
vector<pair<int, int>> edges;
vector<int> g[N];
vector<int> tin(N), tout(N), min_tin(N), comp(N), used(N), val, sizes(N),
root(N), par(N, -1);
vector<vecto... | 24 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const double PI = 3.141592653589793238;
const double eps = 1e-6;
inline int INT() {
register int c = getchar();
int x = 0;
for (; (c < 48 || c > 57); c = getchar())
;
for (; (c > ... | 8 |
#include <bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int &i : A) cin >> i;
sort(A.begin(), A.end());
vector<int> D(1e6 + 1, 0);
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int sum, cnt;
int f[N], a[N];
int find(int k) {
if (f[k] == k) return k;
return f[k] = find(f[k]);
}
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) f[i] = i;
for (int i = 1; i <= m; i++) {
int x, y... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long size;
cin >> size;
if (size % 2 == 1) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
multiset<int> s1, s2;
int n, w, k;
int a[maxn], t[maxn];
bool add[maxn];
int happy, usetime;
bool insert(int idx) {
int pt = t[idx], ph = a[idx];
if (s2.size() < w) {
int pt2 = pt + 1 >> 1;
if (usetime + pt2 > k) return 0;
usetime +... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int vert[MAXN];
int cnt[MAXN];
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m, x1, x2, y;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> vert[i];
}
sort(vert, vert + n);
vert[n] = 10000000... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n <= 2) {
cout << 0;
return 0;
}
int cnt = INT_MAX;
int temp = 0;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
int c... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epo... | 1 |
#include <bits/stdc++.h>
using namespace std;
void use_cio() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
template <typename... Args>
void dbg(Args... args) {
((cout << args << " "), ...);
cout << endl;
}
int n, k;
string s;
int main() {
use_cio();
cin >> n >> k;
cin >> s;
int cut = 0;
for (cut = n -... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50;
int par[MAXN];
vector<int> guise[MAXN];
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void merge(int a, int b) {
a = find(a);
b = find(b);
par[a] = b;
}
int N, M;
int main() {
scanf("%d %d", &N, &M);
for (int... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200002];
vector<int> nums[200002];
int visited[1001][10001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, g, r;
cin >> n >> m;
int isl[m];
for (int i = 0; i < m; ++i) cin >> isl[i];
sort(isl, isl + m);... | 16 |
#include <bits/stdc++.h>
using namespace std;
int N;
struct node {
int x, val;
} a[200200];
bool cmp(node x, node y) { return x.x < y.x; }
int L, R;
int sum;
void getsum(int fx) {
if (fx == 1) {
for (R = R; R <= N; R++) {
if (a[R].x > 0) {
sum += a[R].val;
R++;
getsum(fx ^ 1);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double ESP = 1e-5;
const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int MAXN = 1e5;
int weight[MAXN], pos[MAXN];
int st[MAXN], num[MAXN];
bool vis[MAXN];
int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
mems... | 8 |
#include <bits/stdc++.h>
using namespace std;
const bool db = false;
int mod, a[100010];
int mark[100010], color;
int d[100010];
bool prime(int n) {
for (int i = 2; i * i <= n; ++i)
if (n % i == 0) return false;
return true;
}
bool check(int gen, int last) {
++color;
mark[last] = color;
for (int i = 2; i ... | 15 |
#include <bits/stdc++.h>
constexpr int MAXN = 2e5 + 5;
constexpr int Inf = 0x7fffffff;
using namespace std;
using LL = long long;
template <typename T>
inline void read(T &x) {
int f = 1;
x = 0;
char ch = getchar();
while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
while (isdigit(ch)) x = x * 10 ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, m, k, q, val[maxn][maxn];
vector<pair<int, int> > pos[maxn];
struct bi {
long long sum[maxn][maxn];
void modify(int x, int y, int val) {
for (int i = x; i <= n; i += i & -i)
for (int j = y; j <= m; j += j & -j) sum[i][j] += val;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
void outInt(long long &);
int main() {
string str;
cin >> str;
string showZero;
long double sum = 0, dec = 1, cents = 0;
long long result;
int n = 0, first = 0, i, helpIfNoDots = 0;
for (i = str.length() - 1; i >= 0; i--) {
if (first > 0) helpIfNoDots = 0;... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int IsNine(long long int num) {
long long int flag = 0;
while (num != 0) {
if (num % 10 != 9) {
flag = 1;
break;
}
num /= 10;
}
if (flag == 0)
return 1;
else
return 0;
}
int main() {
std::ios_base::sync_with_stdio(false)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, i, j;
cin >> a >> b >> c;
if (b >= a && c >= a)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>>& conTo, int pos, vector<int>& visited) {
if (visited[pos])
return;
else {
visited[pos] = 1;
for (auto a : conTo[pos]) {
dfs(conTo, a, visited);
}
}
}
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> ... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
using namespace std;
const int mod = 998244353;
const int N = 4e5 + 10, M = 2e6 + 10;
int n, m, d[N], d1[N], cnt[N], dp[N][22], vis[N][22], pw[30], mark[N], a[N],
b[N];
int head[N], nex[M], to[M], w[M], tot, h1[N], h2[N];
inline void add(... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
long long n, m;
long long x[100010], d[100010];
long long sum = 0;
long long mx = 0;
long long add = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (in... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long p;
long long xorr[1000005], xorr2[1000005];
;
int main() {
cin >> n;
long long res = 0;
for (int i = 0; i < n; i++) {
cin >> p;
res ^= p;
}
xorr[0] = 0;
for (int i = 1; i <= n; i++) xorr[i] = i ^ xorr[i - 1];
for (int k = 1; k <=... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0), ios_base::sync_with_stdio(false);
long long w1, h1, w2, h2;
cin >> w1 >> h1 >> w2 >> h2;
cout << 2 * (h1 + h2 + 2) + 2 * w1 << endl;
}
| 0 |
#include <bits/stdc++.h>
long long in() {
long long x = 0, f = 1;
char ch;
while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
for (x = ch ^ 48; isdigit(ch = getchar());
x = (x << 1) + (x << 3) + (ch ^ 48))
;
return x * f;
}
const int maxn = 2e5 + 100;
const int inf = 0x7fffffff;
int n, m, T;... | 18 |
#include <bits/stdc++.h>
int main() {
unsigned short n, m, b[101], i, j, memo[101];
scanf("%hu%hu", &n, &m);
for (i = 1; i <= n; i++) {
memo[i] = 0;
}
for (i = 1; i <= m; i++) {
scanf("%hu", b + i);
}
for (i = 1; i <= m; i++) {
if (!memo[1]) {
for (j = b[i]; j <= n; j++) {
if (!m... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, Q;
class ZYK {
class BIT {
long long b[200020];
inline int lowbit(int x) { return x & (-x); }
public:
inline void Add(int x, long long d) {
while (x <= n) b[x] += d, x += lowbit(x);
}
inline long long Ask(int x) {
long long ans =... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x;
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> x;
m[x]++;
}
int ans = 1;
for (auto it = m.begin(); it != m.end(); it++) {
if (it->second > ans) {
ans = it->second;
}
}
cout << n - ans << e... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 200005;
int n, m;
int maps[MAXN];
long long sum[MAXN][2];
pair<long long, long long> node[MAXN];
inline long long lowbit(long long x) { return x & (-x); }
void add(long long ... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int t;
int fwl[202][202][6][6], fwc[202][202][6][6];
bool viz[202][202][6][6];
vector<pair<int, int> > scoruri;
vector<pair<int, int> > scoruri5;
void dpbuild() {
viz[0][0][0][0] = 1;
for (int i = 0; i <= 200; ++i)
for (int j = 0; j <= 200... | 14 |
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
using Float = long double;
void solve() {
Int n, k;
cin >> n >> k;
vector<pair<Int, Int>> A;
A.push_back(make_pair(0, 0));
{
map<Int, Int> mp;
for (Int(i) = (1); (i) <= (n); (i)++) {
Int a;
cin >> a;
mp[a]++;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, flag = 0;
char ch = getchar();
if (ch == '-') flag = 1;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') x *= 10, x += ch - '0', ch = getchar();
if (flag) return -x;
return x;
}
int main() {
int test;
cin ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int const MAXN = 1501;
void dfs(vector<vector<int>> &g, vector<int> &mark, int i) {
mark[i] = 1;
for (int j = 0; j < (g[i].size()); ++j) {
if (!mark[g[i][j]]) {
dfs(g, mark, g[i][j]);
}
}
}
int main() {
(ios::sync_with_stdio(false));
int n;
cin >> ... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T GCD(T a, T b) {
return b ? GCD(b, a % b) : a;
}
template <class T>
T LCM(T a, T b) {
return a / GCD(a, b) * b;
}
const int MAXN = 1010;
const int MAXM = 20010;
const double eps = 1e-10;
const double pi = atan(1.0) * 4.0;
int n, m, d, h;
int main() {... | 8 |
#include <bits/stdc++.h>
using namespace std;
string in;
int k;
int main(void) {
cin >> in >> k;
int maior;
string res;
string tmp = in;
;
string tmp2;
for (int i = 0; i < in.size(); ++i) {
maior = -0x3f3f3f3f;
int pos;
for (int j = 0; j < tmp.size(); ++j) {
int cost = j;
if (maior... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int inf = 1e9;
using ii = pair<int, int>;
using ll = long long;
using ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (k <= n || n <= 4) {
cout << -1;
return 0;
}
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << a << " " << c << " ";
for (int i = 1; i <= n; i++) {
if (i != a && i != b && i != c && i != d) cout << i << " "... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int dir[4][2] = {{0, -1}, {0, +1}, {-1, 0}, {+1, 0}};
int n, m, k, cid, q, r, c;
char g[1005][1005];
int cp[1005][1005], cnt;
int ans[1000005];
vector<pair<int, int> > reff[1000005];
void flood(int px, int ll, int cc) {
if (cp[ll][cc] != -1) return;
if (ll < 0 || ... | 9 |
#include <bits/stdc++.h>
using namespace std;
char q[50][51];
bool tst(unsigned int r, unsigned int c) {
bool cf = false, ca = false, cc = false, ce = false;
for (unsigned int i = 0; i < 2; ++i) {
for (unsigned int j = 0; j < 2; ++j) {
switch (q[r + i][c + j]) {
case 'f':
cf = true;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
int INF = 0x3f3f3f3f;
int n, q, a[1000005], ps[1000005];
int ans[1000005];
vector<pair<int, int> > qu[1000005];
namespace BIT {
int bit[1000005] = {};
void update(int idx, int v) {
for (; idx <= n; idx += idx & -idx) bit[idx] ^= v;
}
int query(int idx) ... | 13 |
#include <bits/stdc++.h>
const int N = 100100;
char s[1 << 20];
bool dead[N];
int vtop, stov[N];
int in[1 << 21], out[1 << 21];
int R[1 << 21], rtop;
int bit[1 << 21];
struct Node {
int p;
Node *next;
Node(int P = 0, Node *ne = NULL) {
p = P;
next = ne;
}
} h[1 << 21];
void add(int x, int y) { h[x].next... | 20 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> m;
int main() {
string str;
cin >> str;
int f = 0, a = 1, s = 10;
for (int i = 0; i < str.size(); i++)
if (isalpha(str[i]))
m[str[i]]++;
else if (str[i] == '?')
f++;
for (int i = m.size(); i > 0; i--) {
a *= s;
s--;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
if (e == 0) return 1;
if (e % 2 == 0) {
long long t = bigmod(p, e / 2, M);
return (T)((t * t) % M);
}
return (T)((long long)bigmod(p, e - 1, M) * (long long)p) % M;
}
template <class T>
inline T gcd(T a, T ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n;
void update(long long *tree, int pos, long long add) {
while (pos <= n) tree[pos] += add, pos += pos & (-pos);
}
long long query(long long *tree, int pos) {
long long ans = 0;
while (pos) ans += tree[pos], pos -= pos & (-pos);
return... | 17 |
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n, m, q;
std::cin >> n >> m >> q;
std::vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) std::cin >> a[i];
for (int i = 0; i < m; ++i) std::cin >> b[i];
int64_t A = 0;
for (int i = 0; i < n; ++i) {
... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
template <class T>
inline T sqr(T a) {
return a * a;
}
vector<vector<int> > g;
vector<vector<int> > gd;
int n, m, timer = 0;
bool used[1 << 17] = {0}, incomp[1 << 17] = {0};
int tin[1 << 17], tout[1 << 17], fup[1 << 17], p[1 << ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x;
int y;
} point[305], p1, p2;
int main() {
int n;
scanf("%d", &n);
double ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &point[i].x, &point[i].y);
}
for (int i = 1; i <= n - 1; i++) {
for (int j = i + 1; j <= n; j++) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 1e6 + 5;
const int mod = 998244353;
long long p[maxn];
long long qpow(long long a, long long n, long long p) {
long long ans = 1;
while (n) {
if (n & 1) ans = ans * a % p;
a = a * a % p;
n... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[200005];
int deep[200005];
int f[200005];
int b[200005][21];
int kk[200005];
int flag, k;
void dfs(int u, int fu) {
f[u] = fu;
b[u][0] = fu;
for (int i = 1; i <= 20; i++) b[u][i] = b[b[u][i - 1]][i - 1];
deep[u] = deep[fu] + 1;
for (int i = 0; i < (i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int ind = -1;
void binary_search(long long val, vector<long long> &v, int l, int r) {
if (l > r) {
return;
}
int mid = l + (r - l) / 2;
if (v[mid] <= val) {
ind = mid;
binary_search(val, v, mid + 1, r);
} else {
binary_search(val, v, l, mid - 1);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
long long n, j, mx, my;
cin >> n >> j >> mx >> my;
j %= (4 * n);
long long ax[n], ay[n];
for (int i = 0; i < n; i++) {
cin >> ax[i] >> ay[i];
}
for (int i = 0; i < j; i++) {
mx = 2 * ax[i % n] - mx;
my = 2 *... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.