solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9 + 7;
constexpr ll longinf = 1LL << 60;
constexpr ll mod = 1e9 + 7;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
map<pair<int, int>, int> mp;
int n, k... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, unsigned long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) {
res = res * x;
}
y = y >> 1;
x = x * x;
}
return res;
}
long long powermod(long long x, unsigned long long y, long long p) {
long long res = ... | 10 |
#include <bits/stdc++.h>
int main() {
int n2, k2, i;
scanf("%d%d", &n2, &k2);
if (k2 == 1) {
for (i = 1; i < n2; i++) printf("%d ", i);
printf("%d\n", n2);
} else {
if (k2 == n2 - 1) {
for (i = 1; i <= n2 / 2; i++) printf("%d %d ", n2 - i + 1, i);
if (n2 % 2 == 1)
printf("%d\n", ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long x, y, k, ans;
cin >> x >> y;
if (x > y) {
k = x;
x = y;
y = k;
}
if (x == 1) {
k = y / 6;
ans = 6 * k;
if (y % 6 == 4)
ans += 2;
else if (y % 6 == 5)
a... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 6, mod = (int)0;
int pl(int x, vector<int> &a) {
return lower_bound(a.begin(), a.end(), x) - a.begin();
}
int ssz, mn[N << 2], xl[N], xr[N], yl[N], yr[N], cnt[N << 2], ch[N << 2];
vector<int> ax, ay;
void build(int v = 1, int b = 0, int e = ssz) {... | 24 |
#include <bits/stdc++.h>
using namespace std;
string tout[4] = {"NO", "YES", "No", "Yes"};
using vi = vector<int>;
using vll = vector<long long>;
using vld = vector<long double>;
using vch = vector<char>;
using mi = map<int, int>;
using mll = map<long long, long long>;
using msll = map<string, long long>;
using mchll =... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define INF INT_MAX
ll M = 1e9+7;
ll t;
void solve()
{
ll n;
cin>>n;
vector<pair<ll,ll> >vec(n,{0,0});
vector<ll>lrr(n,0);
for(ll i=0;i<n;i++)
{
ll a,b;
cin>>a>>b;
vec[i]={a,b... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e7 + 100;
int n, k;
char s[maxn], t[maxn];
vector<int> ans[maxn];
void findmi(int lpos, int rpos) {
int cnt = 0, tot = 0;
while (1) {
tot++;
int flag = 1;
for (int i = lpos; i <= rpos; i++) {
if (s[i] == 'R... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int M = 500000;
int a[3];
int main() {
while (~scanf("%d%d%d", &a[0], &a[1], &a[2])) {
sort(a, a + 3);
int ans = 0;
for (int i = 0; i < a[1]; i++) {
ans += a[0];
a[0]++;
}
ans *= 2;
a[0]--;
ans += a[0] * (a[2] - a[1] - 1);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpe... | 12 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
for (int i = 0; i * a <= n; i++) {
if ((n - (i * a)) % b != 0) continue;
for (int j = 1; j <= i * a; j ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, k;
cin >> x >> k;
if (x == 0) {
cout << "0\n";
return 0;
}
x = x * 2 - 1;
long long mod = 1000000007, temp = 2;
long long ans = x % mod;
for (int i = 0; i < 63; i++) {
if (k & (1ll << i)) {
ans *= temp;
ans %... | 8 |
#include <bits/stdc++.h>
namespace Helper {
using LL = long long;
const int MAXN = 1e5 + 1;
const int MOD = 1e9 + 7;
const LL INF = 1e18 * 1LL;
template <typename T>
void PrintVector(std::vector<T> v) {
for (typename std::vector<T>::iterator it = v.begin(); it != v.end(); it++) {
std::cout << *it << " ";
}
}
au... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, k;
int a[maxn];
int main() {
std::ios::sync_with_stdio(false);
while (cin >> n >> m >> k) {
for (int i = 1; i <= n; ++i) cin >> a[i];
int tk = k, cnt = 0;
for (int i = n; i >= 1; --i) {
if (tk >= a[i]) {
tk -... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 52 + 20;
const long long oo = 1e18;
const int MOD = 1e9 + 7;
struct st {
st *left, *right;
int mn, l, r, m, lazy;
st(int l, int r) : l(l), r(r), lazy(0), mn(0) {
m = (l + r) / 2;
if (l != r) {
left = new st(l, m);
right = new st(m + 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
bool f = true;
long long x = 0;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = false;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
i... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e6 + 7;
long long a[maxn];
int x, n;
int main() {
scanf("%d", &n);
long long ans = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
a[n - i + x] += x;
ans = max(ans, a[n + x - i]);
}
printf("%lld\n", ans);
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const long long n = 100001;
const long long s1 = 34;
const long long s2 = 32;
const long long s3 = 2;
const string ss1 = "What are you doing while sending \"";
const string ss2 = "\"? Are you busy? Will you send \"";
const string ss3 = "\"?";
const string ini =
"What ar... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long a, b, c, d;
char str[1000000 + 10];
cin >> a >> b >> c >> d;
if (a == 0 && b == 0 && c == 0 && d == 0) {
cout << "0" << endl;
return 0;
}
double x = (1 + sqrt(1 + 8 * a)) * 1.0 / 2,
y = (1 + sqrt(1 + 8 * d)) * 1.0 / 2;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, i, j, c = 0, a, b;
cin >> n >> m;
vector<string> s(n);
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] == '1') {
... | 7 |
#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, k, m, d, s, a, mx, i, x;
cin >> n >> k >> m >> d;
s = n / m;
a = s / k;
if (s % k != 0) a++;
mx = m * a;
for (i = 0; i < d; i++) {
x = n / (i * k + 1);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int arr[n + 1];
long long int sum = 0;
for (int i = 0; i < n; i++) {
char ch;
cin >> ch;
arr[i + 1] = ch - '0';
if (arr[i + 1] % 2 == 0) sum += i + 1;
}
cout << sum << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
double x, y, sum;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (register int i = (1); i <= (n); i++) {
cin >> x >> y;
sum += y;
}
sum /= n;
sum += 5;
printf("%.3lf", sum);
return 0;
}
| 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long k;
long long ans = 0;
for (int i = 1; i <= n; i++) {
cin >> k;
ans += (i * (k - 1));
ans++;
}
cout << ans << "\n";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int kMax = 1000006;
bool cmp1(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.second < p2.second;
}
struct Info {
int st, ed, id;
Info() {}
Info(int st, int ed, int id) {
this->st = st;
this->ed = ed;
this->id = id;
}
};
bool cmp2... | 14 |
#include <bits/stdc++.h>
using namespace std;
int ans, a[10], b[10];
long long tmp[10][19], pw[19];
int main() {
long long lb, ub;
cin >> lb >> ub;
string l = to_string(lb), r = to_string(ub);
if (r == "1" + string(18, '0')) {
if (l == r) cout << "1\n", exit(0);
if (l != "1") ans++;
r = string(18, '... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 123;
const int INF = 1e9 + 123;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
int n;
bool bal[N];
vector<int> ans;
int main() {
ios_base ::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
int x;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, t;
int main() {
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> n >> k;
if (n % k != 0) {
if (n % k < k / 2)
ans = (n / k) * k + n % k;
else
ans = (n / k) * k + (k / 2);
} else
ans = n;
cout << ans <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::locale loc;
string usr;
cin >> usr;
std::replace(usr.begin(), usr.end(), '0', 'O');
std::replace(usr.begin(), usr.end(), '1', 'i');
std::replace(usr.begin(), usr.end(), 'l', 'i');
std::replace(usr.begin(), usr.end(), 'L', 'i');
std::transfo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int>> v;
int main() {
cin >> n;
int t;
for (int i = 0; i < n; i++) {
cin >> t;
v.push_back(make_pair(t, i));
}
sort(v.begin(), v.end());
int cur = v[0].second;
int len = 1;
int lenMax = -1;
for (int i = 1; i < n; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 3, inf = 2e18 + 7;
long long bin_pow(long long a, long long b) {
long long x = 1;
while (b) {
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
}
long long readint() {
long long x = 0, f = 0;
char c = getchar();
while (!isdigit(c)) c... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
int a[300100];
int ans[300010];
int main() {
scanf("%d", &t);
while (t--) {
int n;
int cnt = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
if (i == n - ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxM = 1e5 + 10, maxN = 55;
int N, M, n, m, cnt, res;
int G[maxN + 1][maxN + 1], T[maxN + 1][maxN + 1];
char s[maxN + 1][maxN + 1];
bool flag;
pair<int, int> ans[maxM + 1];
inline void get() {
cnt = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string second;
cin >> second;
int i, j;
i = -1, j = second.size();
vector<int> ans1;
deque<int> dq;
int count = 0;
while (i < j) {
do {
i++;
} while (second[i] != '(' && i < j);
if (i >= j) break;
do {
j--;
} whil... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (b[j] == a[i]) cout << b[j] << " ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MOD2 = 998244353;
vector<int> bases;
const long long int LLINF = 1ll << 60;
const char en = '\n';
void yes() {
cout << "YES" << en;
exit(0);
}
void no() {
cout << "NO" << en;
exit(0);
}
template <class T>
void prVec(vector<T> w)... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
using v = vector<T>;
const ll INF = numeric_limits<ll>::max() / 10 * 9;
const ll TREES = 1e5;
const ll N = 2 * TREES;
ll heights[TREES + 1];
ll dists[TREES + 1];
ll vals[N + 1][2];
struct State {
ll bigsum, biglhs, bigrhs;
};
St... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 85;
int n;
int l[N], r[N];
int pos[N << 1], tot;
double dp[N][N][N];
double ans[N][N];
int st, ed;
void solve(int L, int R, int dep) {
if (L == R) {
if (l[L] <= st && ed <= r[L]) {
for (int j = 0; j <= n; j++)
for (int k = 1; j + k <= n; k+... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 20;
const int mod = 1e9 + 7;
long long fact[N], tavan[N], dp[N];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long n;
cin >> n;
fact[0] = 1;
dp[3] = 2;
for (int i = 1; i <= n; i++)
fact[i] = (((fact[i - 1] * i) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, k, a... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
vector<pair<int, int>> vc[MAXN];
long long dp[MAXN], lz[MAXN << 2], seg[MAXN << 2], c[MAXN];
int n, m;
void input();
void upd(int, int, long long, int, int, int);
void LZ(int);
void solve();
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long n;
bool bsearch(long long mid) {
long long x, y;
if (mid == 0) {
for (long long i = 1; i <= n - 1; ++i) {
if (a[i + 1] >= a[i])
continue;
else
return false;
}
return true;
} else {
x = 1ll << (... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long C[2222], Ans[2222];
int A[2222];
int N, K;
const long long P = 1000000000LL + 7;
long long fast_mod(int x, int y) {
if (y == 0) {
return 1LL;
}
long long ret = fast_mod(x, y >> 1);
ret *= ret;
ret %= P;
if (y & 1) {
ret *= x;
ret %= P;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
string _name[N], text[N];
map<string, int> mp;
int id(string str) {
if (mp.find(str) == mp.end())
return -1;
else
return mp[str];
}
char temp[N];
int vis[N][N], put[N], n, m;
bool check(char ch) {
return ch == '.' || ch == ' ' || ch == ',' |... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1001000, INF = 1e18, MOD = 1000000007;
long long n, l, k, m, q = 1, a[N], b[N], f[N], prefsum[N], z, u, mx, mn, ans;
pair<long long, long long> p[N];
string s;
vector<int> v[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n >> l... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], i, j, k;
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 0; i < n - 1; ++i) {
if (a[i] > a[i + 1]) break;
}
if (i == n - 1) {
cout << "yes\n 1 1\n";
} else {
for (j = 1 + i; j < n; j++) {
if (a[j] > a[j... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 107;
void fll(int n, int *a) {
if (n == 1) {
a[0] = 1;
return;
}
if (n == 2) {
a[0] = 3;
a[1] = 4;
return;
}
if (n % 2) {
a[0] = 2;
for (int i = 1; i < n - 1; ++i) a[i] = 1;
a[n - 1] = (n + 1) / 2;
} else {
fo... | 16 |
#include <bits/stdc++.h>
using namespace std;
char cs[2005];
int main() {
int i, j, k, t1, t2, t3;
int n;
scanf("%d", &n);
scanf("%s", cs);
t1 = strlen(cs);
k = 0;
for (i = n; i < t1; i += n) {
if (cs[i - 1] == cs[i - 2] && cs[i - 1] == cs[i - 3]) ++k;
}
printf("%d\n", k);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 3e5 + 7;
long long int ca[maxn];
long long int cb[maxn];
const long long int mod = 1e9 + 7;
struct qujian {
int len, sum;
};
long long int lowbit(int x) { return x & (-x); }
void update(int x, long long int val, long long int *c) {
while (x < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[10000001 + 1];
int ind[10000001 + 1];
int main() {
int n, ans = 10000001 + 2, out;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", arr + i);
}
for (int i = 0; i <= 10000001; i++) ind[i] = -1;
for (int i = 0; i < n; i++) ind[arr[i]] = max(i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int digit;
vector<long long int> sayilar, sayilar2;
cin >> digit;
if ((digit & 1) == 0) {
cout << -1;
return 0;
}
for (long long int i = 0; i < digit; i++) {
sayilar.push_back(i);
}
for (long long int i = 0; i < digit; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool sortinrev(long long x, long long y) { return x > y; }
void swap(long long* a, long long* b) {
long long temp = *a;
*a = *b;
*b = temp;
}
long long div_ceil(long long a, long long b) { return (a + b - 1) / b; }
long long gcd(long long a, long long b) {
if (b == ... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <int MOD>
class ModInt {
public:
int v;
ModInt() : v(0) {}
ModInt(long long _v) {
v = int((-MOD < _v && _v < MOD) ? (_v) : (_v % MOD));
if (v < 0) v += MOD;
}
friend bool operator==(const ModInt &a, const ModInt &b) {
return a.v == b.v;
}
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
namespace fastio {
char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;
inline char ge... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, r;
cin >> l >> r;
int k = 0;
for (int i = l; i <= r; i++) {
int x = i;
bool b[10];
for (int g = 0; g < 10; g++) b[g] = 0;
int ans = 0, g = 0;
while (x > 0) {
if (b[x % 10] == 0) {
b[x % 10] = 1;
ans += (x... | 0 |
#include <bits/stdc++.h>
const int N = 50000;
const long double PI = acosl(-1);
int n, size, l[N], r[N], bit[2 * N], prev[2 * N], next[2 * N];
long double a[N], b[N];
std::pair<long double, int> event[2 * N];
void extract(long double d) {
size = 0;
for (int i = 0; i < n; ++i) {
long double A = a[i] * a[i] + 1, ... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int suf0 = 0;
int suf1 = 0;
for (int i = 0; i < s.length(); i++) {
suf0 += (s[i] == '0');
suf1 += (s[i] == '1');
}
int ans = min(suf0, suf1);
int pre0 = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a[10] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
string b[10] = {"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool gre(int a, int b) { return a > b; }
set<int> cnt(int n) {
int i = 2;
set<int> s;
s.insert(n);
s.insert(1);
int b = n;
while (n > 0 and i <= sqrt(b)) {
if (n % i == 0) {
s.insert(n / i);
n /= i;
} else
i++;
}
return s;
}
int mai... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, B;
vector<int> R, ans;
vector<int> fo[101];
bool in[101], din[101];
void add_edge() {
int f, t;
if (R.size() > 1) {
t = R.back();
f = R[R.size() - 2];
fo[f].push_back(t);
fo[t].push_back(f);
}
}
int BF, BT;
void dfs1(int vr) {
in[vr] = true... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100002];
int val[100002];
long long inc[100002], decr[100002];
void dfs(int root, int parent) {
for (int node : G[root]) {
if (node == parent) continue;
dfs(node, root);
inc[root] = max(inc[root], inc[node]);
decr[root] = max(decr[root], decr... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool arr[1200006];
bool ch(long long x) {
stringstream ss;
string s;
ss << x;
ss >> s;
for (int i = 0; i <= s.size() / 2; i++)
if (s[i] != s[s.size() - 1 - i]) return 0;
return 1;
}
int main() {
cin.tie(0);
std::ios::sync_with_stdio(false);
for (int i ... | 8 |
/*
*/
#include <bits/stdc++.h>
#define pc putchar
#define gc() getchar()
#define pb emplace_back
typedef long long LL;
const int N=1e5+5;
int A[N],pos[N];
inline int read()
{
int now=0,f=1; char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
}
int main()
{... | 3 |
#include <bits/stdc++.h>
int N, n;
double F, H, K, l[1005], r[1005];
double calc(double x, double y) {
x = abs(x), y = abs(y);
if (x > y) std::swap(x, y);
if (y - K * x > -1e-9) return x * (1 + K) * H;
double h = 2 * H * (K * y - x) / (K - 1) / (x + y),
w = x * (F - H + h) / (F - H);
return ((x + w) ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int gi() {
int res = 0, w = 1;
char ch = getchar();
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
return res * w;
}
const int MAX_N = 2e5 + 5, MAX_Q = 5e5 +... | 20 |
#include <bits/stdc++.h>
using namespace std;
int dest[3123][3123];
bool vis[3123];
vector<vector<int> > adj;
void bfs(int st) {
memset(vis, 0, sizeof vis);
queue<int> q;
q.push(st);
dest[st][st] = 0;
vis[st] = 1;
while (q.size()) {
int u = q.front();
q.pop();
for (int i = 0; i < (int)adj[u].siz... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline int add(int a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
return a;
}
inline int mult(int a, int b) { return (long long)a * b % mod; }
inline int pot(int a, int b) {
int ret = 1;
while (b) {
if (b & 1) ret... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[300000];
int s[2];
int b[300000];
int fp(int a, int k, int m) {
int res = 1;
while (k) {
if (k & 1) res = 1LL * res * a % m;
a = 1LL * a * a % m;
k >>= 1;
}
return res;
}
int main() {
int m, n;
scanf("%d%d", &m, &n);
s[0] = s[1] = 0;
for (i... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int a[maxn], x[maxn];
int main() {
int n;
cin >> n;
int i, j;
for (i = 0; i < n; i++) cin >> a[i];
int sum = 1;
int tmp = 1;
for (i = 0; i < n - 1; i++) {
if (a[i] <= a[i + 1])
tmp++;
else
tmp = 1;
if (tmp >... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
void run(int casenr) {
scanf("%d", &n);
for (int i = (0); i < (n); ++i) {
for (int j = (0); j < (n); ++j) {
if (j != 0) printf(" ");
printf("%d", 1 + n * j + (i + j) % n);
}
puts("");
}
}
int main() {
run(1);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int a[204], vis[204];
int main() {
int n, i, j, k, cnt = 0;
scanf("%d", &n);
for (i = 1; i <= 2 * n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= 2 * n - 1; i++) {
for (j = i + 1; j <= 2 * n; j++) {
if (a[j] == a[i]) {
cnt += j - i - 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0, nb[5] = {0};
while (n--) {
int i;
cin >> i;
nb[i]++;
}
ans = nb[4] + nb[3] + (nb[2] / 2);
nb[2] %= 2;
if (nb[2] > 0) {
if (nb[1] > 1)
nb[1] -= 2;
else if (nb[1] == 1)
nb[1]--;
}
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
}
const int N = 2e5 + 10, K = 30, INF = 0x7fffffff;
int n, a[N];
long long ans;
namespace Trie {
int Next[N << 5... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int T, K;
long long dp[1100][1100];
long long fun(int n, int m) {
if (n == 0) {
if (m == 0) return 1;
return 0;
}
if (dp[n][m] != -1) return dp[n][m];
long long res = (2 * fun(n - 1, (m <= K ? 0 : 1))) % MOD;
res = (res ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int sc[26];
long long t, n, k;
int solve(int k) {
int ans = 0;
for (int m = 1; m * k <= n; m++) {
int used = 0;
for (int i = 0; i < 26; i++) {
if (sc[i] / m + used < k) {
used += sc[i] / m;
} else {
ans = max(ans, m * k);
brea... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int mxor(int x, int y) { return (x | y) & (~x | ~y); }
int isprime(long long n) {
if (n == 1)
return 0;
else if (n... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct jump {
char dir;
int len;
};
const int MAX_M = 100001;
jump grass[MAX_M];
bool viz[MAX_M];
int jumping(jump a) {
if (a.dir == '>')
return a.len;
else
return -a.len;
}
int n;
bool ok(int pos) {
if (pos >= 1 && pos <= n) return 1;
return 0;
}
int ma... | 2 |
#include <bits/stdc++.h>
using namespace std;
int tree[1000005], b[1000005], n, K;
long long ans = 0;
void add(int x, int y) {
for (; x < 1000005; x += (x & -x)) tree[x] += y;
}
int query(int x) {
int ret = 0;
for (; x; x -= (x & -x)) ret += tree[x];
return ret;
}
struct A {
int x, r, q, L, R;
} a[1000005 << ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int distance(const string& a, const string& b) {
assert(a.size() == b.size());
int ans = 0;
for (size_t i = 0; i < a.size(); ++i)
if (a[i] != b[i]) ++ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<string> codes(... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-'; t = getchar())
;
if (t == '-') neg = true, t = getchar();
for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
if ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t;
string s;
vector<int> arr;
vector<vector<int> > dp;
int main() {
int n, m, k;
cin >> n >> m >> k;
string ppc;
cin >> ppc >> ppc;
cin >> s;
t = s.length();
arr.resize(t + 1);
int d = 1;
if (ppc[0] == 'h') d = -1;
arr[0] = k;
if (arr[0] + d < 1 ||... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
bool check(int x) {
int a, b, d, t;
for (auto i : mp) {
int p = i.second;
d = exgcd(x... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, maxx, sum, nn;
int main() {
cin >> n >> m;
if (n == 0 && m == 0) {
cout << "0\n\n0";
return 0;
}
if (n == 0) {
vector<int> vec;
for (int i = 1; i <= m; i++) {
if (i > m) break;
vec.push_back(i);
m -= i;
}
cout << "... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 67;
long long ans[MAXN], nans;
int main() {
long long n;
while (cin >> n) {
nans = 0;
long long p, l, r, m;
for (p = 1; p - 1 <= n; p *= 2) {
l = 1, r = min(n / p, 1LL << 31);
while (l < r) {
m = (l + r) >> 1;
lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve(vector<pair<int, int>> arr) {
int n = arr.size(), sum = 0;
for (int i = 0; i < n; i++) sum += arr[i].first;
int mh = max(arr[0].second, arr[1].second),
sh = min(arr[0].second, arr[1].second),
mi = arr[0].second > arr[1].second ? 0 : 1;
for (in... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 2500, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, a[N][N];
bitset<N> b[N];
pair<int, pair<int, int> > q[N * N];
int main() {
ios_base::sync_with_stdio(0);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, num, h[50010], len[50010], son[50010], tmp[50010 << 1], *id = tmp,
*f[50010];
long long ans = 0;
struct node {
int to, next;
} mp[50010 << 1];
inline void ins(int x, int y) {
mp[++num].to ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c;
long long origA, origB, origC;
scanf("%lld%lld%lld", &a, &b, &c);
origA = a;
origB = b;
origC = c;
long long ans = 9000000000000000000ll;
for (int day1 = 0; day1 < 4; day1++) {
for (int day2 = 0; day2 < 4; day2++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long num(long long n) {
long long s = 0, t, m = 0;
while (n) {
t = n % 10;
if (t > 0) s = s * 10 + t;
n = n / 10;
}
while (s) {
t = s % 10;
m = m * 10 + t;
s = s / 10;
}
return m;
}
int main() {
ios_base::sync_with_stdio(0);
long... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
if (a == 0) return b;
if (b == 0) return a;
if (a == b) return a;
if (a > b) return gcd(a % b, b);
return gcd(a, b % a);
}
long long power(long long x, long long y);
long long modInverse(long long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int con[1000];
bool bet(double val, double a, double b) {
return (val >= a - 1e-8 && val <= b + 1e-8) ||
(val >= b - 1e-8 && val <= a + 1e-8);
}
struct point {
double x, y, z;
point() {}
point(double _x, double _y, double _z) {
x = _x, y = _y;
z = _... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k, q;
string s;
void solve() {
set<int> zero, one;
for (int i = 0; i < n; i++) {
if (s[i] == '0')
zero.insert(i);
else
one.insert(i);
}
while (k > 0 && zero.size() > 0 && one.size() > 0) {
auto it0 = zero.begin(), it1 = one.b... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i < n - 1; i++) {
for (int j = 1; j < n - 1; j++) {
if (a[i][j] == 'X') {
if (a[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, lef[3000], rig[3000], last, ans;
char dom[3000];
scanf("%d", &n);
last = -1;
for (i = 0; i < n; ++i) {
scanf(" %c", &dom[i]);
if (dom[i] == 'L') {
last = -1;
} else if (dom[i] == 'R') {
last = i;
}
lef[i] = la... | 3 |
#include <bits/stdc++.h>
using namespace std;
char M[1000][1001], dir[100000];
int S[4][1000][1000], len[100000], attx[26], atty[26], atcnt;
int d[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid[26];
int num(char c) {
switch (c) {
case 'N':
return 0;
break;
case 'E':
return 1;
b... | 9 |
#include <bits/stdc++.h>
const double pi = acos(-1.0);
using namespace std;
inline long long MAX2(long long a, long long b) {
return (a) > (b) ? (a) : (b);
}
inline long long MAX3(long long a, long long b, long long c) {
return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long MIN2(l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int e[100005];
int o[100005];
int arr[100005];
int main() {
int n;
cin >> n;
int ke = 0, ko = 0;
for (int i = 0; i < n; ++i) cin >> arr[i];
for (int i = 0; i < n; ++i) {
if (arr[i] < 0) {
if ((-arr[i]) % 2 == 1)
o[ko++] = arr[i];
else
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char num1[n];
char num2[n];
for (int i = 0; i < n; i++) cin >> num1[i];
for (int i = 0; i < n; i++) cin >> num2[i];
sort(num1, num1 + n);
sort(num2, num2 + n);
int s1 = 0;
int s2 = 0;
int m = 0;
int j;
for (int i = 0; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, a, b, c, cups, medals;
cin >> a >> b >> c;
cups = a + b + c;
cin >> a >> b >> c >> n;
medals = a + b + c;
if (ceil(cups / 5.0) + ceil(medals / 10.0) <= n)
cout << "YES";
else
cout << "NO";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, D;
cin >> N >> D;
vector<int> s;
multiset<int> p;
multiset<int>::iterator it;
int x;
for (int i = 0; i < N; i++) {
cin >> x;
s.push_back(x);
}
for (int i = 0; i < N; i++) {
cin >> x;
p.insert(x);
}
int sD = s[D - 1];... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.