solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
template <typename T>
using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <typename T>
using max_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
using namespace std;
int main() {
ios_base::sync_with_std... | 1 |
#include <bits/stdc++.h>
using namespace std;
int isPrime[1000005];
void pre() {
for (long long int i = 2; i < 1000005; i++) isPrime[i] = 1;
for (long long int i = 2; i < 1000005; i++)
if (isPrime[i]) {
for (long long int j = i * i; j < 1000005; j += i) isPrime[j] = 0;
}
}
vector<int> prefix;
int firs... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 505;
int n, a[max_n];
int dp[max_n];
vector<int> stk;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= n; i++) {
dp[i] = i;
stk.clear();
for (int j = i; j >= 1; j--) {
int x = a[j];... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(1e7) + 5;
int pr[N];
vector<int> primes;
unsigned long long P[N];
bool PODHODIT(unsigned long long n) {
for (int i = 0; i < primes.size(); i++) {
unsigned long long sn = n;
unsigned long long counter = 0;
while (sn) {
sn /= primes[i];
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt[200009], spec[2000009], node1 = 1e9, ans, mx, node2 = 1e9;
vector<int> v[2000009];
void dfs(int node, int p, int h, int &bstnode) {
if ((h > mx || (h == mx && node < bstnode)) && spec[node])
mx = h, bstnode = node;
for (auto i : v[node])
if (i != p... | 14 |
#include <bits/stdc++.h>
using std::make_pair;
using std::pair;
const int N = 1000 + 10;
std::vector<std::tuple<int, int, int>> edges;
std::vector<int> neighbors[N];
int weights[N], size[N], father[N], n;
namespace union_set {
int ancestor[N], size[N];
void init(int n) {
for (int i = 1; i <= n; ++i) {
ancestor[i]... | 19 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
char buf[1 << 21], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;
inline int read() {
int x = 0, sign = 0;
char s =
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
? EOF
: *p1++);
while (!isdigit(s))... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MOD = 1e9 + 7;
int l[MAXN], r[MAXN];
int inv(int x) {
int ans = 1;
for (int b = MOD - 2; b; b >>= 1) {
if (b & 1) ans = 1LL * ans * x % MOD;
x = 1LL * x * x % MOD;
}
return ans;
}
int d(int i) {
int a = max(0, min(r[i], r... | 17 |
#include <bits/stdc++.h>
int main(void) {
long long int n;
scanf(" %lld", &n);
long long int pos = 0;
for (int i = 1;; i++) {
if (pos + i >= n) {
break;
}
pos += i;
}
long long int r = 0;
while (pos < n) {
pos++;
r++;
}
printf("%lld\n", r);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k, a, b;
cin >> k >> a >> b;
long long an = a / k;
long long ans = b / k;
long long aa = a % k;
long long bb = b % k;
bool fl = true;
if (aa > (ans * k) || bb > (an * k)) fl = false;
if (fl == false)
cout << "-1" << endl;
else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[20005], maxflow = 0;
int n, m, g, sex[20005], v[20005], w[2005], k[2005], b[2005];
int S, T, vis[20005], sign[20005], head[20005], len = 1, cnt = 0;
struct way {
int num, next, cap;
} G[20005 * 6 + 5];
void link(int x, int y, int z) {
G[++len] = (way){y, head[x], ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int maxn = 2009;
int a[maxn], b[maxn];
int q[maxn * maxn];
int mm[maxn];
int pos[maxn];
int ql, qr;
int cur;
int n;
struct segtree {
int maxx[maxn * 4], pos[maxn * 4];
void build(int o, int L, int R) {
if (L == R) {
maxx... | 15 |
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 0x7FFFFFFF;
long long INFF = 0x7FFFFFFFFFFFFFFF;
double PI = acos(-1.0);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
inline void scanf(int &d1) { scanf("%d", &d1); }
inline void scanf(int &d1, int &d2) {... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7;
int n, x;
map<int, int> mp;
int f[N], inv[N];
int inverse(int b) {
int p = mod - 2, ret = 1;
while (p) {
if (p & 1) ret = 1ll * ret * b % mod;
b = 1ll * b * b % mod;
p >>= 1;
}
return ret;
}
int choose(int n, int r) ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long get_ans(long long n, long long k) {
while (true) {
if (k % 2 == 0) {
return k / 2 + 1;
}
long long cnt = (k / 2 + 1);
k += n - cnt;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long inline gcd(long long x, long long y) {
return !y ? (long long)abs(x) : gcd(y, x % y);
}
long long inline lcm(long long a, long long b) {
return ((long long)abs((a / gcd(a, b)) * b));
}
double inline cartesian_dist(double x1, double y1, double x2, double y2) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> divisors[100010];
int a[100010];
long long exp(long long a, int k) {
long long ans = 1LL;
if (a >= 1000000007LL) a %= 1000000007LL;
while (k) {
if (k & 1) ans *= a, ans %= 1000000007LL;
a *= a;
a %= 1000000007LL;
k >>= 1;
}
return ans;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
long long int a, b, c;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> a >> b >> c;
long long int z;
z = (a + b + c) / 2;
long long int k;
k = (a + b + c) % 2;
if (k == 0)
cout << z << endl;
else {
long long... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
void solve() {
cin >> n >> x >> y;
int z = (y - x);
set<int> d;
for (int i = 1; i * i <= z; i++) {
if (z % i == 0) {
d.insert(i);
d.insert(z / i);
}
}
int a = 0;
int dif = 0;
long long int last = 1000000007;
for (auto j : d... | 4 |
#include <bits/stdc++.h>
int n, k;
double point[310][310], area[310];
int main(void) {
int i, j, l;
double max, y;
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) {
for (j = 0; j <= k; j++) scanf("%lf", &point[i][j]);
}
int T = 2000;
for (i = 0; i < k; i++) {
for (j = 0; j <= T; j++) {
max ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int P[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
};
bool isPrime(int n) {
for (int i = 2; i < n; ++i) {
if ((n % i) == 0) return false;
}
return true;
}
bool call(int n) {
int cnt = 0;
for (int i = 0; i < 15; ++i) {
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x) {
x = 0;
int f = 1;
while (*cp < '0' || '9' < *cp) {
if (*cp == '-') f = -1;
cp++;
}
while ('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
x *= f;
}
const int MA... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int prime[5 * MAXN + 100];
int p[5 * MAXN + 100][100];
int vis[5 * MAXN + 100];
int vis_times[5 * MAXN + 100];
int val[MAXN * 5 + 100];
void start() {
for (int i = 2; i <= 5 * MAXN; i++) {
if (!prime[i]) prime[++prime[0]] = i;
for (int j = 1;... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 2 == 0)
cout << (n / 2) << endl;
else
cout << -(n / 2 + 1) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ans = 2 * n;
int arr[2 * n];
int c1 = 0;
int c2 = 0;
for (int i = 0; i < 2 * n; i++) {
cin >> arr[i];
if (arr[i] == 1)
c1++;
else
c2++;
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, s = 0;
cin >> a;
string c;
for (int i = 0; i < a; i++) {
cin >> c;
if (c[c.size() - 2] == 'p' && c[c.size() - 1] == 'o') {
cout << "FILIPINO" << endl;
} else if (c[c.size() - 4] == 'd' && c[c.size() - 3] == 'e' &&
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double sn = 1e-6;
int n;
map<int, long long> mpp;
map<long long, int> dp;
map<long long, bool> vis;
int mex(set<int> &s) {
int c = 0;
while (s.find(c) != s.end()) c++;
return c;
}
int grundy(long long v) {
if (v == 0) return 0;
if (vis[v]) return dp[v];
se... | 14 |
#include <bits/stdc++.h>
using namespace std;
string a[210], b[210];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (int i = 1; i <= n; ++i) {
if (b[i] == "rat") cout << a[i] << endl;
}
for (int i = 1; i <= n; ++i) {
if (b[i] == "woman" || b[i] == "child") cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int a[n], b[n];
long long sumo = 0, sume = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
if (i % 2 == 0) {
sumo = sumo + a[i];
b[i] = sumo;
} else {
sume = sume + a[i];
b[i] = sume;
}
}
int p... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
char str[N][N];
int a[N], vis[N], len;
char ans[N];
bool match(int i) {
int l = strlen(str[i]);
if (l != len) return 0;
for (int j = 0; j < len; j++)
if (ans[j] != '?' && str[i][j] != ans[j]) return 0;
return 1;
}
int main() {
int m, n;
wh... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const N = 5 * 1000 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;
int t, l, r;
int p[N];
ll dp[N];
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
cin >> t >> l >> r;
ll inf = 9e18;
fill_n(dp + 2, r, inf);
for (int i = 2; i <= r; +... | 10 |
#include <bits/stdc++.h>
using namespace std;
char a[10001];
int main() {
cin >> a;
int ans = 0;
for (int i = 0; i < strlen(a); i++) {
if (a[i] == 'A')
ans += 1;
else if (a[i] == '1')
ans += 10;
else
ans += a[i] - '0';
}
cout << ans;
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string second;
cin >> second;
bool u = 0, l = 0, dig = 0;
if (second.size() < 5) return cout << "Too weak", 0;
for (int i = 0; i < second.size(); i++) {
if (islower(second[i])) l = 1;
if (isupper(second[i])) u = 1;
if (isdigit(second[i])) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long T;
cin >> T;
while (T--) {
long long n;
cin >> n;
long long pos[n + 1];
long long a[n];
long long i, j, k, l;
for (i = 0;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char mas[2][2], mas1[2][2], Prob[2][2];
cin >> s;
mas[0][0] = s[0];
mas[0][1] = s[1];
cin >> s;
mas[1][0] = s[0];
mas[1][1] = s[1];
cin >> s;
mas1[0][0] = s[0];
mas1[0][1] = s[1];
cin >> s;
mas1[1][0] = s[0];
mas1[1][1] = s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> strs(n);
for (int i = 0; i < n; i++) {
cin >> strs[i];
}
map<int, int> counters;
set<int> cont;
vector<int> contV;
int specNuls = 0;
for (int i = 0; i < n; i++) {
string curr = strs[i];
int q = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> count_;
int n, a[100007], sum;
int main() {
sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
long long res = 0;
int temp = 0;
for (int i = 1; i < n; i++) {
temp += a[i];
if (temp % 2 == 0 && temp / 2 =... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto &x : a) cin >> x;
vector<int> even, odd;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
even.push_back(a[i])... | 7 |
#include <bits/stdc++.h>
int main() {
long long i, n;
scanf("%I64d", &n);
if (n >= 0) {
printf("%I64d", n);
} else {
if ((n - (n % 10)) / 10 > ((n - (n % 100)) / 10) + (n % 10)) {
printf("%I64d", ((n - n % 10) / 10));
} else {
printf("%I64d", ((n - n % 100) / 10) + (n % 10));
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void edit(vector<int> &skill, int n) {
for (int i = 0; i < n; i++) {
int x;
cin >> x;
skill.push_back(x);
}
}
void achilles() {
int n, l, r, x;
cin >> n >> l >> r >> x;
vector<int> diff;
int ans = 0;
edit(diff, n);
sort(diff.begin(), diff.end());... | 6 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll pwr(ll a, ll b){
ll res=1;
while(b>0){
if(b&1)
res=res*a;
a*=a;
b>>=1;
}
return res;
}
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n;
ll r[n];
for(int i=0;i<n;i++)
cin>>r[i];
cin>>m;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int primes[17] = {2, 3, 5, 7, 11, 13, 17, 19, 23,
29, 31, 37, 41, 43, 47, 53, 59};
int N, A[110], dp[110][1 << 17], s[60];
const int Field = 0x1FFFF;
int main() {
scanf("%d", &N);
int i;
for (i = 0; i <= N - 1; i++) scanf("%d", &A[i])... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
double f[MAXN], p[MAXN], ans, lst = 1, g;
inline int read() {
int x = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
inline double calc(int x) ... | 19 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:3336777216")
using namespace std;
int IT_MAX = 1 << 19;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
int bit[26][10... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, pos = -1, min = 1000000001, max = -1;
bool flag = false;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
if (a <= min && b >= max) {
pos = i;
min = a;
max = b;
flag = true;
} else if (a < min) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s, s2, s3;
cin >> s >> s2 >> s3;
if (s[1] == '<') swap(s[0], s[2]);
if (s2[1] == '<') swap(s2[0], s2[2]);
if (s3[1] == '<') swap(s3[0], s3[2]);
if (s[0] == s2[0])
cout << s3[2] << s3[0] << s[0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int find_mx1(string s) {
int cnt = 0;
vector<int> temp;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
cnt++;
else
cnt--;
temp.push_back(cnt);
}
return *max_element(temp.begin(), temp.end());
}
int find_mx2(string s) {
int cnt = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, flag;
int dx[5] = {1, -1, 0, 0}, dy[5] = {0, 0, 1, -1};
char s[1505][1505];
int vis[1505][1505][3], a[1505][1505];
void dfs(int x, int y, int px, int py) {
if (flag) return;
if (vis[x][y][0] && (vis[x][y][1] != px || vis[x][y][2] != py)) {
flag = 1;
re... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
for (int q = 1; q <= t; q++) {
long long int n, k;
cin >> n >> k;
bool fl = true;
for (long long int i = 2; i * i <= n; i++) {
if (n % i == 0) {
n += i;
fl = false;
break;
}
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
char c = getchar();
bool f = 0;
x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
if (f) x = -x;
return x;
}
template <class t, class... A>
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn(100005);
int n, ans, mx, len[maxn];
string s[maxn];
int main() {
int i, j, c, cnt, lmx, rmx, nmx;
ios ::sync_with_stdio(false);
cin >> n;
for (i = 1; i <= n; ++i) cin >> s[i], len[i] = s[i].size();
for (c = 0; c < 26; ++c) {
mx = cnt = 0;
fo... | 15 |
#include <bits/stdc++.h>
template <typename T>
inline void rd(T& x) {
int si = 1;
char c = getchar();
x = 0;
while (!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... arg... | 14 |
#include <bits/stdc++.h>
int main() {
char s[100];
int l = 0, i, j, max = 0, li = 0;
scanf("%s\n", s);
while (s[l] != '\0') {
l++;
}
for (i = 0; i < l; i++) {
if (s[i] != 'A' && s[i] != 'E' && s[i] != 'I' && s[i] != 'O' &&
s[i] != 'U' && s[i] != 'Y') {
s[i] = '1';
}
}
for (i = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int mod = (int)1e9 + 7;
int a[N];
int stk[N];
int prv[N], nxt[N];
int add(int a, int b) { return (a + b) % mod; }
int sub(int a, int b) { return (a - b + mod) % mod; }
int mul(int a, int b) { return (long long)a * b % mod; }
int fit(int len, int... | 17 |
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 5005
int n, ans[N];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
int lst = 0, res = 0;
for (int i = 2; i <= n; i++)
{
printf("? 1 %d\n", i - 1);
printf("%d\n", i);
for... | 19 |
#include <bits/stdc++.h>
FILE *_stderr = freopen("nul", "w", stderr);
using std::pair;
using std::vector;
template <class T>
inline vector<T> &operator<<(vector<T> &x, const T &y) {
x.push_back(y);
return x;
}
using std::map;
using std::set;
template <class T>
inline set<T> &operator<<(set<T> &x, const T &y) {
x.... | 18 |
#include <bits/stdc++.h>
template <typename T>
inline T max(T a, T b) {
return a > b ? a : b;
}
template <typename T>
inline T min(T a, T b) {
return a < b ? a : b;
}
template <typename T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <typename T>
inline bool repr(T &a, T b) {
return a < b ? a = b, 1 : ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3;
long long q;
int main() {
cin >> q;
for (long long j = 0; j < q; ++j) {
long long n, r;
cin >> n >> r;
--r;
long long sum = 0;
for (long long i = 0; i < n - 1; ++i) {
long long x;
cin >> x;
--x;
sum +=... | 16 |
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
const int N = 100050;
const int mod = 998244353;
int f[N], invf[N];
int c(int n, int k) {
return f[n] * 1ll * invf[k] % mod * invf[n - k] % mod;
}
void solve() {
int n;
scanf("%d", &n);
string s;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, i, j;
cin >> N;
vector<long long> A(N + 1), F(N + 1), G(N + 1), Pre(N + 1, 0);
for (i = 1; i <= N; ++i) {
cin >> A[i];
Pre[i] = Pre[i - 1] + A[i];
}
long long L = Pre[N];
F[N] = Pre[N];
for... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, t[200007], h[200007], a[800007], b[800007], c[800007],
d[800007];
void BT(long long x, long long l, long long r) {
if (l == r) {
a[x] = 2 * h[l] + t[l];
b[x] = 2 * h[l];
c[x] = t[l];
d[x] = 0;
return;
}
long long m1 = (l + r) / ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long nb, ns, nc, pb, ps, pc;
long long cnt[3] = {0};
long long r;
bool can(long long m) {
long long cb = pb * (max(m * cnt[0] - nb, 1LL * 0));
long long cs = ps * (max(m * cnt[1] - ns, 1LL * 0));
long long cc = pc * (max(m * cnt[2] - nc, 1LL * 0));
if (r >= cb ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int __ = 5e5 + 5;
struct DisjointSetUnion {
int pre[__];
DisjointSetUnion() { clear(); }
void un(int x, int y) {
x = fd(x), y = fd(y);
if (x == y) return;
if (pre[x] > pre[y]) swap(x, y);
pre[x] += pre[y], pre[y] = x;
}
int fd(int x) {
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j;
double y1, y2, yw, x, y, r;
scanf("%lf%lf%lf%lf%lf%lf", &y1, &y2, &yw, &x, &y, &r);
if (y2 - y1 <= 2 * r) {
puts("-1");
return 0;
}
yw -= r;
y1 += r;
double x0 = (yw - y1) * x / (2 * yw - y1 - y);
double d2 =
x0 * x0 * ... | 12 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef pair<double, double> pd;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef vector<vector<pi>> vvpi;
typedef vector<pi> vpi;
ll INF = 2e18;
double eps = 1e-12;
#define forn(i, e) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long X, K;
long long fastmod(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
long long tmp = (fastmod(a, b / 2)) % MOD;
tmp = (tmp * tmp) % MOD;
if ((b % 2) != 0) return (tmp * a) % MOD;
return tmp;
}
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, MAX = 0;
bool used[2050];
vector<vector<long long> > s;
long long dfs(long long i, long long len) {
used[i] = 1;
MAX = max(MAX, len);
long long ans = len;
for (int j = 0; j < s[i].size(); j++) ans = dfs(s[i][j], len + 1);
return ans;
}
int main() {... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<int> s;
vector<int> v;
int a, b, m, r0, K, j = 0;
scanf("%d %d %d %d", &a, &b, &m, &r0);
while (true) {
K = (a * r0 + b) % m;
if (s.find(K) != s.end()) {
for (int i = 0;; i++) {
if (v[i] == K) {
printf("%d\n", j - i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[155][6], dem[155], cost[155], tong[155];
void nhap() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 5; j++) {
cin >> a[i][j];
if (a[i][j] != -1) dem[j]++;
}
}
void init() {}
void solve() {
for (int them = 0; them <= 31 * n +... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
struct Sofa {
int x[2], y[2];
int l, r, t, b;
} a[N];
int cntX[N], cntY[N];
int d, n, m;
int cntL, cntR, cntT, cntB;
int main() {
ios::sync_with_stdio(false);
cin >> d;
cin >> m >> n;
fo... | 12 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
template <typename T>
std::istream& operator>>(std::istream& input, std::pair<T, T>& data) {
input >> data.first >> data.second;
return input;
}
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& data) {
f... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, f, e, k, p, ans = 0, rs = 0;
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
k = min(min(b, c), d);
ans += f * k;
p = d - k;
p = min(a, p);
ans += e * p;
k = min(a, d);
rs += k * e;
p = d - k;
p = min(min(b, c), p);
rs += ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void print(int n, int p) {
int x = 2 * n + p;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
printf("%d %d\n", i, j);
x--;
if (x == 0) break;
}
if (x == 0) break;
}
}
int t;
int main() {
scanf("%d", &t);
for (int i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int ri() {
int x;
scanf("%d", &x);
return x;
}
const int N = 100000, NN = 262144;
const int64_t NINF = -1e15;
int d[N * 2], h[N * 2];
int64_t L[N * 2], R[N * 2];
struct P {
int64_t L, R, S;
P operator+(const P &o) const {
return {max(L, o.L), max(R, o.R), max(... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, d, a[500400], t[500400];
bool u[500400];
int q[500400], st = 0, fi = 0;
void add(int x) {
for (int i = 500400 - 1; i >= x; --i) u[i] |= u[i - x];
}
void read(void) {
cin >> n >> d;
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
}
void kill(void) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long bin_pow(int a, int b) {
long long d = a;
long long res = 1;
while (b > 0) {
if (b & 1) {
res = res * d;
}
d = d * d;
b = b / 2;
}
return res;
}
int main() {
int n;
cin >> n;
int t = 2 * n - 2;
int p = (t - n + 1);
int extr... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
long long best = 8e18;
for (int m = 1; m <= 18; ++m) {
for (int x = 0; x <= 9; ++x) {
int sum = 0;
for (int i = 0; i <= k; ++i) sum += (x + i) % 10;
if (... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, s, sum;
int main() {
cin >> a >> b >> s;
sum = abs(a) + abs(b);
s -= sum;
if (s >= 0 && s % 2 == 0)
cout << "Yes";
else
cout << "No";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<long long> a(n);
multiset<long long> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> y(31);
y[0] = 1;
for (int i = 1; i < 30; i++) y[i] ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int sq(int z) { return z * z; }
int INF = 1000 * 1000 * 1000 + 91;
int ox, oy, n;
int xs[27], ys[27];
int d[27][27];
int len[1 << 24], from[1 << 24];
int main() {
cin >> ox >> oy >> n;
for (int i = 0; i < n; i++) cin >> xs[i] >> ys[i];
xs[n] = ox, ys[n] = oy;
for (i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, r;
int cnt, total;
int simul(int a, int b) {
if (b == 0)
return a;
else {
if (a > b) {
if (a % b == 0) {
cnt += a / b - 2, total += a / b;
return simul(b, 0);
} else {
cnt += a / b - 1, total += a / b;
return si... | 13 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
typedef long int LI;
typedef unsigned long int ULI;
typedef long long int LL;
typedef unsigned long long int ULL;
LL mod = 1e9 + 7;
inline int scanInt() {
int n = 0;
char ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (c... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 52;
char a[N][N];
bool block[N][N];
bool vis[N][N];
int n, m;
int tot;
void build_wall() {
int i, j;
for (j = 0; j <= m + 1; j++) {
a[0][j] = a[n + 1][j] = '.';
}
for (i = 0; i <= n + 1; i++) {
a[i][0] = a[i][m + 1] = '.';
}
}
const int Dir[4... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, answerN = 1, ans[10000];
cin >> n >> m;
string s[100];
int k = 0;
for (int i = 0; i < n; i++) cin >> s[i];
for (int j = 0; j < m; j++) {
int max = 0;
for (int i = 0; i < n; i++) {
if (s[i][j] - '0' > max) {
max = s[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
struct TPoint {
double x, y;
};
typedef struct TLine {
double a, b, c;
} TLine;
double max(double a, double b) { return a > b ? a : b; }
double min(double a, double b) { return a < b ? a : b; }
double dis(TPoint p1, TPoint p2) {
return sqrt((p... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int t, n, m, a, b, x, k, y, q, M = 1e9 + 7;
float ans(long long int sum, long long int n) { return (float)sum / (float)n; }
long long int cntless(long long int x) {
long long int ans = 0;
for (long long int i = 1; i <= n; i++) {
ans += (min((x - 1) / i, m)... | 10 |
#include <bits/stdc++.h>
int in() {
int x = 0;
char c = getchar();
bool f = 0;
while (c < '0' && c > '9') f |= c == '-', c = getchar();
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? -x : x;
}
long long lin() {
long long x = 0;
char c = getchar();
bool f... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] >= 'A' && s[0] <= 'Z') {
cout << s;
return 0;
}
s[0] -= 32;
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> factors(long long x) {
vector<long long> v;
for (long long i = 1; i * i <= x; i++) {
if (x % i == 0) {
v.push_back(i);
if (i != x / i) {
v.push_back(x / i);
}
}
}
return v;
}
bool chk(string s, string t) {
int i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
int main() {
cin >> n >> m >> s;
if (m == 0) {
cout << s << "\n";
return 0;
}
int vt;
for (vt = 0; vt < n; ++vt)
if (s[vt] == '.') break;
if (vt >= n) {
cout << s << "\n";
return 0;
}
int i;
for (i = vt + 1; i < n; +... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d = 0;
cin >> n;
char c;
string s;
for (int i = 0; i < n; ++i) {
cin >> c;
if (c == '0') {
s += '0' + d;
d = 0;
} else {
d++;
}
}
if (c == '0') {
s += '0';
} else {
s += '0' + d;
}
cout << s <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string j, l = "";
getline(cin, j);
int i = 0;
while (i < j.length()) {
while (i < j.length() && j[i] == ' ') i++;
if (j[i] == ',') {
cout << ",";
if (i != j.length() - 1) cout << " ";
l = "c";
i++;
} else if (j[i] == ... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
if (n == 1 && m == 1) {
cout << "YES\n1\n";
return 0;
}
if (max(n, m) <= 2 || (min(n, m) <= 2 && max(n, m) == 3)) {
cout << "NO" << endl;
return 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
cout << n + (k - n % k) << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
struct Node {
int l, r, id;
} a[N];
long long flag[N], pre[N];
long long ans[N], Ans = 0;
int cn[N];
int n, m, k;
int L = 1, R = 0;
bool cmp(Node a, Node b) {
if (cn[a.l] == cn[b.l]) return a.r < b.r;
return a.l < b.l;
}
void add(int x) {
Ans ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, deg[N], mn = 1e9, mx, dep[N];
vector<int> adj[N];
void dfs(int x, int p = -1) {
if (adj[x].size() == 1) mn = min(mn, dep[x]);
mx = max(mx, dep[x]);
for (auto& u : adj[x]) {
if (u == p) continue;
dep[u] = dep[x] + 1;
dfs(u, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int from, to;
long long cost;
};
signed main() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
vector<int> ans(n);
vector<bool> use(n + 1, false);
vector<int> zero... | 5 |
#include <bits/stdc++.h>
using namespace std;
int mem[505][505], tot[505], vis[505];
char s[505];
int adj(int a, int b) {
if (s[a] == s[b]) return 1;
if (s[a] - s[b] == 1 || s[a] - s[b] == -1) return 1;
return 0;
}
int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
memset(mem, 0, sizeof(mem));
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int maxDiv[1000005];
int tree[1000005 * 6];
void init(int node, int b, int e) {
if (b == e) {
tree[node] = INT_MAX;
return;
}
int Left = node * 2;
int Right = node * 2 + 1;
int mid = (b + e) / 2;
init(Left, b, mid);
init(Right, mid + 1, e);
tree[node... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, qwq, a[70], in[70], s[70], t[70], tot, tt, ts, cnt[1 << 15], f[70],
num[70], ss;
long long ans = 1, sum, dp[65][1 << 15], fac[70], inv[70], inc[70];
queue<int> q;
const int mod = 1e9 + 7;
void init() {
fac[0] = inv[0] = inv[1] = inc[0] = inc[1] = 1;
for (int ... | 27 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.