solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > e[100010];
int vis[100010], p[100010], c[100010], vis2[100010];
struct P {
int v, col;
P() {}
P(int _v, int _c) : v(_v), col(_c) {}
};
bool bfs(int st, int col) {
c[st] = col;
vis2[st] = 1;
queue<P> que;
que.push(P(st, col));
... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
string R;
int n;
struct st {
string s;
inline void shift(int x) {
stack<char> _s;
int c = 0;
for (int i = int(n - x); i < int((int)s.size()); i++) _s.push(s[i]);
for (int i = int(n - 1); i >= int(0); i--)
if (i - x >= 0) s[i] = s[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long a[N];
int main() {
long long ts, tf, t;
scanf("%I64d%I64d%I64d", &ts, &tf, &t);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%I64d", a + i);
long long pos, ans = 1e18;
long long last = ts;
a[++n] = tf - t + 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main () {
int A, B;
cin >> A >> B;
cout << (A * B) / 2 << endl;
} | 0 |
#include<iostream>
#include<cstdio>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=100100;
int n,m,T,u,v,ans,du[N],d[N],t[N],g[N],b[N],c[N],fa[N];
struct lin{int x,y;}p[N],f[N];
vector<int>ad[N],ve;
queue<int>q;
void add(int u,int v){ad... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e5 + 7;
const long long INF = (long long)1e9 + 7;
const long double EPS = 1e-9;
int main() {
int n, l;
cin >> n;
if (n < 4) return cout << "NO", 0;
cout << "YES\n";
if (n % 2 == 0) {
cout << "2 * 3 = 6\n6 * 4 = 24\n1 * 24 = 24\n";
l = 5... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long m) {
long long r = 1;
a %= m;
for (; b; b >>= 1) {
if (b & 1) r = r * a % m;
a = a * a % m;
}
return r;
}
const int inf = 0x7f... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
using namespace std;
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
cons... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100005];
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
list<long long> b;
for (int i = 59; i >= 0; i--) {
vector<long long> c;
for (... | 3 |
#include<bits/stdc++.h>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
#define fr first
#define sc second
using namespace std;
typedef long long ll;
const int N=3e5+10;
const ll inf=1e18;
vector<int>p[N];int v[N];
void sol(){int n,m;
scanf("%d%d",&n,&m);
rep(i,1,n){
p[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
queue<long long> q;
int t;
cin >> t;
while (t--) {
int n;
long long h;
cin >> n >> h;
vector<long long> v(n);
long long sum = 0;
cin >> v[0];
long long maxm = 0;
for (int i = 1; i < n; i++) {
cin >> v[i];
v[i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans, a[111];
bool f = true;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 0, d; i < n; ++i) {
cin >> d;
++a[d];
}
while (f) {
f = false;
for (int i = k - 1; i > 0; --i) {
if (a[i]) {
f = true;
... | 2 |
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
while(1){
int N;
int fie[10001];
int ans=100000;
cin>>N;
if(N==0)break;
for(int i=0;i<N;i++)cin>>fie[i];
for(int i=0;i<N;i++){
int memo=fie[i],... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, m, i, j, x = 0, y = 1;
cin >> n;
long long int a[n + 5], b[n + 5], c[n + 5];
for (i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
memset(c, 0, sizeof(c));
sort(b, b + n);
reverse(b, b + n);
for (i = 0; i < n - 1; i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int p[maxn];
vector<int> pa;
int main() {
int n, f;
scanf("%d", &n);
p[1] = 1;
for (int i = 2; i <= n; i++) {
scanf("%d", &f);
p[i] = f;
}
int r = n;
while (p[r] != r) {
pa.push_back(r);
r = p[r];
}
reverse(pa.begin... | 1 |
#include <bits/stdc++.h>
using namespace std;
int const N = 3e3 + 10;
int a[N];
int main() {
int n, m = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
for (int j = 0; j < i; ++j)
if (a[j] > a[i]) ++m;
}
int x = (m / 2) * 3 + m - m / 2;
printf("%d\n", x);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m, cnt, now;
struct edge {
int v, i;
bool f;
bool operator<(edge a) const {
if (v == a.v) return f > a.f;
return v < a.v;
}
} a[100005];
queue<pair<int, int>> q;
pair<int, int> ans[100005];
int main() {
scanf("%d %d", &n, &m);
for (i = 1; i... | 4 |
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#inc... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
if (false) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int n, k;
cin >> n >> k;
vector<pair<long long, int> > t, p;
for (int i = 0; i < n; i++) {
long long price;
int type;
cin >> price >> type;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int conversion(string p) {
int o;
o = atoi(p.c_str());
return o;
}
string toString(int h) {
stringstream ss;
ss << h;
return ss.str();
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { re... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int eig = 0, oth = 0, num = 0;
int n;
cin >> n;
char tab[n];
string cards;
cin >> cards;
for (int i = 0; i < n; i++) tab[i] = cards.at(i);
for (int i = 0; i < n; i++) {
if (tab[i] == '8') eig++;
}
oth = n;
while ((oth > 10) && (eig > 0... | 1 |
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VII = vector... | 0 |
#include <bits/stdc++.h>
int a[709];
int f[709][709][2], can[709][709];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
signed main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
can[i][j... | 4 |
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int a[15][15];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
int sum=0;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
int x=0;
for(int k=0;k<m;k++){
x+=(a[i][k]-a[j][k])... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[400005];
int subtree[400005], n, root, maximo;
bool ans[400005];
pair<int, int> max1, max2;
int dfs(int v, int p) {
subtree[v] = 1;
for (int x : G[v])
if (x != p) subtree[v] += dfs(x, v);
return subtree[v];
}
int centroid(int v, int p) {
for (int x... | 3 |
#include<iostream>
using namespace std;
long double x[4], y[4];
int main() {
while (cin >> x[0] >> y[0]) {
cin >> x[1] >> y[1];
cin >> x[2] >> y[2];
cin >> x[3] >> y[3];
if (x[0] > x[1])swap(x[0], x[1]);
if (x[2] > x[3])swap(x[2], x[3]);
if (y[0] > y[1])swap(y[0], y[1]);
if (y[2] > y[3])swap(y[2], y[3]);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
if (b >= 999999999)
cout << a * 9 << endl;
else if (b >= 99999999)
cout << a * 8 << endl;
else if (b >= 9999999)
cout << a * 7 << endl;
else if (b >= 9... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t;
int x, y, a, b;
int main() {
cin >> t;
while (t--) {
cin >> x >> y >> a >> b;
y -= x;
if (y % (a + b) == 0)
cout << y / (a + b) << endl;
else
cout << -1 << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
double n, m, w, d, s[60], b[60];
bool us[60], ub[60];
int bot[60];
vector<pair<int, double> > v[60];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> w >> m;
d = n * w / m;
if (w > d * 2) {
cout << "NO";
return 0;
}
for (int i = 1; i <= n; i++)... | 4 |
#include <bits/stdc++.h>
long long int val[1000004] = {0};
using namespace std;
long long getmul(long long n) {
long long int k{0};
while (n > 0) {
k += n % 10;
n = n / 10;
}
return k;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int arr[n];
for (int i = 0... | 1 |
#include <stdio.h>
#include <stack>
#include <vector>
using namespace std;
//FILE *in = freopen("input.txt", "r", stdin);
//FILE *out = freopen("output.txt", "w", stdout);
int n, m;
char str1[1000];
int ind[15][3];
int indent[15];
int rind[15][3];
int res[15];
int R, C, S;
void input() {
for(int i = 0; i < m; ... | 0 |
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, m;
while (cin >> n >> m && n) {
int t[n], h[m], a = 101, b = 101;
double sum = 0, sum1 = 0, sum2 = 0;
rep(i, n) {
cin >> t[i];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const double eps = 1e-7;
long long s[MAXN << 2], h[MAXN], a[MAXN], Q[MAXN][3], cnt[MAXN << 2];
int n, q, len;
struct node {
long long s, cnt;
};
int Getpos(double x) { return upper_bound(a + 1, a + len + 1, x) - a - 1; }
void Add(int k, int l, in... | 5 |
#include<iostream>
#include<algorithm>
using namespace std;
signed main() {
int a, b, c; cin >> a >> b >> c;
int ans = (c / (a * 7 + b)) * 7; c %= (a * 7 + b);
cout << ans + min((c + a - 1) / a, 7) << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int t = 102;
int n, p;
long long ans[103] = {
10LL, 31LL, 42LL, 51LL, 72LL,
90LL, 131LL, 152LL, 190LL, 271LL,
392LL, 400LL, 572LL, 581LL, 812LL,
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct order {
int begin, end;
} m[500005];
bool cmp(const order a, const order b) { return a.end < b.end; }
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%d %d", &m[i].begin, &m[i].end);
}
sort(m, m + n, c... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+50, mod=998244353;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b... | 0 |
#include <bits/stdc++.h>
int n, fac[1000005], inv[1000005], ans;
int qpow(int a, long long b) {
int s = 1;
for (; b; b >>= 1, a = 1ll * a * a % 998244353)
if (b & 1) s = 1ll * s * a % 998244353;
return s;
}
int C(int n, int m) {
return 1ll * fac[n] * inv[n - m] % 998244353 * inv[m] % 998244353;
}
int add(in... | 3 |
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long ll;
struct {
inline operator int () { int x; return scanf("%d", &x), x; }
} read;
const int maxn = 200005, mod = 998244353;
std::vector<int> G[maxn];
int sg[3][maxn];
ll f[3][max... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i, n) for(int i=0;i<n;i++)
int main() {
int n;
cin >> n;
vector<int> v(n);
r(i, n) cin >> v[i];
int q, x, p;
cin >> q;
while (q--) {
cin >> x;
p = lower_bound(v.begin(), v.end(), x) - v.begin();
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1e17;
const int mod = 998244353;
const long long int N = 600032LL;
long long int fac[N + 2];
long long int inv[N + 2];
long long int add(long long int a, long long int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
return a;
}... | 1 |
#include "bits/stdc++.h"
#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, q, x, y, parent, max_val, max_node, query, max_len;
list<long long> vec[300005];
long long visited[300005];
struct pend {
long long ff, ss;
};
pend p[300005];
int find(int x) {
if (p[x].ff != x) p[x].ff = find(p[x].ff);
return p[x].ff;
}
void dfs(int n... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
long long dp[2007][1007];
int main() {
int n;
scanf("%d", &n);
dp[0][0] = 1;
long long ans = 0;
for (int i = 1; i <= 2 * n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = ((dp[i][j] + dp[i - 1][j + 1]) % 1000000007);
if ... | 4 |
#include <stdio.h>
int H, W, R, C; char s[1001][1007], t[1001][1007];
unsigned long long pw1, pw2, h1[1001][1007], h2[1001][1007], h3[1001];
int main() {
scanf("%d%d", &H, &W);
for(int i = 0; i < H; i++) scanf("%s", s[i]);
scanf("%d%d", &R, &C); pw1 = 1, pw2 = 1;
for(int i = 0; i < R; i++) scanf("%s", t[i]), pw2 *=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> vals(n);
int firstone = -1;
int currentone = -1;
for (int i = 0; i < n; i++) {
cin >> vals[i];
if (vals[i] == 1) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, q, sq, nr;
vector<int> m[100010];
int dist1[100010];
int dist[100010];
bitset<100010> viz;
vector<int> c;
queue<int> c2;
int nivel[200010];
int noduri[200010];
int poz[200010];
int put[25];
int lg[200010];
int rmq[200010][23];
pair<int, int> quers[100010];
void linia... | 5 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
const int MAX_N = 3010, MAX_E = 10000;
int n, m; //????????° ???????????¬??°
vector<pair<int, int> > G[MAX_N];//??°???????????¨?????£??\????????... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
inline void fast_subset_zeta_transform(vector<T>& f) {
for (int i = 0, n = 31 - __builtin_clz((int)f.size()), MSK = 1 << n; i < n;
i++)
for (int msk = 0; msk < MSK; msk++)
if (msk >> i & 1) f[msk] += f[msk ^ 1 <... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b, dist[300010];
string s;
char c[300010];
bool visited[300010];
vector<long long> adj[300010], st;
queue<long long> q;
long long pv(long long x) { return (x + n - 1) % n; }
long long nx(long long x) { return (x + 1) % n... | 6 |
#include <bits/stdc++.h>
using namespace std;
char c[1001][1001], ctmp;
int n, m, dist[1001][1001], d, ans;
pair<int, int> tmp;
pair<int, int> S;
pair<int, int> E;
queue<pair<int, int> > q;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dist[i][j] = -1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, dir[200005];
long long cnt, le;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &dir[i]);
if (dir[i] == 0) le++;
}
for (int i = 0; i < n; i++) {
if (dir[i] == 1)
cnt += le;
else
le--;
}
printf("%I64d", c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
long long l, r;
cin >> T;
for (int i = 0; i < T; i++) {
cin >> l >> r;
cout << l << " " << 2 * l << endl;
}
return 0;
}
| 1 |
#include <stdio.h>
int main(void) {
int i, ans = 0, j, n;
while(scanf("%d", &n) != EOF) {
ans = 0;
for(i = 0; i * n < 600; ++i) ans += n * i * i * n * n;
printf("%d\n", ans);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, m = 0, c = 0;
scanf("%d", &n);
while (n--) {
scanf("%d%d", &a, &b);
if (a > b) {
m++;
} else if (a < b) {
c++;
}
}
if (m > c) {
printf("Mishka");
} else if (m < c) {
printf("Chris");
} else {
pr... | 1 |
#include<bits/stdc++.h>
using namespace std;
int a,now,ans,n;
int main()
{
cin>>n;
for(int s=0;s<n;s++)
{
cin>>a;
if(a>now)ans=ans+a-now;
now=a;
}
cout<<ans<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 1e5, mod = 998244353;
int cnt[N], prim[N], miu[N], vis[N];
inline int read() {
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getch... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double d, l, v1, v2, ans;
cin >> d >> l >> v1 >> v2;
ans = (l - d) / (v1 + v2);
cout << fixed << setprecision(6) << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int M = 10001;
const int md = 1e9 + 7;
void add(int &x, int y) { x += y; while(x >= md) x -= md; if (x < 0) x += md; }
int n, k;
int f[N][M];
int pw[N];
int ans;
int main() {
scanf("%d %d", &n, &k);
pw[0] = 1; for (int i = 1; i < N; ++i) pw[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C;
cin>>A>>B>>C;
C=min(C,A+B+1);
cout<<B+C;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, t;
cin >> t;
while (t--) {
scanf("%d", &n);
printf("%d\n", n);
}
}
| 1 |
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define SIZE 1005
#define MAX 16
struct Edge{
Edge(int arg_word_id,int arg_loc,int arg_dist){
word... | 0 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
#define i64 long long int
int M;
int la;
struct pnt {
int... | 0 |
#include <bits/stdc++.h>
struct Widget {
std::string name;
long long width, height;
Widget(const std::string& name, long long width, long long height)
: name(name), width(width), height(height) {}
~Widget() {}
virtual void calculateSize() {}
};
struct Box : public Widget {
int spacing, border;
std::... | 2 |
#include <bits/stdc++.h>
using namespace std;
int k, len;
string str;
bool used[30];
int cnt;
int main() {
cin >> k >> str;
len = str.length();
for (int i = 0; i < len; i++)
if (str[i] != '?') used[str[i] - 'a'] = true;
for (int i = k - 1; i >= 0; i--) cnt += !used[i];
for (int i = 0; i < (len + 1) / 2; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
char string_in_buffer[(int)260];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void... | 6 |
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> C;
#define EPS (1e-8)
#define EQ(a,b) (abs((a)-(b)) < EPS)
double dot(C a, C b) {
return a.real() * b.real() + a.imag() * b.imag();
}
double xa, ya, xb, yb, xc, yc, xd, yd;
void solve() {
C a(xa, ya), b(xb, yb), c... | 0 |
#include<bits/stdc++.h>
using namespace std;
int i,j,n,x,mx=0,a;
map<int,int>m;
int main()
{
cin>>n;
for(j=1;j<=n;j++)
{cin>>x;
for(i=2;i*i<=x;i++)
{
a=0;
while(x%i==0)
{x/=i;
if(!a){
m[i]++;a++;}
mx=max(m[i],mx);
}
}... | 0 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
priority_queue<int>q;
ll sum;
int m,n,x;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>x;
q.push(x);
}
while(m){
x=q.top()/2;
q.pop();
q.push(x);
m--;
}
while(!q.empty()){
sum+=q.top();
q.pop();
}
cout<<sum;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;
pair<int, int> a[300000];
pair<int, int> b[300000];
multiset<int> aa, bb;
int tree[1048576];
int va... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &_p) {
return os << "(" << _p.first << "," << _p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &_V) {
bool f = true;
os << "[";
for (auto v ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int pod = (1 << 17);
const int nax = 100111;
int n, m, X;
int a[nax];
int type, l, r;
struct node {
long long ans = 0;
vector<pair<int, int>> pref, suf;
node() {
ans = 0;
pref.clear();
suf.clear();
}
} t[2 * pod];
node lacz(const node a, const node... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[300000 + 5];
long long b[300000 + 5];
long long sum[300000 + 5];
long long even[300000 + 5], odd[300000 + 5];
long long find(long long x) {
long long y = 0;
while (x) {
if (x & 1) y++;
x >>= 1;
}
return y;
}
void readin() {
scanf("... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool rd(T &num) {
char in;
bool IsN = false;
while (in = getchar(), in != '-' && (in < '0' || in > '9'))
if (in == EOF) return false;
in == '-' ? (IsN = true, num = 0) : num = in - '0';
while (in = getchar(), in >= '0' && in <= '9') n... | 2 |
#include <bits/stdc++.h>
using namespace std;
class DisjointSet {
public:
vector<int> father;
vector<int> rank;
vector<int> size;
DisjointSet(int n);
DisjointSet(){};
void inite(int n);
int find(int v);
void merge(int x, int y);
};
DisjointSet::DisjointSet(int n) : father(n), rank(n) {
size.resize(n,... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int n; cin>>n;
string s; cin>>s; n--;
map<char,int> x;
for (char ch : s)
x[ch]++;
while(n-->0) {
cin>>s;
map<char,int> y;
for (char ch : s)
... | 0 |
#include <bits/stdc++.h>
const long long oo = (long long)2 * 10e9;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, tmp_k = 0;
cin >> n >> k;
vector<vector<char>> v(n, vector<char>(n));
bool first_sea = false;
for (int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[1000005], cnt[1000005];
set<int> L, R;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, k, d;
cin >> n >> k >> d;
set<int> Set;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i <... | 2 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define W 0
#define S 1
int C[101][101][2][2];
int main()
{
int w,h;
for(int i=1;i<101;++i)
{
C[i][1][S][0] = 0;
C[i][1][W][0] = 1;
C[i][1][S][1] = 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int DFSindex;
int num[100000];
int revnum[100000];
int low[100000];
int p[100000];
vector<pair<int, int> > bridges;
set<int> bridge[100000];
bool instack[100000];
vector<int> adj[100000];
int ncomponents;
int component[100000];
vector<int> adj2[100000];
int level[100000];
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
int inf = 0x3f3f3f3f;
int n, m, q;
int ans[400010];
int num[maxn];
int Instack[maxn];
int dfn[maxn];
int low[maxn];
int tot;
vector<int> edge[maxn];
struct query {
int s, t, k, id;
} Query[400010];
vector<int> temp[maxn];
vector<int> S[maxn];
v... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1000000007LL
#define mod 1000000007LL
#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int C = 26;
void add(int &x, int y) {
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
int fix(int x) {
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
return x;
}
int pw(int a, int b) {
int ret = 1;
while (b) {
... | 3 |
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { re... | 0 |
#include <bits/stdc++.h>
using namespace std;
set<int> s[2];
set<int> sdouble;
int cntdouble[2];
long long sum[2];
int n;
void upd(int id);
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int tp, x;
scanf("%d%d", &tp, &x);
if (x > 0) {
sum[0] += x;
s[0].insert(x);
cntdoubl... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int aib[200002], v[200002];
struct vects {
int pos, val;
};
vects v2[200002];
bool cmp(vects a, vects b) { return a.val < b.val; }
void add(int nod, int val) {
for (; nod <= n; nod += nod & (-nod)) aib[nod] += val;
}
int compute(int nod) {
int sol = 0;
for (;... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int t;
cin >> t;
while (t--) {
int a1, b1;
cin >> a1 >> b1;
int a2, b2;
cin >> a2 >> b2;
if (max(a1, b1) == max(a2, b2) && max(a1, b1) == min(a1, b1) + min(a2, b2))
cout << "YES" << '\n';
else
cout << "NO" << '\n';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, u, r;
long long ans = -1e18;
long long a[35], b[35], k[35], p[35];
void calc(long long aa[]) {
long long mx = 0;
for (int i = 1; i <= n; i++) mx += aa[i] * k[i];
ans = (ans > mx ? ans : mx);
}
void dfs(long long depth, long long aa[]) {
if (depth == u) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int n, a[3000005];
long long int beg = 1;
long long int dfs(long long int i, long long int j) {
if (i == n + beg - 1) {
a[n + beg] = a[n + beg - 1];
return n + beg - 1;
}
if (i > n + beg - 1) return n + beg;
a[dfs(i + j, j)] = a[i];
return i;
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a;
cin >> a;
vector<long long> caja(a);
for (long long i = 0; i < a; i++) cin >> caja[i];
if (a == 1) {
cout << 1;
return 0;
}
caja[0] = 1;
for (long long i = 1; i < a; i++) {
if (caja[i] > caja[i - 1] + 1) caja[i] = caja[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll c, n , m, s[10005], p[10005], dp[2][10005];
int main() {
cin >> c >> n >> m;
for(int i=0;i<n;i++){
cin >> s[i] >> p[i];
}
for(int i=0;i<n;i++){
for(int j=0;j<=c;j++){
int ... | 0 |
#include<iostream>
using namespace std;
int main(void)
{
int h,a; cin>>h>>a;
cout<<(h+a-1)/a<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int p[200020];
int a[10][10];
vector<int> v[5][20000];
int n;
int dfs(int i) {
int x = 0, re = 0, j, z, k;
for (j = 0; j < i; j++) x = x * 10 + a[i][j];
if (i == n - 1) return v[1][x].size();
for (j = 0; j < v[n - i][x].size(); j++) {
z = v[n - i][x][j];
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
int tc, n, x, d, h, maxd, maxdec;
int main() {
cin >> tc;
while (tc--) {
cin >> n >> x;
maxd = maxdec = -1000000000;
while (n--) {
cin >> d >> h;
maxd = max(maxd, d);
maxdec = max(maxdec, d - h);
}
if ((x > maxd) && (maxdec < 1))
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mod 1000000007
typedef struct node{
int first;
int second;
}node;
bool operator<(const node &a, const node &b) {
return a.first > b.first;
}
void solv... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool mini(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool maxi(T &a, T b) {
return a < b ? (a = b, true) : false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long num;
bool found = false;
cin >> num;
vector<int> v(num);
for (unsigned i = 0; i < num; i++) cin >> v[i];
for (unsigned i = 0; i < v.size(); i++) {
while (v[i] % 2 == 0) {
v[i] /= 2;
}
while (v[i] % 3 == 0) {
v[i] /=... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i;
long long arr[100000];
int s = 0;
for (i = sqrt(n); i >= 1; i--) {
if (n % i == 0) {
int x = n / i;
long long ans = 2 + (x - 1) * i;
ans = ans * x;
ans = ans / 2;
arr[s] = ans;
s++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int q[111111];
int a[111111];
int b[111111];
long long len[111111];
int dp[111111];
int query(long long x) {
int id = lower_bound(len + 1, len + n + 1, x) - len;
if (q[id] == 1) return a[id];
long long tp = len[id - 1];
long long w = x - tp;
long long z = w... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.