solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int k1, k2, k3, k4;
cin >> k1 >> k2 >> k3 >> k4;
int k = min(k3, k4);
k = min(k1, k);
int sum = 0;
for (int i = 0; i < k; i++) sum += 256;
int c = k1 - k;
if (c > 0) {
int m = min(c, k2);
for (int i = 0; i < m; i++) sum += 32;
}
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> err;
pair<int, int> combien(int x, int y, int encours, int erreur) {
int z, c;
if (x == 0) {
if (y != 1) return pair<int, int>(-1, -1);
return pair<int, int>(encours, erreur - 1);
} else {
z = y % x;
c = (y - z) / x;
return combien(z, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
int main() {
scanf("%lld%lld", &n, &k);
m = n / 2 / (k + 1);
printf("%lld %lld %lld", m, m * k, n - (k + 1) * m);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 500 * 1000 + 13;
int n, k, m;
pair<pair<int, int>, int> q[N];
int ones[N];
int mx[N], sum[N];
int add(int first, int second) {
first += second;
if (first >= MOD) first -= MOD;
if (first < 0) first += MOD;
return first;
}
int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int X = 0;
char ch = 0, w = 0;
while (ch < 48 || ch > 57) ch = getchar(), w |= (ch == '-');
while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
struct Node {
long long mx, cmx, mx2, tg, tg2, s;
int c;
inline... | 25 |
#include <bits/stdc++.h>
using namespace std;
struct data {
double x, y;
data operator+(const data &b) { return (data){x + b.x, y + b.y}; }
data operator-(const data &b) { return (data){x - b.x, y - b.y}; }
data operator*(const data &b) {
return (data){x * b.x - y * b.y, x * b.y + y * b.x};
}
} w[2][10000... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> suma(n + 1);
suma[0] = 0;
for (int i = 1; i < n + 1; ++i) {
long long a;
cin >> a;
suma[i] = suma[i - 1] + a;
}
long long total = suma[n];
if (total... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long sum = 0;
pair<long long, long long> d[n + 1];
queue<long long> qu;
for (long long i = 0; i < n; i++) {
cin >> d[i].first >> d[i].second;
sum += d[i].first;
if (d[i].first == 1) qu.push(i);
}
vector<pa... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
double pow2[N];
pair<int, int> P[N];
int gcd(int x, int y) {
x = abs(x), y = abs(y);
int tmp;
while (y) {
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d"... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
template <typename T>
inline bool chkmax(T &a, T b) {
return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
return a > b ? a = b, true : false;
}
const long long EQ = 0, LESS = -2, GR = 2;
const long long... | 15 |
#include <bits/stdc++.h>
using namespace std;
string ad(string a, string b) {
long long c = 0;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = 0; i < a.size(); i++) {
a[i] -= '0';
}
for (int i = 0; i < b.size(); i++) {
b[i] -= '0';
}
int gh = max(b.size(), a.size());
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > S;
int N, K;
const int limit = 600005;
bool V[limit];
int Prime[limit];
long long ans = 5;
vector<int> Sol[10005];
map<int, int> M;
void Eratostenes() {
for (int i = 2; i <= limit; i++) {
if (V[i] == 0) {
Prime[++Prime[0]] = i;
for (in... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int i, m = 0, k = 0;
for (i = 0; i <= n - 1; i++)
if ((s[i] == '0' && i % 2 == 0) || (s[i] == '1' && i % 2 == 1))
m++;
else
k++;
cout << min(m, k);
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int k, i, raodl[300005], raodr[300005], mx[300005], ans;
string s, t;
int main() {
cin >> s >> t;
i = -1;
for (k = 0; k < s.size(); k++) {
int b = t.size() - 1;
if (s[k] == t[i + 1] && i < b) i++;
raodl[k] = i + 1;
}
i = t.size();
mx[0] = s.size();
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, u, v, a[120000];
int main() {
scanf("%d%d%d", &n, &u, &v);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
sort(a + 2, a + n + 1);
long long sum = a[1];
for (int i = 2; i <= n; i++) {
sum += a[i];
if (sum * v > (long long)a[1] * u) {
printf("... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, M, K;
vector<int> graph[200000];
vector<int> graph1[200000];
int visited[200000];
int seq[200000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(visited, -1, sizeof(visited));
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> go(long long x) {
vector<int> a;
int curr = 2;
while (x) {
a.push_back(x % curr);
x... | 13 |
#include <bits/stdc++.h>
using namespace std;
int movi[8] = {1, 1, -1, -1, 2, 2, -2, -2};
int movj[8] = {2, -2, 2, -2, 1, -1, 1, -1};
int mida = 500;
int pasos = 100;
long long int inv2 = 500000004;
long long int modulo = 1000000007;
int main() {
long long int movimientos, prohibidos;
cin >> movimientos >> prohibid... | 22 |
#include <bits/stdc++.h>
using namespace std;
void ToVertical(int i, int j, vector<vector<char>> &status,
vector<pair<int, int>> &ret);
void ToHorizontal(int i, int j, vector<vector<char>> &status,
vector<pair<int, int>> &ret);
vector<pair<int, int>> Relay(vector<vector<char>> status) ... | 19 |
#include <bits/stdc++.h>
const int MN = 18;
int N, Adj[MN][MN];
std::vector<int> G[1 << MN];
long long f[1 << MN][MN], g[MN + 1][1 << MN];
void Mul(long long *A, long long *B, long long *C) {
for (int S = 0; S < 1 << N; ++S) C[S] = A[S] * B[S];
}
void FWT(long long *A, int L, void (*T)(long long &x, long long &y)) {
... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, m, cnt[1 << 9], mn = 2e9, mx, pos1 = 1, pos2 = 2;
vector<vector<pair<long long, long long>>> v(1 << 9);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
lon... | 13 |
#include <bits/stdc++.h>
using namespace std;
namespace MCMF {
static const long long INF = 1ll << 62;
const int NODES = 4500;
const int EDGES = 20000;
int nxt[EDGES], ptr[NODES], to[EDGES];
long long cap[EDGES], cz[EDGES];
long long pot[NODES], dis[NODES];
int fr[NODES];
long long flo, fee;
int n, m;
void init(int N) ... | 16 |
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int main(){
int n,m;
cin>>n>>m;
vector<bool> ok(m+1,false);
ok[0] = true;
vector<int> ans(m+1,Inf);
rep(i,n){
long long t,x,y;
scanf("%lld %lld %lld",&t,&x,&y);
if(... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c *r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
template <class c>
muu ... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160")
using namespace std;
const double PI = 3.14159265358979323846;
const long long MODUL = 1000000007;
const long long MAXINT = 2e9 + 2;
const long long MAXLL = 2e18 + 2;
const double eps = 1e-9;
const int MAXN = 2e5 + 10;
int n;
long long mas[MAXN], ans;... | 3 |
#include <bits/stdc++.h>
int sum[1005];
int main(void) {
int n, i, x;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &x);
sum[x]++;
}
for (i = 0; i <= 1000; i++) {
if (sum[i] > (n + 1) / 2) {
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, rt, fc[20], Log[N];
long long ans[N];
namespace IO {
int read() {
int ret = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) ret = ret * 10 + (c ^ 48), c = getchar();
return ret;
}
void write(long long x) ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getcha... | 22 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int MOD = 1000000007;
int i, j, k, m, n, l;
long long ans, s1, s2;
int a[1000001], b[1000001];
long long d[2500][2500];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void what() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, k, cur, ans, am;
pair<int, int> table[1005];
pair<pair<int, int>, int> ar[1005];
vector<pair<pair<int, int>, int>> s;
vector<pair<int, int>> sol;
void solve() {
cin >> n;
for (int i = 0; i < n; ++i)
cin >> ar[i].first.first >> ar[i].first.second, ar[i].second... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXW = 5000000;
int n, cnt[MAXW];
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int w;
scanf("%d", &w);
++cnt[w];
}
int ans = 0;
for (int t = 0; t < 5000000; ++t) {
while (cnt[t] >= 2) {
cnt[t + 1] += 1;
cnt[... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005, INF = 1e9 + 2;
int a[MAXN][10];
int mark[305];
int n, m;
int ans1 = 1, ans2 = 1;
bool check(int x) {
fill(mark, mark + 300, 0);
for (int i = 0; i < n; i++) {
int b = 0;
for (int j = 0; j < m; j++)
if (a[i][j] >= x)
b = b * ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int w[111111], w_[111111], ww[111111];
map<int, set<pair<int, int> > > mp;
vector<pair<int, int> > v;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
ww[i] = y - x;
mp[y - x].insert(pair<int, int>(x, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x(0), f(1);
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void w... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
long long f = 0;
char ch = getchar();
while (!isdigit(ch)) f = ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = f ? -x : x;
}
template <class T>
inline void... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int ans = 0;
vector<long long int> v;
for (long long int i = n - 1; i >= max(n - 81, 0LL); i--) {
long long int temp = i;
long long int sum = i;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 9;
template <typename T>
inline T BigMod(T A, T B, T M = MOD) {
T ret = 1;
while (B) {
if (B & 1) ret = (ret * A) % M;
A = (A * A) % M;
B = B >> 1;
}
return ret;
}
template <typename T>
inline T EGCD(T a, T b, T &x, T &y) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[15], b[15], c[15], d[15];
while (~scanf("%s", a)) {
getchar();
scanf("%s", b);
int l1 = strlen(a), l2 = strlen(b), k = max(l1, l2) - 1, flag = 0,
s1 = l1 - 1, s2 = l2 - 1;
for (int i = max(l1, l2) - 1; i >= 0; i--) {
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long int n;
cin >> n;
long long int a[n];
long long int c[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
c[i] = a[i];
}
for (long long int i = 1; i < n - 1... | 2 |
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=2e5+100;
const int maxn=1e6;
const int MAXL=sqrt(1e5)+1;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(... | 9 |
#include <bits/stdc++.h>
using namespace std;
long double sqr2(long double x, long double y) { return x * x + y * y; }
void inverse(long double& x, long double& y) {
if (fabs(y) < 1e-6) {
y = 0;
x = 1 / x;
} else {
long double d = sqr2(x, y);
x /= d;
y = -y / d;
}
}
int main() {
int numTests... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n % 2)
cout << "Ehab\n";
else
cout << "Mahmoud\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1000000 + 5;
inline int add(int x, int y) {
x += y;
return x >= mod ? x -= mod : x;
}
namespace pam {
int sz, tot, last;
int ch[maxn][26], len[maxn], fail[maxn];
int cnt[maxn], dep[maxn], dif[maxn], slink[maxn];
char s[maxn];
in... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ans = 0, n, i, a[100], sum = 0, sum1 = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = n; i >= 1; i--) {
sum += a[i];
if (sum > sum1) swap(sum, sum1);
}
cout << sum << " " << sum1;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
pair<long long, long long> pnt[100005];
pair<long long, long long> convex[100005];
int cid[100005];
vector<int> e[100005];
int dp[100005][25];
int dep[100005];
void dfs(int now, int d) {
dep[now] = d;
for (int val : e[now]) dfs(val, d + 1);
}
lo... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[200010];
const int MAXN = 1000000;
int ans[200010];
int prime[MAXN + 1];
void getPrime() {
memset(prime, 0, sizeof(prime));
for (int i = 2; i <= MAXN; i++) {
if (!prime[i]) prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++) ... | 4 |
#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long a[500004], b[500004];
int main() {
long long... | 0 |
#include <bits/stdc++.h>
using namespace std;
int vis[100000];
vector<int> adj[100000];
int n, m, x, y;
void dfs(int curr) {
for (int i = 0; i < adj[curr].size(); ++i) {
int u = adj[curr][i];
if (!vis[u]) {
vis[u] = 1;
dfs(u);
}
}
printf("%d ", curr + 1);
}
int main(void) {
cin >> n >> m... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 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 long a, long long b) {
long long res = 1;
while (b > 0)... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, vector<long long int> > M;
long long int n, b, k, x;
long long int digits[10];
long long int power(long long int base, long long int exp, long long int md) {
if (exp == 0) return 1LL;
long long int root = power(base, exp / 2, md);
if (exp & 1LL) ret... | 12 |
#include <bits/stdc++.h>
using namespace std;
long unsigned retATranssf(long unsigned a) {
vector<long unsigned> arr(0);
while (a > 0) {
if (a % 10 == 4 || a % 10 == 7) {
arr.push_back(a % 10);
}
a /= 10;
}
long unsigned ret = 0;
for (long unsigned i = 0; i < arr.size(); i++) {
ret += ar... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
vector<long long> lucky;
void dfs(long long a) {
if (a > (long long)(1e10)) return;
if (a > 0) lucky.push_back(a);
dfs(10 * a + 4);
dfs(10 * a + 7);
}
long long xgcd(long long a, long long b, long long &x, long long &y) {
if (b == 0... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 10;
int a[mn], b[mn];
int main() {
int n;
long long T;
scanf("%d %lld", &n, &T);
long long sum = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if ((sum + a[i]) <= T) {
b[cnt++] = a[i];
sum += a[i];
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
const int L = 1000000;
const int A = 26;
const int inf = 1e9;
vector<vector<int> > nxt[N];
char s[L + 1];
int n, l, m, tmp[A], idx[N], nextindex[N][A], firstoccur[N][A], fstindex[A],
fstpos[A];
pair<int, int> ans[N + 1][N + 1], pos, nxtpos;
const pai... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 != 0)
cout << "0";
else {
int g = n / 2;
double q, w;
q = g;
w = 2;
long long int h = pow(w, q);
cout << h;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
bool upd(bool& fx, int& x, int y) {
if (!fx) {
x = y;
fx = true;
return true;
}
return x == y;
}
void solve2(int d, int a1, int a2, int b1, int b2, int& c1, int& c2) {
i... | 22 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;
int n;
int a[N];
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
cin >> n;
set<int> s;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
... | 9 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[5005];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
memset(a, 0, sizeof(a));
ll n;
scanf("%lld", &n);
for(ll i=1; i<=n; i++)
{
scanf("%lld", &a[i]);
}
ll res=0... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
const long long LIMIT = 1e5;
long long l[MAX], t[MAX], s[MAX], e[MAX];
long long n, r;
void die() {
puts("-1");
exit(0);
}
int main() {
scanf("%lld %lld", &n, &r);
for (int i = int(1); i < int(n + 1); i++) {
scanf("%lld", l + i);
}
f... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(nam... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long nax = 2e5 + 10;
long long add[nax] = {0};
bool alloted[nax] = {false};
long long value[nax] = {0};
long long dp[101][101][11][11];
long long lf, lr;
long long solve(long long n1, long long n2, long long k1, long long k2) {
if ((n1 + n2) == 0) return 1;
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
bool isprime(long long a) {
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
int main() {
long long a;
cin >> a;
if (isprime(a)) {
cout << 1 << end... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int64_t SMALL = LLONG_MIN / 2;
const int64_t N = 100005;
struct person {
int64_t t;
int64_t s[8];
} a[N];
int64_t d[2][1 << 7];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int64_t n, p, k;
cin >> n >> p >> k;
for (int64_t i =... | 15 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 5;
int dp[N][N];
vector<int>o,z;
int fx(int i , int j){
//My Bad : <
if(i == o.size()){
return 0;
}
if(j == z.size()){
if(i == o.size()){
return 0;
}
return 1e18;
}
if(dp[i][j] != -1... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T x) {
return x * x;
}
template <typename T>
inline T gcd(T a, T b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
template <typename T>
inline T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
template <class T>
inline do... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[155][155], t;
char s[151][152];
vector<int> v[152];
int main(int argc, char **argv) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", s[i]);
for (int j = 0; j < m; ++j)
if (s[i][j] == 'W') v[i].push_back(j);
}
int t = 0;
... | 7 |
//created by shubhamsingh1
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//ONLINE_JUDGE
inline void debugMode(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
int main()
{
ios::sync_with_... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 9;
long long ans = 0;
long long cnt[N][10];
int n, k;
std::vector<int> graph[N];
int dfs(int u, int p, int lvl) {
cnt[u][0] = 1ll;
int t = 1;
for (int v : graph[u]) {
if (p - v) {
t += dfs(v, u, lvl + 1);
for (int i = 0; i < k;... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1.1e6;
int p[N], dp[N], ans[N], opt[N];
vector<int> g[N];
signed main() {
int n, cur, son;
cin >> n;
++n;
ans[1] = 1;
for (int i = 2; i <= n; ++i) {
cin >> p[i];
dp[i] = 1;
ans[i] = ans[i - 1];
g[p[i]].push_back(i);
son = i;
f... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T>
inline void write(T x) {
long long i = 20;
char buf[21];
buf[20] = '\n';
do {
buf[--i] = x % 10 + '0';
x /= 10;
} while (x);
do {
putchar(buf[i]);
} while (buf[i++] != '\n');
}
void read(long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
int Q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> Q;
while (Q--) {
int N;
map<int, int> cnt, unos;
cin >> N;
for (int i = 0; i < N; i++) {
int t1, t2;
cin >> t1 >> t2;
cnt[t1]++;
if (t2) unos[t1]++;
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
double max(double a, double b) { return (a > b) ? a : b; }
double cross(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
return ((double)(b.first - a.first) * (c.second - b.second) -
(b.second - a.second) * (c.first - b.first)) *
0.5;
}
int main(... | 13 |
#include <bits/stdc++.h>
using namespace std;
int ans, q, n;
long long k, sum[200010], a[200010];
int GetPos(long long temp) {
int Left = 0, Right = n;
while (Left < Right) {
int Mid = Left + (Right - Left + 1) / 2;
if (sum[Mid] <= temp)
Left = Mid;
else
Right = Mid - 1;
}
return Left;
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
int p[5000];
bool prime[5000];
int a[100005];
int b[100005];
int up;
map<int, int> fm;
map<int, int> fz;
void Prime() {
int i, j;
memset(prime, 0, sizeof(prime));
for (i = 2; i <= 3500; i++) {
if (prime[i] == 1) continue;
p[up++] = i;
for (j = i * i; j <= ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
_out << _p.first << ' ' << _p.second;
return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
_in >> _p.first >> _p.... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1001], dp[1011][1 << 8];
int cnt[8][1011];
int check(int len) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j < (1 << 8); j++) {
dp[i][j] = -100000000;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
int x = a[i + 1];
int l = i + 1,... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int maxm = 2e5 + 5;
struct EDGE {
int to, next;
EDGE() {}
EDGE(int to, int next) : to(to), next(next) {}
} edge[maxm * 2];
int head[maxn], edgecnt;
void init() {
memset(head, -1, sizeof(head));
edgecnt = 0;
}
void add(int s, int t) {
... | 7 |
#include <bits/stdc++.h>
const double pi = 3.14159265359;
const int INF = 0x3f3f3f3f;
using namespace std;
int main(void) {
vector<int> x, y;
map<int, set<int> > xx, yy;
int n, temp1, temp2, count = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> temp1 >> temp2;
x.push_back(temp1), y.push_back(temp... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
double x, y;
pt(double _x = 0, double _y = 0) : x(_x), y(_y) {}
};
pt operator+(const pt &a, const pt &b) { return pt(a.x + b.x, a.y + b.y); }
pt operator-(const pt &a, const pt &b) { return pt(a.x - b.x, a.y - b.y); }
pt operator*(const pt &o, const double ... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, int b, int n) {
long long int rm = 1;
while (b) {
if (b % 2) {
rm = (rm * a) % n;
}
a = (a * a) % n;
b /= 2;
}
return rm;
}
const int N = 100000 + 200;
int dp[305][N] = {0}, p[N], a[N], b[N];
vector<int> po... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
const int INF = (int)1e9 + 7;
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int ini() {
int x;
scanf("%d", &x);
return x;
}
long long inl() {
long long x;
scanf("%lld", &x);
return x;
}
int a[100009... | 5 |
#include <bits/stdc++.h>
using namespace std;
char mp[5004][5004];
int fp[5004][5004];
int n, m;
int cnt1 = 0, cnt0 = 0, ans = 1999122700ll;
int orphan(int cp) {
int lop = 0, rm;
for (int i = 1; i + cp - 1 <= n * 2; i += cp) {
for (int j = 1; j + cp - 1 <= m * 2; j += cp) {
rm = fp[i + cp - 1][j + cp - 1]... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
ostream &operator<<(ostream &os, __int128 a) {
char c[40], tot = 0;
if (a < 0) os.put('-'), a = -a;
whil... | 17 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 10;
using namespace std;
map<int, int>::iterator it;
int str[MAXN];
int main() {
int T;
double m, n;
cin >> T;
while (T--) {
cin >> m;
int flag = 0;
if (int(m * m - 4 * m) < 0)
printf("N\n");
else {
double a, b;
a = (m + sqrt(m * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 5;
const int inf = (int)1e9 + 7;
int n;
int b[N], u[N], pos[N], c[N], sz;
vector<int> g[N];
int main() {
scanf("%d", &n);
for (int i = 1; i < n; ++i) {
int x, y;
scanf("%d %d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
... | 9 |
#include <bits/stdc++.h>
static const int INF = std::numeric_limits<int>::max();
int main() {
int n;
std::cin >> n;
std::vector<int> b(n);
for (int i = 0; i < n; ++i) {
std::cin >> b[i];
}
std::vector<int> a(b);
std::sort(a.begin(), a.end());
int numdiff = 0;
for (int i = 0; i < n; ++i) {
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1000000;
map<long long int, long long int> idx, Xor[N + 5];
vector<long long int> v[N + 5];
long long int par[N + 5];
void init() {
for (long long int i = 1; i <= N; ++i) {
par[i] = i;
v[i].push_back(i);
Xor[i][i] = 0;
}
}
long long i... | 16 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
using vi=vector<int>;
vi get_pf(int x){
vi ans;
for(int p=2;p*p<=x;p++) if(x%p==0) {
while(x%p==0) x/=p;
ans.push_back(p);
}
if(x>1) ans.push_back(x);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first)
return a.first > b.first;
else
return a.second < b.second;
}
int main() {
int n, k, s = 0, p = 0;
vector<pair<int, int>> V;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
int x;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
long long m, a(0);
cin >> n >> m;
int c[n], w[n], ansc[n];
for (int ___(0); ___ < n; ++___) cin >> c[___];
for (int ___(0); ___ < n; ++___) cin >> w[___];
memset(ansc, 0, size... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 10;
const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 5;
long long prefix[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
prefix[i] = prefix[i - 1] + x;
}
int l = 0, r = 0;
long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[";
for (int i = 0; i < (int)v.size(); i++) cout << v[i] << " ";
stream << "]";
return stream;
}
long long fpow(long long x, long long p, long long m) {
long long r = 1;
for ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
const int p = 1111111111;
int n, m;
int a[N];
int b[N];
long long pp[N];
long long h[N], hr[N];
set<int> answ;
set<int>::iterator it;
long long calc(int l, int r) { return h[r]... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const int mod9 = 1000 * 1000 * 1000 + 9;
const double PI = 3.1415926535897932;
double sqr(double first) { return first * first; };
long double sqr(long double fir... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T& re) {
re = 0;
int re2 = 1;
char ch = '!';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') re2 = -1, ch = getchar();
while (ch >= '0' && ch <= '9') re = re * 10 + ch - '0', ch = getchar();
re *= re2;... | 18 |
#include <bits/stdc++.h>
using namespace std;
bool mark[300 * 1000 + 5];
queue<int> q;
vector<pair<int, int> > adj[300 * 1000 + 5];
int par[300 * 1000 + 5];
set<int> st;
int main() {
int n, k, d;
cin >> n >> k >> d;
int x, y;
for (int i = 0; i < k; i++) {
cin >> x;
if (!mark[x]) {
mark[x] = true;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 1e6 + 666;
ll p[N], a[N], d[N], n;
void query(int l, int r, ll x, ll y) {
if (l > r) return;
a[l] += x;
a[r + 1] -= x + (r - l) * y;
d[l + 1] += y;
d[r + 1] -= y;
}
void process() {
for (int i = 0; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
scanf("%d", &test);
for (int i = 0; i < test; i++) {
vector<int> v1;
char arr[2 * 100000];
scanf("%s", arr);
v1.push_back(0);
int j = 0, cnt = 1;
while (arr[j] != '\0') {
if (arr[j] == 'R') {
v1.push_back(j ... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.