solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 998244353;
const long long maxn = 1e6 + 7;
const double pi = acos(-1.0);
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
tem... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int x, long long int y) {
return y == 0 ? x : gcd(y, x % y);
}
bool isPalin(string x) {
long long int len = x.length();
for (int i = 0; i <= (len / 2) - 1; ++i) {
if (x[i] != x[len - 1 - i]) return false;
}
return true;
}
string tol... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int r, c;
cin >> r >> c;
char arr[r][c];
bool b = 0;
bool b2 = 0;
bool check = 1;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> arr[i][j];
if (arr[i][j] ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000404;
const long long MOD = 1000000007ll;
const long double PI = acos(-1.0);
const long long INF = 1000000000000000404ll;
const long double EPS = 1e-9;
template <typename t1, typename t2>
inline void upmax(t1 &a, t2 b) {
a = max(a, (t1)b);
}
template... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
v.push_back({-a[i], i});
}
sort(v.begin(), v.end());
int m;
cin >> m;
for (int i = 0; i < m; i++) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int ar[15], br[15];
int main() {
int n, m, i, j;
cin >> n >> m;
for (i = 0; i < n; i++) cin >> ar[i];
for (i = 0; i < m; i++) cin >> br[i];
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (ar[i] == br[j]) {
cout << ar[i] << " ";
br... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
char g[N][N + 1];
int di[] = {0, 0, 1, -1};
int dj[] = {1, -1, 0, 0};
int Qi[N * N], Qj[N * N];
bool was[N][N];
int main() {
int n, m, si, sj;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", g[i]);
for (int j = 0; j < m; +... | 12 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using dou = long double;
string yes = "yes";
string Yes = "Yes";
string YES = "YES";
string no = "no";
string No = "No";
string NO = "NO";
template <class T>
inline bool chmax(T& a... | 6 |
#include <bits/stdc++.h>
int n, data[200000], ret;
int main() {
std::cin >> n;
for (int i = 0; i < n; i++) std::cin >> data[i];
std::sort(data, data + n);
int k = 0;
for (int i = 1; i < n; i++)
if (data[i] != data[k]) data[++k] = data[i];
n = k + 1;
for (int i = 0; i < n; i++) {
int it = 2 * data[... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 9;
struct s {
long long d, w, idx;
s(long long _d, long long _w, long long _idx) {
d = _d;
w = _w;
idx = _idx;
}
};
vector<s> edges[MAX];
long long dis[MAX], counter = 0, par[MAX], cost[MAX];
bool vis[MAX];
set<int> ans;
map<pair<int,... | 12 |
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
struct LineReader
{
std::vector<uint32_t> const &readLine()
{
std::getline(std::cin, line);
values.clear();
uint32_t value = 0;
bool gotValue = false;
for (std::size_t i = 0... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int INF = 10000000;
int a[N], b[N];
int n, x0;
int main() {
int i, j;
scanf("%d%d", &n, &x0);
for (i = 0; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
if (a[i] > b[i]) swap(a[i], b[i]);
}
int minerg = INF;
bool p = false;
for (i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> ns, ms;
int n, m;
long long ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
ns[i % 5]++;
}
for (int i = 1; i <= m; i++) {
ms[i % 5]++;
}
for (pair<int, int> a : ns) {
for (pair<int, int> b : ms) {
if ((a.first + b.... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double ini_place;
double fin_place;
int begin_end;
int id;
} T[400019];
bool cmp(node n1, node n2) {
if (n1.ini_place == n2.ini_place) return n1.begin_end < n2.begin_end;
return n1.ini_place < n2.ini_place;
}
int val_worker[400019];
int main() {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, ma[1005][1005], ans, x[1000005], y[1000005], top, srt[1000005];
long long sum[1005][1005], cost[1000005], mini[1005][1005];
bool use[1000005];
deque<pair<long long, int> > dq;
bool cmp(int i, int j) {
return cost[i] < cost[j] ||
cost[i] == cost[j]... | 17 |
#include <bits/stdc++.h>
int a[105];
int cnt[105];
using namespace std;
int main() {
int n;
cin >> n;
int t = n;
while (t--) {
string s;
cin >> s;
memset(cnt, 0, sizeof(cnt));
int len = s.length();
int flag = 0;
for (int i = 0; i < len; i++) {
a[i] = s[i] - 'a';
cnt[a[i]]++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 55;
int n, m, a[M];
double pro[M], dp[M][M], cnt[M][M];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%d", a + i);
}
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i <= n; ++i) {
cnt[i][0] = 1;
for (int j = 1; j ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, a, d, prev = 0, t1, t2;
cin >> n >> a >> d;
for (int i = 0; i < n; ++i) {
cin >> t1 >> t2;
double t = t2 / a;
double s = a * t * t / 2;
double tt = t1 + t + (d - s) / t2;
if (s >= d) tt = t1 + sqrt(2 * d / a);
if (tt < pr... | 8 |
#include <bits/stdc++.h>
const int MAXN = 1.5e5 + 10;
int n, m, p;
int a[MAXN];
struct Node {
int tot, num[5], cnt[5];
inline friend Node operator+(Node a, Node b) {
Node res = a;
for (int i = 0; i < b.tot; ++i) {
int flg = 0;
for (int j = 0; j < res.tot; ++j)
if (b.num[i] == res.num[j])... | 24 |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define IN insert
#define ALL(a) a.begin(),a.end()
typedef long long int ll;
int main() {
// ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m, val, pos;
void fail() {
cout << "NO";
exit(0);
}
void ck(long long int p, long long int q, long long int z) {
if (val[q] == 1 || m[q] == 0) fail();
val[p] = 1;
val[q] = 1;
pos[p] = z;
pos[q] = z;
}
long long int a[1000002];... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int nMax = 1e6 + 5;
const long long mod = 1e9 + 7;
long long t, n, ps[1000005];
long long p[1000005];
vector<long long> v;
int binser(int x) {
int ans = -1, l = 0, r = v.size() - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (v[mid] * v[mid] <= x) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500010, M = 104;
inline int read() {
int s = 0, w = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(... | 4 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> r[5555];
pair<int, int> c[5555];
int main() {
int n, m, k, i, j, ch, idx, cl;
cin >> n >> m >> k;
for (i = 1; i <= k; i++) {
cin >> ch >> idx >> cl;
if (ch == 1)
r[idx] = make_pair(cl, i);
else
c[idx] = make_pair(cl, i);
}
fo... | 4 |
#include <bits/stdc++.h>
const int N = 1e5 + 10;
using namespace std;
int book[1010], vis[1010];
struct node {
int num;
int flag;
} a[1010];
int main() {
int n, m, d;
while (~scanf("%d %d %d", &n, &m, &d)) {
memset(book, 0, sizeof(book));
memset(vis, 0, sizeof(vis));
long long ans = 0;
ans += (m... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline bool iseq(double x, double y) {
if (fabs(x - y) < 1e-8) return true;
return false;
}
template <typename T>
inline T Min(T a, T b) {
return ((a) < (b) ? (a) : (b));
}
template <typename T>
inline T Max(T a, T b) {
return ((a) > (b) ? (a) : (b));
}
template <ty... | 14 |
#include <bits/stdc++.h>
using namespace std;
int fa[101], a[101], d[101], c[101];
int n, i, j;
int Find(int x) { return fa[x] == x ? fa[x] : fa[x] = Find(fa[x]); }
void Union(int x, int y) { fa[Find(x)] = Find(y); }
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
fa[i] = i;
}
for (i = 1;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = (double)1e-8;
const int mod = (int)1000000007;
const int maxn = (int)1e5 + 5;
int n, m, l, c, kol, ans;
long long x;
int p[maxn], t[maxn], k[maxn], a[30];
vector<int> pr[maxn], prs;
char b[maxn];
int main() {
ios_base::sync_wit... | 17 |
#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);
struct point {
int x, y;
};
long long cross(point x, point y) { return x.x * y.y - x.y * y.x; }
long long dot(point x, point y) { return x.x * y.x + x.y * y.y; }
double nor(point a) {
double ans = dot(a, a);
return sqrt(ans);
}
bool ss(point a, p... | 10 |
#include <bits/stdc++.h>
using namespace std;
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
void chkmax(T& x, T y) {
if (x < y) x = y;
}
template <typename T>
void chkmin(T& x, T y) {
if (x > y) x = y;
}
inline int read() {
int x = 0;
char c = getchar();
w... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long int n, d;
cin >> n >> d;
if ((n + 1) * (n + 1) < 4 * d)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
ret... | 3 |
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
std::vector<int> fa(n, -1);
std::vector<std::vector<int>> son(n);
for (int i = 1; i < n; ++i) {
std::cin >> fa[i];
son[fa[i]].push_back(i);
}
std::vector<int> dis(n, 0);
for (i... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;
int v[maxn + 5];
int vi;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n;
scanf("%d", &n);
map<int, int> cm;
priority_queue<int> pq;
for (int i = 0; i < n * n; i++) {
int num;
scanf("%d", &num);
cm[... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 2222;
const long long INF = 1e18;
struct node {
int l, r;
} a[MN * MN];
int N, M, rk[MN][MN], lcp[MN][MN], r[MN], tot;
char s[MN];
long long dp[MN], K;
inline bool cmp(node a, node b) {
int p = a.l + lcp[a.l][b.l], q = b.l + lcp[a.l][b.l];
if (p > a.r |... | 20 |
#include <bits/stdc++.h>
const int N = 1e6 + 19;
const int mod = 998244353;
using namespace std;
int get_second(pair<int, int> i) { return i.second; }
long long power(long long x, long long y) {
int res = 1;
x = x % mod;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 333;
const double eps = 1e-10;
struct Point {
double x, y;
Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
} p[N];
Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
double cross(Point a, Point b) { return (a.x * b.y - b.x * a.... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int solve1(int n, int a, int b, int T, string s) {
int pre = 0;
vector<int> v;
for (int i = n - 1; i >= 0; --i) {
if (s[i] == 'w') {
pre += b;
}
pre += 1;
v.push_back(pre);
pre += a;
}
int mxlen = 0;
pre = 0;
fo... | 11 |
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 10;
int m, nf, ne, ns, cnt[N], upp[N], sum;
double rf, re, rs, df, de, ans, diff[N * 2];
inline void trans(double& d) { d = sqrt(d * d - 1); }
inline int pos(int i) { return (i >= sum / 2) ? i - sum / 2 : i; }
inline double calc(double r0, int x0, double r... | 18 |
#include <bits/stdc++.h>
const int INF = 1e9 + 12312, MOD = 1e9, MAXN = 200000;
const long double EPS = 0.0000000001;
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
int ans = 0;
if (t % 2) {
t -= 9;
ans++;
}
if (t % 4) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long in() {
int32_t x;
scanf("%d", &x);
return x;
}
const long long maxn = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 10;
long long p[maxn];
long long fen[2][maxn];
inline long long get(long long id, long long x) {
x++;
long l... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans;
int a[111];
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
if (m + i >= 1 && m + i <= n) {
if (a[m + i] != 0 && a[m + i] <= k) {
ans = i;
break;
}
}
if... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool DBG = false;
template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const std::pair<T, S>& p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int b[8] = {1, 0, -1, 0, 1, -1, -1, 1};
queue<pair<int, int> > q;
int n, m, dot, z, t, u, v;
char c[2010][2010];
bool fr[2010][2010];
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = (1), _b = (n); i <= _b; i++)... | 16 |
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 100000000000000000LL
#define ll long long
#define debug(x) cout << #x << " "<< x <<endl;
#define debug_vector(v) cout << #v << " "; _print(v);
const ll inf =1e9+44;
const int MAX=3e5+9;
const ll MOD= 1e9+7;
const double eps=1e-10;
double const ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int maxn = 20;
double dp[1 << maxn][maxn], pk[maxn][maxn];
int bit[1 << maxn], vis[1 << maxn][maxn], n;
double solve(int st, int cp) {
double &ans = dp[st][cp];
if (v... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
const int inf = 1e9 + 1e8;
int N, par[MAXN], c[MAXN];
vector<int> graph[MAXN];
bool works = true;
int ans[MAXN], sz[MAXN], root, solved;
int get_min(int cur) {
int min_val = ans[cur];
for (int node : graph[cur]) {
min_val = min(min_val, get_mi... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int Get() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
int n, m;
i... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 1011;
double bad[MN], f[MN], p[MN][MN];
bool done[MN];
int n;
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
cout << (fixed) << setprecision(9);
while (scanf("%d", &n) == 1) {
for (int i = (1), _b = (n); i <= _b; ++i)
for (int j = (1), _... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int f[3];
int temp = 0;
int k[800000];
bool check(int f[]) {
memset(k, 0, sizeof(k));
for (int i = 0; i <= 30; i++) {
k[1 + i * f[0]] = 1;
k[2 + i * f[1]] = 1;
k[3 + i * f[2]] = 1;
}
for (int j = 1; j <= 20; j++) {
if (k[j] != 1) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, pair<long long, long long> > dp;
long long N;
pair<long long, long long> DP(long long n, long long mx) {
if (n < 10) return pair<long long, long long>(1LL, n - max(mx, n));
pair<long long, long long> ret = pair<long long, long long>(n, mx... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> child[100007];
unordered_map<string, int> levelName[100007];
int uniqueLevelNames[2 * 100007];
int p[100007];
string name[100007];
int subtreeSize[100007];
int level[100007];
int maxChild[100007];
void dfs(int u) {
subtreeSize[u] = 1;
maxChild[u] = -1;
for... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a[36] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[36] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long w, c;
};
bool comp(node i, node j) { return (i.c > j.c); }
long long dp[300020];
long long ans;
node arr[100005];
int main() {
long long i, j, n, m;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> arr[i].w >> arr[i].c;
arr[i].c = ((ar... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long a[4], mins = 1000000000000;
long long c, A, B;
int main() {
for (int i = 0; i < 4; i++) cin >> a[i];
char s[3];
for (int i = 0; i < 3; i++) cin >> s[i];
sort(a, a + 4);
do {
c = a[0];
for (int i = 0; i < 3; i++) {
if (s[i] == '+') c += a[i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1e6 + 5;
string s;
int N, cnt;
bool Add[Nmax];
int main() {
ios ::sync_with_stdio(false);
cin >> s;
N = s.size();
for (int i = 0; i < N; ++i) {
if (!i || s[i] ^ s[i - 1])
Add[++cnt] = 1;
else
Add[cnt] = 0;
}
if (s[0] == s[N -... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
long long int a = (r1 + l1) / 2;
long long int b = (r2 + l2) / 2;
if (a == b) {
cout << a << " " << b + 1 << '\n';
;
} else {
cout << a << " " << b << '\n';
;
}
}
int mai... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool flag = false;
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if ((a[i] == (a[j... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005, mod = 1e9 + 7;
int sum[N << 2];
inline void read(int &x) {
char ch;
int t = 0;
x = 0;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') t = 1;
for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar())
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int MAX_N = 200200;
int n, q;
long long arr[MAX_N];
long long mpow(long long base, long long exp) {
if (exp == 0) return 1;
long long res = mpow(base, exp / 2);
res *= res;
res %= MOD;
if (exp % 2 == 1) {
res *= base;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
for (long long i = 0; i < n; i += 1) cin >> a[i];
}
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return a.secon... | 8 |
#include <bits/stdc++.h>
int inp() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
return sum;
}
int a[510][510];
int ans[510][510];
int sum[510][510];
int max1[510][510], max2[510][510];
long long... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v[200005], g;
int dq, dep[200005], root;
void dfs(int x, int fa) {
dep[x] = dep[fa] + 1;
for (int i = 0; i < v[x].size(); ++i) {
int y = v[x][i];
if (y == fa) continue;
dfs(y, x);
}
}
int main() {
scanf("%d%d", &n, &k);
if (n - k ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mxn = 1e18;
int main() {
long long a;
scanf("%lld", &a);
long long l = a - mxn % a * 9 % a * 9 % a;
long long r = l + mxn - 1;
cout << l << " " << r << endl;
}
| 17 |
#include <bits/stdc++.h>
using namespace std;
void solver();
long long gcd(long long A, long long B) {
if (A == 0) return B;
if (B == 0) return A;
return gcd(B % A, A);
}
long long power(long long A, long long B) {
long long res = 1;
while (B > 0) {
if (B % 2 != 0) res = (res * 1ll * A) % 1000000007;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Node {
int val, pri, ind;
bool operator<(const Node &o) const {
return val == o.val ? pri < o.pri : val < o.val;
}
} b[maxn];
int a[maxn];
int n;
void op(int i) {
int tmp = a[i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dp[1000005];
bool vis[1000005];
int back(int v) {
if (vis[v]) return dp[v];
vis[v] = true;
dp[v] = 0;
if (v == 1) return 0;
int no[20];
for (int i = 0; i <= 10; i++) no[i] = 0;
for (int x = 1; x * x <= v; x++) {
if (v <= x * x * x * x) {
no[back(... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, s1, s2, s3, s4, d, i, o, n[5], m, j, k, l;
int main() {
cin >> a >> b >> c;
s1 = a + b + c;
s2 = a * 2 + b * 2;
s3 = a * 2 + c * 2;
s4 = b * 2 + c * 2;
n[0] = s1;
n[1] = s2;
n[2] = s3;
n[3] = s4;
sort(n, n + 4);
cout << n[0];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int l[30], m[30], w[30];
map<pair<int, int>, pair<int, int> > fst, scnd;
void solve(int low, int up, int a, int b, int c, int path,
map<pair<int, int>, pair<int, int> > &hs) {
if (low == up) {
if (hs.find(make_pair(a - b, b - c)) == hs.end()) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
static const int c[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
{1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
static inline long long sqr(long long x) { return x * x; }
static inline long long dist(int x[3], int y[3]) {
return sqr(x[0] - y[0]) + sqr(x[1] - y[... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 10005;
const int Q_MAX = 10005;
struct query {
int a, b, x;
};
int N, Q;
query queries[Q_MAX];
bitset<N_MAX> answer;
void solve(int start, int end, bitset<N_MAX> sums, bitset<Q_MAX> done) {
for (int q = 0; q < Q; q++) {
if (!done[q] && queries[q].a... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long x, n;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n >> x;
cout << 2 * x << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
setlocale(LC_ALL, "RUS");
int n, x, j = 0, a, b, u = 0;
cin >> n >> a >> b;
b *= 2;
while (n--) {
cin >> x;
if (x == 1) {
if (a > 0)
a--;
else {
if (b > 0) {
b -= 2;
u++;
} else if (u > 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int poz[10001];
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
poz[a[i]] = i;
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--, r--, x--;
in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MV = 2000008;
const int ME = 10000006;
const int MOD = 1000000007;
int is[ME];
int prime[MV];
int add[ME];
int get_prime(int n) {
memset(is, 0, sizeof(is));
int en = 0;
is[0] = is[1] = 1;
for (int i = 2; i < n; i++) {
if (is... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
long long pow... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
const int mxN = 1e5 + 5;
const int mxM = 1e5 + 5;
const int mxQ = 1e5 + 5;
const int B = sqrt(mxN);
int N, M, Q;
vector<ii> edges[mxM];
ii qry[mxN];
struct UFDS {
vector<int> p, s;
void init(int n) {
p.resize(n);
iota((p).begin(), (p).... | 16 |
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).be... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int cnt;
int files;
string name;
vector<int> next;
};
struct disk {
vector<node> t;
void add(string);
int filenum(int);
int dirnum(int);
};
disk d[6];
string line;
int maxfile, maxdir;
int main() {
node n;
n.files = 0;
for (int i = 0; i <... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b, c, n;
string s;
cin >> n;
cin.ignore();
cin >> s;
long long an = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] != '0') an += (s[i] - '0' + 1);
if (i == s.size() - 1 and s[i] != '0') an--;
}
cout << an;
cout << "\... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> l;
vector<int> r;
int ask(int p) {
int cnt = 0;
for (int i = 0; i < l.size(); i++) {
if (r[i] < p) {
cnt++;
} else {
break;
}
}
return l.size() - cnt;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5005;
const int INF = 1 << 30;
const double EPS = 1e-7;
int H, M, N;
int cnt;
int h[MAX], mk[MAX];
map<int, int> Map;
int main() {
scanf("%d %d %d", &H, &M, &N);
for (int i = 0; i < (H); ++i) h[i] = -1;
long long ans = 0;
for (int i = 0; i < (N); ++i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
long long int x, y, z;
x ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long xx[105], yy[105], cnt;
long long gcd(long long x, long long y) {
int res = (y == 0 ? x : gcd(y, x % y));
xx[++cnt] = x;
yy[cnt] = y;
return res;
}
long long ans[105];
bool check(long long a, long long b) {
if (a % 2 == 1) {
return (b / a - 1) % 2;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > root;
pair<int, int> rt(int i, int j) {
if (root[i][j] == make_pair(i, j)) {
return root[i][j];
}
return root[i][j] = rt(root[i][j].first, root[i][j].second);
}
int main() {
int n, m;
while (~scanf("%d%d", &n, &m)) {
vector... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long sqr(long long x) { return x * x; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
long long i = 1, start = 0, ans = 0;
whil... | 9 |
#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 main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, m;
cin >> n >> m;
vector<int> v;
int c = 1;
while (n-... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> al[100100];
long long a[100100], t[100100];
pair<long long, long long> dfs(long long v, long long p = -1) {
pair<long long, long long> ans = make_pair(0, a[v]);
vector<long long> vec;
long long k = 0;
for (int i = 0; i < al[v].size(); i++)
if (... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ta, tb, a[200000 + 5], b[200000 + 5];
vector<int> A[200000 + 5], B[200000 + 5];
inline void Gmax(long long& x, const long long& y) { x < y && (x = y); }
inline int gcd(const int& x, const int& y) { return y ? gcd(y, x % y) : x; }
inline void exgcd(const int& x, co... | 23 |
#include <bits/stdc++.h>
using namespace std;
int N;
int C[105];
bool Vis[105];
set<int> Cyc;
int MaxCnt[105];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> C[i];
for (int Len, Now, i = 1; i <= N; i++) {
if (Vis[i]) continue;
Len = 0, Now = i;
while (!Vis[Now]) {
Vis[Now] = 1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
double PI = 3.141592653589793;
const double EPS = 1e-6;
const int N = 1e6 + 5;
const long long mod = 1e9 + 7;
int oo = 1e9;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int n;
vector<string> g;
int sum[55][55];
int dp[55][55][55][55];
int ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long mod) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
void solve() {
int n, v;
cin >> n >> v;
vector<double> a(n), b(n);
double... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
double a, b;
double ax[MAXN], ay[MAXN], bx[MAXN], by[MAXN], dist[MAXN];
bool visit[MAXN];
int N;
inline double sq(double x) { return x * x; }
inline void insert(double x1_, double y1_, double x2_, double y2_) {
if (x1_ > x2_) swap(x1_, x2_);
if (y... | 14 |
#include <bits/stdc++.h>
using namespace std;
char S[5001];
int main() {
int n;
scanf("%d ", &n);
vector<string> A(n);
vector<string> B(n);
for (auto &e : A) {
scanf("%s", S);
e = S;
}
for (auto &e : B) {
scanf("%s", S);
e = S;
}
string ret;
string retwith;
int mret = 0;
int p = ... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline double sq(double a) { return a * a; }
int n, x[512], p[512];
double rs[512], radius[512];
vector<int> s;
double f(int d, double r) { return sq(d) / (4 * r); }
void relax(int i, int j) {
const int t = s[j];
radius[i] = min(radius[i], sq(x[i] - x[t]) / (4 * radius[... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n;
char a[9][9];
int main() {
ios_base::sync_with_stdio(0);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cin >> a[i][j];
}
}
long long fb, fw;
long long f = 0;
long long mw = 1000000, mb = 10000000;
for (long long i = 0; ... | 4 |
#include <bits/stdc++.h>
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
using namespace std;
long long power(long long x, long... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const int maxn = 2 * (1e6 + 5);
long long mod_pow(long long x, long long n) {
long long ans = 1;
while (n > 0) {
if (n & 1) ans = ans * x % Mod;
x = x * x % Mod;
n >>= 1;
}
return ans;
}
long long fac[maxn], cfac[maxn];
voi... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, maxp = 0, sum = 0;
pair<long long, long long> a[200005];
cin >> n;
for (int i = 0; i < n; i++) {
long long k, maxx = 0;
cin >> k;
for (int i = 0; i < k; i++) {
long long tmp;
cin >> tmp;
maxx = max(maxx, tmp);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
long long toInt(char xx) { return xx - '0'; }
char toChar(long long xx) { return xx + '0'; }
long long isDigit(char xx) { return ('0' <= xx && xx <= '9'); }
bool isCharacter(char xx) {
return (... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.