solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 1;
vector<int> adj[N];
int a[N], b[N];
int depth[N], par[N];
void dfs_init(int u) {
for (auto c : adj[u]) {
if (c != par[u]) {
depth[c] = depth[u] + 1;
par[c] = u;
dfs_init(c);
}
}
}
vector<int> path;
bool in_path[N];
int... | 26 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
int sum[n + 1];
memset(sum, 0, sizeof(sum));
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i];
}
int ans = INT_MIN;
int total = sum[n];
for (int i = 1;... | 4 |
#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... | 20 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
int n;
int a[maxn];
const int maxv = 1e6 + 5;
int map[maxv];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
std::sort(a + 1, a + n + 1);
n = std::unique(a + 1, a + n + 1) - a - 1;
map[0] = -1;
int last = -1;
for (int i = 1;... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int maxN = 5100;
int n;
int a[maxN][3];
int s[3], c[3];
int l[6], r[6], p[6];
int w, scores[maxN];
int m;
int b[maxN][3];
int ans = n;
bool can(int solutions, int challenges, int group) {
int xl = max(0, solutions - r[grou... | 23 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < v.size(); i++) os << v[i] << " ";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
for (type... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e8 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
long long a[100005], c[100005];
long long used[100005];
struct pr {
lon... | 17 |
#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar();
bool flag = false;
while (!isdigit(c)) {
if (c == '-') flag = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
if (flag) x = -x;
}
using name... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long sum[263000], pro[263000], a[263000];
long long S, E, V;
void ini(long long s, long long e, long long node) {
if (s == e) {
a[node] = s;
return;
}
long long lft = node << 1, rht = (node << 1) | 1, mid = (s + e) >> 1;
ini(s, mid, lft);
ini(mid + 1,... | 16 |
#include <bits/stdc++.h>
using namespace std;
int32_t const N = 1001;
int32_t X[N];
int32_t Y[N];
int32_t gcd(int32_t a, int32_t b) { return a == 0 ? b : gcd(b % a, a); }
struct point {
int32_t x, y;
};
struct line {
int32_t a, b;
int64_t c;
bool operator<(const line &l) const {
if (a != l.a) {
return... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, d;
cin >> n >> a >> d;
long double lastt = 0;
for (int i = 0; i < n; i++) {
int t, v;
cin >> t >> v;
long double T = (v * 1.0) / a;
long double l = a * T * T / 2;
long double ans = t;
if (l > d) {
ans += sqrt(2.0 ... | 8 |
#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
const int maxn = 1e5 + 100;
std::vector<int> v[maxn];
int component[maxn];
int current_component = 0;
int farthest[maxn];
int component_diameter[maxn];
std::vector<int> in_component[maxn];
std::vector<int> prefix_sum[... | 17 |
#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
return n * n;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a,... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
long long ans = 0;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
ans += a[i] * x;
if (x > 1) x--;
}
cout << ans << endl;
}
| 4 |
#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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
templat... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void... | 9 |
#include <bits/stdc++.h>
using namespace std;
int h, m, n, ans = 0;
int H[500000];
bool used[500000];
map<int, int> pl;
void add() {
int x, y;
cin >> x >> y;
while (used[y]) {
y = (y + m) % h;
ans++;
}
used[y] = 1;
pl[x] = y;
}
void del() {
int x, t;
cin >> x;
t = pl[x];
used[t] = 0;
}
int m... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 401, MODM = 1e9 + 7;
vector<int> g[MAXN];
int main() {
int n, m;
cin >> n >> m;
bool fl = 0;
set<pair<int, int>> qq;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
if ((a == 1 && b == n) || (a == n && b == 1)) fl = 1;
a--;
... | 8 |
#include<bits/stdc++.h>
#define ll unsigned long long
#define N 1010
using namespace std;
int t, a[N], n;
int main()
{
cin >> t;
while(t --)
{
cin >> n;
int flag = 1;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
if(a[i] < 0) flag = 0;
}
if(!flag)
{
cout << "NO" << endl;
continue;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, length;
char s[101];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> length;
scanf("%s", s);
x = -1;
y = 0;
for (int j = 0; j < length; j++) {
if (s[j] == 'A') {
if (x != -1) {
y = max(y, j - x - 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[30005];
vector<int> ans;
bool marked[30005];
void dfs(int node) {
marked[node] = true;
for (vector<int>::iterator it = v[node].begin(); it != v[node].end(); ++it)
if (!marked[*it]) dfs(*it);
ans.push_back(node);
}
int main() {
int n, m;
scanf("%d... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
ll res = 1;
a = a % MOD;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0, n, a[4000], sum[4000], i, j, edg, st, end, ls, rs;
scanf("%d", &n);
edg = pow(2, n + 1) - 2;
for (i = 1; i <= edg; i++) scanf("%d ", &a[i]);
st = pow(2, n);
end = pow(2, n + 1) - 1;
for (i = st; i <= end; i++) {
sum[i] = 0;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i <= n - 1; i++) {
cin >> a[i];
}
long long int ans = 0;
for (long long int i = n - 2; i >= 0; i--) {
if (a[i] == 1) {
if (a[i + 1] == 2)
ans ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
scanf("%d\n", &n);
int both = 0;
int one = 0;
for (int i = 0; i < n; i++) {
char x;
int a, b;
scanf("%c %d %d\n", &x, &a, &b);
int small = min(a, b);
int big = max(a, b);
if (x == '+') {
both = max(both, small)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
if (0 == 1) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int n, m;
int t, i;
int luu[1100];
bool check = false;
cin >> n >> m;
luu[0] = 1;
int luutmp[1100];
for (int i = 1; i <= n; i++) {
int value;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
unsigned long long int total1 = 0, total2 = 0;
for (int i = 0; i < n / 2; i++) {
total1 += arr[i];
}
for (int i = n / 2; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << fixed << setprecision(12);
long long t;
cin >> t;
while (t--) {
long long d;
cin >> d;
if (d == 0) {
double x = 0;
cout << "Y " << x << " " << x << endl;
} else if (d < 4)
cout << "N" << endl;
else {
d... | 5 |
#include <bits/stdc++.h>
int64_t psum[300010];
int a[300010];
int main() {
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
std::sort(a, a + n);
psum[0] = a[0];
for (int i = 1; i < n; ++i) {
psum[i] = a[i] + psum[i - 1];
}
int64_t tota... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
int k, A, B, x, y, z;
int v[4] = {118, 60, 94, 62};
while (cin >> a >> b >> k) {
A = (int)a;
B = (int)b;
if (A == 118) {
x = 0;
} else if (A == 60) {
x = 1;
} else if (A == 94) {
x = 2;
} else if (A =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 14;
void priyanshu() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long b[maxn];
long long a[maxn];
int main() {
priyanshu();
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 30010;
const int mod = 998244353;
struct node {
long long v;
int id;
};
bool cmp(node a, node b) { return a.v < b.v; }
int posa[maxn], posb[maxn], ban[maxn];
long long w1[maxn], w2[maxn], w3[maxn], f[maxn];
node a[maxn], b[maxn];
void cal(int i) {
w1[... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n;
string s;
bool good(int i, int j) {
for (int m = i + 1; m < j; m++) {
for (int l = m - 1; l >= i; l--) {
int r = 2 * m - l;
if (r <= j && s[l] == s[m] && s[m] == s[r]) {
return true;
}
}
}
return false;
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1000, M = 20;
const int sqt = 318;
int n, m, q;
pair<int, int> nex[N][M];
string s[N];
void dfs(int x, int y) {
if (s[x][y] == '^') {
if (x == 0 || (x - 1) / sqt < x / sqt)
nex[x][y] = {x, y};
else
nex[x][y] = nex[x - 1][y];
ret... | 19 |
#include <bits/stdc++.h>
using namespace std;
int arr[1005 * 1005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
while (arr[i] % 2 == 0) arr[i] /= 2;
while (arr[i] % 3 == 0) arr[i] /= 3;
}
bool flag = true;
for (int i = 2; i <= n; i++) {
if (arr[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> na, nb, nc, nd;
long long a, b, c, d;
int main() {
string x, y;
long long n;
cin >> n >> x >> y;
for (long long i = 0; i < n; i++) {
if (x[i] == '1') {
if (y[i] == '1')
... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int main() {
int n;
cin >> n;
string s1, s2;
for (int i = 0; i < n; i++) {
bool b = 1;
cin >> s1 >> s2;
if (!m.empty()) {
for (auto a : m) {
if (a.second == s1) {
m[a.first] = s2;
b = 0;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
string y;
std::cin >> n;
while (true) {
y += "47";
sort(y.begin(), y.end());
do {
if (stoll(y) >= n) {
std::cout << y << '\n';
return 0;
}
} while (next_permutation(y.begin()... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
struct cmplx {
double x, y;
double real() { return x; }
cmplx operator+(const cmplx &b) { return {x + b.x, y + b.y}; }
cmplx operator-(const cmplx &b) { return {x - b.x, y - b.y}; }
cmplx operator*(const cmplx &b) {
return {x * b.... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int> > v(m);
int x;
for (int i = 0; i < m; i++) {
for (int j = 0; j < 3; j++) {
cin >> x;
v[i].push_back(x);
}
}
vector<int> color(n + 1, 0);
color[v[0][0]] = 1;
color[v[0][1]] = 2;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
string s = "", ans = "";
int used[MAX_N], k;
vector<pair<int, char> > v;
int main() {
cin >> s >> k;
for (int i = 'a'; i <= 'z'; i++) {
int aux = count(s.begin(), s.end(), i);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string str;
cin >> str;
int N = str.length();
if (N == 1) {
if (str[0] == '0') {
printf("red\n");
} else
printf("cyan\n");
} else {
int sum = 0;
int zc, ec;
z... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
set<long long> st;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
for (int i = 0; i < n; i++) {
for (long long j = 1; j <= 2e9; j <<= 1) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
void solve() {
cin >> n >> m;
char a[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cin >> a[i][j];
}
int ctr = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 'W') {
int up = max(0,... | 3 |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define eb emplace_back
#define mp make_pair
typedef pair<int,int> pii;
#define f first
#define s second
#ifdef local
#define debug(x,label) cerr<<"DEBUG "<<label<<" "<<x<<'\n';
#else
#define debug(x,label);
#endif
#define min(a,b) ((a<b)?a:b)
#defin... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long int> vel;
vector<long long int> pos;
bool collision(double time) {
double rightmost = -2000000000.0;
for (int i = 0; i <= n - 1; ++i)
if (vel[i] > 0)
rightmost = max(rightmost, pos[i] + vel[i] * time);
else if (pos[i] + vel[i] * tim... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b) {
int same = 0;
for (int i = 0; i < 4; i++) {
if (a % 10 == b % 10) same++;
a /= 10;
b /= 10;
}
return (same >= 3);
}
int main() {
int n;
int year[1000];
int mini = 1000, maxi = 2011;
int flag = 1;
cin >> n;
for (int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int p[200010], t[200010];
int n, w, k, l, r, ans, v, tim;
multiset<int> ms, que;
multiset<int>::iterator it;
int main() {
scanf("%d%d%d", &n, &w, &k);
for (int i = 0; i < n; i++) scanf("%d", &p[i]);
for (int i = 0; i < n; i++) scanf("%d", &t[i]);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long w = 0;
int n, a;
cin >> n;
vector<int> v, x, y;
cin >> a;
v.push_back(a);
for (int i = 1; i < n; i++) {
cin >> a;
while (v.size() >= 2 && v[v.size() - 1] <= a &&
v[v.size() - 1] <= v[v.size() - 2]) {
w += min(a, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, xx;
int counter[1000009];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &xx);
counter[xx]++;
}
int cnt = 0;
long long x = 0, y = 0, tot = 0;
for (int i = 1000000; i > 0; i--) {
if (counter[i] >= 1 && counter[i + 1] > ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, i, j, k, flag = 1, sum = 0;
cin >> n;
long long ara[n], ara2[n];
for (i = 0; i < n; i++) {
cin >> ara[i];
sum += ara[i];
}
for (i = 0; i < n; i++) cin >> ara2[i];
sort(ara2, ara2 +... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
int XR[N], YR[N], XB[N], YB[N], arr[N][N];
bool ccw(int i, int j, int k) {
int x1 = XR[j] - XR[i], y1 = YR[j] - YR[i], x2 = XB[k] - XR[i],
y2 = YB[k] - YR[i];
return 1LL * x1 * y2 - 1LL * x2 * y1 > 0;
}
int main() {
int n, m;
scanf("%d %d", ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int shu[1100000];
int sushu[110000];
long long dai[1100000];
long long ans;
int n;
long long a[1100000];
long long aa, bb;
int aaa, bbb;
map<long long, int> w1, wn;
int main() {
for (int i = 2; i <= 1000000; i++) {
if (!shu[i]) {
for (int j = i * 2; j <= 1000000... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long v[200000], t[200000];
long long cnt[200000];
signed main() {
int n;
scanf("%d", &n);
for (int i = 0; i < (n); i++) scanf("%lld", &v[i]);
for (int i = 0; i < (n); i++) scanf("%lld", &t[i]);
priority_queue<pair<long long, long long>, vector<pair<long long,... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 7, inf = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-10;
int n, a, b, mx = 40;
double p[maxn], u[maxn], dp[maxn];
int na[maxn], nb[maxn];
double ansa, ansb;
void solve(double ca, double cb) {
dp[0] = 0.0;
na[0] = nb[0] = 0;
for (int i = 1; ... | 22 |
#include <bits/stdc++.h>
using namespace std;
void input(vector<long long>& v, long n) {
for (long long i = 0; i < n; i++) {
long long in;
cin >> in;
v.push_back(in);
}
}
void output(vector<long long> v) {
for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
}
long long max_of_three(long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
long long ans[25];
void solve() {
ans[2] = 1, ans[4] = 3, ans[6] = 40, ans[8] = 1260;
ans[10] = 72576, ans[12] = 66528... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, s, x, c[10], I, J, K, ans, t;
int main() {
scanf("%d%d", &n, &s);
for (int i = 0; i < n; i++) scanf("%d", &x), c[x]++;
ans = 1000000000;
for (int i = s / n; i >= 0; i--)
for (int j = (s - c[3] * i) / (n - c[3]); j >= i; j--) {
int k = (s - c[3] * i ... | 16 |
#include <bits/stdc++.h>
const bool DEBUG = false;
using namespace std;
const long long maxn = 3e5 + 5 + 1;
const long long INF = 4e18;
const long long M = 1e9 + 7;
const int lg = 21;
#pragma GCC Optimize("Ofast")
long long y, p;
bool ok() {
for (int i = 2; i * i <= y && i <= p; i++) {
if (y % i == 0) {
ret... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct segtr {
long long int siparis, normal, fazlaysa;
} seg[4 * 200005];
long long int N, k, slow, fast, Q;
void update(long long int k, long long int l, long long int r, long long int tg,
long long int extra) {
if (l > tg || r < tg) return;
if (l == tg ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, h0, m0, h, m, count = 1, cash = 1;
cin >> n;
cin >> h0 >> m0;
for (i = 0; i < n - 1; i++) {
cin >> h >> m;
if (h0 == h && m0 == m) {
count++;
if (count > cash) cash = count;
} else
count = 1;
h0 = h;
m0 = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a;
int main() {
scanf("%d%d", &n, &a);
if (a % 2 == 1) {
cout << (a + 1) / 2 << endl;
} else {
cout << n / 2 + 1 - a / 2 << endl;
}
return 0;
}
| 3 |
#include<bits/stdc++.h>
#include <cstdarg>
#include <cstdint>
// @author : sam000013
#define int long long
#define PI 3.14159265
#define pb(x) push_back(x)
#define all(v) v.begin(), v.end()
// #define endl cout<<"\n"
#define dbg(x) cout<<#x<<" "<<x<<endl;
// #define bye endl;return
#define uni 1.000000
#define... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
long long r, x, y, x1, y1;
cin >> r >> x >> y >> x1 >> y1;
cout << ceil((double)sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)) /
(2 * r))
<< "\n";
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a(100500);
int main() {
long long n, m, k, i, j, q;
cin >> n >> k;
long long h = k, t = 0;
for (j = 1; j <= k; j++) {
cin >> a[0];
for (i = 1; i <= a[0]; i++) {
cin >> a[i];
}
if (a[1] == 1)
for (i = 2; i <= a[0]; i++)
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int tab[1000000];
bool porownaj(int a, int b) { return a > b; }
int main() {
int a, b, ile = 1;
cin >> a >> b;
for (int i = 0; i < a; i++) {
cin >> tab[i];
}
if (a == 1) {
cout << 1 << endl;
exit(0);
}
sort(tab, tab + a, porownaj);
for (int i = 0... | 0 |
#include <bits/stdc++.h>
char s[50 + 5][50 + 5];
int n, m, x[100000 + 5], y[100000 + 5], xn, cnt, t, k[256];
void solve() {
int i, j;
for (i = k[t] = 0; i < n; ++i) {
scanf("%s", s[i]);
for (j = 0; j < m; ++j) ++k[s[i][j]];
}
while (k[t]) {
for (i = 0; i < n; ++i)
for (j = 0; j < m; ++j)
... | 19 |
#include <bits/stdc++.h>
using namespace std;
void yay(int flag) {
if (flag == 0)
cout << "NO";
else
cout << "YES";
cout << endl;
}
int eve(long long int x) {
if (x % 2 == 0) return 1;
return 0;
}
void solve() {
long long int n, x, y, a, b;
cin >> n >> x >> y;
a = min(x - 1, y - 1);
a += max(x... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, t, a, b, da, db;
cin >> x >> t >> a >> b >> da >> db;
int **A = new int *[t];
for (int i = 0; i < t; i++) {
A[i] = new int[t];
}
if (x == 0) {
cout << "YES" << endl;
return 0;
}
int u;
int y = 0;
int o = 0;
for (int i = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a, b, c;
cin >> a >> b >> c;
if (n == 1) {
cout << 0;
return 0;
}
cout << min(a, b) + min(min(a, b), c) * (n - 2);
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
using namespace std;
long long fastexp(long long base, long long exp, long long nod = LLONG_MAX) {
long long ans = 1;
while (exp) {
if (exp & 1) ans = (ans * base) % nod;
base = (base * base) % nod;
... | 2 |
#include <bits/stdc++.h>
int main() {
int n, i, a[100001];
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = n; i >= 2; i--)
if (a[i] < a[i - 1]) break;
printf("%d\n", i - 1);
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e+15;
const long long int mod = 1e9 + 7;
long long int n, m, k, ans;
long long int expo(long long int x, long long int y) {
long long int ans = 1;
long long int b = y;
while (x > 0) {
if (x % 2 == 1) ans = (ans * b) % mod;
x = x >> 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1600 + 3;
int h, w;
bool A[MAXN][MAXN];
bool B[MAXN][MAXN];
void add(bool A[][MAXN]) {
static bool tmp[MAXN][MAXN];
memcpy(tmp, A, sizeof(tmp));
for (int i = 1; i < h - 1; i++)
for (int j = 1; j < w - 1; j++) {
if (A[i + 1][j] || A[i][j + 1]... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sta, count, sum;
bool a[105], b;
ios::sync_with_stdio(false);
while (cin >> n) {
count = 0;
sum = 0;
b = 0;
sta = 1;
a[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i]) b = 1;
if (!b && !a[i])... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long P, q, tot, Prime[105], fac[105], mod = 998244353;
inline long long read() {
long long s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e14;
const long long N = 2e3 + 1;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
long long n, m, x, y, a[N], cnt, ans;
int main() {
string dp[2] = {"NO", "YES"};
ios_base::sync_with_stdio(0);
;
string s;
cin >> s;
for (int i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int x[1001];
int a[1001];
int cnt;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
x[i] = a[i];
}
sort(a, a + n);
sort(x, x + n);
for (int i = 0; i < n; i++) {
bool ok = true;
for (int j = i + 1; j < n; j++) {
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x, y, inf = 2e6, lx = inf, rx = -1, ly = inf, ry = -1, ls = inf,
rs = -inf;
cin >> n;
string s;
for (int i =... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 20;
const int mod[] = {1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9};
const int base[] = {727, 4001};
string s[maxn], t[maxn];
int l[maxn], r[maxn], pw[maxn][2], hs[maxn][2], ht[maxn][2];
void prepare() {
pw[0][0] = pw[0][1] = 1;
for (int i = 1;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int mod1 = 998244353;
const int mod2 = 1e9 + 9;
int n;
char s[N];
bool vis[N][N];
int f[N];
long long ha1[N], ha2[N], pw1[N], pw2[N];
long long getha(long long *ha, long long *pw, long long mod, int l, int r) {
return (ha[r] - pw[r - l + 1] * ha[... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool solve() {
int n;
cin >> n;
int f[n + 1], j;
for (int i = 1; i <= n; i++) cin >> f[i];
for (int i = 1; i <= n; i++) {
if (f[f[f[i]]] == i) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
in... | 0 |
//copied
#include<bits/stdc++.h>
using namespace std;
const int maxn=6007;
int n;
int x[maxn],y[maxn];
vector<int> perm;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n;
for (int i=0;i<n;++i) cin>>x[i]>>y[i];
for (int i=0;i<n;++i){
perm.push_back(i);
f... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int p = 0;
if (s[0] == '1' && s.size() == 1) {
cout << "1\n";
continue;
}
vector<int> q;
if (s[0] == '1') p++;
char ch = s[0];
int y = s.size();
for (in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, y1, x2, y2, d, x, y;
cin >> x1 >> y1;
cin >> x2 >> y2;
y = abs(y1 - y2);
x = abs(x1 - x2);
d = max(x, y);
cout << d;
return 0;
}
| 0 |
#include<stdio.h>
#include<math.h>
int main()
{
long long int W,E,s,x,y,a,b,c,d,i,j,z,k,N,M,t,m,max;
scanf("%lld", &N);
for(i=0; i<N; i++)
{
scanf("%lld", &M);
if((M%2)!=0)
{
printf("YES\n");
}
else
{
y=0;
E=M;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;
char ch;
string ss = "", str = "";
long long a[200005], b[200005];
void dbg(long long x = 0, long long y = 0, long long z = 0, long long a = 0) {
cout << "Dbg: " << x << " " << y << " " << z << " " << a ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void _in(long long *a, ...) {
va_list arg_ptr;
scanf("%I64d", a);
long long *temp;
va_start(arg_ptr, a);
temp = va_arg(arg_ptr, long long *);
while (temp) {
scanf("%I64d", temp);
temp = va_arg(arg_ptr, long long *);
}
va_end(arg_ptr);
}
void _in(int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m, counter;
char repr[500050];
vector<int> adj[500050];
pair<int, int> seg[500050];
vector<pair<int, int>> occur[500050];
void go(int u, int depth) {
counter++;
int current = 1 << (repr[u] - 'a');
occur[depth].push_back(
make_pair(counter, occur[depth].ba... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
long long arr[MAX];
long long best[MAX];
long long down[MAX];
vector<int> adj[MAX];
long long ans;
void dfs(int s, int p) {
vector<long long> help;
for (int i = 0; i < adj[s].size(); i++) {
int u = adj[s][i];
if (u != p) {
dfs(u, s... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, count = 0, x = 0;
cin >> n;
int a[n], b[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 < n; i++) a[i] -= b[i];
sort(a, a + n);
for (int i = n - 1; i > 0; i--) {
for (int j... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, ans, a, b, p;
int main() {
scanf("%d%d", &n, &k);
a = (n - 1) / k;
b = (n - 1) % k;
ans = 2 * a + min(2, b);
printf("%d\n", ans);
p = 1;
for (int i = 1; i <= b; i++) {
p++;
printf("1 %d\n", p);
for (int j = 1; j <= a; j++) {
printf(... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int n, m, cnt;
long long v;
int p[MAXN];
void calc(int v) {
if (!v)
cnt += 4;
else if (v == 1 || v == 3)
cnt += 3;
else if (v == 2 || v == 4)
cnt += 2;
else
cnt += 1;
return;
}
void slv(int tmp, int v) {
if (v == 0) {
pri... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
const int MAXK = 101;
int n, m, s, k;
int d[MAXN][MAXK];
vector<int> cor[MAXK];
vector<int> adj[MAXN];
void bfs(int x) {
queue<int> q;
for (int v : cor[x]) {
q.push(v);
d[v][x] = 0;
}
while (!q.empty()) {
int f = q.front();
... | 8 |
#include <bits/stdc++.h>
#include<string>
#define ll long long
#define mod 1000000007
using namespace std;
ll
gcd (ll x, ll y)
{
if (!y)
return x;
return gcd (y, x % y);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t ;
cin >> t ;
//t=1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
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 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int f, t;
bool flag = false;
while (n--) {
cin >> s >> f >> t;
if (f >= 2400 and t > f) flag = true;
}
if (flag)
cout << "YES";
else
cout << "NO";
return 0;
}
| 0 |
#include <bits/stdc++.h>
namespace chtholly {
char buf[1 << 23], *p1 = buf, *p2 = buf;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) f ^= c == '-';
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
return f ? x : -x;
}
template <typename mits... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
using namespace std;
char a[4000020];
int f[4000020], g[4000020], h[4000020];
deque<int> q;
void InitSA(char *s, int n, int m) {
static int l[4000020], r[4000020], c[4000020];
int i, p, k;
int *x, *y;
x = l;
y = r;
for (i =... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
long double sum;
int x, y, n;
double k, s = 50.000;
int a[N];
int b[N];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n - 1; i++) {
sum += sqrt(((a[i] - a[i + 1]) * (a[i] - a[i + 1... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.