solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 9;
struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }
Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); }
Point operato... | 6 |
#include <bits/stdc++.h>
using namespace std;
void cout_vector(vector<int> v) {
for (vector<int>::iterator it = v.begin(); it != prev(v.end()); it++)
cout << *it << " ";
cout << *prev(v.end());
cout << endl;
}
int sum_vector(vector<int> v) { return accumulate(v.begin(), v.end(), 0); }
vector<int> liss;
vector... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long n, s, i, lazykol;
string ch;
map <int, long long> mprkol;
set <pair<long long, int>> prkol;
void skip() {
int u, v;
while (i < n) {
i++;
cin >> ch;
if (ch == "end")
return;
cin >> u;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > go_add[1000000 + 5];
vector<pair<int, int> > ret_add[1000000 + 5];
int go_cost[1000000 + 5], ret_cost[1000000 + 5];
multiset<int> go_avl[1000000 + 5], ret_avl[1000000 + 5];
int main() {
int i, n, m, k, d, u, v, c, min_d, r;
long long int mn = 0, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
int n, k, g, h, u[200001], d[200001];
long long ans;
vector<int> v[200001];
vector<pair<int, int> > tmp;
bool ind[200001];
int dfs(int i, int x, int p) {
u[i] = x;
int cnt = 0;
for (int a : v[i]) {
if (a ==... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> data;
for (int i = 0; i < k; i++) {
data.push_back(i);
}
vector<int> in[n];
for (int i = 0; i < n; i++) {
int a;
cin >> a;
for (int j = 0; j < k; j++) {
in[i].push_back(a % 10);
a /=... | 6 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long arr[1000005], nxt[1000005], pre[1000005], n;
long long vis[1000005];
queue<long long> q;
void add(long long i) {
if (i == 0) return;
if (i == n + 1) return;
if (vis[i]) return;
if (arr[i]... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
const int MOD = 1e9 + 7;
long long m, x;
void gao(long long M, vector<pair<long long, long long>> &res) {
for (long long i = 2; i * i <= M; ++i) {
if (M % i == 0) {
res.emplace_back(i, 0);
while (M % i == 0) {
M /= i;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int s[110], r[110], h[110], c[110];
int main() {
int n;
cin >> n;
vector<int> pos;
for (int i = 0; i < n; i++) {
cin >> s[i] >> r[i] >> h[i] >> c[i];
}
int p = -1;
for (int i = 0; i < n; i++) {
bool is = 1;
for (int j = 0; j < n; j++) {
if (s... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int w, b;
double dp[maxn][maxn];
double f(int w, int b) {
if (w <= 0) return 0;
if (b <= 0) return 1;
if (dp[w][b] != -1) return dp[w][b];
if (w == 1 and b == 1) return 0.5;
return dp[w][b] = (double)w / (w + b) +
f(... | 10 |
#include <bits/stdc++.h>
using namespace std;
char CRTBUFF[30000];
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 2.0 * acos(0.0);
long long MIN() { return INF; }
temp... | 17 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int w = 0, flg = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flg = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
w = w * 10 - '0' + ch, ch = getchar();
}
return w * flg;
}
int head[200010], ednum;
str... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 9;
int n, m;
struct E {
int next, to;
} edge[MAXN << 1];
int head[MAXN], edge_num = 1;
int ANS;
int ans[MAXN][5];
bool vis[MAXN];
bool pd[MAXN << 1];
int depth[MAXN];
int fa[MAXN];
void addedge(int x, int y) {
edge[++edge_num].next = head[x];
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100, M = 3;
int n, q, dex, ans, f[N], good[M], bad[M], fen[M][N];
string s;
set<int> st[M];
inline void add(int dex, int type, int val) {
for (; dex < N; dex += (dex & -dex)) fen[type][dex] += val;
}
inline int get(int dex, int type) {
return (dex > ... | 17 |
#include <bits/stdc++.h>
using namespace std;
void err() { cout << '\n'; }
template <class T, class... Ts>
void err(T arg, Ts... args) {
cout << arg << ' ';
err(args...);
}
void read() {}
template <class T, class... Ts>
void read(T &x, Ts &...xs) {
T f = 1;
char ch;
x = 0;
for (ch = getchar(); ch < '0' || c... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k;
int sg[10] = {0, 1, 0, 1, 2};
int grundy(long long int x) {
if (x <= 4) return sg[x];
if (x % 2 == 1) return 0;
int vis[3];
memset(vis, 0, sizeof(vis));
vis[0] = 1;
vis[grundy(x / 2)] = 1;
int g = 0;
while (vis[g]) g++;
return g;
}
int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double d, l, v1, v2;
cin >> d >> l >> v1 >> v2;
cout << setprecision(10) << (l - d) / (v1 + v2);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long md = 1000000007;
long long bexp(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
long long r = bexp(a, b / 2);
r = r * r;
if (b % 2 == 0)
return r;
else
return r * a;
}
long long bs(vector<long long> v, long long n, long ... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<string> ans, name;
vector<pair<int, int> > cannot;
int n, m, i, j, num1, num2, mask, x, p;
string s1, s2;
inline bool settedbit(int _mask, int _numbit) {
return (((_mask & (1 << _numbit))) != 0);
}
int main() {
cin >> n >> m;
name.resize(n);
for (i = 0; i < n... | 7 |
#include <bits/stdc++.h>
using namespace std;
using li = long long;
using ld = long double;
void solve(bool);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
srand(time(0));
solve(true);
return 0;
}
const int maxn = 1e5 + 55;
vector<int> g[maxn];
int cnt[m... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void filejudge() {
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
}
inline int read() {
int x = 0;
bool f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = 0;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 3... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &num) {
T x = 0, f = 1;
char ch = getchar();
for (; ch > '9' || ch < '0'; ch = getchar())
if (ch == '-') f = -1;
for (; ch <= '9' && ch >= '0'; ch = getchar())
x = (x << 3) + (x << 1) + (ch ^ '0');
num = x * f;
}
in... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
if (a > b)
return a;
else
return b;
}
long long int power(long long int a, long long int b) {
long long int ans = 1;
for (long long int i = 1; i <= b; i++) ans *= a;
return ans;
}
int main() {
long lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct rec {
double x, y;
} d[100100], pr[10100];
struct data {
int a;
double b;
} ys[10100];
int pos, v, n, m, i, last;
double t, jd[10100];
inline double f(int a) {
double t, y;
t = d[a].x / (cos(ys[pos].b) * v);
y = t * (v * sin(ys[pos].b) - 9.8 * t * 0.5);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int m[6], w[6], hs, hu;
int x[6];
int main() {
for (int i = 1; i <= 5; i++) scanf("%d", &m[i]);
for (int i = 1; i <= 5; i++) scanf("%d", &w[i]);
for (int i = 1; i <= 5; i++) x[i] = 500 * i;
scanf("%d%d", &hs, &hu);
int ans = 0;
for (int i = 1; i <= 5; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ch[50050][12], l1, l2, fail[50050], ct = 1, dp[50050][52][2][2][2],
is[50050], fa[50050];
char s[50050], l[50050], r[50050];
void ins(int l, int r) {
int st = 1;
for (int i = l; i <= r; i++) {
int vl = s[i] - '0';
if (... | 24 |
#include <bits/stdc++.h>
using namespace std;
void gt(int &a, int b) {
if (a < b) a = b;
}
string n2s(int a) {
stringstream ss;
ss << a;
return ss.str();
}
long long b[4000 + 1][4000 + 1]{0}, a[4000 + 1]{0}, c[4000 + 1][4000 + 1];
int main() {
int n;
long long ans = 0;
cin >> n;
for (int i = 0; i <= n; ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = 1;
string s;
cin >> n >> s;
while ((i * i + i) / 2 <= n) {
cout << s[(i * i + i) / 2 - 1];
i++;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ms[1000005], inv[1000005], ans;
bool bio[1000005], ug[1000005];
int n, m;
void fun(int x) {
if (x > n) return;
if (bio[x]) {
fun(x + 1);
return;
}
bio[x] = 1;
vector<int> v;
for (vector<int>::iterator i = ms[x].begin(); i != ms[x].end(); ++i)... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> x;
vector<pair<int, pair<long long, long long>>> d;
map<string, int> w;
void calh(int i);
void calv(int in) {
d[in].first = 0;
long long w = 0, h = 0, c = 0;
for (auto it : x[in]) {
c++;
if (d[it].first == 1) calv(it);
if (d[it].first =... | 15 |
#include <bits/stdc++.h>
using namespace std;
int checker, n, u[100005], v[100005], c[100005];
vector<int> graph[100005];
bool vis[100005];
void dfs(int u, int p, int color) {
if (c[u] != color) checker = 1;
for (int i = 0; i < graph[u].size(); i++) {
int v1 = graph[u][i];
if (v1 != p) dfs(v1, u, color);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int t, n;
vector<long long int> arr;
int main() {
cin >> t;
for (; t--;) {
long long int s = 0, z = 0;
cin >> n;
arr.resize(n);
for (long long int i = 0; i < n; ++i) {
cin >> arr[i];
s += arr[i];
if (arr[i] == 0) z++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long solve() {
long long n, i, j, min;
cin >> n;
vector<long long> v;
vector<pair<long long, pair<long long, long long>>> h;
for (i = 0; i < n; i++) {
cin >> j;
v.push_back(j);
}
for (i = 0; i < n - 1; i++) {
h.push_back(make_pair(abs(v[i + 1]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 1, tp = 8;
cin >> n;
while (n != 0) {
if (n & 1) ans = ans * tp % 10;
n >>= 1;
tp = tp * tp % 10;
}
cout << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
typedef struct node {
struct node* fd;
struct node* fg;
int leaf;
int nb;
} Node;
Node* trie;
Node* insert_(Node* curr, int val, int pos) {
if (curr == NULL) {
curr = new Node();
curr->nb = 0;
}
if (pos == 32) {
curr->leaf = val;
curr->nb++;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100004;
int a[N], m, k, t, p = 0, n;
int b[N], pt = 0, pos[N];
bool ok[N];
vector<pair<int, int> > v;
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &k);
for (int j = 1; j <= k; j++) {
scanf("%d", &t);
a... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
const long long md = 1e9 + 7;
long long ans[N];
map<int, int> dp;
void add(int l, int r, int x) {
dp[l] += x;
dp[r + 1] -= x;
if (dp[l] == 0) dp.erase(l);
if (dp[r + 1] == 0) dp.erase(r + 1);
}
int main() {
int n, k;
scanf("%d%d", &n, &k);... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
int n, k, i, t, min1, j, s = 0;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i];
i = 1;
t = k;
while (a[i] < 0 && t > 0) {
a[i] = a[i] * -1;
t--;
i++;
}
if (t > 0) {
min1 = a[1];
j = 1;
for (i = 2; i <=... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, vector<pair<int, int>>> rutas;
map<int, int> panaderias;
int n;
int m;
int k;
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
vector<pair<int, int>> aux;
rutas[i + 1] = aux;
panaderias[i + 1] = 0;
}
if (k >= n || k == 0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
int sum = 0;
for (int& x : a) cin >> x, sum += x;
if (sum % n == 0)
cout << 0 << '\n';
else
cout << 1 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, b;
cin >> n;
vector<pair<long long int, long long int> > v;
for (long long int i = 0; i < n; i++) {
cin >> a >> b;
pair<long long int, long long int> p;
p.first = a;
p.second = b;
v.push_back(p);
}
vector<pair... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 13;
long long bufer[N];
long long maxi[N];
int siz[N];
int numofleafs[N];
long long a[N];
vector<int> g[N];
int n;
void calcleaf(int v) {
for (auto x : g[v]) {
calcleaf(x);
numofleafs[v] += numofleafs[x];
}
if (g[v].empty()) numofleafs[v] =... | 11 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
const int MAXN = 2e5 + 5;
int N, M;
bool forb[MAXN];
pair<int, int> egcd(long long a, long long b) {
if (b == 0) return {1, 0};
pair<int, int> RES = egcd(b, a % b);
return {RES.second, RES.first - R... | 15 |
/// .-~~~~~~~~~-._ _.-~~~~~~~~~-.
/// __.' ~. .~ `.__
/// .'// \./ \\`.
/// .'// | \\`.
/// .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`.
/// .'//... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, sum = 0, t = 0, ans = 0;
scanf("%d", &x);
int y[x];
for (int i = 0; i < x; i++) {
scanf("%d", &y[i]);
sum += y[i];
}
sort(y, y + x);
for (int i = x - 1; i >= 0; i--) {
t += y[i];
sum -= y[i];
ans++;
if (t > sum) brea... | 1 |
#include <bits/stdc++.h>
int f[50], n, k, c, x;
bool ok;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
c = 0;
for (int j = 1; j <= k; j++) {
scanf("%d", &x);
c <<= 1;
c |= x;
}
f[c]++;
}
for (int i = 0; i <= 1 << k; i++)
for (int j = 0; j <= i; j++)
... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
long long z = min(n - 1, m);
z = (z * (z + 1)) / 2;
if ((n - 1) < m) z++;
cout << z << endl;
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
vector<char> ans;
struct stroka {
int x, s;
};
void pause() {}
int main() {
ios::sync_with_stdio(false);
int l, i, j, n, m;
cin >> n;
vector<string> s(n);
vector<pair<int, int>> q(n);
int a, b, c, max_l;
max_l = l = 0;
for (i = 0; i < n; i++) {
cin >> ... | 9 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const double pi = acos(-1.0);
int n;
bool G[26][26];
int c[26];
string ans(26, ' ');
int pos;
bool dfs(int cur) {
c[cur] = -1;
for (int(i) = (0); (i) < (26); ++(i))
if (G[cur][i]) {
if (c[i] == -1 || (!c[i] && !dfs(i))) {
cerr << "... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q, a;
int n, flag = 0;
cin >> p >> q >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (q <= 0 || a > (p / q)) {
flag = 1;
break;
}
p = p - a * q;
swap(p, q);
}
if (flag != 1) {
if (q == 0)
print... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const long long INF = 1e17;
const int UP = 0;
const int RIGHT = 1;
const int DOWN = 2;
const int LEFT = 3;
struct List {
int data, d[4];
};
vector<List> work;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n, m, q;
inline bool check(int x, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int vis[2005];
int low[2005];
int num[2005];
int t, n;
vector<int> g[2005];
vector<int> S;
int cnt;
void dfs(int u) {
vis[u] = 1;
low[u] = num[u] = ++t;
S.push_back(u);
for (int i = 0; i < (int)g[u].size(); i++) {
int v = g[u][i];
if (!num[v]) dfs(v);
if... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, c, d;
long long arr[1000000];
vector<long long> v;
cin >> t;
for (int a = 1; a <= t; a++) {
cin >> c >> d;
if ((c + d) % 2 == 1) {
cout << -1 << endl;
} else {
if (c == 0 && d == 0) {
cout << 0 << endl;
... | 0 |
#include <bits/stdc++.h>
long long f(int x) {
long long ans = 1;
while (ans <= x) {
ans *= 2;
}
return ans / 2;
}
int main() {
long long n, m;
while (~scanf("%lld%lld", &m, &n)) {
long long k = f(m);
long long t = k;
int flag = 0;
while (t > n * 1.25) {
t /= 2;
if (t < n * 0.... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, INF = 0x3f3f3f3f;
int a[maxn], d[maxn][25];
int vis[maxn], mx[maxn];
int n;
void init() {
for (int i = 1; i <= n; i++) d[i][0] = a[i];
for (int j = 1; (1 << j) <= n; j++) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
d[i][j] = max(... | 17 |
#include <bits/stdc++.h>
using namespace ::std;
int ar[2005], ar2[2005], p1[2005], p2[2005], ans;
vector<pair<int, int>> v;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> ar[i], p1[ar[i]] = i;
for (int i = 0; i < n; i++) cin >> ar2[i], p2[ar2[i]] = i;
for (int i = 0; i < n; i++)
for (int... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
long long read(long long &a) {
scanf("%lld", &a);
return a;
}
int read(int &a) {
scanf("%d", &a);
return a;
}
int read() {
int a;
scanf("%d", &a);
return a;
}
int read(int &a, int &b) {
scanf("%d %d", &a, &b);
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int level = 0;
getline(cin, s);
for (int i = 0; i < s.length(); i++) {
if (s[i] == '<') {
if (s[++i] == '/') {
level -= 2;
cout << string(level, ' ') << s.substr(i - 1, 4) << endl;
} else {
cout << strin... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[32] = {0}, b[32] = {0};
double n, cnt;
cnt = 0.0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < 1000000; i++) {
for (int j = 0; j < n; j++) {
if (i % a[j] == b[j]) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MIN = -1e9;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (auto &z : v) cin >> z;
for (int i = 0; i < n - 1; ++i) {
if (abs(v[i] - v[i + 1]) >= 2) {
cout << "YES\n";
cout << i + 1 << ' ' << i + 2 << '\n';
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long max(long long a, long long b) {
if (a < b) return b;
return a;
}
long long min(long long a, long long b) {
if (a < b) return a;
return b;
}
long long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 255;
int a[MAX][MAX];
int ans[MAX][MAX];
int n, m;
int di[4] = {0, 0, 1, -1};
int dj[4] = {1, -1, 0, 0};
bool valid(int i, int j) {
if (i < 0 || i >= n) return false;
if (j < 0 || j >= m) return false;
return true;
}
int num_neighbors(int i, int j) {
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
double rast(int x1, int y1, int x2, int y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int dp[500005][30];
int pre[500005][30];
int a[500005];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[200005];
int dep[200005];
int lca[200005][21];
int st[200005], ed[200005];
int cnt = 0;
vector<int> ht[200005];
void dfs(int root, int prev) {
st[root] = cnt++;
ht[dep[root]].push_back(st[root]);
for (int ver : adj[root]) {
if (ver != prev) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, m, root, b, x, y, num, q;
long long p[2 * 200009], a[200009], par[200009][25], pos[200009], nums[200009],
last[200009], sz[200009];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
for (i = 1; i <... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string non = "1";
long long zeroes = 0;
int n;
cin >> n;
while (n--) {
string in;
cin >> in;
if (in == "0") {
cout << in << "\n";
return 0;
}
bool good = false;
int ones = 0;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, sum;
cin >> a >> b;
sum = a * b / 2;
cout << sum << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[1000000], b[100000];
long long minans(long long x) {
long long sum = 0;
for (int i = 0; i < n; i++)
if (a[i] < x) sum += x - a[i];
for (int i = 0; i < m; i++)
if (b[i] > x) sum += b[i] - x;
return sum;
}
int main() {
long long a... | 9 |
#include <bits/stdc++.h>
using namespace std;
double p[3010][310], f[3010][310], q[3010], c[3010], ans;
int n, m, w;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) f[0][i] = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
scanf("%d", &w), p[i][j] = w / 1000.,
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e6 + 3;
const int maxn = 8e5 + 10;
const int maxv = 1e3 + 10;
const double eps = 1e-9;
long long inv[maxn], A[maxn];
long long Pow(long long a, long long n) {
long long ret = 1;
while (n) {
if (n & 1) ret = ret * a % MOD;... | 10 |
#include <bits/stdc++.h>
using namespace std;
constexpr long long N = 9e5 + 9;
long long n, k;
char a[N];
vector<long long> s[N];
vector<long long> pos[N];
long long fa[N];
long long sz[N];
long long w[N];
long long find(long long x) {
if (fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
void uni(long long x, lo... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, c[123456], a[1111234], b[1125678], d[123456], l, ll, r, s, t,
k, m, xh, x, x1, y, z;
string p;
vector<string> q[123];
int main() {
cin >> p;
n = p.size();
for (i = 0; i < n; i++) {
if (p[i] == 'o') {
a[l] = 0;
l++;
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int const maxn = 200010;
int n, m;
vector<int> p[4][maxn];
int X[maxn], Y[maxn];
int ans[9];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d", &X[i], &Y[i]);
int x = X[i], y = Y[i];
p[0][x].push_back(y);
p[1][y].push_back... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, c;
int a[10005], b[10005];
long long dp[2][10005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n >> c;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
int n;
int a[MAXN];
int ans[MAXN];
bool vis[MAXN];
vector<vector<int> > cyc[MAXN];
bool check() {
for (int i = 1; i <= n; i++)
if (!(i & 1) && (cyc[i].size() & 1)) return false;
return true;
}
void work() {
for (int i = 1; i <= n; i++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a[110][110], b[110], t, x, n, m, i, j;
int main() {
scanf("%lld %lld", &n, &m);
memset(b, 0, sizeof(b));
for (i = 1; i <= m; i++) {
t = 0, x = 1;
for (j = 1; j <= n; j++) {
scanf("%lld", &a[i][j]);
if (a[i][j] > t) {
t = a[i][j];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int t1, t2, tot;
int n, cnt;
int head[210000], nex[210000 * 2], to[210000 * 2];
int f[210000], g[210000], son[210000], bj[210000];
void add(int x, int y) {
tot++;
nex[tot] = head[x];
head[x] = tot;
to[tot] = y;
}
void dfs1(int x, int y, int deep) {
g[x] = bj[x];
... | 14 |
#include <bits/stdc++.h>
const long long MOD = 998244353;
const double ZER = 1e-9;
const double PI = acos(-1);
using namespace std;
struct pt {
int x, y;
pt(int _x, int _y) {
x = _x;
y = _y;
}
pt() {
x = 0;
y = 0;
}
};
const int N = 1e5 + 1;
int n;
map<int, vector<pt> > grp;
vector<int> grpNum... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int mulmod(long long int a, long long int b, long long int m) {
long long int q =
(long long int)(((long double)a * (long double)b) / (long double)m);
long long int r = a * b - q * m;
if (r > m) r %= m;
if (r < 0) r += m;
return r;
}
template <type... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int TS = 2125864;
int n, m, a[303][303];
inline void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> a[i][j];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
if ((i == 1 ||... | 4 |
#include <bits/stdc++.h>
using namespace std;
int isPrime(int a)
{
for(int b=2;b<=a/2;b++)
{
if(a%b==0)
return 0;
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t,d,a1,a2,i;
cin>>t;
while(t--)
{
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
register T f = 1;
register char ch = getchar();
t = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
t ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int p, q;
int f[5000004], rub[5000004];
bool sh[5000004];
void shai(int N) {
memset(sh, 0, sizeof(sh));
sh[1] = 1;
for (int i = 1; i <= N; i++) {
if (!sh[i])
for (int j = i + i; j <= N; j += i) sh[j] = 1;
}
}
bool kat(int x) {
int p = x, t[14], cnt = 0;
... | 8 |
/*
Author: mr_cruise/krishrustagi
Rules:
1. Work for satisfaction and not for hunger.
2. Read the question carefully.
3. Check for the corner cases.
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fori(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define foria(i,... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 100011, inf = 0x3f3f3f3f3f3f3f3fLL;
struct P {
long long f, tg;
long long p, d;
};
P mn[MX << 2];
struct E {
long long t, w;
E(long long _t = 0, long long _w = 0) : t(_t), w(_w) {}
};
struct E2 {
long long l, r, w;
E2(long long _l = 0, long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int dp[5005][5005];
struct PAM {
int nex[maxn][30];
int fail[maxn];
int cnt[maxn];
int num[maxn];
int len[maxn];
int S[maxn];
int last, n, p;
int create(int rt) {
memset(nex[p], 0, sizeof(nex[p]));
cnt[p] = 0;
num[p] = 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const double eps = 1e-12;
template <typename T>
inline void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (ch >= '0'... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, i, i1, j, k = 0, d, d1, l, m, o = 0, n, f, f1, a[1001] = {0},
ste[10] = {0};
string s;
f = 0;
ste[0] = 1;
for (i = 1; i <= 9; i++) ste[i] = ste[i - 1] * 7;
cin >> n >> m;
k = 1;
for (i = 0; i <= 9; i++)
... | 9 |
#include <bits/stdc++.h>
const int Maxn = 1e3 + 1, md = 1e9 + 7;
using namespace std;
int n, m;
int main() {
cin >> n >> m;
if (m & 1)
cout << (m + 1) / 2;
else
cout << (n - m) / 2 + 1;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int i, s, n, y, z, nr, nr1, a[104], q, r;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
if (i == 1)
scanf("%d", &z);
else {
scanf("%d", &y);
if (y >= z) a[++nr] = y;
}
}
q = 1;
sort(a + 1, a + nr + 1);
for (i = nr; i >= 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
unsigned long long a, b, c;
scanf("%llu %llu %llu", &a, &b, &c);
printf("%llu\n", (a + b + c) / 2);
}
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int mod = 1000000007;
long long int fact[1000001];
void fac() {
fact[0] = 1;
for (int i = 1; i <= 1000000; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 15;
const int P = 105;
const int K = 105;
const int MAXI = 2e9;
int dp[K][P];
int pen[2][P][K];
void update(int id, int k, int pos, int val) {
while (pos < P) {
pen[id][k][pos] = min(pen[id][k][pos], val);
pos += pos & (-pos);
}
}
int query(i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int n, i;
cin >> n;
int k;
int count = 0;
for (i = 0; i < n; i++) {
cin >> k;
if (k > b && k < c) {
count++;
}
}
cout << count;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
int n;
int main() {
vector<pair<pair<int, int>, int> > v;
cin >> n;
a.resize(n);
int ans = 0;
int K = 0;
for (int i = 0; i < n; i++) {
int k;
long long l;
cin >> k >> l;
long long x, y, m;
cin >> x >> y >> m;
a[i].... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> rows(N);
vector<int> columns(M);
vector<vector<int>> matrix(N, vector<int>(M));
vector<vector<int>> row_adjList(N);
vector<vector<int>> col_adjList(M);
priority_queue<pair<int, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int A[100], B[2];
void poor() {
int m = 0, i = 0;
A[0] = 2;
for (int j = A[i] + 1; j < 200; j++) {
for (int k = 2; k < j; k++) {
if (j % k == 0) {
m = 1;
}
}
if (m == 0) {
A[i + 1] = j;
i++;
}
m = 0;
}
}
void input... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 1;
int t[MAXN], cnt[MAXN];
vector<int> a[MAXN];
void upd(int i, int v) {
for (; i < MAXN; i |= (i + 1)) {
t[i] += v;
}
}
int get(int i) {
int res = 0;
for (; i > -1; i = (i & (i + 1)) - 1) {
res += t[i];
}
return res;
}
int get(int... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<long long int, long long int> &a,
const pair<long long int, long long int> &b) {
return (a.first > b.first);
}
bool sortbysec(const pair<long long int, long long int> &a,
const pair<long long int, long long int> &b) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, t, a, b, c, m, k, u, v, s, res, d[100005];
vector<int> adj[100005];
bool volu[100005], Free[100005];
void bfs() {
queue<int> q;
d[s] = 1;
q.push(s);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = 0, _n = (adj[x].size()); i < _n; i++... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.