solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int p = 1000000007;
int lowbit(int x) { return x & (-x); }
int fast_power(int a, int b) {
int x;
for (x = 1; b; b >>= 1) {
if (b & 1) x = 1ll * x * a % p;
a = 1ll * a * a % p;
}
return x % p;
}
char st[105];
int a[105];
bool cm... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int day = 0;
for (int i = 0; i < n; i++) {
cout << arr[i] / k << " ";
arr[i + 1] = arr[i + 1]... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans[1007];
int res[1007];
int f(int u) {
for (int i = 2; i <= u; i++) {
if (u % i == 0) return i;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, ans;
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
T res = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
res = (res << 3) + (res << 1) + c - '0';
c = getchar();
}
x = res * f;
}
const long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
bool ans = true;
for(int i=0; i<n; i++){
int a; cin >> a;
if(a % 2 == 1){
ans = false;
break;
}
}
if(ans) cout << "second" << endl;
else cout << "first" << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, e, f, g, h, i, d;
cin >> a >> b >> c;
e = a + b + c;
f = 2 * (a + b);
g = 2 * (b + c);
h = 2 * (c + a);
if (e < f) {
i = e;
} else {
i = f;
}
if (g < h) {
d = g;
} else {
d = h;
}
if (i < d) {
cout << i... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
set<string> u;
int n, m, cnt;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
cin >> s;
u.insert(s);
}
for (int i = 0; i < m; i++) {
cin >> s;
if (u.find(s) != u.end()) cnt++;
}
n = (n - cnt) + cnt % 2, m = m - cnt;
... | 2 |
#include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
int mox[2][2]={{1,-1},{0,-1}},moy[2][2]={{-1,1},{-1,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
if(then==-1)then=3;
if(x==0&&y==0){
cout<<endl;
exit(0);
}
for(int i=0;i<4;i++){
int now=(t... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
char s[30];
sprintf(s, "%X", a);
int ans = 0;
for (int(i) = (0); (i) < (strlen(s)); i++) {
switch (s[i]) {
case '4':
case '6':
case '9':
case '0':
case 'A':
case 'D':
ans++;
br... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T a, const T b) {
return a < b ? a : b;
}
template <typename T>
inline T qmax(const T a, const T b) {
return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T b) {
if (a > b) a = b;
}
template <typename T... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename X>
inline X abs(const X& a) {
return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
const int size = 1e5 + 2;
const double eps = 0.0001;
const long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932;
int a[30];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a;
int l;
cin >> l >> a;
if (l > a.size()) {
cout << 1;
for (int i = 0; i < l - 1; i++) cout << 0;
} else if (l == a.size()) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int ss;
int smin[20][1000001], smax[20][1000001];
int ans[1000001];
double st1[1000001];
double lg[1000001];
int lgt[1000001];
pair<int, int> get(int l, int r) {
int s = lgt[r - l + 1];
int u = l;
int v = r - (1 << s) + 1;
return make_pair(max(smax[s][u], ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
cout << 3 * n + min(n - k, k - 1);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(...) 0
#define DEBUG_ENDL 0
#defin... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int M = 200005 * 25;
int n, T, lx, ly, rx, ry, s1, s2, s3, s4, s5, s6, s7, x, y, tot, s;
long long ans;
int cnt[M], ls[M], rs[M], rt[N];
int insert(int last, int l, int r, int p) {
int now = ++tot;
if (l == r) {
cnt[now] = cnt[last] + 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int limN = 105;
typedef pair<int,int> pii;
#define x first
#define y second
int area(pii a, pii b, pii c) {
return a.x*b.y + b.x*c.y + c.x*a.y -
(a.y*b.x + b.y*c.x + c.y*a.x);
}
int sgno(int x) {
if(x==0)
return x;
return x<0? -1 : 1;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[6000 + 2];
map<pair<int, int>, int> m;
int val[6000 + 1];
int solve(int u, int v);
int solve_iter(int x, int y, int u) {
int ans = 0;
for (auto const& it : g[x]) {
if (it == y) continue;
if (val[it] < val[u]) ans = max(ans, solve(it, x));
ans =... | 6 |
#include <bits/stdc++.h>
const long long int M = 1000000007;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = x * res;
y = y >> 1;
x = x * x;
}
return res;
}
long long power(long long x, long long y, long long mod) {
long long res... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int A = 1e3;
const int INF = (int)1e9;
int n, m;
int a[N];
int dp[N * N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
n = unique(a + 1, a + n + 1) - (a + 1);
int all = a[1] * m;
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int rec(long long lo, long long hi, long long target, long long ans) {
long long mid = lo + (hi - lo) / 2LL;
if (target < mid)
return rec(lo, mid - 1, target, ans - 1);
else if (target > mid)
return rec(mid + 1, hi, target, ans - 1);
else
return ans;
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (k-- > 0) {
if (n % 10 == 0)
n /= 10;
else
n--;
}
cout << n;
}
| 1 |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long lo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, count = 0, x = 0, m = 0, sum1 = 0, sum2 = 0;
cin >> n >> k;
vector<pair<long long int, pair<long long int, long long int> > > vi;
long long int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
long long a1, b1, c1, a2, b2, c2;
cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;
if (b1 - a1 > b2 - a2) swap(a1, a2), swap(b1, b2), swap(c1, c2);
long long d2 = b2 - a2, d... | 3 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
long long n, g, b, a, d;
cin >> n >> g >> b;
a = (n + 1) / 2;
d = a / g;
if (a % g) {
d++;
}
cout << max(a + (b * (d - 1)), n) << "\n";
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 9e6;
int n, a[1000006], d[maxn + 6], z[maxn + 6];
void Solve() {
cin >> n;
for (int i = 1, _b = n; i <= _b; i++) {
cin >> a[i];
d[a[i]]++;
}
for (int i = 1, _b = maxn; i <= _b; i++) {
for (int j = 0, _b = 23; j <= _b; j++) {
if (!(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
unordered_map<int, int> m;
for (long long int i = 0; i < n; i++) {
long long int a;
cin >> a;
m[a % k]++;
}
vector<int> v;
int ans = 0;
for (auto it = m.begin(); it != m.end(); it++) v.push_back(it-... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, p, j, flag;
cin >> n;
long long x[n], d[n];
for (i = 0; i < n; i++) cin >> x[i] >> d[i];
for (i = 0; i < n - 1; i++) {
flag = 0;
p = x[i] + d[i];
for (j = i + 1; j < n; j++) {
if (x[j] == p && x[j] + d[j] == x[i]) {
... | 1 |
#include<bits/stdc++.h>
using namespace std;
map<int,int>Q;
int main(){
int n;
cin>>n;
Q.clear();
int tmp;
for(int j=0;j<n;j++){
cin>>tmp;
Q[tmp]++;
}
int m;
cin>>m;
int flag=0;
for(int j=0;j<m;j++){
cin>>tmp;
if(Q[tmp]>0)
Q[tmp]--;
else flag=1;
}
if(flag)
cout<<"NO";
else cout<<"YES";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
char s[maxn];
vector<int> g;
int main() {
int T;
cin >> T;
while (T--) {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
int cur = 1;
g.clear();
for (int i = 2; i <= n + 1; ++i) {
if (s[i] != s[i - 1]) {
g.p... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed idiot() {
long long n;
cin >> n;
set<long long> s;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
s.insert(x);
}
cout << s.size() << '\n';
return 0;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
... | 1 |
/*
* AOJ 2212: Stolen Jewel
* ???????????°?????????????????°??°???????????¨?????¨???????????????????????¨???????????¶?????????????????¢?????????????????¨???????????????????????¢????¬????????????¶????±???°????????????????°???\??°???
* ?±???????DP+?????????
* ??????????????¢?§???????????????????????????¶???????¢?????... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160")
const int INF = 1000000000;
using namespace std;
long long uns, a[100001], b[100001], c[100001], x[100001], t1, t2, t3, k1, k2,
k3, i, l, n;
int main() {
cin >> k1 >> k2 >> k3;
cin >> t1 >> t2 >> t3;
cin >> n;
for (i = 1; i <= n; i++) scan... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> cells;
int n, t, x;
bool check = false;
cin >> n >> t;
cells.push_back(-10);
for (int i = 1; i < n; i++) {
cin >> x;
cells.push_back(x);
}
for (int i = 1; i <= n;) {
if (i == t) {
check = true;
break;
} el... | 1 |
#include <bits/stdc++.h>
int main() {
long long int n;
scanf("%lld", &n);
printf("25\n");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, x2, x3, x4, a, b, c, d, maxi;
cin >> x1 >> x2 >> x3 >> x4;
maxi = max(x1, x2);
maxi = max(maxi, x3);
maxi = max(maxi, x4);
a = maxi - x1;
b = maxi - x2;
c = maxi - x3;
d = maxi - x4;
if (a == 0) {
cout << b << " " << c << " " << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout.sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
cout << int(ceil(n / 2.0)) << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, m, d, f[100] = {0};
float k;
char c, cc[1000];
map<string, float> a;
map<string, float>::iterator it;
string s;
scanf("%i %i %f\n", &n, &m, &k);
for (i = 0; i < n; i++) {
c = 'q';
s.clear();
while (c != ' ') {
scanf("... | 1 |
#include <bits/stdc++.h>
const int N = 2000000 + 10;
int a[N], n;
int Zero[N], One[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
memset(Zero, 0, sizeof Zero);
memset(One, 0, sizeof One);
for (int i = 1; i <= n; ++i) One[i] = One[i - 1] + (a[i] == 1);
for (int i = n; i >=... | 1 |
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll a[3005];
ll dp[3005][3005];
int main()
{
ll n, s;
cin >> n >> s;
for(int i = 0; i < n; i++) cin >> a[i];
ll ans = 0;
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= s; j++) dp[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<vector<long long int>> a;
priority_queue<pair<long long int, long long int>,
vector<pair<long long int, long long int>>,
greater<pair<long long int, long long int>>>
pq;
int main() {
ios_base::sync_with_stdio(false... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, num25 = 0, num50 = 0, num100 = 0;
bool flag = 0;
cin >> n;
while (n--) {
cin >> a;
if (a == 25)
num25++;
else if (a == 50) {
(num25) ? num25-- : flag = 1;
num50++;
} else if (a == 100) {
if (num50) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int MOD = 1e9 + 7;
long long bin_pow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1ll) {
res = (res * a) % MOD;
}
a = (a * a) % MOD;
b >>= 1ll;
}
return res;
}
int main() {
long long x, k;
cin ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[2000001];
int n;
long long f[2000001], ni[2000001];
long long ans;
bool cmp(int x, int y) { return x > y; }
long long calc(long long x, long long y) {
long long s = 1;
while (y) {
if (y & 1) (s *= x) %= 1000000007;
(x *= x) %= 1000000007, y /= 2;
}
ret... | 5 |
//#pragma comment(linker, "/STACK:1000000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <limits.h>
#include <ra... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n], c = 0, d = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (a[i] == 1 && b[i] == 0) c++;
if (a[i] == 0 && b[i] == 1) d++;
}
if (c > d)
cout << 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double pi = 3.141592653589793;
const double eps = 1e-8;
const int N = 3010;
const int M = 5010;
int n, m;
int head[N], ver[M], nxt[M], tot;
int d[N][N];
pair<int, int> st[N][4], to[N][4];
struct node {
int a, b, c, d;
int val;
};
node a... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double EPS = 1e-9;
signed main() {
do {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
} while (0);
int n;
cin >> n;
vector<int> v1(6);
vector<int> v2(6);
vector<int> v3(6);
bool flag1 = 0;
for (int i = 0; i < (int)(6... | 2 |
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int mo = 1e9 + 7;
int f[1<<17], g[1<<17], p[50], n, x, y, z, m, ans;
inline void add(int &x, int y) {
x += y; if (x >= mo) x -= mo;
}
int main() {
scanf("%d%d%d%d", &n, &x, &y, &z); m = x + y + z;
f[0] = p[0] = 1; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int Matrix[405][405];
int temp[405][405];
void rotate(int n, int m) {
memset(temp, 0, sizeof(temp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
temp[j][n - i + 1] = Matrix[i][j];
}
}
memcpy(Matrix, temp, sizeof(temp));
}
void Read(in... | 4 |
#include <bits/stdc++.h>
using namespace std;
int r;
int n, m;
int dh[2][210];
int dt[2][210];
int h0, t0;
void read() {
scanf("%d %d %d", &h0, &t0, &r);
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d %d", &dh[0][i], &dt[0][i]);
scanf("%d", &m);
for (int i = 1; i <= m; i++) scanf("%d %d", &dh[1][i], ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[200010], b[200010];
double ans = 0;
int main() {
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), b[i] = b[i - 1] + a[i];
for (int i = k; i <= n; i++) ans += b[i] - b[i - k];
ans /= (n - k + 1) * 1.0;
printf("%.10lf\n... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long binom[1001][1001];
long long bell[1001];
int main() {
binom[0][0] = 1;
bell[0] = 1;
for (int i = 1; i <= 1000; i++) {
binom[i][0] = 1;
for (int j = 1; j <= 1000; j++) {
binom[i][j] = binom[i - 1][j - 1] + binom[i - 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int ans = 0, n = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x % 2 == 0) ans = i;
}
if (ans)
cout << "1\n" << ans << "\n";
else {
if (n == 1)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define MOD (1000000000+7)
int main()
{
long long m, n;
cin >> m >> n;
long long ans = 1;
while( n ) {
if( n % 2 ) ans = ans * m % MOD;
m = m * m % MOD;
n /= 2;
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long powe(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b = b >> 1;
}
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2005;
int n, m;
char B[Maxn][Maxn];
bool U[Maxn][Maxn], D[Maxn][Maxn], L[Maxn][Maxn], R[Maxn][Maxn];
long long res;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", B[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j <... | 6 |
#include <bits/stdc++.h>
using namespace std;
const vector<long long> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
void solve(const long long &d, long long n, const long long &i,
const long long &K, long long &ans) {
if (d == 1 && (!ans || n < ans))
ans = n;
else
for (long long j = 1; j... | 5 |
#include<queue>
#include<iostream>
using namespace std;
typedef long long LL;
priority_queue<LL>L;
priority_queue<LL,vector<LL>,greater<LL>>R;
LL tL,tR,ans;
int n,l[123456],r[114514];
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;++i)cin>>l[i]>>r[i];
L.push(l[1]),R.push(l[1]);... | 0 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int N = 1e5 + 7;
const int MOD = 1e9 + 7;
int Dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int Dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long powm(long lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int C, Pr, Ps, Wr, Ws;
cin >> C >> Pr >> Ps >> Wr >> Ws;
if (max(Wr, Ws) >= sqrt(C)) {
if (Ws > Wr) {
swap(Pr, Ps);
swap(Wr, Ws);
}
long long int t = C / Wr;
long long int max;
bool flag = false;
long long int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 * 2 + 10;
vector<int> e[N];
queue<int> q;
int n, m, i, s, t, v[N], x[N], y[N], c[N], ans[N], f[N], g[N];
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d%d%d", &x[i], &y[i], &c[i]);
f[x[i]] += c[i];
f[y[i]] += c[i];
... | 3 |
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1000000;
const int INF = 1<<29;
int main() {
vector<int> dp(MAX, INF), odddp(MAX, INF);
dp[0] = odddp[0] = 0;
for (int i = 1;; ++i) {
int num = i * (i+1) * (i+2) / 6;
if (num >= MAX) break;
for (int j = num;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int gmatrix[100009][64];
long long int basis[100009];
void add(long long int x, long long int index) {
basis[index] = basis[index - 1];
for (long long int i = 19; i >= 0; i--) {
gmatrix[index][i] = gmatrix[index - 1][i];
}
for (long long int i = 19; i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
int n, k;
char a[maxn];
template <int maxn>
struct Theap {
int n;
struct Tsqy {
int l, r;
inline void build(int a1, int a2) {
l = a1;
r = a2;
}
inline bool operator>(const Tsqy &y) const {
const Tsqy &x = *this;... | 2 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tot, sum;
int dx[] = {-1, +0, +1, +0};
int dy[] = {+0, +1, +0, -1};
bool check(int x, int y) {
if (x < 0 || x >= n) return 0;
if (y < 0 || y >= m) return 0;
return 1;
}
struct node {
int x, y;
void make(int a, int b) {
x = a;
y = b;
}
};
queue<... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
int t, z = 0, l, i = 0, len;
int n, k = 0, m = 0, bam = 0, dan = 0, ans = 0;
scanf("%d", &n);
for (l = 0; l < n; l++) scanf("%d", &k), a[k] = 1;
l = 1;
while (a[l]) l++;
printf("%d", l);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100
#define MAX_C 100001
#define INF (1<<29)
typedef pair<int, int> pii;
int m[MAX_N];
pii dp[2][MAX_C];
void set_m(vector<int> &p)
{
for (int i = 0; i < (int)p.size(); i++) {
m[i] = ((p[i] - 1) / 1000 + 1) * 1000;
}
}
void update(pii ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void printVec(vector<int> v2, string s = "") {
cout << s;
for (int i = 0; i < (int)v2.size(); ++i) cout << v2[i] << " ";
cout << "\n";
}
bool isOdd(int a) { return (a % 2 == 1); }
bool comp(int i1, int i2) { return (i1 > i2); }
char s[101];
char t[101];
int main() {
... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (1 << 29) + 5;
const long long int LLINF = (1ll << 59) + 5;
const int MOD = 1000 * 1000 * 1000 + 7;
int n, q;
pair<string, string> arr[228];
map<string, bool> can;
queue<string> now;
int main() {
cin >> n >> q;
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K,c=1;
cin>>N>>K;
for(int i=0;i<N;i++){
if(c<=K)c+=c;
else c+=K;
}
cout<<c<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
char a[8][9];
int main() {
for (int i = 0; i < 8; i++) {
scanf("%s", a[i]);
}
int black = 9, white = 9;
for (int j = 0; j < 8; j++) {
for (int i = 0; i < 8; i++) {
if (a[i][j] == 'B') {
break;
}
if (a[i][j] == 'W') {
white =... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
const int N = 2e5 + 5;
int n, k;
int h[N], cnt;
int ans, cr;
struct factorial {
int n;
long long mod;
int *a;
int powm(int a, int b) {
int ans = 1;
while (b) {
if (b & 1) ans = int(1ll * ans ... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int data;
int group;
Node *next, *previous;
Node() { group = 0; }
};
bool acompare(Node *lhs, Node *rhs) { return lhs->data > rhs->data; }
void Add(Node *&presentNode, int data) {
Node *newNode = new Node;
newNode->data = data;
newNode->next = NU... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 * 100 + 10;
int par[maxn], st[maxn], ft[maxn], tim, type[maxn], x[maxn], y[maxn], num[maxn],
doc[maxn];
bool mark[maxn], f[maxn];
pair<int, int> req[maxn];
vector<int> e[maxn], vec[maxn];
int find_root(int v) {
if (par[v] == -1) return v;
retur... | 5 |
#include <bits/stdc++.h>
using namespace std;
int base = 1000 * 1000 * 1000;
vector<long long> operator*(const vector<long long>& c, int b) {
vector<long long> a = c;
long long carry = 0;
for (size_t i = 0; i < a.size() || carry; ++i) {
if (i == a.size()) a.push_back(0);
long long cur = carry + a[i] * b;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
int val[111][111];
int n, m, k;
int used[111][111];
pair<int, int> pre[211][1 << 8];
int dp[211][1 << 8];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void doit(int p, int st... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
long long rand_int(long long l, long long r) {
static mt19937_64 ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <typename T>
void readArray(vector<T> &A) {
for (T &i : A) cin >> i;
}
template <typename T>
void printArray(vector<T> A) {
for (T i : A) cout << i << " ";
cout << endl;
}
long long fastPow(long long a, long long b, long long m = mod)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int temp;
int arr[10000];
int n, d, sum = 0, p;
cin >> n >> d;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (arr[j] > arr[j + 1]) {
tem... | 1 |
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e15;
const long long int M = 1e9 + 7;
void solve() {
long long int n, m;
cin >> n >> m;
vector<pair<long long int, long long int> > bus(m);
for (long long int i = 0; i < m; i++) {
cin >> bus[i].second >> bus[i].first;
bus[i].second... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#ifdef ROHIT_SYS
#include "headers/debug.hpp"
#endif
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef ROHIT_SYS
freopen("in.t... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010], ans;
int ini[100010], fim[100010];
void solve(int u, int pai = -1, int f1 = 0, int f2 = 0, int depth = 0) {
if ((depth % 2 == 0 && f2) || (depth % 2 == 1 && f1)) ini[u] = 1 - ini[u];
if (ini[u] != fim[u]) {
ans.push_back(u);
if (depth % ... | 1 |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N + 1), B(N);
for (auto &a : A) cin >> a;
for (auto &b : B) cin >> b;
long long ans{};
for (int i = 0; i != N; ++i) {
auto d = min(B[i], A[i] + A[i + 1]);
ans += d;
A[i + 1] -= max(d - A[... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
long long T, a, b, n, s;
int main() {
scanf("%lld", &T);
while (T--) {
scanf("%lld%lld%lld%lld", &a, &b, &n, &s);
if (a * n < s) {
if (b >= s - a * n)
puts("YES");
else
puts("NO")... | 1 |
#include <bits/stdc++.h>
using namespace std;
char S[2000];
int len, fa[2000], P[2000], sz, osz, Ans;
int Color[2000], B[2000], H[2000], O[2000];
int getf(int k) {
if (fa[k] == k)
return k;
else
return fa[k] = getf(fa[k]);
}
void initp() {
for (int i = 2; i <= 1000; i++) {
bool f = 1;
for (int j =... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
vector<pair<int, int>> mp[100005];
int gg(pair<int, int> p) { return p.second - p.first + 1; }
int main() {
scanf("%d%d%d", &n, &m, &k);
int x, s = -1, l = -1;
for (int(i) = 0; (i) < (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, idx;
cin >> N;
vector<string> g(N);
for (int i = 0; i < N; ++i) cin >> g[i];
vector<int> pred(N);
for (int i = 0; i < N; ++i) cin >> pred[i];
vector<bool> selected(N, false);
for (int i = 0; i < N; ++i) {
bool zero = false;
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long n;
long long power() {
long long res = 1, a = 2;
while (n) {
if (n & 1) {
res *= a;
}
a *= a;
a %= mod;
n >>= 1;
res %= mod;
}
return ((res * (res + 1)) / 2) % mod;
}
int main() {
cin >> n;
cout... | 1 |
#include <bits/stdc++.h>
using namespace std;
int ans[10][10];
int in[2020][2020];
int nums[4040][4040];
int l[10], r[10], u[10], d[10];
int notes[100100];
int main() {
int N, M, S, K;
scanf("%d%d%d%d", &N, &M, &K, &S);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
scanf("%d", &in[i][j]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char c) {
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u')
return 1;
return 0;
}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const lon... | 5 |
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>
using namespace std;
#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxi = 1005;
int arr[maxi];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
if (n >= 2)
cout << arr[n / 2];
else
cout << arr[0];
}
| 1 |
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 100000;
for (int i = 0; i < n; i++)
ans = ceil(ans * 1.05 / 1000) * 1000;
cout << ans << endl;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.