solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long double EPS = (long double)1e-11L;
const double PI = 3.141592653589793238462;
const int INF = 2e9 + 7;
const long long LINF = 9e18 + 7;
int N = 20;
long long k;
bool isLess(long long x, long long y) {
return !(x != 0 && y >= (k + x - 1) / x || y != 0 && x >= (k + y - ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
int n;
cin >> n;
if (n <= 3) return cout << "NO", 0;
cout << "YES" << endl;
if (n % 2 == 1) {
cout << "5 - 1 = 4" << endl
<< "4 - 2 = 2" << endl
<< "3 * 2 = 6" << endl
... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[5];
const int N = 1e5 + 10;
int id, p[N], c[N];
int n, m, mm;
struct node {
int l, r, peo;
};
vector<int> person;
vector<node> vec;
bool tag[N], vis[N];
int ans[N];
int lowbit(int a) { return a & (a ^ (a - 1)); }
void add(int i, int x) {
while (i <= mm) {
c[i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
int arr1[n], arr2[n];
for (int i = 0; i < n; i++) cin >> arr1[i], arr2[i] = arr1[i];
sort(arr1, arr1 + n);
for (int i = 0; i < n; i++)
if (arr1[i] != arr2[i]) cnt++;
cnt > 2 ? cout << "NO" : cout << "YES";
return 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<int> g[N], d[N];
unordered_map<long long, int> f[N];
int i, j, n, m, x, len, y;
int sz[N], h[N], v[N], ans[N], qb[N], cur[N], Fa[N];
char a[N];
long long name[N];
long long cal() {
long long MOD1 = 100000007, MOD2 = 100000009, p1 = 0, p2 = 0;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<vector<int> > seats(n, vector<int>(4, 0));
bool window = true;
bool left = true;
int cur_ligne = 0;
int cur = 1;
while (cur <= m) {
if (left) {
if (window) {
seats[... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 100;
multiset<long long> use;
long long a[N];
long long ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
use.insert(a[i]);
}
sort(a + 1, a + n + 1);... | 5 |
#include <bits/stdc++.h>
int n;
unsigned f[100001];
char str[100001];
int main() {
scanf("%d%s", &n, str + 1);
if (n & 1) {
puts("0");
return 0;
}
f[0] = 1;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (str[i] == '?')
for (unsigned j = (i >> 1), *a = f + j, *b = f + j - 1;
j >... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
if (b == (long long int)0) return (long long int)1;
long long int c = power(a, b >> 1);
c %= ((long long int)1000000009);
c *= c;
c %= ((long long int)1000000009);
if (b & 1) {
c *= a;
c %= ((long l... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, t;
cin >> n >> t;
vector<int> s(n), d(n);
int ans = 1e+9;
for (int i = 0; i < n; ++i) {
cin >> s[i] >> d[i];
s[i] -= t;
if (s[i] < 0) {
s[i] %= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long double epsylon = 1e-9;
const std::string PROGRAM_NAME = "ivo";
int main() {
int n;
cin >> n;
vector<string> a(n);
getline(cin, a[0]);
for (int i = 0; i < (int)a.size(); ++i) {
getline(cin, a[i]);
}
vector<string> ans(2 * n - 1, string(2 * n - 1,... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a[3000005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
long long x;
scanf("%lld", &x);
a[x]++;
}
long long ans = 0;
for (int i = 0; i <= 2000005; i++) {
ans += (a[i] & 1);
a[i + 1] += a[i] / 2;
}
cout <<... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, res, ans[2005], dd[2005];
struct event {
int u, id, type;
event(int u = 0, int id = 0, int type = 0) : u(u), id(id), type(type) {}
};
event v[2005];
bool cmp(event p, event q) {
if (p.u != q.u) return p.u < q.u;
return p.type < q.type;
}
void nhap() {
scanf... | 11 |
#include <bits/stdc++.h>
const int val = (2e5) + 5;
const int INF = (1e9);
using namespace std;
long long a[val];
map<long long, vector<pair<int, int> > > g;
int solve() {
int k;
cin >> k;
for (int x = 1; x <= k; ++x) {
int n;
cin >> n;
long long sum = 0;
for (int i = 1; i <= n; ++i) {
cin >... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int M = 1000000;
const int INF = 1000001;
struct flight_t {
int date, idx, cost;
flight_t() = default;
flight_t(const int& date, const int& idx, const int& cost)
: date(date), idx(idx), cost(cost) {}
bool operator<(const flight_t& t... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long n;
cin >> n;
if (n % 2 == 0)
cout << n / 2 << endl;
else
cout << (n + 1) / 2 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], t[N];
vector<int> vec[N];
int n, m, sum;
bool check(int x) {
memset(t, 0, sizeof t);
int mon = min(N - 1, x), res = sum;
for (int i = min(N - 1, x); i; i--) {
if (mon > i) mon--;
for (auto j : vec[i]) {
int buy = min(mon,... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, k;
const int mx = 1e5 + 9;
const long long mod = 1e9 + 7;
long long w[mx], x[mx], d[mx];
long long sum;
long long ncr[2005][2005];
long long a[mx];
int main() {
for (int i = 0; i < 2005; i++) {
ncr[i][0] = 1;
for (int x = 1; x <= i; x++)
ncr[... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
string s, k;
cin >> s;
map<char, int> m;
map<char, int>::iterator it;
for (int i = 0; i < s.length(); i++) {
m[s[i]]++;
}
string result;
for (it = m.begin(); it != m.end(); it++) {
if (it->second % n != 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int book[200010][40];
int main() {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int n, k;
string str;
cin >> n >> k >> str;
int ans = n;
int len = str.length();
for (int i = 0; i < k; i++) {
for (int l = 0; l < 27; l++) b... | 7 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
long long a[4];
char o[3];
long long ans = 1LL << 56;
int main() {
for (int i = 0; i < 4; i++) cin >> a[i];
sort(a, a + 4);
cin >> o[0] >> o[1] >> o[2];
do {
vector<long long> tt(a + 1, a + 4);
if (o[0] == '+')
tt[0] += ... | 8 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pii> containers(m);
for (int i = 0; i < m; ++i) {
cin >> containers[i].second >> containers[i].first;
}
sort(c... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
if (k % n == 0LL) {
cout << k / n << endl;
} else {
cout << k / n + 1LL << endl;
}
}
| 0 |
#include <bits/stdc++.h>
int main() {
int array1[8];
int i;
for (i = 0; i < 8; i++) {
scanf("%d", &array1[i]);
}
int x = (array1[1] * array1[2]) / (array1[6]);
int y = (array1[3] * array1[4]);
int z = (array1[5]) / (array1[7]);
if (x <= y && x <= z) {
printf("%d", x / array1[0]);
return 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e7 + 7;
const int MOD = 998244353;
const int N = 1e5 + 10;
const int Z = 2e4 + 5;
long long Sxx[N];
long long Syy[N];
long long Sx[N];
long long Sy[N];
long long ans;
int xx[N];
int yy[N];
int n;
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
std::vector<long long> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long n, m;
cin >> n >> m;
v.push_back(-1);
for (long long i = 1; i <= m; ++i) {
long long x;
cin >> x;
v.push_back(x);
}
long long temp = 1;
long l... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int last[20];
set<int> S;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
memset(last, -1, sizeof last);
for (int i = 0; i < n; ++i) {
int mask = 0, cur = i;
S.insert(a[i]);
for (int j = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[2010];
int n, c[2010], a[2010], sz[2010];
int l[2010], r[2010], t = 0;
bool ok = 1;
struct node {
int v, id;
} b[2010];
bool cmp(const node& x, const node& y) { return x.v < y.v; }
void dfs(int rt) {
if (ok == 0) return;
++t;
l[rt] = t;
b[t].id = rt;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
char a[6][8] = {'.'}, tmp, flag = 0;
a[0][0] = a[0][1] = a[0][6] = a[0][7] = '3';
a[1][0] = a[1][1] = a[1][6] = a[1][7] = '3';
a[0][3] = a[0][4] = '4';
a[1][3] = a[1][4] = '4';
a[2][0] = a[2][1] = a[2][6] = a[2][7] = '2';
a[3][0] = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[1001];
int ret[21][21];
int main() {
cin >> n;
for (int i = 1; i < n * n + 1; i++) {
int a;
cin >> a;
arr[a]++;
}
vector<int> v;
for (int i = 1; i < 1001; i++) {
if (arr[i]) v.push_back(arr[i]);
}
sort(v.begin(), v.end());
bool... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b;
c = (a * b) / 2;
cout << c;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, K;
vector<int> D;
cin >> n;
K = n;
for (i = 1; i <= n / 2; i++) {
D.push_back(i);
D.push_back(K);
K--;
}
if (n % 2 == 1) D.push_back(n / 2 + 1);
for (i = 0; i < D.size(); i++) cout << D[i] << " ";
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 2e5 + 5;
long long int t, n, m;
pair<bool, pair<long long int, long long int> > dp[N][2];
bool vis[N][2];
map<string, long long int> mpcnt, mpidx;
vector<string> s;
vector<long long int> val;
set<string> st;
long lo... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, x, i, j, a, b;
cin >> t;
while (t--) {
cin >> n;
x = n / 2;
a = b = 0;
for (i = 1; i < x; i++) {
a = a + pow(2, i);
}
a = a + pow(2, n);
for (i = x; i < n; i++) {
b = b + pow(2, i);
}
cout <<... | 0 |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ppb pop_back
#define int ll int
#define float double
#define endl '\n'
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define mii map<int,i... | 6 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
*OS++ = x;
if (OS == OT) flush();
}
template <class I>
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum1 = 0, sum2 = 0;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int i = 0;
int ar[2] = {0, 0}, p = 0, r = n - 1;
while (i <= r) {
if (arr[i] >= arr[r]) {
ar[p] += arr[i];
i++;
} else {
ar[p] +=... | 0 |
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long INF = LLONG_MAX;
const long double EPS = 1e-9;
const long double pi = 3.141592653589793238462643383279502884;
const long long M = 1e9 + 7;
const long long MAXN = 1e6 + 7;
long long n, m, a, b;
vector<long long> fact(MAXN);
vector<l... | 16 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
int bounds[7];
int quantity[5];
int qq[2][5];
int scoreDiff[5];
int n;
int CalcScore(int j, int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int t = 240 - k;
int ans = 0;
for (int i = int(1); i <= int(n); i++) {
if (i * 5 > t) break;
ans++;
t -= i * 5;
}
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000010;
int st[N], w[N];
inline int gi() {
int x = 0, o = 1;
char ch = getchar();
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') ch = getchar(), o = -1;
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar()... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long nax = 3e5 + 5;
vector<long long> adj[nax];
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 7;
set<long long> a;
long long ans[nax];
vector<long long> v;
signed main() {
long long n, m;
cin >> n >> m;
for (long long i = 1; i <= n; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
string s;
cin >> s;
int l = -1e9, r = 1e9;
for (int i = 4; i < n; i++) {
if (s[... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char G[301][301];
int dx[5] = {0, -1, 1, 0, 0};
int dy[5] = {0, 0, 0, -1, 1};
int valid(int i, int j) {
if (i < 0 || i >= n || j < 0 || j >= m) return 0;
return 1;
}
int isStar(int i, int j, int r) {
for (int k = 0; k < 5; k++) {
int x = i + dx[k] * r, y... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long int t, sx, sy, ex, ey;
cin >> t >> sx >> sy >> ex >> ey;
long long int n = 0, s = 0, e = 0, w = 0;
if (ex - sx > 0)
e += ex - sx;
else
w += sx - ex;
if (ey ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int z) {
if (y == 0)
return 1;
else {
long long int p = power(x, y / 2, z);
if (y % 2 == 0)
return (p * p) % z;
else
return (x * ((p * p) % z)) % z;
}
}
long long int gcd(long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
int n, m, Q;
int a[maxn][maxn];
int l[maxn][maxn], r[maxn][maxn], u[maxn][maxn], d[maxn][maxn];
int hehe[maxn], haha[maxn];
int Solve(int arr[], int p, int q) {
int L = p, R = p;
int tmp = -1;
for (int i = arr[p]; i >= 1; i--) {
while (L >= ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int cnt1 = 0;
int cnt2 = 0;
int a;
vector<int> v;
v.clear();
int ret1 = 0;
int ret2 = 0;
int temp = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
if (!a || a == 100) {
v.p... | 8 |
#include <bits/stdc++.h>
int FASTBUFFER;
using namespace std;
void dfs(long long i, long long p, long long s);
long long calc(long long Min, long long Max, long long x);
long long n, m, l, r, mo, i, j, ans, now, a, tot, Min, Max, b[14];
long long Hash[100000 + 5];
long long sq[100000 + 5][14];
int main() {
for (i = 2... | 17 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int res = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) res = (res << 1) + (res << 3) + (c ^ '0');
return res * f;
}
void get(char *s) {
char c = getchar();
while (c < ... | 15 |
#include <bits/stdc++.h>
using namespace std;
class BIT {
public:
vector<map<int, int>> m1;
int n;
BIT(int _n) : n(_n) { m1.resize(n + 1); }
int LSone(int u) { return u & (-u); }
void add(int x, int t) {
for (int i = t; i <= n; i += LSone(i)) m1[i][x]++;
}
void remove(int x, int t) {
for (int i =... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
int cnt[maxn];
bool prime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
return (n > 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int s;
while (n--) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d %d", &n, &m);
char mmap[80][80];
for (int i = 0; i <= n - 1; i++) {
scanf("%s", mmap[i]);
}
int cov[80] = {0}, coh[80] = {0};
bool valid = false;
int count = 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s = "ROYGBIV";
cout << s;
n -= 7;
s = "GBIV";
while (n > 0) {
cout << s.substr(0, min(n, 4));
n -= min(n, 4);
}
cout << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
const long long maxn = 1e5 + 10;
long long a[maxn], sum, cnt[10];
int32_t main() {
long long n = in();
bool fl = true;
bool saw = ... | 8 |
#include <bits/stdc++.h>
int MOD = int(1e9) + 7;
inline int add(int a, int b) {
return (a + b >= MOD) ? (a + b - MOD) : (a + b);
}
inline void inc(int &a, int b) { a = add(a, b); }
inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); }
inline void dec(int &a, int b) { a = sub(a, b); }
inline i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inft = 1000000009;
const int MAXN = 1000006;
const double eps = 1e-15;
inline bool iszero(double first) { return first <= eps && first >= -eps; }
int sgn(double first) { return iszero(first) ? 0 : (first < 0 ? -1 : 1); }
struct pt {
int first, second;
int nr;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long s[100010][6];
long long sum[400010][6];
long long num[400010];
long long ans[6];
int n, m;
int x, k;
char ch[3];
int l, r;
long long calc(int l, int r, int k) {
return ((s[r][k] - s[l - 1][k]) % 1000000007 + 1000000007) % 1000000007;
}
void pushup(int rt) {
fo... | 17 |
#include <bits/stdc++.h>
using namespace std;
int arr[5010];
bitset<5010> used;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sort(arr, arr + n);
int visible = 0;
int prev;
for (int i = 0; i < n; i++) {
if (used[i] != 1) {
visible++;
prev = -1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int d, s;
int id;
};
node a[100009], b[100009];
map<int, int> Map;
vector<int> e[100009], vec;
int match[100009];
int vis[100009];
int n, m;
bool cmp(node x, node y) { return x.d > y.d; }
bool find(int x) {
for (int i = 0; i < e[x].size(); i++) {
if ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 3;
int n, a[N];
void init() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
}
int cnt[N];
void solve() {
fill_n(cnt, n + 1, 0);
for (int i = 0; i < n; i++) {
cnt[a[i]]++;
}
vector<int> freq;
for (int i = 0; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e9 + 5;
const double eps = 1e-7;
const double PI = acos(-1.0);
inline void debug_vi(vector<int> a) {
for (long long i = (long long)(0); i < (long long)(a.size()); i++)
cout << a[i] << " ";
}
inline void debug_vl... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
constexpr int lim = 1000001;
vector<int> divisors(lim, 1);
for (int i = 2; i <= lim; i++)
for (int j = i; j <= lim; j += i) divisors[j]++;
int a, b, c;
cin >> a >> b >> c;
int s = 0;
for (int i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int l[7][7], h[7][7], A[7][7], a[36], b[36], sum[7];
int n, m, ans1, ans2, nowans, x, y, tot;
void dfs(int x) {
if (x > tot) {
if (n > 2 && sum[n - 1] != 0) return;
if (sum[1] == ans1) ans2 = max(ans2, nowans);
if (sum[1] < ans1) {
ans1 = sum[1];
a... | 14 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long mod = 1e9 + 7;
long long quick_mod(long long a, long long b) {
long long ans = 1;
a %= mod;
while (b) {
if (b % 2 != 0) {
ans = ans * a % mod;
b--;
}
b /= 2;
a = a * a % mod;
}
return ans;
}
long long judg... | 11 |
#include <bits/stdc++.h>
using namespace std;
int dadsadasda;
const int INF = 0x3f3f3f3f;
const long long LLINF = 1e18;
const int MAXN = 2e5 + 10;
int N, A[MAXN];
int t;
int v[MAXN];
int h[MAXN], in[MAXN], out[MAXN];
vector<int> G[MAXN];
void dfs(int x, int f = -1) {
in[x] = t++;
A[in[x]] = v[x];
for (auto u : G[... | 12 |
#include <bits/stdc++.h>
struct City {
long long g;
long long w;
long long gf;
long long bg;
long long minbg;
};
class Data {
public:
City cities[100000];
int n;
int k;
long long gifts;
long long gas;
long long nextGas;
int maxL;
City* end;
City* head;
City* tail;
City* start;
City* f... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 31;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
char st[N];
vector<string> s;
bool ok = 0;
vector<string> ans;
void check(vector<vector<char> > &v) {
ok = 1;
bool f = 0;
if (!ans.size())
f = 1;
else {
int i1 = 0, i2 = 0;
while (... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {
fin >> pr.first >> pr.second;
return fin;
}
template <class T0, class T1, class T2>
inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {
fin >> get<0>(t) >> get<1>(t... | 16 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
long long int power(long long int x, long long int n) {
if (n == 0)
return 1ll;
else if (n % 2 == 0)
return power((x * x), n / 2);
else
return (x * power((x * x), (n - 1) / 2));
}
int main() {
ios_bas... | 5 |
#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... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int x, k;
cin >> x >> k;
vector<int> v(x + 1);
while (k--) {
int a, b, c;
cin >> a;
if (a == 2) {
cin >> b;
v[b]++;
} else {
cin >> b >> c;
v[b]++;
v[c]++;
}
}
int mn = 0, mx = 0;
for (int i = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, lead;
long long c[50][50], ans;
string sg[2], s, t1 = "000000000000000000", t2 = "999999999999999999",
t3 = "1000000000000000000";
void solve(int pos, int ct, string &l, string &r) {
if (pos > 17 || ct < 0) return;
if (l[pos] == r[pos]) {
if ... | 11 |
#include <bits/stdc++.h>
const int N = 1000005;
bool isp[N], ud[N];
int p[N], cnt, o1[N], o2[N], q[N], n, tp[N], cn, cnum;
inline void pri() {
register long long x;
for (int i = 2; i <= n; i++) {
if (!isp[i]) p[++cnt] = i;
for (int j = 1; (x = 1ll * p[j] * i) <= N && j <= cnt; j++) {
isp[x] = true;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long n, m;
cin >> n >> m;
vector<bool> b(m, 0);
vector<vector<bool>> a1(n, b), a2(n, b);
for (long long i = 0; i < n; ++i) {
for (long long j = 0; j < m; ++j) {
bool t;
cin ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int A[N], n, k;
int L[N], R[N], cnt;
int q1[2 * N], q2[2 * N], h1, r1, h2, r2;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
int maxx = 1;
h1 = 0, r1 = -1, h2 = 0, r2 = -1;
for (int r = 1, l = 1; r <= ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
constexpr int MAXN = 1e6 + 5;
constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr int LOG = 3e1 + 1;
co... | 16 |
#include <bits/stdc++.h>
struct laptop {
size_t a, b;
};
bool operator<(const laptop& lhs, const laptop& rhs) { return lhs.a < rhs.a; }
std::istream& operator>>(std::istream& is, laptop& l) {
return is >> l.a >> l.b;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
size_t n;
std::cin ... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> arr[2000];
bool check(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
int main() {
int dx[4], dy[4];
dx[0] = 1;
dx[1] = -1;
dx[2] = 0;
dx[3] = 0;
dy[0] = 0;
dy[1] = 0;
dy[2] = 1;
dy[3] = -1;
int n, m;
cin >> n >> m;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool chkmax(int &x, int y) { return x < y ? x = y, true : false; }
bool chkmin(int &x, int y) { return x > y ? x = y, true : false; }
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > servers;
void print(int l1, int r1, int l2, int r2) {
cout << "Yes" << endl << r1 - l1 + 1 << " " << r2 - l2 + 1 << endl;
for (int(i) = (l1); (i) < (r1 + 1); ++(i)) cout << servers[i].second << " ";
cout << endl;
for (int(i) = (l2); (i) < (r2... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 3e3 + 10;
const int mod = 998244353;
vector<int> g[maxn];
int n;
long long cnt[maxn][maxn];
long long dp[maxn][maxn], fa[maxn][maxn];
void init(int root, int u, int pa) {
cnt[root][u] = 1;
fa[root][u] = pa;
for (auto to : g... | 15 |
#include <bits/stdc++.h>
struct Solver {
void solve() {
int64_t n;
double P;
std::cin >> n >> P;
auto c2 = [](int n) {
if (n <= 1) {
return 0;
}
return n * (n - 1) / 2;
};
auto c3 = [](int64_t n) { return n * (n - 1) * (n - 2) / 6; };
double total = c3(n);
;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 50;
int n, q, b[N], num[N], h = 0;
int vis[N], st[N], ed[N];
struct node {
int z, id;
} a[N];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long modu = 998244353;
long long power(long long x, long long y) {
long long res = 1;
x = x;
while (y > 0) {
if (y & 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
long long powe(long long x, long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
char s[41][41];
int g[41][41];
int f[41][41][41][41];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
for (int j = 1; j <= m; j++) {
if (s[i][j] == '0')
g[i][j] = g[i][j - 1] + 1;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long mod = 1000000007;
long long expMod(long long base, long long exponente) {
long long res = 1;
while (exponente > 0) {
if ((exponente & 1) != 0) {
res *= base;
res %= mod;
}
base *= base;
base %= mo... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 500000 + 10;
vector<int> adj[NMAX];
char s[NMAX];
int n, m;
vector<int> depMap(NMAX, 0);
vector<vector<int> > depth(NMAX, vector<int>(0, 0));
void updateDepth() {
queue<pair<int, int> > q;
depMap[1] = 1;
depth[1].push_back(1);
q.push(make_pair(1, 1)... | 14 |
#include <bits/stdc++.h>
int main() {
int a[3005] = {0};
int n, v, s, x, y, m, i;
scanf("%d %d", &n, &v);
while (n--) {
scanf("%d %d", &x, &y);
a[x] += y;
}
s = 0;
for (i = 1; i <= 3002; i++) {
m = v;
if (a[i - 1] > 0) {
if (a[i - 1] >= m) {
s += m;
m = 0;
} els... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(2 * n);
for (int i = 0; i < 2 * n; i++) {
cin >> a[i];
}
int ans = 0;
int pos = 0;
while (pos < 2 * n) {
if (a[pos] == a[pos + 1]) {
pos += 2;
continue;
}... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const int inf = 1000111222;
const int max_n = 211;
struct point {
int x, y;
};
long long get_sqr(const point& p1, const point& p2, const point& p3) {
long long res = 0;
res += (p2.x - p1.x) * 1LL * (p1.y + p2.y);
res += ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s, p = "hard";
cin >> n >> s;
vector<long long> c(n);
for (int i = 0; i < n; i++) cin >> c[i];
vector<vector<long long> > dp(n + 1, vector<long long>(5, 1e18));
for (int j = 0; j < 4; j++) dp[0][j] = 0;
for (int i = 0; i < n; i++)
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e4) + 5, inf = int(1e9) + 5;
const int xx[5] = {0, 1, 0, -1, 0};
const int yy[5] = {1, 0, -1, 0, 0};
int n, m, D[maxn], rowD[maxn], colD[maxn];
vector<int> row[maxn], col[maxn];
vector<pair<int, int>> A;
map<pair<int, int>, int> mp;
inline bool valid(i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5, mum = 1e9 + 7;
int n, m;
int tobe[4], F[4][maxn], f[4][maxn], md[4] = {mum, 998244353, mum - 4, mum - 2},
g[34][maxn];
struct node {
int f[4];
bool operator==(const node& A) const {
int num = 0;
for ... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
pair<int, int> fib(int n) {
if (n == 0) return {0, 1};
cout << n << endl;
auto p = fib(n >> 1);
int c = p.first * (2 * p.second - p.first);
int d = p.first * p.first + p.second * p.second;
if (n & 1)
return {d, c + d};
else
ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long p[200001];
long long s[200001];
long long res[200001];
vector<long long> v;
bool cmp(long long i, long long j) { return abs(p[i] - i) < abs(p[j] - j); }
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (long long i = 0; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int q, n, k;
char s[200005];
int pa[200005], push_back[200005], pc[200005];
bool a[200005], b[200005], c[200005];
int main() {
scanf("%d", &q);
for (int z = 0; z < q; z++) {
for (int i = 0; i < n; i++) {
a[i] = false, pa[i] = 0, push_back[i] = 0, pc[i] = 0;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool prec(char c1, char c2) {
if (c1 == c2)
return false;
else if (isdigit(c2)) {
if (c1 > c2)
return true;
else
return false;
} else if (c1 == 'A')
return true;
else if (c1 == 'K' && c2 != 'A')
return true;
else if (c1 == 'Q' && c2... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, vas, pet, cnt = 0, mov;
bool fg = 0;
string s1, s2 = "";
scanf("%d", &(n));
cin >> s1;
mov = (n - 11) / 2;
vas = mov;
pet = mov;
s2 = s1;
reverse(s2.begin(), s2.end());
for (i = 10; i < n; i++) {
if (s2[i] == '8') cnt +... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int K = 3;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const double alpha = 0.75;
long long qpow(long long a, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int now;
stru... | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.