solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e3 + 10;
int n, m, a[N];
long long dp[N][N], x;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
memset(dp, inf, sizeof(dp));
dp[n + 1][0] = 0;
for (int i = n; ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d1, d2, d3, sum = 0, p;
cin >> d1 >> d2 >> d3;
sum += min(min(d1, d2 + d3), min(d2, d1 + d3));
if (sum == d1)
p = d1;
else
p = d2;
sum += min(d3, (d2 + d1));
if (p == d1)
sum += min(d2, (d1 + d3));
else
sum += min(d1, (d2 + d... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
long long int a[N], b[N];
int main() {
int n;
scanf("%d", &n);
long long int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
}
sort(b, b + n, g... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, p[100005][2], front[100005], t;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i][0] >> p[i][1];
}
cin >> t;
for (int c = 0; c < t; c++) {
int x, y;
cin >> x >> y;
bool f = 0;
for (int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 1e5 + 10, L = 18;
int n, m, q, k, c[N], h[N], par[N][L], mx[N][L];
vector<pair<int, int> > adj[N];
long long sum;
struct edge {
int x, y, w;
bool operator<(const edge snd) const { return w < snd.w; }
} e[N <... | 19 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
int n = s.length(), d = 0;
string x = "[]|:";
bool kn = 0, kc = 0;
int l, r;
for (int i = 0; i < n && (kn == 0 || kc == 0); i++)
if (x.find(s[i]) == x.npos)
d++;
else {
if (kn == 0) {
if (s[i] == '[')
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline bool compare(long long int i, long long int j) { return i < j; }
template <typename T>
T gcd(T a, T b);
template <typename T>
T modpow(T number, T power, T mod_value);
string s;
char ch[3] = {'a', 'b', 'c'};
bool check(long long int p) {
bool left_, right_;
if (p... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
char buf[100002];
int s[100002];
int t[100002];
int pl[100002];
int neg[100002];
int tmp[100002];
set<int> P;
set<int> N;
vector<pair<int, int> > ans;
int main() {
cin >> n;
scanf("%s", buf);
for (int i = 0; i < n; i++) {
s[i] = buf[i] - '0';
tmp[i] = s... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200;
const int INF = 1000000007;
char buf[MAXN][MAXN];
int cnt[MAXN][MAXN];
int dp[MAXN][MAXN];
int main() {
int r, c, t, ans;
scanf("%d%d", &r, &c);
for (int i = 0; i < r; ++i) {
scanf("%s", buf[i]);
}
t = 0;
for (int i = 0; i < r; ++i) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000000;
int main() {
int c, w1, v1, w2, v2;
scanf("%d%d%d%d%d", &c, &v1, &v2, &w1, &w2);
if ((long long)v1 * w2 < (long long)v2 * w1) swap(v1, v2), swap(w1, w2);
int sq = sqrt(maxn + 0.5);
long long ans = 0LL;
if (w1 <= sq)
for (long lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int INF = 1e9;
struct robot {
long long c, f;
} mas[N];
bool cmp1(robot a, robot b) {
if (a.c == b.c) return a.f > b.f;
return a.c > b.c;
}
bool cmp2(robot a, robot b) { return a.f < b.f; }
int main() {
int n, d, s;
cin >> n >> d >> s;
... | 15 |
#include <bits/stdc++.h>
int n, k;
std::string s;
char e;
unsigned long long c = 0;
std::set<char> keys;
unsigned long long ans = 0;
int main() {
std::cin >> n >> k;
std::cin >> s;
for (size_t i = 0; i < k; i++) {
std::cin >> e;
keys.insert(e);
}
for (size_t i = 0; i < n; i++) {
if (keys.count(s[i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005, MOD = 1e9 + 7;
int f[N][N], C[N][N], las[N], tmp[26];
char s[N];
int main() {
C[0][0] = 1;
for (int i = 1; i < N; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
}
int n;
scanf("%d... | 16 |
#include <bits/stdc++.h>
using namespace std;
long int a[1111], b[1111];
int main() {
int n, m;
cin >> n >> m;
long long ans = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
vector<long int> v;
for (int i = 0; i < m; i++) {
cin >> b[i];
sum -= a[b[i] - 1];
v.push... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T from_string(string s) {
T result;
istringstream sin(s);
sin >> ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
a -= b;
if (a < 0) a += md;
}
inline int mul(int a, int b) { return (int)((long long)a * b % md); }
int pow(int a, int b) {
int res = 1;
whi... | 11 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
int q;
cin >> q;
while (q--) {
int l, r, k;
scanf("%d %d %d", &l, &r, &k);
l--, r--;
k %= (r - l + 1);
string p = s;
for (int i = l; i <= r; i++) {
int to = i - k;
if (to < l) to = r - (l - to - 1)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double Eps = 1e-8;
struct point {
double x, y;
};
point v, p, w1, w2, m1, m2, o, _p;
void input() {
scanf("%lf%lf", &v.x, &v.y);
scanf("%lf%lf", &p.x, &p.y);
scanf("%lf%lf%lf%lf", &w1.x, &w1.y, &w2.x, &w2.y);
scanf("%lf%lf%lf%lf", &m1.x, &m1.y, &m2.x, &m2.y)... | 16 |
#include <bits/stdc++.h>
int main() {
char a[200], b[200], c[200];
gets(a);
gets(b);
int i, j, k, l = 0;
int m = strlen(a), n = strlen(b);
for (i = m - 1, j = 0; i >= 0; i--, j++) {
c[j] = a[i];
if (c[j] == b[j]) {
l = l + 1;
}
}
if (l == m) {
printf("YES");
} else {
printf("... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[714514];
long long dp[5100][5100];
int main() {
scanf("%d%d", &N, &K);
for (int(i) = 0; (i) < (N); (i)++) scanf("%d", &A[i]);
sort(A, A + N);
int p1 = N % K;
int p2 = K - p1;
int w = N / K;
for (int(i) = 0; (i) < (5100); (i)++)
for (int(j) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<pair<long long, long long> > ip(n);
for (int i = 0; i < n; i++) {
long long t;
cin >> t;
;
ip[i] = {t, i + 1};
}
sort(ip.begin(), ip.end()... | 7 |
#include <bits/stdc++.h>
const int N = 200200;
const int Q = 2 * N;
using namespace std;
int n;
int a[N];
int c[N];
int s[N];
int le[N];
int ri[N];
int f[Q];
int mx;
set<int> S;
int t[N];
void upd(int x, int y) {
while (x < N) {
t[x] += y;
x += x & -x;
}
}
int get(int x) {
int res = 0;
while (x > 0) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const size_t Nmax = 100000;
struct participant_t {
int s, a, b;
void read() { scanf("%i %i %i", &s, &a, &b); }
friend bool operator<(const participant_t& p, const participant_t& q) {
return p.a - p.b > q.a - q.b;
}
} P[Nmax + 1];
int N, S;
long long T;
inline in... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const N = 1e6 + 10;
ll a[N];
struct Node {
ll maxx{0LL}, minn{0LL}, sum{0LL}, lazy{0LL}, num{0LL};
Node() = default;
} tree[N];
void pushup(ll rt) {
tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
tree[rt].maxx = max(tree[rt << 1]... | 18 |
#include <bits/stdc++.h>
using namespace std;
int x[510];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = (0); i < (n); ++i) {
scanf("%d", &x[i]);
}
double res = 0;
for (int i = (0); i < (m); ++i) {
int v1, v2, c;
scanf("%d%d%d", &v1, &v2, &c);
double now = x[v1 - 1] + x[v2 - 1];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 * 3 + 2, oo = INT_MAX, mod = 100000007;
void debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
cerr << " " << to_string(H);
debug(T...);
}
int main() {
ios_base::sync_with_stdio(false);
cin.t... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool visit[1000005];
int main() {
int n;
cin >> n;
vector<int> x;
int MAX = INT_MIN;
int y;
for (int i = 0; i < n; i++) {
cin >> y;
x.push_back(y);
MAX = max(y, MAX);
}
int c = 0;
int i = 0;
int dirC = 0;
bool increOn = true;
bool justSta... | 4 |
#include <bits/stdc++.h>
using namespace std;
double a[50005];
int main() {
double n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double mx = 0, sum = 0, d = 0;
for (int i = k; i <= n; i++) {
sum = 0;
for (int j = 0; j < i; j++) {
sum += a[j];
}
d = sum / double(... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long head[100005], cnt, n, m, k, ans, x[100005];
bool y[100005];
struct ed {
long long next, to, val;
} e[100005 * 4];
inline void ins(int u, int v, int w) {
e[++cnt].to = v;
e[cnt].val = w;
e[cnt].next = head[u];
head[u] = cnt;
}
int main() {
scanf("%I64d%... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long x, k;
const int MOD = 1e9 + 7;
long long mod_pow(long long x, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
cin >> x >> k;
if (x == 0)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, ans(1000000007);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(0);
cin >> n >> m >> l >> r;
if (l == 1 && r == n) ans = 0;
if (l == 1) ans = min(ans, abs(m - r) + 1);
if (r == n) ans = min(ans, a... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int cmp(double x, double y = 0, double tol = 1e-10) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
vector<long long int> v;
void solve(long long int n) {
if (n > 777777777) return;
v.push_back(n);
solve(n * 10 + 4);
solve(n * 10 + 7);
}
int main() ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int mod_pow(long long int a, long long int b, long long int m) {
long long int res = 1;
while (b) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
bool isPrime(long long int n) {
if (n <= 1) return false;
for (lon... | 2 |
#include <bits/stdc++.h>
int n;
int ex[105];
int a, b;
int sum;
int main() {
scanf("%d", &n);
for (int i = 1; i < n; ++i) scanf("%d", &ex[i]);
scanf("%d%d", &a, &b);
for (int i = a; i < b; ++i) sum += ex[i];
printf("%d", sum);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
cin >> t;
while (t--) {
long long n, i, s = 0, j = 1, q = 0;
cin >> n;
long long a[n];
for (i = 0; i < (n); i++) cin >> a[i];
for (i = 0; i < (n); i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Res {
int u, v;
long long w;
void read() { scanf("%d %d %lld", &u, &v, &w); }
bool operator<(const Res &t) const { return w < t.w; }
} edge[N];
struct Node {
int u;
long long w;
bool operator<(const Node &t) const { return w > t.... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100100], rs;
map<long long, long long> M;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], M[a[i]]++;
sort(a + 1, a + n + 1);
if (a[3] != a[2])
cout << M[a[3]];
else if... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long MAXN = 1000000;
using ll = long long;
void fast_stream() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll doit(vector<ll> s) {
if (s.size() == 1) {
return 1;
}
ll mini = ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int power(long long int x, long long int n) {
if (n == 0) return 1;
if (n % 2) return x * power(x * x, (n - 1) / 2);
return power(x * x, n / 2);
}
long lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, X, Y;
int pm[(1 << 17)], pc[(1 << 17)];
int mmd[(1 << 17)], ddt[(1 << 17)];
int mrk[(1 << 17)];
int Ans;
int main() {
scanf("%d%d%d%d", &n, &m, &X, &Y);
for (int i = 0; i < n; i++) {
scanf("%d", &pm[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d", ... | 13 |
#include <bits/stdc++.h>
inline long long read() {
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
long long k = 0, kk = 1;
if (c == '-') c = getchar(), kk = -1;
while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
return kk * k;
}
using namespace std;
void write(lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 100;
int s[N], n, K;
void read() {
cin >> n >> K;
for (int i = 0; i < n; i++) cin >> s[i];
}
bool cal(int x) {
int i = 0, j = n - 1, k = 0;
while (i <= j) {
if (s[i] + s[j] <= x)
i++, j--, k++;
else if (s[i] > s[j] && s[i] <=... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200007, MAXK = 5;
vector<int> G[MAXN];
int n, k;
bool used[MAXN];
long long ans = 0, cnt[MAXN][MAXK], sum[MAXN][MAXK];
void dfs(int v, bool root) {
used[v] = true;
cnt[v][0]++;
for (int i = (0); i < (((int)(G[v]).size())); ++i) {
int to = G[v][i];... | 13 |
#include <bits/stdc++.h>
int main() {
int n;
std::string s;
std::cin >> n >> s;
std::vector<int> mx(26, 0);
std::vector<int> dp(n, 1);
for (int i = 0; i < n; ++i) {
for (int c = 25; c > s[i] - 'a'; --c) dp[i] = std::max(dp[i], mx[c] + 1);
mx[s[i] - 'a'] = std::max(mx[s[i] - 'a'], dp[i]);
}
std::... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1009;
bool arr[sz][sz], out[sz][sz];
int16_t x, y, l[sz][sz], r[sz][sz], t[sz][sz], b[sz][sz];
int16_t A, B, C, D;
char inp;
vector<int> vec;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
bool check = 1;
cin >> x >> y;
int counter = 0;
for (in... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1000000007;
const int N = 100000 + 7;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 1; i <= 200; i++) {
for (int j = 1; j < i; j++) {
for (int k = 1; k < i; k++) {
if (a <= i && i <= 2 * a && b <= j && j... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 1;
int n, m, a[maxn], ans[maxn];
const int B = 20;
struct LB {
int vec[B], pos[B];
LB() {
memset(vec, 0, sizeof(vec));
memset(pos, 0, sizeof(pos));
}
inline void push(int value, int pos) {
for (int i = B - 1; i >= 0; --i)
if ... | 17 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
struct DSU {
vector<int> rank;
vector<int> prev;
DSU(int n) {
rank.assign(n, 0);
prev.assign(n, -1);
}
int findSet(int x) {
if (prev[x] == -1) return x;
return prev[x] = findSet(prev[x]);
}
void unionS... | 15 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
void solve(std::istream& in, std::ostream& out) {
int n;
in >> n;
int first = 1;
auto ask = [&](int one_cnt) {
out << "? " + std::string(one_cnt, first == 0 ? '0' : '1') +
std::string(n - one_cnt, first == 0... | 12 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl "\n"
ll const INF=1000000007;
ll mod=1e9+7;
ll gcd(ll a,ll b)
{
if(a==0)
return b;
if(b==0)
return a;
return gcd(b,a%b);
}
void test()
{
ll... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, x0, y0;
scanf("%d%d%d%d", &x, &y, &x0, &y0);
char b[100010];
getchar();
gets(b);
int a[501][501];
memset(a, 1, sizeof(a));
int t = strlen(b);
int sum = x * y;
int z;
for (int i = 0; i < t; i++) {
if (a[x0][y0])
z = 1;
... | 8 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mhp, reg, sp[1010][2], got[1010] = {0};
scanf("%i %i %i\n", &n, &mhp, ®);
for (int i = 0; i < n; i++) {
scanf("%i %i", &sp[i][0], &sp[i][1]);
sp[i][0] = sp[i][0] * mhp / 100;
}
int sub = 0;
int t = -1;
int resind = 0;
int res[1... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const long long MAXN = 300000;
const long long INF = 21474836... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long x, y;
cin >> x >> y;
long long a = abs(1 - x) + abs(1 - y);
long long b = abs(n - x) + abs(n - y);
if (a <= b)
cout << "White" << endl;
else if (a > b)
cout << "Black" << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 2e5 + 1;
int n, m, x[3];
vector<int> a[N], dis[3];
long long p[N];
void bfs(int s, int cur) {
dis[cur].assign(n + 1, -1);
;
queue<int> ... | 13 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> ps[2002];
int id[2002], pos[2002];
pair<int, int> line[4000006];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long s;
cin >> s;
s <<= 1;
for (int i = 1; i <= n; ++i) cin >> ps[i].first >> ps[i].second;
sort(ps... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long inv[1009];
int f[200009];
long long mod = 998244353;
long long P[200009], IP[200009], S[200009];
long long F(int l, int r) {
return ((S[r - 1] - S[l - 1] + mod) * IP[l - 1] + 1) % mod * IP[r] % mod *
P[l - 1] % mod;
}
int main() {
long long n, q;
ci... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cout << 1 << " ";
cout << endl;
t--;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int max1[1000010];
int max2[1000010];
int nmax1[1000000];
int nmax2[1000000];
int d[1000010];
int p[1000010];
void calc(int v, int id, int nd) {
bool changed = 0;
if (id == nmax1[v]) {
max1[v] = nd;
} else if (id == nmax2[v]) {
max2... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 9;
const int shift = 1e3 + 9;
const double Eps = 1e-7;
int cnum[20000009];
int n, k, d;
int main(void) {
if (fopen("in", "r") != NULL) {
freopen("i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, rslt, x1, x2, y1, y2;
cin >> n;
cin >> x1 >> y1 >> x2 >> y2;
int a = abs(x2 - x1);
int b = abs(y2 - y1);
if (b == n || a == n)
rslt = x1 + x2 + y1 + y2;
else
rslt = a + b;
cout << min(rslt, 4 * n - rslt);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXQ = 200005;
int rx[MAXQ], ry[MAXQ];
int qx[MAXQ][2], qy[MAXQ][2];
int res[MAXQ];
struct node {
int l, r, m, v;
} s[MAXN << 2];
void push_up(int n) { s[n].v = min(s[n << 1].v, s[n << 1 | 1].v); }
void build(int l, int r, int n) {
int... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long ask(long long x, int y, long long k) {
int now = 0;
long long ans = 0, t = 1;
while (y < 0) {
y++;
t *= 2;
}
while (x) {
if (x & 1) ans += t;
now++;
if (ans > k || t > k) return 0;
if (now > y) t *= 2;
x /= 2;
}
return 1;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> w(n), b(m);
for (int i = 0; i < n; ++i) cin >> w[i];
vector<int> was(n);
vector<int> v;
for (int i = 0; i < m; ++i) {
cin >> b[i];
--b[i];
if (!was[b[i]]) v.push_back(b[i]);
was[b[i]] = 1;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[101];
bool f[101];
int main() {
int n, d, ans = 0, cnt = 0;
scanf("%d%d", &n, &d);
for (int i = 1; i <= d; i++) {
scanf("%s", s + 1);
for (int j = 1; j <= n; j++)
if (s[j] == '0') f[i] = 1;
}
for (int i = 1; i <= d; i++)
if (!f[i]) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a, m;
struct koor {
int i, ch;
};
map<int, bool> pizda;
bool cmp(koor a, koor b) { return a.ch < b.ch; }
koor t;
int z;
vector<koor> q;
int main() {
ios_base::sync_with_stdio(false), cout.tie(), cin.tie();
cin >> n;
for (int i = 1; i <= n; ++i) pizda[i] = fal... | 4 |
#include <bits/stdc++.h>
using namespace std;
int numclouds;
struct node {
node *parent;
bool change;
int subsize;
node() : parent(this), change(false), subsize(1) {}
void moveUp() {
if (parent != this) {
parent->moveUp();
change ^= parent->change;
parent = parent->parent;
}
}
};
b... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, dis[105], vis[105], mx[105], mn[105], flag = 1;
long long tot, head[105], nx[30005], to[30005], gc[30005], lc[30005];
void jia(long long aa, long long bb, long long cc, long long dd) {
tot++;
nx[tot] = head[aa];
to[tot] = bb;
gc[tot] = cc;
lc[tot] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long b, long long s) { return (s != 0) ? gcd(s, b % s) : b; }
long long Pow(long long a, long long b, long long c) {
if (b == 0)
return 1 % c;
else if (b == 1)
return a % c;
else {
long long A = Pow(a, b / 2, c);
A = (A * A) % c;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T Bitcnt(T a) {
int sum = 0;
while (a) {
if (a & 1) sum++;
a /= 2;
}
return sum;
}
template <class T>
T Max3(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
T Lcm(T a, T b) {
T tmp = __gcd(a, b);
return (a / tmp) * b;... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, g[13][13], lca[13][13];
long long dp[1 << 13][13];
long long f(int s, int root) {
s &= ~(1 << root);
if (s == 0) return 1;
if (dp[s][root] != -1) return dp[s][root];
long long res = 0;
int must = 0;
for (int i = (0); i < (n); i++)
if (s & 1 << i... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-4;
double f[1100][1100];
double mp[1100][1100], g[1100][1100];
int n, m, X, Y;
void gauss(int row) {
for (register int i = 1; i <= m; i++)
for (register int j = i + 1; j <= m; j++) {
if (mp[j][i] == 0) break;
double temp = mp[j][i] / ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 503;
int n, m, mod, F[N][N], G[N][N], C[N][N], f[N], g[N];
void qmo(int &x) { x += x >> 31 & mod; }
int main() {
scanf("%d%d%d", &n, &m, &mod);
for (int i = 0; i <= n; ++i)
for (int j = *C[i] = 1; j <= i; ++j)
qmo(C[i][j] = C[i - 1][j] + C[i - 1]... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
struct node {
int s, t, no;
long long ans;
} e[maxn];
int n, q;
long long f[maxn];
int a[maxn], len;
bool cmp(node x, node y) { return x.t < y.t; }
long long baoli(node x) {
long long ans = 0;
for (int i = x.s; i <= n; i += x.t) ans += a[i];... | 13 |
#include <bits/stdc++.h>
using namespace std;
void input() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long x = (n + 3) / 4;
for (int... | 2 |
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<stack>
#include<cmath>
using namespace std;
#ifndef POJ
#define Cpp11
#endif
#ifdef Cpp11
#define _for(i,a,b)... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 14;
int n, a[maxn], d[maxn];
bool mark[maxn];
vector<int> g[maxn];
int get(int col) {
fill(d, d + n, 0);
queue<int> leaves;
fill(mark, mark + n, false);
for (int i = 0; i < n; i++) {
d[i] = g[i].size();
if (d[i] <= 1) {
mark[i] =... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long N, M;
long long myPow(long long a, long long b) {
long long ret = 1;
while (b > 0) {
if (b % 2 == 1) {
ret *= a;
ret %= 1000000007;
}
a *= a;
a %= 1000000007;
b /= 2;
}
return ret;
}
int main() {
ios::sync_with_stdio(0);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
if (a[i] >= 0) a[i] = -a[i] - 1;
}
if (n % 2) {
int ind = 1;
int _min = 2;
for (int i = 1; i <= n; i++)
if (a[i] != -1 && _min > a[i]) {
... | 7 |
#include <bits/stdc++.h>
int main() {
int n, s;
std::cin >> n >> s;
std::vector<int> deg(n);
for (int i = 0; i + 1 < n; i++) {
int u, v;
std::cin >> u >> v;
u--, v--;
deg[u]++;
deg[v]++;
}
int leaves = 0;
for (int i = 0; i < n; i++) {
leaves += deg[i] == 1;
}
std::cout << std::... | 9 |
#include <bits/stdc++.h>
using namespace std;
int long long n;
int long long x, y;
inline int long long u(int long long t) {
int long long h = t - x + 1;
if (h > 0)
return h * h;
else
return 0;
}
inline int long long r(int long long t) {
int long long h = t - n + y;
if (h > 0)
return h * h;
else... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long u, long long v) {
while (v != 0) {
long long r = u % v;
u = v;
v = r;
}
return u;
};
double lng(double a, double b, double c, double d) {
double s;
s = sqrt((a - c) * (a - c) + (b - d) * (b - d));
return s;
};
struct name {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, q;
pair<double, double> a[1 << 18];
pair<double, double> merge(pair<double, double> x, pair<double, double> y) {
double l1 = x.first;
double r1 = x.second;
double l2 = y.first;
double r2 = y.secon... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 105;
char ch[SIZE];
int n, k;
int main() {
while (cin >> n >> k) {
scanf("%s", ch);
int len = n;
if (k > len / 2) {
for (int i = k; i < len; i++) {
puts("RIGHT");
}
for (int i = len - 1; i >= 0; i--) {
printf(... | 1 |
#include <bits/stdc++.h>
long long n, m, S, T;
long long head[2001], nxt[200001], b[200001], v[200001], k;
long long dis1[2001], dis2[2001];
long long q[1000001], h, t, orig[2001], p[2001];
long long cnt[2001][2001];
long long sum[2001][2001], f[2001][2001], g[2001][2001];
long long last1[2001], last2[2001];
bool inq[2... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int a[200009], b[200009], ans;
int mod(long long x) { return (x % 99824435... | 8 |
#include <bits/stdc++.h>
bool notsame(char* c, int len) {
bool a = false;
for (int i = 0; i < len - 1; ++i) {
if (c[i] != c[i + 1]) a = true;
}
return a;
}
bool notpresent(int* nums, int ele, int idx) {
bool a = true;
for (int i = 0; i < idx; i++) {
if (nums[i] == ele) a = false;
}
return a;
}
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[200010];
int ans[200010];
int main() {
int n, a, b, k, i, j, l = 0, falg;
cin >> n >> a >> b >> k;
cin >> s;
for (i = 0; i < n; i++) {
if (s[i] == '0') {
falg = 0;
for (j = i; j <= i + b - 1; j++) {
if (j == n) {
falg = 1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 5;
const int MOD = 998244353;
const long long ooll = 3e18;
const int N = 5e3 + 5;
int mn[N], p[N];
void pre() {
mn[0] = 0;
for (int i = 1; i < N; ++i) {
int dep = 0, j = i;
while (i > 1) {
i >>= 1;
dep++;
}
i = j;
mn[... | 14 |
#include <bits/stdc++.h>
int main() {
int a1, a2, a3;
scanf("%d %d %d", &a1, &a2, &a3);
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
int n;
scanf("%d", &n);
int cups = a1 + a2 + a3;
int medals = b1 + b2 + b3;
int num_shelfs = ceil(cups / 5.0) + ceil(medals / 10.0);
if (num_shelfs <= n)
prin... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
set<int> dif;
for (int i = 1; i < n; i++) dif.emplace(abs(a[i] - a[i - 1]));
if (int(dif.size()) > 2 or dif.count(0) == 1 or
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int x, long long int y) {
return y ? gcd(y, x % y) : x;
}
long long int x, y;
void cal(long long int x, long long int y) {
if (x == 1 && y == 1) return;
if (x == 1) {
printf("%I64dB", y - 1);
return;
}
if (y == 1) {
printf("... | 16 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int (*itoi)(int);
typedef int (*iitoi)(int, int);
typedef int (*iiitoi)(int, int, int);
typedef ll (*ltol)(ll);
typedef ll (*lltol)(ll, ll);
typedef ll (*llltol)(ll, ll, ll);
const long double PI = acos(0) * 2;
const int INF = 0x3f2f1f0f;
const... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else
return false;
}
template <class T>
bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else
return false;
}
const int MAXN = 5050;
int a[MAXN];
int g[... | 10 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
t = 1;
while (t--) {
long long n;
cin >> n;
string s;
long long x;
char y;
vector<long long> v1{-1000000007}, v2{1000000007}, v3{-1000000007},
... | 6 |
#include <bits/stdc++.h>
int main() {
int a, b, n;
scanf("%d %d %d", &a, &b, &n);
if (n % 2) {
for (int i = 0; i < a - (n / 2 + 1); i++) printf("0");
for (int i = 0; i < n / 2 + 1; i++) printf("01");
for (int i = 0; i < b - (n / 2 + 1); i++) printf("1");
} else {
if (a >= n / 2 + 1) {
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') p = 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + (c ^ 48);
if (p) x = -x;
}
const int N = 1... | 18 |
#include <bits/stdc++.h>
using namespace std;
int pct(int x) { return __builtin_popcount(x); }
int pct(long long x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); }
int bt(long long x) { return 63 - __builtin_clzll(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<long long int> city;
vector<long long int> towers;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
city.push_back(a);
}
for (int i = 0; i < m; i++) {
int a;
cin >> a;
towers... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.