solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[104], b[104];
int main() {
int p, f, n, i = 0, tt = 0;
cin >> p >> f;
for (i = 1; i <= p; i++) cin >> a[i] >> b[i];
tt += (f - a[p]);
tt += (max(0, b[p] - tt));
for (i = p - 1; i >= 1; i--) {
tt += (a[i + 1] - a[i]);
tt += (max(0, b[i] - tt));
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MX_SZ = 2e+6 + 42;
int main() {
int n1, m1;
scanf("%d%d", &n1, &m1);
long long n = n1, m = m1;
long long odd = 0, even = 0;
for (int i = 0; i < m; i++) {
int t;
scanf("%d", &t);
if (t == 1) {
int r1;
scanf("%d", &r1);
long l... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int c = 0;
for (int i = 5; i > 0; --i) {
c += x / i;
x = x % i;
}
cout << c;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int ans, n;
struct aa {
int x, eat;
} que[100010];
int main() {
int tail = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", a + i);
int i = 1;
while (a[i - 1] < a[i] && i < n) i++;
que[tail].x = a[i - 1], que[tail++].eat = 0;
for (;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int d[111], cnt[111], a[111], END, LEN;
vector<pair<pair<int, int>, pair<int, int> > > rv;
void check() {
int A = -1;
for (int i = 0; i < 3 && i < LEN; ++i) {
if (A == 0) break;
if (A == -1)
A = a[i];
else
A = A * 10 + a[i];
int B = -1... | 12 |
#include <bits/stdc++.h>
class LaptopPower {
private:
std::vector<std::pair<int, int>> workIntervals = {};
decltype(workIntervals.size()) n = 0;
int p1 = 0;
int p2 = 0;
int p3 = 0;
int t1 = 0;
int t2 = 0;
public:
LaptopPower() = default;
LaptopPower(int n, int p1, int p2, int p3, int t1, int t2,
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n > m) swap(n, m);
long long int ans = 0;
for (int i = 1; i <= n; i++) ans += (m + i) / 5 - i / 5;
cout << ans << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[4], num, sum;
string s[4], str;
bool check(char ch) {
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}
int z() {
sum = 0;
for (int i = str.length() - 1; i >= 0; i--) {
sum += check(str[i]);
if (sum == m) return i;
}
retur... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, d;
scanf("%d %d %d", &n, &m, &d);
int i, j, k = 0;
int a[n][m], arr[n * m];
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
arr[k] = a[i][j];
k++;
}
}
sort(arr, arr + k);
int mid = k... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n, d;
cin >> n >> d;
int m;
cin >> m;
while (m--) {
int x, y;
cin >> x >> y;
if ((y - x + d) * (y - x - d) <= 0 &&
(x + y + d - 2 * n) * (x + y - d) <= 0) {
cout << "YES" << endl;
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m;
int ara[n + 1];
memset(ara, 0, sizeof(ara));
for (int i = 1; i <= m; i++) {
cin >> x;
for (int j = x; j <= n; j++)
if (ara[j] == 0) ara[j] = x;
}
for (int i = 1; i <= n; i++) cout << ara[i] << " ";
cout ... | 1 |
#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
vector<int> adj[1000005];
int a[1000005], b[1000005], dp... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 30010;
const int inf = 1e9;
int a[maxn];
int sum[maxn];
int n, k;
int dp[maxn][202][2], mx[maxn][202][2];
void up(int &x, int y) { x = max(x, y); }
int coe[2];
int main() {
coe[0] = -1;
coe[1] = 1;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int MAXN = 1e5 + 5;
const int MAXM = 2e6 + 5;
const int MOD = 1e9 + 7;
int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
long long pw... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ar[105];
cin >> n;
for (int i = 0; i < 2 * n; i++) cin >> ar[i];
sort(ar, ar + 2 * n);
int mn = INT_MAX, ci, pv;
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < 2 * n; j++) {
if (i == j) continue;
ci = 0;
pv = -1;
... | 7 |
#include <bits/stdc++.h>
int main() {
short a[500001], b[500001];
int i, j, k, l, m, n, x, y;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
a[0] = a[1];
a[n + 1] = a[n];
x = 1;
y = 1;
m = 0;
for (i = 1; i <= n; i++) {
if (a[i] == a[i + 1]) {
y = i;
if (a[x] == a[y]) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100050;
int n, f[MAXN], s[MAXN], pre[MAXN];
bool flag[MAXN];
vector<int> g[MAXN];
vector<pair<int, int> > match;
pair<int, int> ans, dp[MAXN][2];
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
return make_pair(a.first + b.fir... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
long long idx = str.find(',');
cerr << str.substr(0, idx) << " : " << t << ", ";
dbs(str.substr(idx + 1), s...);
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2][25][2];
int main() {
int n;
cin >> n;
int tmp = n, sum = 0;
while (tmp > 1) tmp /= 2, sum++;
dp[1][sum][0] = 1;
if ((1 << (sum - 1)) * 3 <= n) dp[1][sum - 1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= sum; j++) {
dp[i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x;
cin >> x;
cout << x / 2520 << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long linf = (((long long)1) << 60) - 1;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int main() {
ios_base::sync_with_stdio(false);
int n, m, q, l, r, tlen, cnt;
char s[N], t[N];
bool match[N] = {0};
cin >> n >> m >> q >> s >> t;
tlen = strlen(t);
for (int i = 0; s[i]; ++i) {
match[i] = !strncmp(s + i, t, tlen);
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long dp[200005][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
long long arr[26] = {0};
for (int i = 0; i < n; i++) {
cin ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int nm(string k) {
int res = 0;
int o = 1;
for (int i = k.size() - 1; i >= 0; i--) {
if (k[i] % 2 == 1) {
res += o;
}
o *= 2;
}
return res;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char c;
string... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 200010;
int dfn[N], stk[N], f[N], low[N], s[N], c[N];
int cnt = 0, num = 0, top = 0;
void tarjan(int now) {
num++;
top++;
dfn[now] = low[now] = num;
stk[top] = now;
f[now] = 1;
if (!dfn[s[now]]) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long N, M, ans, temp;
vector<pair<long long, long long> > m;
long long a[6];
long long visited[100000], vCnt;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
for (long long i = 0; i < 6; i++) {
cin >> a[i];
}
cin >> N;
for (... | 11 |
#include <bits/stdc++.h>
using namespace std;
char rep[26];
char rep2[26];
void init(string p) {
for (int i = 0; i < 26; i++) {
rep[i] = 0;
}
int pos;
for (int i = 0; i < p.size(); i++) {
pos = (int)(p[i] - 'a');
rep[pos]++;
}
}
void print() {
for (int i = 0; i < 26; i++) {
printf("%c (%d, %... | 2 |
#include <bits/stdc++.h>
void Get(int &T) {
char C;
bool F = 0;
for (; C = getchar(), C < '0' || C > '9';)
if (C == '-') F = 1;
for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
;
F && (T = -T);
}
int N, M;
int A[400005];
int B[400005];
int Min[400005];
int Belong[400005];
i... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, a[800000], pos[800000], bit[800000], mn[800000], mn2[800000],
num[800000], tag[800000];
long long ans, out[800000];
void add(int x) {
for (; x <= n; x += x & (-x)) ++bit[x];
}
int qry(int x) {
int ret = 0;
for (; x; x -= x & (-x)) ret += bit[x];
return re... | 25 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> self, shop;
vector<pair<int, int> > vec;
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
self[x]++;
}
for (int i = 0; i < m; ++i) {
int x;
scanf("%d", &x);
shop[x]... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int m;
long long dp[1 << 18][101];
int num[20];
int c[10];
int digitLen;
long long Fac(int x) { return x == 0 ? 1 : Fac(x - 1) * x; }
int main() {
cin >> n >> m;
while (n) {
int t = (int)(n % 10);
num[digitLen++] = t;
c[t]++;
n /= 10;
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int lt = 1000;
long long dp[1000001];
int main() {
int n, hr, hb, wr, wb;
while (scanf("%d", &n) != EOF) {
scanf("%d%d%d%d", &hr, &hb, &wr, &wb);
long long ans = 0;
if (wr > lt) {
for (int ct = 0; ct * wr <= n; ct++) {
ans = max(ans, 1ll * ct *... | 12 |
#include <iostream>
#include <cmath>
#include <vector>
#include <numeric>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long int
#define i_run_i_speed_i_sanic ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define rall(x) x... | 3 |
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main(){
#ifdef LOCAL
//freopen("C_input.txt"... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int int_inf = 0X3f3f3f3f;
const long long ll_inf = 9223372036854775807;
long long minm(long long a, long long b, long long c) {
return min(a, min(b, c));
}
int n;
long long a[1000005];
long long r1, r2, r3, d;
long long dp[1000005][2];
int main() {
cin >> n >> r1 ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[300000];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << n + n / 2;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int main() {
int n, flag = 0;
scanf("%d", &n);
for (register int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (flag == 1 && a[i] > a[i - 1]) {
flag = 2;
break;
}
if (a[i] < a[i - 1]) {
flag = 1;
}
}
if (flag == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 17;
int N, Q;
long long s[MAXN];
long long sum[MAXN];
long long d[MAXN];
template <typename T>
T read_() {
T t;
cin >> t;
return t;
}
template <typename T>
T read(T& t) {
cin >> t;
return t;
}
template <typename T>
void write(const T& t) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
long long n, k, kq;
long long a[maxn];
int rf() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
return 0;
}
int xl() {
sort(a, a + n, greater<long long>());
kq = a[0];
for (int i = 1; i <= k; i++) {
kq += a[i];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
int n, k;
cin >> n >> k;
int length = n / k;
for (int i = 0; i < length; i++) cin >> a[i];
for (int i = 0; i < length; i++) cin >> b[i];
long long ans = 1;
long long limit = 1;
for (int i = 0; i < k; i++) limit *= 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005], dp[100005];
int main() {
long long int n, sum = 0, second, ans = 0;
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
(scanf("%d", &arr[i]));
sum += arr[i];
}
if (sum % 3 != 0) {
cout << "0";
return 0;
}
second = sum / 3;
sum... | 4 |
#include <bits/stdc++.h>
const long long INF = 2e18;
const long long N = 1e4 + 1;
const long long mod = 1e9;
const long double eps = 1E-7;
using namespace std;
vector<int> v, s;
int dx, d, ct;
void solve() {
for (int i = 0; i < 5; ++i) {
int x;
cin >> x;
v.push_back(x), ct += x;
}
for (int i = 0; i < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
return x * x;
}
string s, w;
vector<int> res;
void norm(int &pos) {
w... | 9 |
#include <bits/stdc++.h>
const long long inf = 1000000000000000000;
using namespace std;
bool prime[1000005];
long long fact[1000005];
long long gcd(long long a, long long b) {
if (a < b) gcd(b, a);
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
long long x = (a / gcd(a,... | 4 |
/***************************************************************
File name: D.cpp
Author: ljfcnyali
Create time: 2021年04月05日 星期一 19时27分49秒
***************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; +... | 18 |
#include <bits/stdc++.h>
using namespace std;
int aib[200005];
void update(int n, int poz, int val) {
for (; poz <= n; poz += (poz & -poz)) aib[poz] += val;
}
int query(int poz) {
int ans = 0;
for (; poz > 0; poz -= (poz & -poz)) ans += aib[poz];
return ans;
}
int a[200005];
struct Query {
int a, x;
} q[20000... | 11 |
#include <bits/stdc++.h>
using namespace std;
string t2 = "miao.", t1 = "lala.";
bool check1(string s) {
if (s.size() < t1.size()) return false;
int j = 0;
for (int i = s.size() - t1.size(); i < s.size(); i++) {
if (s[i] != t1[j]) return false;
j++;
}
return true;
}
bool check2(string s) {
if (s.siz... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool iprimes[1000];
int ans[1000001], divisors[1000], nums[1000001], primes[1000], pCount;
int main() {
for (int i = int(2); i < int(1000 >> 1); i++) {
for (int j = 2; j * i < 1000; j++) {
iprimes[i * j] = true;
}
}
pCount = 0;
for (int i = int(2); i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
namespace NTT {
const int EXP = 23;
const unsigned long long EXP_MULT = 119, NTT_MOD = (EXP_MULT << EXP) + 1;
unsigned long long rt[EXP + 1], invrt[EXP + 1];
bool built;
unsigned long long modPow(unsigned long long a, unsigned long long p) {
return p ? modPow((a) * (a) % ... | 21 |
#include <bits/stdc++.h>
using namespace std;
vector<list<int> > a(100004);
long long int ans = 1;
int child[100004];
long long int fact[100004];
long long int modinv[100004];
long long int dp[103][103][103];
void initialisebool(int n, bool a[]) {
for (int i = 1; i <= n; i++) a[i] = false;
}
void initialiselong(int n... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 5;
const int SQ = 300;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
bool flag;
int l[maxN], pt[maxN];
vector<int> P[maxN];
vector<pair<int, int> > Q[maxN];
int main() {
time_t START = clock();
ios_base::sync_with_stdio(0);
cin.tie(... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
int g[26][26];
int dp[105][105][27];
int main() {
char s[105];
scanf("%s", s);
int n = strlen(s), m;
scanf("%d", &m);
int tt, c;
scanf("%d", &tt);
char a[3], b[3];
while (tt--) {
scanf("%s%s%d", a, b, &c);
g[a[0] - 'a'][b[0] ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long n;
cin >> n;
if (n <= 2) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
cout << 2 << " " << 1 << " " << n << endl;
cout << n - 2 << " ";
for (long i = 2; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long ans = 0;
long long n, k;
vector<long long> prefix[3005];
void solve(long long l, long long r, vector<long long> dp) {
if (l == r) {
long long sz = (long long)prefix[l].size() - 1;
fo... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int q[maxn];
int n, x;
bool cmp(int x, int y) { return x > y; }
int main() {
int t;
cin >> t;
while (t--) {
cin >> n >> x;
for (int i = 0; i < n; i++) cin >> q[i];
sort(q, q + n, cmp);
int ans = 0;
long long int sum = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj(200101, vector<int>(0));
int k = 0, n;
int from[200201], to[200201], t[200201];
int segment[800810], f1[800810];
int pos[200201];
void dfs(int v) {
from[v] = ++k;
pos[k] = t[v];
int l = adj[v].size();
for (int j = 0; j < l; j++) {
dfs(ad... | 12 |
#include <bits/stdc++.h>
using namespace std;
char s[500001];
int n, t;
bool judge(int x) {
int far = 0, far2 = 0, sum = x;
for (int i = 1; i <= n; i++) {
if (s[i] == 'S') sum++;
if (s[i] == 'H') sum--;
if (sum == 0 || s[i] == 'H') far = i;
if (s[i] == 'H') far2 = i;
}
if (sum < 0) return false;... | 15 |
#include <bits/stdc++.h>
void run();
int main() {
std::ios::sync_with_stdio(false);
run();
return 0;
}
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "; ";
err(++it, a... | 6 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int i=sqrt(2*n-1);
int j=(i-1)/2;
printf("%d\n",j);
}
}
| 7 |
#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>
using namespace std;
const int mn = 210;
const long double zero = 1e-7;
int hp1, dt1, l1, r1, p1, L;
int hp2, dt2, l2, r2, p2, t1, t2;
double f1[mn], f2[mn], ans;
bool atk(double* f, int l, int r, int p) {
int i, j;
double w;
bool res = 0;
for (i = 1; i <= L; ++i) {
if (f[i] < zero)... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i % j == 0 && i * j > n && ((double)i) / j < n) {
printf("%d %d\n", i, j);
return 0;
}
}
}
printf("-1\n");
return... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 1e5 + 100, mod = 1e9 + 7;
long long n, l, r, a[MX], p, b[MX];
set<pair<long long, long long>> s;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> l >> r;
for (long long i = 1; i <= n; i++) cin >> a[i];
for ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, pos = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') pos = 0;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return pos ? x : -x;
}
const int N = 2e5 + 200;
struct node {
int l, r,... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005, Maxm = 100005, Mo = 1000000007,
sp[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long oo = INT_MAX >> 2;
struct Tree {
int x, y;
};
struct edge {
int v, c, w, Ft;
};
typedef int IArr[Maxn];
typedef long long LArr[Maxn];
typede... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n == 1) {
cout << "NO";
return 0;
}
if (n < 1000) {
if ((n * (n - 1)) / 2 <= m) {
cout << "NO";
return 0;
}
}
vector<pair<int, int> > b(m);
vector<int> a(n);
int l, r;
for (int i = 0; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
w = (w << 3) + (w << 1) + ch - 48;
ch = getchar();
}
return w * f;
}
int n, m, f... | 16 |
#include <bits/stdc++.h>
#define ll long long
#define ch char
using namespace std;
bool chek(string s)
{
ll k = 0;
for(auto to: s)
{
if(to == '(')
k++;
else
k--;
if(k < 0)
return false;
}
if(k == 0)
return true;
else
ret... | 8 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int a[100000 + 10], s[100000 +... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000100;
int C[MAX];
vector<int> pos;
int check(int s) {
int res = 0;
for (auto p : pos) {
int pres = 200000000;
if (ceil((double)C[p] / s) <= ((double)C[p] / (s - 1))) {
res += ceil((double)C[p] / s);
} else {
return -1;
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e15;
long long a[100010], ts, tf, t;
int n;
int main() {
long long now, ans, ansv = oo;
scanf("%I64d%I64d%I64d%d", &ts, &tf, &t, &n);
for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
now = ts;
if (a[1] > ts) {
printf("%d\n", ts);
r... | 13 |
#include <bits/stdc++.h>
using namespace std;
int c[200010];
int main() {
int k, m, n;
cin >> k;
string x, y;
cin >> x >> y;
for (int i = 0; i < k; i++) {
m = x[k - i - 1] - 'a';
n = y[k - i - 1] - 'a';
c[i] += m + n;
c[i + 1] += c[i] / 26;
c[i] %= 26;
}
for (int i = k - 1; i >= 0; i--... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 52;
const int MOD = (int)1e9 + 7;
long long C[MAXN][MAXN], f[MAXN][MAXN][2], inv_2;
long long qp(long long x, long long y) {
long long res = 1;
for (; y > 0; y >>= 1) {
if (y & 1) res = res * x % MOD;
x = x * x % MOD;
}
return res;
}
void in... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int x[100010], y[100010], s[100010], d[100010], sx[100010], dx[100010],
sp[100010 * 2], dp[100010 * 2];
long long ans[100010];
void ssort(int l, int r) {
int i = l, j = r, mid = s[(l + r) / 2];
do {
while (s[i] < mid) i++;
while (s[j] > mid) j--... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline void add(int &x, int y) {
x += y;
if (x >= md) {
x -= md;
}
}
inline int mul(int x, int y) { return (int)((long long)x * y % md); }
inline int inv(int a) {
if (a < 0) {
a += md;
}
int b = md, u = 0, v = 1;
while (a) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
const long long int MOD = 1e9 + 696969;
mt19937_64 rng(time(0));
int random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
const long long INF = 1e18;
const int maxn = 400100;
int spo, n, k;
vector<int> v[maxn];
vector<bool> odw;... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n;
cin >> n;
map<long long, long long> map;
long long ans = 1e9;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (map.find(a[i]) == map.end()) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int M = 100005;
struct Point {
int x, y;
};
int n, m, k;
char G[N][N];
int L[N][N], R[N][N], U[N][N], D[N][N];
char dir[M];
int len[M];
bool flag[26];
Point pos[26];
string res;
void Test(int K[N][N]) {
int i, j;
for (i = 0; i < n; i++) {
... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
const long long mod = 1e9 + 7;
long long n, m, k, c[1 << 20], p[1 << 20], depth[1 << 20];
long long a, b;
map<long lon... | 14 |
#include <bits/stdc++.h>
int main() {
int i, n, m, k, a, ans;
scanf("%d%d%d", &n, &m, &k);
if (!(n & 1))
printf("0\n");
else {
ans = (((long long)m / ((n + 1) / 2) * k) < (1000000)
? ((long long)m / ((n + 1) / 2) * k)
: (1000000));
for (i = 1; i <= n; i++) {
scanf... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
scanf("%d %d", &N, &M);
int p = N / M, d = N % M;
for (int i = 1; i <= M - d; i++) {
printf("%d ", p);
}
for (int i = 1; i <= d; i++) {
printf("%d ", p + 1);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
vector<pair<int, int> > a(3);
set<pair<int, int> > ans;
a[0] = make_pair(x1, y1);
a[1] = make_pair(x2, y2);
a[2] = make_pair(x3, y3);
sort(a.begin(), a.end());
if ((a[0].seco... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
const long long MOD = 1e9 + 7;
int N, M;
vector<int> pos[MAXN + 10];
vector<pair<int, int> > V[MAXN + 10];
int A[MAXN + 10], B[MAXN + 10], vvv;
int ans[MAXN + 10];
long long twopow[MAXN + 10];
int main() {
int i, j, k, p;
scanf("%d%d", &N, &M);
... | 17 |
#include <bits/stdc++.h>
int main() {
char Vowels[] = "AEIOUY";
char String[101];
int Max = 1, Current = 1;
std::cin >> String;
for (int i = 0; i < (strlen(String) + 1); ++i) {
if (strchr(Vowels, String[i]) == nullptr)
++Current;
else {
if (Current > Max) Max = Current;
Current = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n >> s;
for (int i = 0; i + 1 < n; i++) {
if (s[i] > s[i + 1]) {
cout << "YES" << endl << i + 1 << " " << i + 2;
return 0;
}
}
cout << "NO";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
long long a[105];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long sum = 0;
for (int i = 1; i < n - 1; i++) {
if ((a[i - 1] == 1) && (a[i] == 0) && (a[i + 1] == 1)) {
a[i + 1] = 0;
sum++;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long sz = 1e5 + 5;
string s[2];
long long a[2][105];
long long dp[105][105];
long long rec(long long m, long long n) {
if (m < 0 || n < 0) return 0;
if (dp[m][n] != -1)
return dp[m][n];
else {
long long l1, l2, l3, l4, l5, l6, l7, l8;
l2 = rec(m... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int test_case = 0; test_case < t; ++test_case) {
int a, b;
cin >> a >> b;
long long res = 0;
for (int i = 0; (1ll << i) <= a and (1ll << i) <= b; ++i) {
const long long temp = 1ll << i;
if (temp & a and te... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Info {
int x, y;
} q[200010];
struct Onfo {
int nu, ne, qu;
} a[200010];
int n, m, g[10][10], f[10][10], fa[10], nu[10], s, t, b[10 * 10], cur[10 * 10],
num, di[10 * 10], li[10 * 10], ans, da[10], xi[10];
int get() {
char ch = getchar();
int an = 0;
whi... | 24 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5005;
const ll oo = 1e18;
int n, b;
int c[N], d[N], x[N];
vector<int> g[N];
vector<ll> dp[N];
vector<ll> sub[N];
void prec_sub(int u) {
sub[u].push_back(c[u]);
for (int v : g[u]) {
prec_sub(v);
int oldsz = (int)sub[u].size();
... | 16 |
#include <bits/stdc++.h>
using namespace std;
void fastscan(int &number) {
bool negative = false;
register int c;
number = 0;
c = getchar();
if (c == '-') {
negative = true;
c = getchar();
}
for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
if (negative) number *= -1;
}
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long M;
vector<tuple<int, int, int> > dot;
vector<int> V[100000];
vector<int> rV[100000];
bool used[100000];
int deg[100000] = {0};
int upp[100000] = {0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> M;
long long x, y, id;
long long ans = 0;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
char s[2510];
long long n, m, k, r, a[2510][2510], u[2510][2510];
long long ss(long long x1, long long x2, long long y1, long long y2) {
return a[x2][y2] - a[x1][y2] - a[x2][y1] + a[x1][y1];
}
void dfs(long long x1, long long x2, long long y1, long long y2, long long t) {... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, x;
vector<int> a;
void next(int n, int x, vector<int> a) {
int less = 0;
int more = 0;
int steps = 1;
for (int i = 0; i < n; i++) {
if (a[i] < x) {
less++;
} else {
if (a[i] > x) {
more++;
} else {
steps = 0;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct Dancer {
int coord;
int t;
int id;
bool operator<(const Dancer& d) const { return coord < d.coord; }
};
int n, w, h;
vector<Dancer> vers;
vector<Dancer> hors;
bool read() {
if (scanf("%d%d%d", &n, &w, &h) < 3) {
return 0;
}
vers.clear();
hors.clea... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int dp[N][N];
int com[N][N] = {};
char s[N];
int n;
int M = 1000000007;
bool bigger(int x, int y, int len) {
if (com[x][y] >= len) return 0;
return s[x + com[x][y]] > s[y + com[x][y]];
}
void init() {
for (int i = n - 1; i >= 0; --i) {
for (int... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100], b[100];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
int id = upper_bound(a, a + n, b[i]) - a;
cout << a[id % n] << " ";
}
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int an[50010];
bool vis[50010][1000][2];
bool anw[50010][1000][2];
bool sw(int p, int ms, int c) {
if (p == n) {
if (ms == 0 && c) return true;
return false;
}
if (vis[p][ms][c]) return anw[p][ms][c];
vis[p][ms][c] = true;
bool w1 = sw(p + 1, ms,... | 11 |
#include <bits/stdc++.h>
using namespace std;
int T, ans, mid, r, az;
int b[2000005];
string s;
string ycl(string t, int x) {
string res = "@#";
for (int i = x; i < (int)t.length() - x; i++) res += t[i], res += '#';
return res;
}
int main() {
scanf("%d", &T);
while (T--) {
string t = "";
cin >> s;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
int n, m;
long long a[MaxN + 5];
struct In {
long long val, pos, len;
int op;
} PP[MaxN + 5];
struct Out {
long long val, pos;
} ans[MaxN + 5];
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d", &... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.