solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long int i, j, k, l, r, n, m, it;
cin >> n >> k >> l;
if (k > l) swap(k, l);
if (k == 1) {
for (i = 1; i <= n; i++) cout << i << " ";
return 0;
}
if (n % k == 0) {
j = n / k;
vect... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int SQ = 102;
int n, q;
string s[MAX];
int lcp[MAX];
set<int> active;
const int LIM = 3e5 + 5;
struct node {
int lsuf[SQ], rsuf[SQ], maxi, len;
node() {
maxi = len = 0;
for (int i = 0; i < SQ; i++) {
lsuf[i] = rsuf[i] = 0;
... | 21 |
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<utility>
#include<stdlib.h>
#include<limits.h>
#include<cmath>
#include<set>
#include<initializer_list>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<iomanip>
#include<algorithm>
#include<queue>
#incl... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, M, tiempo = 0, parents[300010], subtreeSizes[300010],
dfsOrder[300010][2];
vector<pair<int, long long>> adjacency[300010];
long long depths[300010], curDist, diff = 5000000000000000000,
other = -5000000000000000000;
void d... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
int n, m, l, a;
int idx[400005][2];
vector<int> model;
vector<... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long infinity = 1000000000000000000;
const int inf = 1e9 + 5;
bool do_debug = false;
const int maxn = 2005;
int len, target;
int v[maxn];
long long dp[maxn][maxn];
long long f(int index, int open) {
if (open < 0) {
return 0... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n;
cin >> t;
set<long long int> unicrating;
set<long long int>::iterator uniciterator;
for (long long int i = 0; i < t; i++) {
cin >> n;
long long int sqrtofn = sqrt(n);
for (long long int j = 1; j <= sqrtofn; j++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
while (cin >> n >> k) {
long long s = 0;
k = min(k, n / 2);
s += (k - 1) * k / 2;
for (long long i = 0; i < k; i++) s += n - i - 1;
s += (n - 2 * k) * k;
cout << min(s, n * (n - 1) / 2) << endl;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
double add[3 * 100 * 1000];
const double inf = 1e18;
double max(double a, double b, double c, double d) {
return max(max(a, b), max(c, d));
}
struct rmq {
int l, r;
double pref, suf, all, best;
rmq *left, *right;
};
rmq *build(int l, int r) {
rmq *root = (rmq *)ma... | 14 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define CC(t) int t; cin>>t; while(t--)
#define FOR(i,a,b) for (int i = a; i < b; i++)
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j;
cin >> n >> k;
int arr[26];
for (i = 0; i < 26; i++) {
arr[i] = 0;
}
string str;
cin >> str;
int len = str.size();
for (i = 0; i < len; i++) {
arr[str[i] - 65]++;
}
sort(arr, arr + 26);
long long int ans = 0;
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(unsigned long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (unsigned long long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, y, max = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
if (x + y > max) max = x + y;
}
cout << max;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && c != '-')
;
if (c == '-') {
c = getchar();
nega = 1;
}
x = c - 48;
while (isdigit(c = getchar())) x = x * 10 + c - 48;
if (nega) x = -x;
}
i... | 18 |
#include <bits/stdc++.h>
using namespace std;
int w = 1, b = 2;
int power(int a) {
if (a == 0)
return w;
else if (a % 2 != 0) {
w = w * b;
a--;
} else {
b = b * b;
a = a / 2;
}
}
int main() {
int n;
cin >> n;
int sum = 0, total = 0, p = 0;
int a[n];
for (int i = 0; i < n; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
double sum;
int main() {
int x;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> x;
sum += x;
}
while (round(sum / n) < k) {
sum += k;
n++;
ans++;
}
cout << ans;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int a[300001];
long long int b[300001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> ... | 8 |
#include <bits/stdc++.h>
const int N = 2000 + 10;
int n;
std::vector<int> adj[N];
int dfn[N], low[N], stack[N], top, timestamp;
bool instack[N];
int block_count, belong[N];
void dfs(int x) {
timestamp++;
dfn[x] = low[x] = timestamp;
stack[++top] = x;
instack[x] = true;
for (int i = 0; i < ((int)(adj[x]).size(... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[1000005], cnt;
string s[1000005];
int val[1000005];
struct Tree {
long long cnt, mod[5];
} tree[4 * 1000005];
void push_up(int x) {
for (int i = 0; i < 5; i++)
tree[x].mod[i] = tree[x << 1].mod[i] +
tree[x << 1 | 1].mod[((i - tree[x ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 200010;
int n, m;
int a[max_n];
int lb[max_n], ub[max_n], p[max_n];
vector<pair<int, int> > races[max_n];
long long ST[4 * max_n], A[4 * max_n];
long long queryST(int r, int b, int e, int i, int j) {
long long p1 = 0, p2 = 0;
if (i > e || j < b) return... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int N = 1e5 + 5;
inline long long read() {
long long x = 0, rev = 0, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') rev = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch ... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, idx;
bool operator<(const node &B) const { return x < B.x; }
} h[1020];
int a[1020][1020], mi[1020][1020], mx[1020][1020], mmx[1020][1020],
mmi[1020][1020];
int main() {
int n, m, c;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a;
cin >> a;
if (a >= 2)
cout << a - 2 << "\n";
else
cout << "0\n";
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T S(T a) {
return a * a;
}
template <class T>
inline string tostring(T a) {
ostringstream os("");
os << a;
return os.str();
}
template <typename T>
inline long long tolong(T a) {
long long res;
istringstream os(a);
os >> res;
ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 512345, LG = 21, mod = 1000000007;
const double eps = 1e-3, pi = acos(-1.0);
int a[N], b[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = n; i > 0; --i) {
b[i] = a[i] + a[i + 1];
}
for (int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> drag[1001];
int main() {
int s = 0, n;
scanf("%d%d", &s, &n);
for (int i = 0; i < n; i++) scanf("%d%d", &drag[i].first, &drag[i].second);
sort(drag, drag + n);
for (int i = 0; i < n; i++)
if (s > drag[i].first)
s += drag[i].second;
els... | 2 |
#include <bits/stdc++.h>
using namespace std;
int w, h, n, sx, sy, fx, fy, wk[300][300] = {0}, tps, sum[10010] = {0};
void dfs(int x, int y) {
if (x < 0 || y < 0 || x > h + h || y > w + w) return;
if (wk[x][y] == 1 || wk[x][y] == 3) return;
if (wk[x][y] == 0) tps++;
wk[x][y] = 3;
dfs(x + 1, y);
dfs(x, y + 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
char buf[32];
int ps[32];
int ctable[16][16];
int fac7[16];
const int MOD = 1000000007;
long long int pp(long long int a, int b) {
int ret = 1;
while (b) {
if (b & 1) ret = ret * a % MOD;
b >>= 1;
a = a * a % MOD;
}
return ret;
}
int table[16][16][16];
l... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100020;
int n;
int f[Maxn];
long long h1[Maxn], h2[Maxn];
int sz[Maxn], fa[Maxn];
vector<pair<long long, int> > G[Maxn];
void dfs(int u, int p) {
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i].first;
if (v == p) continue;
dfs(v, u);
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
struct circle {
long long x, y, r;
double area;
circle(){};
void read() {
scanf("%lld %lld %lld", &x, &y, &r);
area = acos(-1.0) * r * r;
}
bool contains(circle c) {
double d = sqrt((double)((x - c.x) * (x - c.x) + (y - c.y) * (y ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int s1[10][10];
int temp[20];
map<int, int> ma;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
ma.clear();
for (int a = 1; a <= n; a++)
for (int b = 1; b <= 6; b++) scanf("%d", &s1[a][b]);
int sum = 0;
if (n >= 1) {
for (int i = 1; i <=... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k, sk[1000005], cnt, w[1000005], us[1000005];
bool cmp(int a, int b) { return w[a] < w[b]; }
int main() {
for (int i = 2; i < 1000005; ++i) {
if (!us[i]) sk[++cnt] = i, w[i] = i - 1;
for (int j = 1; j <= cnt; ++j) {
if (1ll * sk[j] * i >= 1000005) bre... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long)1e15;
bool cmp(pair<int, int> &a, pair<int, int> &b) { return a.second > b.second; }
void solve() {
int n;
cin >> n;
long long a[n], b[n];
long long ma = INF, mb = INF;
for (long long i = 0; i < n; i++) {
cin >> a[i];
m... | 0 |
#include <bits/stdc++.h>
using namespace std;
int constexpr mod = 1e9 + 7, max_n = 5e3 + 10;
int dp[max_n][max_n], ps[max_n][max_n];
int32_t main() {
int n, a, b, k;
cin >> n >> a >> b >> k;
if (a > b) {
a = n - a + 1;
b = n - b + 1;
}
dp[a][0] = 1;
for (int i = 1; i < b; i++) {
ps[i][0] = ps[i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], sum[2][100010];
int anscnt = 0;
struct ANS {
int k, s;
bool operator<(const ANS &b) const {
if (s != b.s)
return s < b.s;
else
return k < b.k;
}
} ans[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
s... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long n, m, x, dis[N], sum = 0, arr[27], brr[2 * N];
vector<int> v[N], vv;
queue<int> q;
bool vis[N];
int main() {
long long t;
string s;
cin >> t;
while (t--) {
cin >> n >> m;
cin >> s;
for (int i = 0; i < n; i++) {
arr... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N, K, a, b;
vector<pair<int, int>> v;
bitset<200100> removed;
vector<int> res;
int ed[200100];
int seg = 0;
priority_queue<pair<int, int>> pq;
pair<int, int> x;
int main() {
scanf("%d %d", &N, &K);
for (int i = 1; i <= N; i++) {
scanf("%d %d", &a, &b);
ed[i]... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long arr[10];
cin >> arr[0] >> arr[1] >> arr[2];
sort(arr, arr + 3);
if (arr[2] < arr[1] + arr[0]) {
cout << 0;
} else {
cout << arr[2] - (arr[1] + arr[0]) + 1;
}
return 0;
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const int MaxN = int(2e5) + 256;
const long long INF = (long long)(1e18);
const int inf = (int)(1e9);
const int mod = (int)(1e9) + 7;
const... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long Log2(long long n) {
if (n == 1) return 0;
return Log2(n / 2) + 1;
}
int main() {
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
};
long long t, n, m;
string str;
cin >> t;
while (t--) {
cin >> n;
if (n % 2 != 0) n--;
co... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
if (a < b) a = b;
}
long long N, A, B, K;
signed main() {
cin >> N >> A >> B >> K;
string S;
cin >> S;
vector<lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
bool f = 0;
x = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = ge... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 100;
const int M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
long long modPow(long l... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
long long gcd(long long x, long long y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
long long ksm(long long a, long long b) {
long long r = 1;
while (b) {
if (b & 1) r = (r * a) % mod;
a =... | 9 |
#include <bits/stdc++.h>
int N = 25;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
long long a, b, c;
cin >> a >> b >> c;
int a1 = -1, a2 = -1;
if (a < c) a1 = 1;
long long k = a * b;
if (c < k) a2 =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
string s;
cin >> n >> x;
char ch;
cin >> s;
map<char, long long> m;
for (long long i = 0; i < x; i++) {
cin >> ch;
m[ch] = 1;
}
long long cnt = 0, sum = 0;
for (long long i = 0; i < s.length(); i++) {
if (m[s[i]] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 6;
const int md = 1e9 + 7;
string a[maxn];
int dp[maxn][maxn];
int pref[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < maxn; i++) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool all_str(string s, char x) {
for (char a : s) {
if (a != x) {
return false;
}
}
return true;
}
int len_pref(string s, char x) {
int c = 0;
for (char a : s) {
if (a == x) {
c++;
} else {
break;
}
}
return c;
}
int len_s... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
long long n, p;
cin >> p >> n;
long long x;
map<long long, long long> m;
for (__typeof(n) i = 0; i < n; i++) {
cin >> x;
if (m[((x) % p)] >= 1) {
cout << i + 1 << "\n";
return 0;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n;
cin >> m;
if (n % m == 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long x, y, k, ans = 0;
cin >> x >> y >> k;
long long sticks = k + (y * k);
long long xcount = 1;
if (sticks >= x) {
xcount = 1 + ((sticks - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
*ooh++ = c;
}
template <class T>
inline void print(T x) {
static int buf[30], cnt;
if (x == 0)
pri... | 20 |
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define mp make_pair
#define MOD 998244353
#define f first
#define s second
#define rand(i, j) uniform_int_distribution<ll>((ll)(i), (ll)(j))(rng)
mt19937 rng(std::chrono::steady_clock::now().time_since_... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x = 0, y = 0, n;
for (int i = 0; i < 3; ++i) {
int c;
cin >> c;
x += c;
}
for (int i = 0; i < 3; ++i) {
int c;
cin >> c;
y += c;
}
cin >> n;
int total = x / 5 + (x % 5 != 0) + y / 10 + (y % 10 != 0);
cout << (total <=... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
int print_value(A title, B val) {
cout << title << " = " << val << "\n";
return 1;
}
int break_point() {
char c;
while ((c = getchar()) != '\n')
;
return 0;
}
template <typename A>
int logg(A v) {
cout << v << "\n";
return... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, p, w, d;
cin >> n >> p >> w >> d;
long long i;
bool found = false;
for (i = 0; i < w; i++) {
if ((p - i * d) % w == 0) {
found = true;
break;
}
}
if (found) {
long long x = (p - i * d) / w;
if (x >= 0 && x ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char a[101][101];
memset(a, 'S', sizeof(a));
cin >> n >> k;
if (((n * n) / 2 + (n * n) % 2) < k) {
cout << "NO";
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (k != 0 && i % 2 == 1 && j % 2 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tostr(const T& t) {
ostringstream os;
os << t;
return os.str();
}
int N, M;
vector<string> W;
vector<string> probs[15];
vector<pair<vector<string>, int> > perms;
bool canMake;
int findLoc(vector<string>& v, string& s) {
for (int i = (int... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;
const int MAXN = 1e5 + 1, MODM = 1e9 + 7, P = 1e6 + 3, MULT1 = 30, MULT2 = 239,
LUCKY = 13, ELEVEN = 11, MAXM = 101;
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
set<pair<int, int> > ma... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<char, set<long long>> mas;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
mas[s[i]].insert(i);
}
long long n;
cin >> n;
vector<int> otw;
for (long long i = 0; i < n; i++) {
int a;
cin >> a;
if (a == 1) {
lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int ct_primes = 168;
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
103, 107, 109, 113, 127, 131, 137, 139, 14... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool check(string s) {
int balance = 0;
for (int i = 0; i < (int)(s).size(); i++) {
if (s[i] == '(') {
balance++;
} else {
balance--;
}
if (balance < 0) {
return false;
}
}
return (balance == 0);
}
vector<int> have[3];
inline in... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXX = 1e5 + 10;
long long n, a[MAXX], o, last;
set<int> st;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], st.insert(a[i]);
for (int i = 0; i < n; i++) {
o = a[i], last = 0;
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, p, t[N];
long long m, ans, sum, c[N], aa[N], bb[N];
struct rec {
int id;
long long p;
} a[N], b[N];
bool operator<(const rec a, const rec b) {
return (a.p < b.p || a.p == b.p && a.id < b.id);
}
void change(int l, int r, long long d) {
i... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int speed = 0;
int hmovertake = 0;
int answer = 0;
stack<int> s;
s.push(oo);
for (int i = 0; i < n; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
double pow_x(double x, unsigned i) {
double prod = 1;
if (i == 0) return 1;
while (i) {
prod *= x;
i--;
}
return prod;
}
long long factorial(unsigned n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
double expo(double x, int terms) {
double ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
int ans = 0;
if (n == 1) {
if (m > 2) {
cout << "1\n";
cout << n << " " << m << " 1 1\n";
} else {
cout << 0 << "\n";
}... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long m[4][100000];
int main() {
int t[3], k[3], i, j, n;
cin >> k[0] >> k[1] >> k[2];
cin >> t[0] >> t[1] >> t[2];
cin >> n;
memset(m, 0, sizeof(m));
for (i = 0; i < n; ++i) cin >> m[0][i];
for (i = 0; i < 3; ++i) {
for (j = 0; j < k[i] && j < n; ++j)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int n, m, i, sum = 0, diff, count = 0;
cin >> n >> m;
pair<long long int, long long int> arr[n];
long long int str[n];
for (i = 0; i < n; i++) {
cin >> arr[i].first >> arr[i].second;
str[i] = arr[i].first - arr[i].second;
sum... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
set<ll> factors(ll n) {
set<ll> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i == 0) {
res.insert(i);
res.insert(n / i);
}
}
return res;
}
bool is_prime(int n) {
if (n < 2) return false;
if (n == 2) return true;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int M = 1e4 + 5;
const long long INF = 1e15;
struct node {
int s, e, next, f, mark;
long long w;
} edge[M << 1];
int tot;
int first[N], inq[N], pre[N], up[N];
long long dis[N];
void init(int n) {
tot = 0;
for (int i = 0; i <= n; i++) fir... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
bool has(int a, int b, int c, int d) {
if (min(a, b) <= min(c, d) && max(a, b) >= max(c, d)) return 1;
if (min(c, d) <= min(a, b) && max(c, d) >= max(a, b)) return 1;
return 0;
}
bool dfnt(int a, int b, int c, int d) {
if (max(a, b) <= min(c, d) || min(a, b) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
int mul(int a, int b) { return 1ll * a * b % Mod; }
void Add(int &a, int b) { a = add(a, b); }
const int N = 55;
int f[N][N], c[N][N], g[N][N][N], a[N], n, d[N];
void work() {
c[... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
vector<pair<int, int> > edge[maxn];
int dp[maxn][2];
int dd[maxn];
int sum;
void dfs(int u, int f, int tag) {
if (f == -1) {
dp[u][0] = dp[u][1] = 0;
dd[u] = 0;
} else {
dp[u][1] = dp[f][1] + tag;
dp[u][0] = min(dp[f][0], dp[f][1])... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 7;
inline int sign(double x) { return (x > eps) - (x < -eps); }
inline int add(int a, int b) {
a += b;
return a < 0 ? a + mod : a >= mod ? a - mod : a;
}
inline int mul(long long a, long long b) { return a * b % mod; }
cons... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, p, i, mat = 0, tow = 0, bot = 0, t;
cin >> n >> b >> p;
i = 0;
mat = n - 1;
bot = (b * 2) + 1;
bot = mat * bot;
tow = n * p;
cout << bot << " " << tow;
}
| 2 |
#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... | 5 |
#include <bits/stdc++.h>
using namespace std;
int w[205], d[205][205], f[205][205], b[205], c[205], n, v, x, y;
void dfs(int x, int y) {
for (int j = 1; j <= n; j++) f[x][j] = w[d[x][j]] + v;
for (int i = 1; i <= n; i++)
if (d[x][i] == 1 && y - i) {
dfs(i, x);
for (int j = 1; j <= n; j++) f[x][j] +=... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
int safe(long long x) {
int y = (int)(x % M);
if (y < 0) {
y += M;
}
return y;
}
int mul(long long x, long long y) {
int x2 = safe(x), y2 = safe(y);
return (int)((long long)(x2)*y2 % M);
}
int exp(long long x, long long y) {
assert... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> rd[200001];
int n, m, i, a[200001], b[200001], bel[200001], visited[200001] = {0}, fail;
void dfs(int x, int y) {
int j;
visited[x] = 1;
bel[x] = y;
for (j = 0; j < rd[x].size(); j++) {
if (visited[rd[x][j]]) {
if (bel[rd[x][j]] != 3 - y) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2100;
const int M = 200010;
const int p = 1000000007;
int r[N], c[N], n, m, k, S, id[N];
long long f[N][22], C[N][N], jie[M], rev[M], two[22], P, Q;
bool bad[N], con[N][N];
long long fast(long long x, int k) {
long long ans = 1;
for (; k; k >>= 1) {
if... | 21 |
#include <bits/stdc++.h>
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")
using namespace std;
const long long maxn = 2e5 + 100;
const long long inf = 1e15;
long long n, m, k;
long long V[4 * maxn];
vector<long long> A;
vector<long long> A1;
long long C[maxn];
void build(long long v, long long tl, l... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q, x;
cin >> q >> x;
vector<int> rem(x);
vector<bool> a(q);
int mes = 0;
for (int i = 0; i < q; i++) {
int y;
cin >> y;
int r = y % x;
rem[r]++;
long long ind = (long long)... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
T data = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
data = (data << 3) + (data << 1) + ch - '0';
ch = getchar();
}
x = f * ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, x, y;
int main() {
cin >> t;
while (t--) {
cin >> n >> x;
m = 0;
for (long long i = 1; i < n; i++) {
cin >> y;
if (y < x) m = max(m, x - y);
x = max(x, y);
}
cout << ceil(log2(m + 1)) << endl;
}
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char s[N];
int to[N];
vector<pair<int, char> > v;
vector<int> ans;
int main() {
scanf("%s", s);
int len = strlen(s);
memset(to, -1, sizeof(to));
for (int i = 0; i < len; ++i) {
if (v.empty()) {
v.push_back(make_pair(i, s[i]));
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve(string &s) {
if (s[0] >= s[1] && s.length() == 2) {
cout << "NO\n";
} else {
cout << "YES\n";
cout << "2\n";
cout << s[0] << " " << s.substr(1, s.length() - 1) << "\n";
}
}
int main() {
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int A;
cin >> A;
cout << 2 * A - 1 << " " << 2 << "\n";
cout << "1 2\n";
return 0;
}
| 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
using namespace std;
const int N = 200050;
const int MOD = 1000000007;
long long step, len, n, m, T = 1, k, lent1, lent2, con1, con2, a[N], ans[N],
p[N];
char tmp[N], t1[N], t2[N], t3[N], nex[N];
struct matr... | 16 |
#include <bits/stdc++.h>
const int N = 519;
int K, n, i, j, k, T, x[99], y[99], ans;
long long a[N][N], b[N][N];
int main() {
scanf("%d", &K);
n = 1 << K;
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j) scanf("%lld", a[i] + j);
scanf("%d", &T);
for (i = 0; i < T; ++i) scanf("%d%d", x + i, y + i), --x[i], ... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
bool b = 0;
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= 100; j++) {
if (3 * i + 7 * j == x) b = 1;
}
}
if (b)
cout << "YES";
else
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010100, INF = 1e9;
int f[N], g[N], reg[N], remf[N];
char S[N], s[N >> 1], t[N >> 1];
namespace SAM {
struct Node {
int len, fa, ch[26], par;
} T[N];
int tot, lst;
void Init(void) {
T[tot = lst = 1].len = -1;
T[0].len = 0;
T[0].fa = 1;
}
void Append(in... | 25 |
#include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;
constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();
templ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a, x;
if (s[0] == 'f' && s[1] == 't' && s[2] == 'p') {
cout << "ftp://";
x = 3;
} else {
cout << "http://";
x = 4;
}
a = x;
while (s[x] != 'r' || s[x + 1] != 'u' || x == a) {
cout << s[x];
x++;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
string s;
const int INF = 0x3f;
struct Martix {
int a[5][5];
Martix() {
memset(a, INF, sizeof(a));
a[0][0] = a[1][1] = a[2][2] = a[3][3] = a[4][4] = 0;
}
Martix operator+(const Martix b) const {
Martix res;
for (int i = 0; i < 5; i++) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int p[maxn];
int dp[maxn][4];
int main() {
int k1, k2, k3;
scanf("%d%d%d", &k1, &k2, &k3);
int x;
for (int i = 1; i <= k1; i++) {
scanf("%d", &x);
p[x] = 1;
}
for (int i = 1; i <= k2; i++) {
scanf("%d", &x);
p[x] = 2;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
long long INF = 1e18;
int n, k, a, b, q, arr[200005] = {}, suma[800005], sumb[800005];
void segbuild(int u = 1, int lo = 0, int hi = n + 1) {
if (lo == hi) {
suma[u] = sumb[u] = 0;
} else {
int mi = lo + hi >> 1;
segbuild(u << 1, lo, mi);
... | 9 |
#include <bits/stdc++.h>
int dense(char c, char *cc, int l, int m) {
int i, i_;
i_ = -1;
for (i = 0; i <= l; i++)
if (i == l || cc[i] <= c) {
if (i - i_ > m) return 0;
i_ = i;
}
return 1;
}
int main() {
char c;
int i, m, l;
static char cc[100000];
static int ii[100000 + 2];
static ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max() / 4;
int n, m, S, T, SCRAP;
long long res = 0;
string enemy[1234];
int enemyi[1234], mei[1234];
struct MinCostMaxFlow {
int N;
vector<vector<long long> > cap, flow, cost;
vector<int> found;
vector<long long> dis... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> diff;
vector<long long> ar;
vector<long long>::iterator it;
long long prefix[100005];
long long arr[100005];
int main() {
int z;
scanf("%d", &z);
for (int q = 1; q <= z; q++) {
scanf("%lld", &arr[q]);
}
sort(arr + 1, arr + 1 + z);
long long... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.