solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
int l = 1, r = (1e9) + 1, asmall = 1;
while (l < r) {
int mid = l + r >> 1;
long long sum = 0;
for (... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long mod7 = 1000000007LL;
inline long long getint() {
long long _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, t, a[100], tg = 0, day = 0;
cin >> n >> t;
for (long i = 0; i < n; i++) cin >> a[i];
for (long i = 0; i < n; i++) {
if (a[i] >= 86400 && tg < t)
day++;
else if (a[i] < 86400 && tg < t) {
day++;
tg += 86400 - a[i];
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, last;
int nxt[500500 * 2][2], link[500500 * 2], dp[500500 * 2], pos[500500 * 2];
char s[500500];
void extend(int c) {
int x = last, y = last = ++m;
dp[y] = dp[x] + 1;
pos[y] = pos[x] + 1;
while (x && !nxt[x][c]) nxt[x][c] = y, x = link[x];
if (!x)
li... | 18 |
#include <bits/stdc++.h>
const int maxBufSize = (10000000);
using namespace std;
long long int n, m;
vector<pair<long long int, long long int> > v[100005];
pair<long long int, long long int> p[100005], pred[100005];
queue<long long int> q;
long long int vis[100005];
pair<pair<long long int, long long int>, long long in... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool parz(int k) {
for (int j = 2; j <= sqrt(k); j++) {
if (k % j == 0) return false;
}
return true;
}
struct araj {
string x;
int y, z;
};
char a[101][101];
int b[1001];
int main() {
int c = 0, d, e = 0, q, i, j, k, l, m, n, v = 0, t = 0;
int s1 = 0, s2 =... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, p;
map<int, int> row[1001];
int prod[1001], C[1001][1001];
int pow(int a, int n) {
int ret = 1;
while (n)
if (n & 1)
n--, ret = (long long)ret * a % p;
else
n >>= 1, a = (long long)a * a % p;
return ret;
}
int calc(int n, int prod) {
... | 17 |
// PRAGMAS
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
// INCLUDES
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
// DEF... | 13 |
#include <bits/stdc++.h>
using namespace std;
int c[300010];
char s[300010];
struct EDGE {
int to, next;
} e[600010];
int head[300010], top, fa[300010];
struct node {
int ch[26], sum;
} Trie[2000000];
int ttop = 1, thead[300010];
int ans[300010];
void add(int u, int v) {
e[top].to = v;
e[top].next = head[u];
... | 16 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
void solve() {
int n;
string s;
cin >> n >> s;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
if (s[i] != '0') {
ans += s[i] - '0' + 1;
}
}
ans += s[n - 1] - '0';
cout << ans << '\n';
}
int mai... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void chmin(T &t, T f) {
if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
if (t < f) t = f;
}
int in() {
int x;
scanf("%d", &x);
... | 13 |
#include <bits/stdc++.h>
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
using namespace std;
string s;
vector<int> pos[26];
bool read() {
cin >> s;
return true;
}
void solve() {
int l = s.length();
for (int i ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, t, x;
cin >> n >> t;
int ans = 0;
bool ck = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
long long rem = 86400 - x;
t -= rem;
if (t <= 0 && ck == 0) {
ans = i;
ck = 1;
}
}
cout << ans << endl;
return 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897923846;
const long long int MOD = 998244353;
const long long int N = 998244353;
long long int power(long long int x, long long int n) {
long long int res = 1;
while (n > 0) {
if (n & 1) res = res * x % MOD;
x = x * x % MOD;
... | 9 |
#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;
const int INF = (1 << 29);
const int MAX = 23;
int n, m;
int dis[MAX][MAX][(1 << 8) + 3];
int val[MAX], A[MAX];
char g[MAX][MAX];
int tot;
vector<pair<int, int> > V;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
bool good(in... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc = 1;
cin >> tc;
while (tc--) {
int n = 0;
long long x, y, z;
cin >> x >> y >> z;
if (z == max(x, y)) {
cout << "YES\n";
cout << 1 << " " << x << " " << y << "\n";
} else if (y == max(x, z)) {
cout << "YES\n";
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 3005;
long long dp[N][N];
int main() {
ios_base::s... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-15;
int n;
int m[maxn];
int t[maxn];
void init() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &m[i]);
}
}
int main() {
init... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[4000];
int b[4000];
int q[4000];
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int mx = 0;
int aa = -1, bb = n + 1;... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
void factorize(ll n,... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1e5 + 100;
int a[maxn];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 30; i >= 0; i--) {
int ans = 0, sum = 0;
for (int j = 1; j <= n; j++)
if (a[j] & (1 << i)) ans = j, sum++;
if (sum != 1) con... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
void chmax(int &x, int y) {
if (x < y) x = y;
}
void chmin(int &x, int y) {
if (x > y) x = y;
}
int ran() {
static int x = 1364684679;
x += (x << 2) + 1;
return x;
}
st... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
bool mk[n + 1];
for (int i = 1; i < n; i++) {
mk[i] = 0;
cin >> a[i];
}
mk[n] = 0;
int root = a[1];
cout << root << endl;
int cur = n;
for (int i = 1; i < n; i++) {
mk[a[i]] = 1;
while (mk[cur]) c... | 14 |
#include <bits/stdc++.h>
using namespace std;
int pwr(int base, long long exp) {
if (exp == 0) return 1;
if (exp == 1) return base;
int res = (1LL * base * base) % 1000000007;
return (1LL * pwr(res, exp >> 1LL) * pwr(base, exp & 1LL)) % 1000000007;
}
int main() {
int a, b, x, an;
long long n;
cin >> a >> ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const long long MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
long long power_md(long long a, long long n) {
long long res = 1;
while (n) {
if (n % 2) res = (res % md * a % md) % md;
a = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << "YES\n";
while (n--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1 = abs(x1);
y1 = abs(y1);
cout << (1 + x1 % 2 + y1 % 2 * 2) << '\n';
}
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int a[20], mp[5][5], ss;
int check() {
int ans = 0, t;
for (int(i) = 0; (i) < (int)(n); (i)++)
for (int(j) = 0; (j) < (int)(n); (j)++) mp[i][j] = a[i * n + j];
for (int(i) = 0; (i) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int N = 200005;
int n;
int main() {
scanf("%d", &n);
long long ans = 0;
for (int a = 1; a <= n; ++a)
for (int b = a; b <= n; ++b) {
int c = a ^ b;
if (c <= n && c >= b && a + b > c) ++ans;
... | 5 |
#include <bits/stdc++.h>
int n;
bool v[100001];
void dfs(int x) {
v[x] = true;
if (x == 1) {
printf("0 1");
} else {
dfs(v[(x + n) / 2] ? x / 2 : (x + n) / 2);
printf(" %d", x);
}
}
int main() {
scanf("%d", &n);
if (n & 1)
puts("-1");
else
dfs(0);
return 0;
}
| 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z, i, j, k, a[11], b[11], l = 0;
cin >> x >> y;
for (i = 0; i < x; i++) {
cin >> a[i];
}
for (j = 0; j < y; j++) {
cin >> b[j];
}
for (k = 0; k < x; k++) {
l = 0;
for (z = 0; z < y; z++) {
if (a[k] == b[z]) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, i, j, pos, k, n, m, min, sum = 0, max = 0, sum1, c1 = 0,
flag = 0, count = 0;
long long a[200005], b[200005];
scanf("%I64d", &n);
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
sum += a[i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
string s;
cin >> s;
if (k > 0) {
if (s.length() != 1) {
if (s[0] != '1') {
s[0] = '1';
k -= 1;
}
} else {
s[0] = '0';
k -= 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
map<long long, int> x1;
map<long long, int> x2;
long long s = 0LL;
long long z = 0LL;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
x2[a[i]]++;
s += a[i];
}
for (int i = 0; i < n; i++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int o = 1;
long long l;
int a[1000010];
int *p[1000010];
int F[1000010];
int S[1000010];
bool cmp(int *i, int *j) { return *i < *j; }
int main() {
scanf("%d%I64d%d", &n, &l, &k);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]), p[i] = &a[i];
sort(p, p + n... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 150000 + 5;
int n, q, k;
int kase, num;
long long t[mxn];
int isonline[mxn];
int cnt = 0;
long long minum = 0x3f3f3f3f;
vector<pair<int, long long> > vec;
long long record[6];
bool cmp(pair<int, long long> a, pair<int, long long> b) {
return a.second > b.s... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const long long OO = 0x3f3f3f3f3f3f3f3fLL;
const int oo = 0x3f3f3f3f;
const int maxn =... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,O2")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... ar... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void pr(int x) { cerr << x; }
void pr(long x) { cerr << x; }
void pr(long long x) { cerr << x; }
void pr(unsigned long long x) { cerr << x; }
void pr(float x) { cerr << x; }
void pr(double x) { cerr << x; }
void pr(long double x) { cerr << x; }
void pr... | 4 |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int n, e;
vector<int> p;
long long arr[1234];
int main() {
while (cin >> n) {
p.clear();
for (int i = 0; i < n; i++) {
cin >> e;
e--;
p.push_back(e);
}
arr[0] = 2;
for (int i = 1; i <= n; i++) {
ar... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N[5], T[5];
unsigned int NS, NM, NL, NXL, NXXL;
unsigned int K, i;
string S[5];
scanf("%u%u%u%u%u%u", &NS, &NM, &NL, &NXL, &NXXL, &K);
N[0] = NS;
N[1] = NM;
N[2] = NL;
N[3] = NXL;
N[4] = NXXL;
T[0] = 0;
T[1] = 1;
T[2] = 2;
T[3] =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100004;
long long mod = 1000000007;
long long qpow(long long n, long long m) {
long long ans = 1;
for (; m; m >>= 1) {
if (m & 1) ans = ans * n % mod;
n = n * n % mod;
}
return ans;
}
int main() {
int k, p;
scanf("%d %d", &p, &k);
long lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
long double n, m, t, k, k1, k0;
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
k1 = 1e6 + 12;
for (int i = 0; i < n; i++) {
cin >> t >> k;
k0 = t / k;
k1 = min(k1, k0);
}
cout << fixed << setprecision(8) << m * k1;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool no(string& a, string& b) {
vector<int> mask_a(200, 0);
vector<int> mask_b(200, 0);
for (int i = a.length(); i >= 0; --i) ++mask_a[a[i]];
for (int j = b.length(); j >= 0; --j) ++mask_b[b[j]];
for (int i = 0; i < 200; ++i)
if ((mask_b[i] > 0) && (mask_a[i] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
string i_s(int x) {
if (x == 0) return "0";
string ret = "";
while (x) {
ret = ret + (char)(x % 10 + '0');
x /= 10;
}
reverse(ret.begin(), ret.end());
return ret;
}
string add(string a, string b) {
if (a == "") a = "0";
if (b == "") b = "0";
if (a.... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, n;
cin >> n >> x;
long long min_cost = 0;
int s, e;
s = e = x;
int ls, le;
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &ls, &le);
if (ls > e) {
min_cost += ls - e;
s = e;
e = ls;
} else if (le < s) {
min... | 13 |
#include <bits/stdc++.h>
using namespace std;
void input() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long mx = 0,... | 4 |
#include <bits/stdc++.h>
int take() {
int n;
scanf("%d", &n);
return n;
}
double ttake() {
double n;
scanf("%lf", &n);
return n;
}
long long takes() {
long long n;
scanf("%lld", &n);
return n;
}
int cas;
using namespace std;
bool approximatelyEqual(float a, float b, float epsilon) {
return fabs(a - ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, m, y;
scanf("%d %d %d %d", &n, &x, &m, &y);
if (x > y) swap(n, m), swap(x, y);
long long ans = n + m + 1;
for (int i = 1; i <= m; i++) {
int l = y - x - i;
int r = y - x + i;
if (l >= 0) {
l = min(l, n);
r = min(r, n ... | 15 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) solve();
}
const int N = 1e5 + 5;
std::vector<int> last(N);
void solve() {
int m, k;
cin >> m >> k;
std::vector<int> a(k);
for (int i = 0; ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int N, Y;
map<int, string> IAOs;
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
IAOs.clear();
char str[128];
scanf("%s", str);
char num[12] = {'\0'};
strcpy(num, str + 4);
const int _l = strlen(num);
for (int j = 0; j < _l; ++j) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int bits[8];
const int N = 1 << 24;
int dp[N];
int main() {
for (int i = 1; i < 8; i++) {
for (int j = 0; j < 3; j++) {
if (i & (1 << j)) {
bits[i] = bits[i ^ (1 << j)] + 1;
break;
}
}
}
int n;
cin >> n;
for (int i = 1; i <= n; ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
vector<long long int> v1, v2;
for (long long int i = 0; i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[100];
cin >> arr;
int size = strlen(arr);
int count1 = 0, count2 = 0, count3 = 0, l = 0;
for (int i = 0; i < size; i++) {
if (arr[i] == '1') count1++;
if (arr[i] == '2') count2++;
if (arr[i] == '3') count3++;
}
for (int d = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, l, r, ans;
long long ppow(long long a, long long x) {
long long tans = 1;
while (x) {
if (x & 1) tans = tans * a % 998244353;
a = a * a % 998244353;
x >>= 1;
}
return tans;
}
int main() {
scanf("%lld%lld%lld%lld", &n, &m, &l, &r);
if ... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > ranges;
pair<int, int> rr[200001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
rr[i] = {a, b};
ranges.push_back({a, {1, i}});
ranges.push_back({b + 1, {-1, i}});
}
so... | 12 |
#include <bits/stdc++.h>
using namespace std;
char str[100][100];
int cnt[100];
int mark[100];
int n, m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> str[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (!mark[j] && strcmp(str[i], str[j]) == 0) {
... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long N = 2e3 + 100;
const long long MOD = 1e9 + 7;
const long long inf = 2e9;
const long double eps = 1e-12;
const long double EPS = 1e-10;
long long rx[] = {1, -1, 0, 0};
long long ry[] = {0, 0, 1, -1};
int32_t main() {
ios_base::... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000LL * 1000000LL;
const long long MOD = 1000000007;
int f(long long a) {
int left = 0;
int right = 1000001;
while (left < right) {
int mid = (left + right + 1) / 2;
if (a >= (1LL * mid * (mid - 1)) / 2)
left = mid;
else
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n;
double a, d;
double calcT(double st, double sp) {
double spup = min(sp / a, sqrt(2 * d / a));
double offset = spup / 2 * spup * a;
double unif = (d - offset) / sp;
return st + unif + spup;
}
int main() {
std::ios_base::sync_with_stdio(false);
cin >>... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
string s;
bool judge() {
int n = s.length();
int l = 0, r = n - 1;
while (s[l] == s[r]) {
l++, r--;
}
if (l >= r) return true;
return false;
}
void solve() {
cin >> s;
int n = s.length();
cout << 3 << endl;
cout << "R " << 2 <<... | 6 |
#include <bits/stdc++.h>
int n, m, f[153][53][53][53], v[151][3], z, MOD = 51123987, u;
char s[160];
bool check(int a, int b, int c) {
if (abs(a - b) > 1) return false;
if (abs(a - c) > 1) return false;
if (abs(b - c) > 1) return false;
return true;
}
int main() {
scanf("%d%s", &n, s + 1);
for (int i = n; i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> col[300010];
vector<int> edge[300010];
int id[300010];
int ans;
bool bad[300010];
int parent[300010];
void dfs_par(int i, int prev) {
parent[i] = prev;
for (int j = 0; j < edge[i].size(); j++) {
if (edge[i][j] == prev) {
continue;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long x, long long y) {
if (x >= y)
return y;
else
return x;
}
int main() {
long long minn = 12222222;
long long h, n;
cin >> h >> n;
long long a[n];
long long sum = 0;
long long tim = 0;
for (int i = 0; i < n; i++) cin >> a[i], s... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b) {
long long res = 1;
a %= 1000000007;
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
int gcd(int x, int y) {
while (y) {
int t = x % y;
x = y;
y =... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct Shoe {
long long cost;
int size;
int nr;
bool operator<(const Shoe& shoe) const { return size < shoe.size; }
};
struct Cust {
long long money;
int len;
int nr;
bool operator<(const Cust& cust) const {
if (len == cust.len) {
return money < cu... | 17 |
#include <bits/stdc++.h>
using namespace std;
#define fo(i, z, n) for (int i = z; i < n; i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define gcd(x, y) __gcd(x, y)
typedef vector<int> vi;
typedef vector<ll> vl;
int c... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, z, d[100010], p[100010];
vector<long long int> G[100010], grp[1010];
void dfs(int x, int y, int z) {
p[x] = y;
d[x] = z;
grp[d[x] % (k - 1)].push_back(x);
for (int w : G[x])
if (w != y) {
if (d[w]) {
if (d[x] - d[w] >= k - 1)... | 17 |
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> itsc;
int vote[300100];
int vote_sort[300100];
int n, p;
int bs(int l, int t) {
if (vote_sort[n - 1] < t) return -1;
int r;
r = n - 1;
while (l < r) {
int m = (l + r) / 2;
if (vote_sort[m] < t) {
l = m + 1;
} else
r =... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x;
for (y = x + 1; y <= 9999; y++) {
int a = y % 1000 % 100 % 10;
int b = y % 1000 % 100 / 10;
int c = y % 1000 / 100;
int d = y / 1000;
int ans;
if (y > x && (a != b && a != c && a != d && b != c && b != d && c !=... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
int N, M, vl[500100][2];
bitset<2 * MAXN> a[MAXN];
int main() {
cin >> N >> M;
int i, j;
for (i = 1; i <= M; i++) {
cin >> vl[i][0] >> vl[i][1];
a[vl[i][0]][vl[i][1]] = 1;
}
for (i = 1; i <= N; i++) a[i][N + i] = 1;
for (j = 1; j <... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c;
cin >> n >> m >> c;
int nums[1500];
for (int i = 0; i < n; i++) cin >> nums[i];
int add[1500];
for (int i = 0; i < m; i++) {
int a;
cin >> a;
for (int j = i; j < n - m + i + 1; j++) {
nums[j] += a;
nums[j] %= c;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, r;
int cnta;
int cntb;
int flag = 0;
scanf("%d%d%d", &n, &l, &r);
for (int i = 0; i * l <= n; i++) {
int tmp = n - i * l;
if (tmp % r == 0) {
cnta = i;
cntb = tmp / r;
flag = 1;
break;
}
}
int pos = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const long long M = 998244353;
long long fac[N];
long long n, k;
long long qpow(long long a, long long k, long long p) {
long long re = 1;
while (k) {
if (k & 1) re = (re * a) % p;
k >>= 1;
a = (a * a) % p;
}
return re;
}
long long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 100;
const long long inf = 0x3f3f3f3f;
const long long iinf = 1 << 30;
const long long linf = 2e18;
const long long mod = 998244353;
const double eps = 1e-7;
template <class T = long long>
T chmin(T &a, T b) {
return a = min(a, b);
}
template ... | 23 |
#include <bits/stdc++.h>
using namespace std;
bool check(int k, const vector<int> &p) {
bool ok = true;
vector<bool> vis(k);
vis[0] = true;
int c = 1;
for (int i = 0; i < k && c < k; ++i) {
for (int j = 0; j < k; ++j) {
if (vis[p[j]] && !vis[j]) {
vis[j] = true;
++c;
}
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, X, Y;
int main() {
cin >> n >> m >> x >> y >> X >> Y;
n = abs(x - X);
m = abs(y - Y);
if (n >= 5 && m >= 5)
printf("Second\n");
else {
if (min(n, m) <= 2 && max(n, m) <= 4)
printf("First\n");
else if (n == 3 && m == 3)
print... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int c = 0;
for (int i = n; i >= 1; i--) {
if (i > n - i + 1 && c % 2 == 0) {
swap(a[i], a[n - i + 1]);
}
c++;
}
for (int i = 1; i <= n; i++) {
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &m, const T &v) {
if (v > m) return m = v, true;
return false;
}
template <typename T>
bool chmin(T &m, const T &v) {
if (v < m) return m = v, true;
return false;
}
template <typename T>
bool chinc(T &v1, T &v2) {
if (v1 > v2) re... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int no, c[2], d, n;
cin >> n;
cin >> d;
cin >> no;
int a[no][2];
for (int i = 0; i < no; i++) {
cin >> c[0];
cin >> c[1];
a[i][0] = c[0];
a[i][1] = c[1];
}
for (int i = 0; i < no; i++) {
if ((a[i][1] - a[i][0] <= d) && (a[i][... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int L[2001111], R[200111];
int last[200111];
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
cin >> n;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
L[i] = a;
R[i] = a + b;
}
int now =... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const bool db = false;
int r, g, levels;
int dp[2][200010];
int as, ds, qqq;
int main() {
cin >> r >> g;
while (levels * (levels + 1) / 2 <= r + g) ++levels;
--levels;
dp[0][0] = 1;
for (int i = 1; i <= levels; ++i) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string... | 15 |
#include <bits/stdc++.h>
using namespace std;
int c;
int arr[100000];
int main() {
int n;
int k;
cin >> n >> k;
if (k > n) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
if (arr[j] < arr[j - 1]) {
c = a... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<V<T>>;
template <typename T>
using Mi = map<long long, T>;
template <typename T>
using MMi = map<long long, Mi<T>>;
const double PI = 3.141592653589793238463;
pair<long long, long long> zero ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void task();
int main() {
task();
return 0;
}
const int N = (int)1e5 + 10;
const long long int MODULO = (long long int)1e9 + 7;
const int INF = (int)1e9 + 10;
const int BUF_SIZE = (int)1e4 + 10;
int a[N];
void task() {
ios_base::sync_with_stdio(0);
int n;
cin >> n... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class A>
void read(vector<A>& v);
template <class A, size_t S>
void read(array<A, S>& a);
template <class T>
void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d = stod(t);
}
void read(long double& d) {
string t;
read(t);
d = sto... | 8 |
#include <bits/stdc++.h>
int operations[100005]{0};
int lit_time[100006]{0};
int main() {
int operation_count, time_length;
scanf("%d%d", &operation_count, &time_length);
bool lit = true;
for (int i = 1; i <= operation_count; ++i) {
scanf("%d", &operations[i]);
lit_time[i] += lit_time[i - 1] + lit * (op... | 7 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> st[1509][1509];
char s[1509][1509];
int n, m;
int sa = 24000000;
bool mo(pair<int, int> t, int p, int pp) {
if (t.first == p && t.second == pp) {
return 1;
}
return 0;
}
int baghi(int a, int b) {
if (a < 0) {
return b - ((-a) % b);
}
retur... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
int main() {
long long t;
cin >> t;
while (t--) {
long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, r, c;
string a;
int t;
void output(int a) {
if (a <= 0) return;
if (a % 26 == 0) {
output(a / 26 - 1);
cout << 'Z';
} else {
output(a / 26);
cout << char(a % 26 + 'A' - 1);
}
}
int main() {
cin >> n;
while (n--) {
cin >> a;
int len... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, d;
int dp[700000];
int main() {
scanf("%d%d", &n, &d);
int sum = 0;
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
sum += x;
for (int j = sum; j >= x; j--) {
if (dp[j - x]) {
dp[j] ... | 14 |
//Lets Begin With Name Of Lord Mahadev..
#include<bits/stdc++.h>
#define mod 1000000007
#define pi 3.1415926535
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define p(v) cout<<v<<endl
#def... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
if (n % 2) {
cout << "black" << endl;
} else {
cout << "white" << endl;
cout << "1 2" << endl;
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 101111, max_m = 12, bsize = 1000, inf = 1111111111;
struct block {
pair<int, int> a[bsize][max_m];
};
int n, m, q, l[bsize], r[bsize], dx[222], dy[222], num[max_n];
char s[max_n][max_m];
block b[bsize];
pair<int, int> p(2, 2);
bool is_in(int num, int x, ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
cin >> t;
while (t--) {
cin >> n;
cout << n * (n + 1) / 2 - 2 * ((1 << ((int)log2(n) + 1)) - 1) << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 111111, inf = 111111111;
int n, a[max_n], b[max_n];
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
int sum = a[0] - b[0], d = sum;
for (int i = 1; i < n; ++i) {
sum... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, pair<int, int> > > v;
long long int a[1005][1005], n, m, r, c, xs[1000005], xsq[1000005], y[1000005],
ysq[1000005], ys[1000005], dp[1000005];
long long int mod = 998244353;
long long int p(long long int a, long long int b) {
long long int r ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9;
const long long MB = 20;
const long long MOD = 1e9 + 7;
const long long maxN = 19;
struct node {
node* left;
node* right;
long long cnt, sum, h;
node(long long x) {
left = nullptr;
right = nullptr;
cnt = 0;
sum = 0;
h =... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double v;
int dmg, id, mark;
} scr[1005];
bool cmp(node aa, node bb) {
if (aa.v == bb.v)
return aa.dmg > bb.dmg;
else
return aa.v > bb.v;
}
int a[1005], b[1005];
int main() {
int n, max, reg;
int i, j;
int x, y, t, sum;
while (scanf("%d... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long m, n, k;
int main() {
cin >> m >> n >> k;
if (k > n + m - 2) {
puts("-1");
return 0;
}
long long ar = -1;
if (k <= m - 1)
ar = max(ar, (m / (k + 1)) * n);
else
ar = max(ar, (n / (k - m + 2)));
if (k <= n - 1)
ar = max(ar, (n / (k ... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.