solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 3e3 + 10;
const int MAXM = 1400000 + 10;
const long long mod = 1e9 + 7;
bool vis[MAXN];
struct node {
int p, c, id;
} a[MAXN];
vector<node> vec[MAXN];
bool cmp(node x, node y) { return x.c < y.c; }
int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 9;
int n, m, vout, cnt, num[MAXN], tag[MAXN];
queue<int> que[MAXN];
inline int read() {
char c = getchar();
int ret = 0;
while (c < '0' || c > '9') c = getchar();
while (c <= '9' && c >= '0') ret = ret * 10 + c - '0', c = getchar();
retur... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, r;
cin >> l >> r;
if (r - l < 2)
cout << -1 << "\n";
else {
if (l % 2 == 0)
cout << l << " " << l + 1 << " " << l + 2 << "\n";
else if (r % 2 == 0)
cout << r - 2 << " " << r - 1 << " " << r << "\n";
else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N, x[5555], Last[2222];
int F[2222][2222], Ans[2222];
char CMD[5555][10];
inline void Plus(int s[], int a[]) {
s[0] = max(s[0], a[0]);
for (int i = 1; i <= s[0]; i++) {
s[i] += a[i];
if (s[i] >= 10) {
s[i] -= 10;
s[i + 1]++;
}
}
if (s[s[0... | 12 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long ap(unsigned long long a, unsigned long long b) {
return (b + a) * (b - a + 1) / 2;
}
int main() {
int n, m;
cin >> n >> m;
unsigned long long A, B, C;
cin >> A >> B >> C;
vector<unsigned long long> U(m), V(m);
for (int i = 0; i < m; i++) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
namespace DynamicTree {
unsigned int randxor() {
static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
unsigned int t;
t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
struct D_NODE {
int laz... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100 * 1000 + 5;
int n, x1, x2;
set<pair<long double, int> > mys1, mys2;
pair<long double, long double> d[Maxn];
int main() {
cin >> n >> x1 >> x2;
int k, b;
for (int i = 0; i < n; i++) {
scanf("%d%d", &k, &b);
pair<long double, int> d1, d2;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int _N = 100010;
int n, s;
long long cnt[_N];
vector<int> edge[_N];
int aN, a[_N], bN;
long long b[_N];
int pre[_N];
long long eat[_N], res[_N];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) cin >> cnt[i];
for (int i = 0; i < ... | 13 |
#include <bits/stdc++.h>
using namespace std;
queue<long long> q;
map<long long, vector<long long> > m;
int cnt;
bool solve = true;
void factor(long long ele, long long turn) {
if (ele == 1) {
cout << 1 << " ";
cnt++;
if (cnt == 100000) {
solve = false;
}
return;
}
if (m[ele].size() == 0... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v[200001];
stack<char> sta;
map<long long, long long> mp, pm;
set<long long> st;
set<long long>::iterator P;
long long A[200001], B[200001], n, m, t, k, i, j, sum;
string s;
long long a, b, c, d;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NUL... | 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--) {
long long int n, x;
cin >> n >> x;
vector<long int> vec(n);
for (int i = 0; i < n; i++) cin >> vec[i];
sort(vec.begin(), vec.end(), g... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int sum = 0;
vector<int> ta(101, 0);
for (int i = 0; i < n; i++) {
sum += a[i];
if (sum <= m) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long memo[52][52];
long long nCr(int n, int r) {
if (n < r) return 0;
if (n == r) return 1;
if (!r) return 1;
long long &ret = memo[n][r];
if (~ret) return ret;
return ret = nCr(n - 1, r - 1) + nCr(n - 1, r);
}
const int N = 52;
double memo2[N][N][2];
int n... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
int a[1004];
int p[1004];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
a[t]++;
}
cin >> t;
p[0] = 0;
int res = 0;
for (int i = 1; i < 1004; i++) {
p[i] = p[i - 1] + a[i];
}
for (int i = 1; i < 1004; i++) {
if (i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool qf = false;
int n, i, j, a[2016], first, second, third, temp, ans = 2, cnt, t;
map<int, int> f;
map<int, int>::iterator it;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]), f[a[i]]++;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n, best;
int a[111][55][211][3];
void go(int pos, int change, int x, int dx) {
if (a[pos][change][x + 100][dx + 1]) return;
a[pos][change][x + 100][dx + 1] = 1;
if (pos == s.size()) {
if (change == 0) best = max(best, abs(x));
return;
}
for (... | 10 |
#include <bits/stdc++.h>
using namespace std;
int N[5], M[5];
int main() {
int sum, a, b, c, d;
scanf("%d", &sum);
for (int ix = 1; ix <= 4; ix++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
N[ix] = min(a, b);
M[ix] = min(c, d);
}
for (int ix = 1; ix <= 4; ix++)
if (N[ix] + M[ix] <= sum) {
cout... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
int q;
cin >> n >> q;
while (q--) {
long long x;
scanf("%I64d", &x);
long long len = n, cur = n, pre = 0;
while (x % 2 == 0) {
x = cur + (x - pre + 1) / 2;
if (len % 2 == 1 && cur % 2 == 0)
len = len / 2 ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct punkt {
int x, i;
};
punkt p;
vector<punkt> tab;
int n, m, x, y, f, ans, i[100001], pos[100001],
koniec = 10000009, mini = 100000009, pol, con[100001];
bool blad = 0;
bool cmp(punkt x, punkt y) {
if (x.x < y.x)
return 1;
else if (x.x == y.x) {
if (x... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long inf = 2e18;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long mini = inf;
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-14;
struct point {
double x, y;
} g[100002];
struct Matrix {
double a[4][4];
long long n, m;
} ans, s[40];
Matrix operator*(Matrix a, Matrix b) {
Matrix c;
memset(c.a, 0, sizeof(c.a));
c.n = a.n;
c.m = b.m;
for (long long i = 1; i <= a.... | 23 |
#include <bits/stdc++.h>
using namespace std;
char a[200010];
int t, n, m;
int main() {
int i, j, k, l;
scanf("%d%d%s", &n, &t, a);
for (k = 0; k < n && a[k] != '.'; k++)
;
for (i = k + 1; i < n && a[i] < '5'; i++)
;
if (i == n) return 0 * puts(a);
for (; i > k + 1 && a[i] > '4' && t--; a[i] = '\0',... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, ans = 0, mod;
cin >> a >> b;
if (a == b) {
cout << "1" << endl;
continue;
}
if (a == 1 || b == 1) {
cout << max(a, b) << endl;
continue;
}
while (a != b) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXX = 2000000000000000009;
long long inv[20][20];
long long dp[(1 << 20)];
long long pom[20];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, tab[400009];
cin >> n;
int a;
for (int i = 0; i < n; i++) {
cin >> tab[i];
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20004;
int users[N];
int main() {
deque<int> curr;
int n, m, t;
cin >> n >> m >> t;
--t;
bool reached = false;
int cnt_users = 0;
for (int i = 0; i < n; ++i) {
int a, b, c;
char tmp;
cin >> a >> tmp >> b >> tmp >> c;
c += 60 * (b ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
pair<int, int> a[N];
int ans[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].first, a[i].second = i;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
a[i].... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d", &n), scanf("%d", &k);
int A[105];
vector<int> V[105];
int cnt = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &A[i]);
V[A[i]].push_back(i);
if (V[A[i]].size() == 1) cnt++;
}
if (cnt < k)
printf("NO\n");
els... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool mmax(T &m, const T q) {
if (m < q) {
m = q;
return true;
} else
return false;
}
template <typename T>
bool mmin(T &m, const T q) {
if (m > q) {
m = q;
return true;
} else
return false;
}
long long pw(long long a, lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long const INF = 1000000000;
const int MOD = 1e9 + 7;
const int N = 2e5 + 500;
void SpeedForce() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int simple(int n) {
int i, sq;
if (n % 2 == 0) {
return 0;
}
sq = (int)sqrt(n);
for (i = 3; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
void chmin(T &a, const T &b) noexcept {
if (b < a) a = b;
}
template <class T>
void chmax(T &a, const T &b) noexcept {
if (a < b) a = b;
}
void debug_out() { cout << "\n"; }
template <class T, class... A... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
char a[1001][1001] = {0};
int t = 0;
int mx = 0;
int openb(int v, int fl = false) {
a[mx - v][t] = '+';
a[mx - v][t + 1] = '-';
for (int i = mx - v + 1; i <= mx - v + 1 + 2 * v - 1 - 1; i++) {
a[i][t] = '|';
}
a[mx - v + 1 + 2 * v - 1][t] = '+';
a[... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> answer;
struct TreeNode {
long long nvalue;
struct TreeNode* left;
struct TreeNode* right;
};
long long globalCount = 0;
void generateTrees(string s, long long direction, long long E, long long total,
vector<string>& alls) {
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
;
long long sum = 0;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
};
long long mx = *max_element(a, a + n);
;
cout << ((2 * mx) - sum + 1) << endl;
;
}
int32_t main() {
io... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 5;
struct str {
int a, id;
} node[maxn];
int a[maxn], b[maxn], que[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &node[i].a);
node[i].id = i;
}
node[n + 1].a = 0;
sort(node + 1, node + n ... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int b, l, c;
} g[91005 << 1];
int gap[305], cur[305], h[305], t, dis[305], n, pre[305];
int graph[305][305], link[305], vis[305];
bool hungry(int u) {
for (int i = 1; i <= n; i++)
if (vis[i] != t && graph[u][i]) {
vis[i] = t;
if (!link[i] |... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 85 - 69;
queue<int> q[maxn];
set<pair<int, int> > s;
int n, qu;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int cnt = 0;
cin >> n >> qu;
for (int i = 0; i < qu; i++) {
int ty, fi;
cin >> ty >> fi;
if (ty == 1) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3;
vector<int> g[MAX_N];
vector<int> v(MAX_N);
vector<int> ene(MAX_N, 0);
vector<bool> mark(MAX_N, false);
int n;
int main() {
int m;
cin >> n >> m;
int inp1, inp2;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
long long sum = 0;
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int M = 200 + 5;
vector<int> adj[N];
int state[N], cur[N], taken[N];
int main() {
int n, m, a, b, k;
cin >> n >> m;
k = n;
vector<int> sol;
for (int i = 0; i < m; i++) {
cin >> a >> b;
a--, b--;
adj[a].push_back(b);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, k, i, j, x, y, ans, mode;
cin >> q;
k = 750;
vector<int> s(500000 + 10, 0);
vector<vector<int> > l;
l.resize(k + 5);
for (i = 1; i < k + 5; i++) {
l[i].resize(i + 5);
for (j = 0; j < i + 5; j++) l[i][j] = 0;
}
for (i = 0; i < q;... | 13 |
#include <bits/stdc++.h>
namespace Quick_Function {
template <typename Temp>
void Read(Temp &x) {
x = 0;
char ch = getchar();
bool op = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') op = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getcha... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long p;
int k, a[111], cnt = 0;
cin >> p >> k;
while (p) {
if (cnt & 1) {
long long pp;
if (p % k == 0)
pp = p;
else
pp = (p / k + 1) * k;
a[cnt++] = (pp - p) % k;
p = pp / k;
} else {
a[c... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct CoordInt {
int x, y;
};
int main() {
int n;
cin >> n;
vector<CoordInt> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].x;
cin >> v[i].y;
}
int idx_min_x = 0, idx_max_x = 0, idx_min_y = 0, idx_max_y = 0;
for (int i = 1; i < n; i++) {
if (v[... | 12 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 7 |
#include <bits/stdc++.h>
using namespace std;
int jump[305], cost[305];
int gcd(const int& a, const int& b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void put(map<int, int>& m, const int& k, const int& v) {
if (m.count(k) == 0)
m[k] = v;
else
m[k] = min(m[k], v);
}
int main() {
int n;
cin >> n... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int n, a, x[N], y[N], st[N * 2];
double r[N], d[N];
vector<pair<double, int>> b;
bool chk(double w) {
int i, t = 0;
double p, q, u, v, o, z;
b.clear();
for (i = 1; i <= n; ++i)
if (w + r[i] > d[i] && fabs(r[i] - w) < d[i]) {
z = (d[i... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long max_n = 2e5 + 4;
long long n;
long long a[max_n];
vector<long long> gr[max_n];
long long sz[max_n];
pair<long long, long long> dfs(long long v) {
pair<long long, long long> res(0, 0);
for (long long i : gr[v]) {
pair<lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1;
return 0;
}
int arr1[100000], arr2[100000], arr3[100000];
for (int i = 0; i < n; i++) arr1[i] = arr2[i] = i, arr3[i] = (2 * i) % n;
for (int i = 0; i < n; i++) cout << arr1[i] << ' ';
cout <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d;
long long ret;
int main() {
cin >> n >> a >> b >> c >> d;
for (int i = 1; i <= n; i++) {
bool ok = true;
ok &= (b + i - c <= n && b + i - c > 0);
ok &= (a + i - d <= n && a + i - d > 0);
ok &= (a + b + i - c - d <= n && a + b + i - c -... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 1000000007, mod = 1000000000;
double Pi = 3.141592653589793238;
const double long rad = Pi / 180.0;
template <class tone>
tone gcd(tone a, tone b) {
return b == 0 ? a : gcd(b, a % b);
}
template <class tone>
tone lcm(tone a, tone b) {
return (a * ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
int ans = 0;
for (int i = 0; i < m; i++) {
if (arr[i] < 0) ans += arr[i];
}
cout << (-1) * ans << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
x += y;
if (x >= mod) x -= mod;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[10000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[i] = make_pair(x, y);
}
sort(a, a + n);
int cur = -1;
for (int i = 0; i < n; i++) {
if (a[i].second >= cur) {
cur = a[i].secon... | 6 |
#include <bits/stdc++.h>
using namespace std;
double n, r;
double pi = acos(-1);
int main() {
cin >> n >> r;
double x = sin(pi / n);
double y = 1 - x;
printf("%.7lf\n", r * x / y);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int f[1000005], a[5005];
int v[1000005];
int n, K;
bool check(int x) {
for (int i = 0; i < x; i++) v[i] = 0;
int t, ret = 0;
for (int i = 1; i <= n; i++) {
t = a[i] % x;
v[t]++;
if (v[t] > 1) ret++;
}
return ret <= K;
}
int main() {
while (scanf("%d ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct edge {
int y, nex;
} s[N << 1];
int first[N], len = 0, n, d[N], p;
vector<pair<int, int> > V;
void ins(int x, int y) {
s[++len] = (edge){y, first[x]};
first[x] = len;
d[x]++;
}
void dfs(int x, int fa, int t) {
int las = t;
V.push_bac... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[(int)1e5 + 1], b[(int)1e5 + 1];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
sort(a, a + n);
sort... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ohh, omm, hh, mm, cnt, same = 1, mx = 1;
cin >> n;
cin >> ohh >> omm;
for (int i = 1; i < n; i++) {
cin >> hh >> mm;
int t = (hh - ohh) * 60 + (mm - omm);
if (t) {
ohh = hh;
omm = mm;
same = 1;
} else {
sam... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
int j = i;
while (j < n && s[j] == s[i]) {
j++;
}
string q = "RGB";
q.erase(q.find(s[i]), 1);
if (j < n) {
q.erase(q.find(s[j]), 1)... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool win(string a, string b) {
if (a == "rock" && b == "scissors") return 1;
if (a == "scissors" && b == "paper") return 1;
if (a == "paper" && b == "rock") return 1;
return 0;
}
int main() {
string a, b, c;
cin >> a >> b >> c;
if (win(a, b) && win(a, c))
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 777777777;
const int UNDEF = -1;
const long long INF = 1e18;
template <typename T>
inline bool chkmax(T& aa, T bb) {
return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T& aa, T bb) {
return aa > bb ? aa = bb, true : false;... | 16 |
#include <bits/stdc++.h>
using namespace std;
class line {
public:
long double a, b;
long double eval(long double x) { return a * x + b; }
line(long double A = 0., long double B = 0.) : a(A), b(B) {}
};
long double intersection(line l1, line l2) {
return (l2.b - l1.b) / (l1.a - l2.a);
}
const int maxn = 2e5 + ... | 16 |
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
namespace {
namespace shik {
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(doub... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7, MAX = 1e18;
struct wins {
int st;
int en;
};
bool prime[1000001];
void Sieve(int n) {
n = 1000000;
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int now = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c == '-' && (f = -1), c = getchar())
;
for (; isdigit(c); now = now * 10 + c - 48, c = getchar())
;
return now * f;
}
const int mod = 998244353;
inline int add(int a, int b) { ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 35;
const int MAXN = 202020;
const int MOD = 998244353;
uint64_t ans[MAXM + 1];
vector<uint64_t> RREF;
uint64_t msb(uint64_t x) {
int lg = 63 - __builtin_clzll((unsigned long long)x);
return ((uint64_t)1) << lg;
}
void put(uint64_t x) {
for (auto y : ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
int arr[100005];
int dis = 0, mit = 0;
int res = 0;
scanf("%d%d", &N, &K);
for (int i = 0; i < N; i++) {
scanf("%d", &arr[i]);
if (arr[i] == K) mit = i + 1;
}
if (mit == 0) {
arr[N++] = K;
res++;
}
sort(arr, arr + N... | 7 |
//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#defi... | 18 |
#include <bits/stdc++.h>
void build(int root, int l, int r);
int query(int root, int l, int r);
int n;
int a[100100];
struct node {
int l, r, v;
} tr[500100];
long long dp[100100];
int main(void) {
int i, cont, pos;
long long ans;
ans = 0;
scanf("%d", &n);
for (i = 1; i < n; i++) {
scanf("%d", &a[i]);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int Max_N(105);
const int Max_K(105);
int N, M, S, T, G[Max_N][Max_N], K, A[Max_K], B[Max_K], Cnt[Max_N];
bool Must[Max_K][Max_N];
int Dist[Max_N][Max_K];
bool InQ[Max_N][Max_K];
vector<pair<int, int> > Go[Max_N][Max_K];
bool update(int u, int x) {
int Ret(0);
if ... | 18 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
string s;
long long n, m, k;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(time(0));
cin >> n;
cout << n / 3 * 2 + (n % 3 != 0);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, q, head[N], pos[N], cnt = 1, child[N], part[N], num = 1, used[N],
p[N][20], range[N], sum[N], f[N], st[N], en[N],
place[N], c[N], arr[N], amount;
const long long inf = 1e15 + 5;
vec... | 22 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &res) {
res = 0;
T f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <c... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double d, l, v1, v2;
double num;
scanf("%lf %lf %lf %lf", &d, &l, &v1, &v2);
num = (l - d) / (v1 + v2);
printf("%lf\n", num);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
--x, --y;
g[y].emplace_back(x, z);
}
... | 17 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%i", &n);
int w, h;
int max_h = 1000000001;
int i = 0, f = 1;
while ((i < n) && f) {
scanf("%i %i", &w, &h);
if (w >= h) {
if (max_h >= w) {
max_h = w;
} else {
if (max_h >= h) {
max_h = h;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, LOG = 20;
int tree[LOG][4 * MAXN], lazy[LOG][4 * MAXN], A[MAXN];
void updatenode(int id, int now, int L, int R) {
tree[id][now] = (R - L + 1) - tree[id][now];
lazy[id][now] ^= 1;
}
void pushdown(int id, int now, int L, int R) {
if (lazy[id][no... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class F, class T>
T convert(F a, int p = -1) {
stringstream ss;
if (p >= 0) ss << fixed << setprecision(p);
ss << a;
T r;
ss >> r;
return r;
}
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
ret... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline bool xdy(double x, double y) { return x > y + 1e-9; }
inline bool xddy(double x, double y) { return x > y - 1e-9; }
inline bool xcy(double x, double y) { return x < y - 1e-9; }
inline bool xcdy(double x, double y) { return x < y + 1e-9; }
const long long int mod = 10... | 11 |
#include <bits/stdc++.h>
using namespace std;
class point {
public:
int id, val;
};
bool operator<(const point &a, const point &b) {
if (a.val < b.val) return true;
return false;
}
const long long maxn = (long long)1e18;
int i, t, v, len, col;
long long n;
long long f[101], dp[101][3][3];
int a[101];
long long r... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, k, a, b, c, d;
bool used[4 * N];
int main() {
scanf("%d%d%d%d%d%d", &n, &k, &a, &b, &c, &d);
if (n <= 4 || n >= k) {
puts("-1");
return 0;
}
used[a] = used[b] = used[c] = used[d] = 1;
int ptr = 1, out = 4;
printf("%d %d ", a, c... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int diri[8] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dirj[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
int f, c, k;
cin >> f >> c >> k;
vector<int> v;
bool infR = false, infG = false;
for (int i = 0; i < f; ++i) {
string s;
... | 18 |
#include <bits/stdc++.h>
int cmp(const void* a, const void* b) { return *(int*)b - *(int*)a; }
int sz[100010], st[100010], px[100010], n, dy[100010], la[100010], dp[100010];
int find(int x) {
int l = -1, r = n;
while (l < r) {
int m = (l + r + 1) >> 1;
if (st[m] < x)
l = m;
else
r = m - 1;
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(0);
vector<int> cnt(64, 0);
for (int i = 0; i < 64; ++i)
for (int j = 0; j < 64; ++j) ++cnt[i & j];
string str;
cin >> str;
int l = str.length();
long long ans = 1;
for (int... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897923846;
const long long int MOD = 1e9 + 7;
const long long int N = 998244353;
void solve() {
string str;
cin >> str;
long long int indez = 0, n = str.length(), sum = 0;
long long int ans = INT_MAX;
vector<long long int> pref(n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a[3 * n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
a[i + n] = a[i];
a[i + 2 * n] = a[i];
}
int s, f;
cin >> s >> f;
int dur = f - ... | 8 |
#include <bits/stdc++.h>
int main() {
int n, l, ans, cnt, x, y, z;
scanf("%d", &n), n /= 2;
cnt = 2, x = 1, y = 1, z = 2;
for (l = 2; l <= n; l++) {
cnt = (cnt + x * 4LL) % 1000000009;
z = z * 2 % 1000000009;
y = (y + z) % 1000000009;
x = (long long)x * y % 1000000009;
}
ans = ((long long)cn... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 10;
int h[sz];
vector<int> sv[sz], an;
bool comp(int a, int b) { return h[a] < h[b]; }
void dfs(int v) {
h[v] = 0;
for (int a = 0; a < sv[v].size(); a++) {
int ne = sv[v][a];
dfs(ne), h[v] = max(h[v], h[ne] + 1);
}
sort(sv[v].begin(), sv... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const long long INF = 1e9;
const long long MOD = 10000007;
long long strtoll(string s) {
stringstream str(s);
long long number = 0;
str >> number;
return number;
}
string lltostr(long long n) {
stringstream ss;
ss << n;
return ss.s... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int a, b, c;
cin >> a >> b >> c;
int ans = 0;
if (c >= 2 * b) {
ans += b * 3;
b = 0;
} else {
ans += c / 2 * 3;
b -= c / 2;
}
if (b >= 2 * a)
ans += a * 3;
else
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
const int mod = 1e9 + 7;
int n, a[N], p, c, child[N], ans;
long long dist[N];
vector<pair<int, int> > g[N];
void dfs1(int u, int p = -1) {
for (auto e : g[u]) {
if (e.first == p) continue;
dfs1(e.first, u);
child... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int sgn(long long x) {
if (x > 0) return 1;
if (x < 0) return -1;
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
long long v[n];
long long msk[n];
long long sum = 0;
for (int i = 0; i < n; i++) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
void solve();
long long int c, d, n, m, k;
const long long int N = 1e5;
vector<long long int> dp(N, -1);
long long int sol(long long int rem) {
if (rem <= 0) {
return 0;
}
if (dp[rem] != -1) {
return dp[rem];
}
long long int op1 = c + sol(rem - n);
long ... | 7 |
#include <bits/stdc++.h>
const int N = 1e3 + 10;
inline int read() {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int a[N], b[N], A[N], B[N], x[N], y[N];
std::bitset<N * N> f[N];
int ... | 21 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * f;
}
const int N = 1 << 18;
int a... | 16 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, m, x, y, i, j, ans = 0, c = 0, sum = 0;
string s, t;
cin >> s >> t;
if (s.length() != t.length()) {
cout << "NO\n";
return;
}
if (s.length() == 1) {
if (s != t)
cout << "NO\n";
else
cout << "YES\n";
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
int sx = 0, sy = 0;
int x, y;
bool has[2][2] = {{false, false}, {false, false}};
for (int i = 0; i < n; i++) {
cin >> x >> y;
has[x % 2][y % 2] = true;
sx += x;
sy += y;
}
if ((sx + sy) % 2 == 1) return -1;
if... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int m;
int n;
int ans = 0;
void getans(int l1, int r1, int l2, int r2, int p) {
int maxl = max(l1, l2);
int minr = min(r1, r2);
ans = max(ans, minr - maxl + 1);
if... | 16 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long x = n / 2;
if (x & 1) {
cout << "NO"
<< "\n";
continue;
}
long long sum = 0;
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double pi = acos(-1);
bool isVowel(char ch) {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
return 1;
}
return 0;
}
bool compar... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.