solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
struct circle {
double x, y, r;
};
circle ci[3];
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double eval(double x, double y) {
double dst[3];
for (int i = 0; i < 3; i++) dst[i] = dist(x, y, ci[i].x, ci[i].y) / c... | 18 |
#include <bits/stdc++.h>
using namespace std;
namespace sol {
int n;
long long a[50] = {0};
vector<long long> c;
vector<int> b, ans;
int main() {
cin >> n;
for (int i = -1; ++i < (n);) {
long long t;
cin >> t;
if (__builtin_popcountll(t) != 1) {
c.push_back(t);
continue;
}
int p = 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, f;
int ff;
} a[100000];
set<pair<pair<double, double>, int> > s;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lf%lf", &a[i].x, &a[i].f);
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
const long long Mod = 1e9 + 7;
long long calc(int n) {
long long ans = 1;
for (int i = 1; i <= n; i++) {
ans = (ans * i) % Mod;
}
return ans;
}
int main() {
cin >> n;
long long f = calc(n);
long long k = 1;
for (int i = 1; i <= n - 1; i++) {
k... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
vector<int> sche[507];
int clas[507];
int dp[507][507];
int value[507][507];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n;
cin >> n;
long x;
map<long, int> m;
for (int i = 0; i < n; i++) {
cin >> x;
m[x]++;
}
vector<int> a;
for (auto x : m) {
a.push_back(x.second);
}
so... | 10 |
#include <bits/stdc++.h>
using namespace std;
int const N = 2111;
int f[N][N], o[N + 1];
char s[N], p[N];
int main() {
scanf("%s%s", s, p);
int ls = strlen(s), lp = strlen(p);
for (int i = 0; i < ls; ++i)
for (int j = 0; j <= i; ++j) {
int k = j % lp, l = (j + 1) / lp, &x = f[i + 1][j + 1] = N,
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class heap : public priority_queue<T, vector<T>, greater<T> > {};
long long powm(long long a, int e) {
long long ans = 1;
while (e) {
if (e & 1) ans *= a;
a *= a;
e >>= 1;
}
return ans;
}
int main(void) {
long long n;
scanf("%ll... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, L;
cin >> n >> L;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sor... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000003, maxn = 2012;
int f[maxn][maxn], v[maxn];
char str[maxn];
int main() {
int i, j, k, t = 0, s = 1, ans = 0, o = 0;
gets(str + 1);
for (i = 1; str[i]; i++) {
if ((str[i] == '*' || str[i] == '/') &&
(str[i - 1] < '0' || str[i - 1] > '9... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, x, y, z;
while (~scanf("%d%d%d%d%d%d", &a, &b, &c, &x, &y, &z)) {
int r = a - x;
int s = b - y;
int t = c - z;
if (r > 0) r = r / 2;
if (s > 0) s = s / 2;
if (t > 0) t = t / 2;
int sum = r + s + t;
if (sum >= 0)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int k, m, size, cnt = 0;
int num[4], sym[3];
int vis[2 * 10005];
int t = 0;
inline int Analysis(int x) {
int size = 0;
do {
size++;
x = x / 10;
} while (x > 0);
return size;
}
inline void Cal() {
int x = num[0];
int y = 0, mid = 0;
bool flag = 1;
for... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long a[100001];
int main() {
long long n;
cin >> n;
long long mn = 1000000001;
long long ind = 0;
for (int k = 1; k <= n; k++) {
cin >> a[k];
if (a[k] < mn) {
mn = a[k];
ind = k;
}
}
for (int k = 1; k <= n; k++) {
a[k] -= mn;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e9 + 7;
int n, a[N];
long long bigmod(long long b, long long p) {
long long t = 1;
for (; p; b = (b * b) % M, p >>= 1)
if (p & 1) t = (t * b) % M;
return t;
}
long long go(int now) {
vector<int> div;
for (int i = 1; i * i <= now; i+... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int mod = 1e9 + 7;
int f[MAXN], sz[MAXN];
int getf(int k) { return k == f[k] ? k : f[k] = getf(f[k]); }
bool loop[MAXN], cycle[MAXN];
int main() {
int n, x, y, u, v;
cin >> n;
for (int i = 0; i <= 2 * n; i++) f[i] = i, sz[i] = 1;
for (... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
int f, s, d, ans = 0;
scanf("%d%d%d", &f, &s, &d);
for (int e = 0; e <= f; e++) {
for (int p = 0; p <= s - (e * 2); p++) {
if (p * 2 <= d) {
ans = max(ans, e * 3 + p * 3);
... | 0 |
#include<iostream>
#include<cstring>
#include<vector>
#include<utility>
#include<map>
#include<set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<unordered_set>
#include<stack>
#include<array>
#include<iomanip>
using namespace std;
#define int long long
#define ld long double ... | 6 |
#include <bits/stdc++.h>
const int N = 100, M = 3, K = 2;
int a[N], p[M], t[M];
inline int solve(int n) {
int sum = 0;
for (int i = 0; i < t[0] && n > 0; ++i, --n) {
sum += p[0];
}
for (int i = 0; i < t[1] && n > 0; ++i, --n) {
sum += p[1];
}
return sum + (p[2] * n);
}
int main() {
int n, l, r, su... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m;
char S[N][N];
int cnt[N], Ex[N], Ey[N];
bitset<N> A[N];
queue<int> q[N];
bool vis[N];
int main() {
int Case;
scanf("%d", &Case);
while (Case--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
A[i].reset(), vis[i] = fal... | 25 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
LL a[N], b[N];
LL d[N];
struct Line {
LL m, c;
LL eval(LL x) { return m * x + c; }
long double intersectX(Line l) { return (long double)(c - l.c) / (l.m - m); }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(n... | 13 |
#include <bits/stdc++.h>
using namespace std;
int ht[300][300], tt[4][300][300], n, m, t, tp, tu, td;
void print(const char *s, int k) {
cout << s << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) cout << setw(2) << tt[k][i][j] << " ";
cout << endl;
}
}
int main() {
int i1, j1, i2, j2, ... | 15 |
#include <bits/stdc++.h>
#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#defin... | 8 |
#include <bits/stdc++.h>
const int mx = 2e5 + 10, alphaNum = 30;
using namespace std;
long long int alpha[alphaNum], arr[mx], p[mx], counter[mx];
int main() {
string s;
int t;
int n, m;
scanf("%d", &t);
while (t--) {
cin >> n >> m >> s;
for (int i = 0; i < m; i++) scanf("%d", &p[i]);
memset(alpha,... | 5 |
#include <bits/stdc++.h>
int n, r, a[(1 << 18) + 5];
long long ans;
int main() {
scanf("%d%d", &n, &r);
for (int i = 0; i < (1 << n); ++i) scanf("%d", &a[i]), ans += a[i];
double w = 1 << n;
printf("%.10f\n", ans / w);
for (int p, i = 0; i < r; ++i) {
scanf("%d", &p);
ans -= a[p];
scanf("%d", &a[p... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int arr[n];
long long int mx = 0, cnt = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
mx = max(mx... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s;
cin >> s;
int i = 0;
while (true) {
if (s.length() <= i) break;
if (s[i] == '1') {
i++;
if (s[i] == '4') {
i++;
if (s[i] == '4') {
i++;
}
}
} else {
cout << "NO" << endl... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
char s[maxn];
int main() {
int n, k;
cin >> n >> k;
if (k > n || (k == 1 && n != 1)) {
cout << -1;
return 0;
}
if (n == 1) {
cout << 'a';
return 0;
}
int id = 2;
for (int i = n - (k - 2); i < n; i++) {
s[i] = 'a'... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int DP[5001][5001];
long long int num[5001];
long long int sums[5001];
long long int point[5001];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = (1); i < (n + 1); i++) {
cin >> num[i];
sums[i] = sums[i - 1] + num[i];
}
for (int i = (0... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int k;
cin >> s >> k;
for (int i = 0; i < s.size(); i++) {
int idx = -1, mx = 0;
for (int j = i + 1; j < s.size(); j++)
if (j - i <= k) {
if (s[j] > s[i] && s[j] > mx) {
mx = s[j];
idx = j;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long maxP = -1, maxS = -1;
long minP = 1000000001, minS = 1000000001;
long a, b;
long T1[n];
long T2[n];
for (int i = 0; i < n; i++) {
cin >> a >> b;
T1[i] = a;
T2[i] = b;
if (a >= maxP) {
maxS = maxP;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v[1000000];
map<long long int, long long int> vis;
void dfs(long long int c) {
vis[c] = 1;
for (long long int i = 0; i < v[c].size(); i++) {
if (vis[v[c][i]] == 0) {
dfs(v[c][i]);
}
}
}
int main() {
long long int n, m, k;
cin >>... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int Destruct(vector<int>& jiro_atk, vector<int>& jiro_def, vector<int>& ciel) {
vector<bool> used(m);
int def = 0;
for (int i = 0; def < jiro_def.size() && i < used.size(); ++i) {
if (ciel[i] > jiro_def[def]) {
used[i] = true;
++def;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
int x, y, id;
void scan(int id) {
this->id = id;
scanf("%d%d", &x, &y);
}
} a[100010];
int ans[100010];
long long dis(long long x1, long long y1, long long x2, long long y2) {
return (x1 + x2) * (x1 + x2) + (y1 + y2) * (y1 + y2);
}
int m... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, K, m;
string s[100005];
int a[100005], bel[100005];
map<string, int> ma;
vector<int> vs[100005];
bool cmp(const int &x, const int &y) { return a[x] < a[y]; }
long long ans;
int main() {
scanf("%d%d%d", &n, &K, &m);
for (int i = 1; i <= n; ++i) {
cin >> s[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
vector<int> pos[30];
int d[30], a[N], tr[N], n;
void string_update(int x) {
while (x <= n) {
tr[x]++;
x += (x & -x);
}
}
int query(int x) {
int res = 0;
while (x) {
res += tr[x];
x -= (x & -x);
}
re... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
long long int power(long long int x, long long int n, long long int m) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return (power(((x % m) * (x % m)) % m, n / 2, m)) % m;
else
return ((x % m) * power(x, n - 1, m) % m);
}... | 7 |
#include <bits/stdc++.h>
std::bitset<2001> f[65536];
int n, k, a[16], now;
std::priority_queue<std::pair<int, int> > heap;
void findpath(int i, int j) {
if (!i) return;
if (j * k <= 2000 && f[i][j * k]) {
++now, findpath(i, j * k);
} else {
for (int l = 0; l < n; l++)
if ((i & (1 << l)) && j >= a[l]... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<int> a;
vector<int> b;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.insert(x);
}
set<int>::iterator i = a.begin();
for (; i != a.end(); i++) {
b.push_back((*i));
}
if (b[0] > 1) {
cout << 1;
r... | 4 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> r[3000];
int main() {
int n;
map<pair<int, int>, pair<int, int> > arr;
cin >> n;
for (int i = 0; i < n; ++i) {
pair<int, int> _;
cin >> _.first >> _.second;
arr[_] = _;
r[i] = _;
}
int answer = 0;
for (int i = 0; i < n; ++i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double h, l;
cin >> h >> l;
printf("%.8lf\n", (l * l - h * h) / 2 / h);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i;
while (cin >> n) {
long long int a[n + 5], mx = 0, c = 1;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
if (a[i] > mx) {
cout << i + 1 << endl;
c = 0;
break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXNODE = 222222, BOOKCASEZIZE = 3333;
class Node {
public:
int x, y, queryType, queryId;
Node() {}
Node(int queryType, int x, int queryId) {
this->queryType = queryType;
this->x = x;
this->queryId = queryId;
}
Node(int queryType, int x, int... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 5;
const int MOD = (int)1e9 + 7;
const int LOG = 18;
const int INF = 1e9;
const int N = 1e5 + 5;
const int M = 8e5 + 5;
const int SQ = 350;
char s[M];
int n, l, sz, cnt;
struct trie {
int ed[26];
vector<int> v[2];
} T[N * 10];
vector<pair<i... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const long long N = 2e5 + 10;
long long a[N], b[N], aa[N], bb[N], c[N], ans[N];
long long n, m;
pair<long long, long long> t1[N], t2[N];
inline long long read() {
long long X = 0, w = 0;
char c = 0;
while (c < '0' || c > '9') {
w |= c == '-... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt;
struct data {
int r, c, val, id;
} a[1000001];
int res[1000001];
int k[1000001], p[1000001];
int rmax[1000001], cmax[1000001];
bool cmp(data X, data Y) { return X.val < Y.val; }
int Find(int x) {
if (p[x] == x) return x;
return p[x] = Find(p[x]);
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
const int INF = 0x3f3f3f3f;
int main(void) {
int k, a, b, v;
while (scanf("%d%d%d%d", &k, &a, &b, &v) == 4) {
int ans = 0;
while (1) {
int sec = 0;
if (b >= k - 1) {
b -= (k - 1);
sec = k;
} else if (b... | 3 |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void solve() {
int x;
cin >> x;
ll jumps = 0;
while(x > 0)
x -= ++jumps;
if(x == -1)
jumps++;
cout << jumps << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
int t;
c... | 4 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
}
long long n, m, x, y;
vector<long long> freqCol;
long long cost(long long idx, bool b) {
return (b ? freqCol[idx] : n - freqCol[idx]);
}
long long mem[1001][1001][2];
long long solve(lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 51, K = 5001, MOD = 1e9 + 7;
int n, k, a, b, dp1[2][N][N][201], dp2[2][N][N][201], C[N][N];
void build() {
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 - 1] + C[i - 1][j]) % MOD;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string str;
cin >> n;
cin >> str;
int x = 0, y = 0, z;
while (y < n) {
cout << str[y];
x++;
y = (x * (x + 1) / 2);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n1, n2, a, b, c, d, e, sum1 = -1000000, sum2 = -100000;
string s;
string name;
cin >> t;
while (t--) {
cin >> s >> n1 >> n2 >> a >> b >> c >> d >> e;
sum1 = (n1 * 100) - (n2 * 50) + a + b + c + d + e;
if (sum1 > sum2) {
name =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k, a, b;
cin >> n >> k;
vector<pair<int, int>> p(n);
vector<long long> c(n);
for (i = 0; i < n; i++) {
cin >> a;
p[i] = {a, i};
}
for (i = 0; i < n; i++) cin >> c[i];
priority_que... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long x, long long t) {
long long ret = 1 % 1000000007ll;
x = x % 1000000007ll;
while (t) {
if (t & 1) ret = ret * x % 1000000007ll;
t >>= 1;
x = x * x % 1000000007ll;
}
return ret;
}
long long a[210000], iv[210000];
long long getc... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, maxcash, t, hour[100010], minute[100010], cash = 1;
cin >> t;
for (i = 0; i < t; i++) {
cin >> hour[i] >> minute[i];
}
i = 0;
maxcash = 1;
while (i < t) {
cash = 1;
j = i + 1;
while (j < t && hour[j] == hour[i] && minute[... | 2 |
#include <bits/stdc++.h>
using namespace std;
void PLAY() {
cout << fixed << setprecision(10);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool cmp(pair<long long, long long> &a, pair<long long, long long> &b) {
if (a.first != b.first) {
return a.first > b.first;
}
return a.second < b.second;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
char a[200][40000];
int n, m, i, j, ans, f, b[200][40000];
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++)
for (j = 0; j < m; j++) b[i][j] = 1000000;
for (i = 1; i <= n; i++) {
scanf("%s", a[i]);
for (j = 0; j < 2 * m; j++)
if (a[i][j % ... | 7 |
#include <bits/stdc++.h>
struct Tblock {
char order;
bool L, R, U, D;
};
const int maxn = 207;
int n, m;
int a, b, c;
int x, y;
Tblock block[maxn][maxn];
char Map[maxn][maxn];
void empty() {
for (int i = 0; i <= n; i++) block[i][0].R = true, block[i][m + 1].L = false;
for (int j = 0; j <= m; j++) block[0][j].D ... | 20 |
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 2 * 1e5 + 3;
int l[N], r[N], t[N], a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q, m;
cin >> n >> q >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < q; i++) {
cin >> t[i] >> l[i] >> r[i];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, qs;
int root[100005];
vector<int> vec[100005];
vector<int> q[100005];
int d[100005], dis[100005];
int t, mlen, gg;
bool flag;
int sz[100005];
void dfs(int f, int now, int lens) {
if (lens >= mlen) {
mlen = lens;
t = now;
}
dis[now] = max(lens, dis[no... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout.precision(16);
int n, m;
cin >> n >> m;
double ans = INT_MAX;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
double cur = a;
cur /= b;
cur *= m;
ans = min(ans, cur);
}
cout << ans;
cin >> n;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
ios::sync_with_stdio(false);
string ans[] = {"Stack", "Queue", "Front", "Back"};
int n;
cin >> n;
vector<pair<int, int> > v;
while (n--) {
int x;
cin >> x;
if (x)
v.push_back(make... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 7, mod = 1e9 + 7;
int T, n, ans;
int fa[MAXN];
int f[MAXN][2], g[MAXN][2][2];
vector<int> son[MAXN];
void dfs1(int now) {
f[now][1] = 1;
f[now][0] = 0;
g[now][1][1] = 0;
g[now][1][0] = 1;
g[now][0][0] = 1;
g[now][0][1] = 0;
int i2, i3, j... | 19 |
#include <bits/stdc++.h>
using namespace std;
char s[60][60];
int f[][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}, vis[60][60];
struct U {
int first, second;
inline void u(int x, int y) { first = x, second = y; }
} P[2600];
int t, n, m, flag, idx;
bool finds(int first, int second) {
int fl = 0;
if (first > n || sec... | 9 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = (int)2e5 + 7;
int n, a[N], l[N], r[N], f[N], pt[N], su[N], x[N], y[N];
vector<int> p[N];
void se() {
map<int, int> tr;
for (int i = 1; i <= n; i++) {
tr[a[i]] = i;
}
int ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
string h, v;
cin >> h >> v;
if ((h[0] == '>' && h[x - 1] == '<' && v[0] == '^' && v[y - 1] == 'v') ||
(h[0] == '<' && h[x - 1] == '>' && v[0] == 'v' && v[y - 1] == '^'))
cout << "YES";
else
cout << "NO";
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 7;
vector<int> seg[4 * MAXN];
pair<int, int> ox[MAXN];
void change(int idx, int val, int x, int b, int e) {
seg[x].push_back(val);
if (e - b == 1) return;
int mid = (b + e) >> 1;
if (idx < mid)
change(idx, val, x << 1, b, mid);
else
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int getint() {
int t = 0, flag = 1;
char c = getchar();
while (c < '0' || c > '9' || c == '-') {
if (c == '-') flag = -1;
c = getchar();
}
while (c >= '0' && c <= '9') t = t * 10 + c - '0', c = getchar();
return t * flag;
}
int... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, x, y, top;
int main() {
scanf("%d %d %d %d %d", &n, &a, &b, &x, &y);
if (a == x && (a == 0 || a == n))
printf("%d", max(b - y, y - b));
else if (b == y && (b == 0 || b == n))
printf("%d", max(a - x, x - a));
else {
top += min((n - a + n - x)... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
long long a, b;
cin >> a >> b;
long long m = (a * b) / gcd(a, b);
int t1 = m / a, t2 = m / b;
t1 > t2 ? ++t2 : ++t1;
if (t1 == t2) {
cout << "Equal" << '\n... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, head[100010], o = 0, sz[100010], rt = 0, mx[100010], bel[100010];
long long dis[100010], ans;
set<int> all[100010], mn;
set<pair<int, int> > s;
struct edge {
int to, link, w;
} e[200010];
void add_edge(int u, int v, int w) {
e[++o].to = v, e[o].link = head[u], he... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<long long, long long> mp;
long long n, k;
cin >> n >> k;
long long a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(a, a + n);
long long sum = 0, t = 0, p = n - 1;
while (t < k) {
sum += a[p];
mp[a... | 4 |
#include <bits/stdc++.h>
using namespace std;
int cntInit[26], cnt[26];
int main() {
string s, t;
cin >> s >> t;
int n = t.size();
for (int i = 0; i < s.size(); i++) cntInit[s[i] - 'a']++;
for (int i = n; i >= 0; i--) {
for (int j = 0; j < 26; j++) cnt[j] = cntInit[j];
bool good = true;
for (int j... | 11 |
#include <bits/stdc++.h>
const int INF = 123456789;
int n, k;
std::vector<std::pair<int, int>> edge[410];
int dp[410][2][410];
int dp2[410][410];
void dfs(int v, int p) {
dp[v][0][0] = 0;
dp[v][1][1] = 0;
for (auto [w, e_idx] : edge[v])
if (w != p) {
dfs(w, v);
for (int l = 1; l <= k; l++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x, y;
cin >> n >> x >> y;
long long int zero = 0L, one = 0L;
string str;
cin >> str;
for (int i = 0; i < n - 1; i++) {
if (str[i] != str[i + 1]) {
if (str[i] == '0') {
zero++;
} else {
one++;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(co... | 6 |
#include <bits/stdc++.h>
using namespace std;
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 int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 25;
int main() {
int N, M;
cin >> N >> M;
int a[N];
for (int i = 0; i < N; ++i) cin >> a[i];
int l[M], r[M];
for (int j = 0; j < M; ++j) {
cin >> l[j] >> r[j];
--l[j], --r[j];
}
int center = 0, maxscore = -INF;
for (int c = 0; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k2, k3, k5, k6;
cin >> k2 >> k3 >> k5 >> k6;
int num1 = 0, num2 = 0;
num1 = min(k2, min(k5, k6));
k2 -= num1;
k5 -= num1;
k6 -= num1;
num2 = min(k2, k3);
cout << 32 * num2 + 256 * num1 << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double e = 0.0000001;
double maabs(double a) {
if (a < 0) return -a;
return a;
}
bool isequal(double a, double b) { return (maabs(a - b) < e); }
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
vector<do... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n;
vector<vector<int>> t(n + 1);
vector<long long> s(n + 1);
for (int i = 2; i <= n; ++i) {
cin >> k;
t[k].push_back(i);
}
for (int j = 1; j <= n; ++j) {
cin >> k;
s[j] = k;
}
queue<int> q;
q.push(1);
long ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, ck[105];
struct info {
int point, change, id;
info() {}
info(int a, int b, int c) { point = a, change = b, id = c; }
};
bool cmp(info a, info b) {
if (a.point != b.point) return a.point > b.point;
return a.id < b.id;
}
vector<info> v;
int main() {
scanf("... | 14 |
#include <bits/stdc++.h>
using namespace std;
int str[5100];
int dp_pre[5100][5100];
int dp_nxt[5100][5100];
int main() {
int i, j, k;
int n, sum, ans;
int tmp, cnt;
while (cin >> n) {
for (i = 1; i <= n; i++) {
cin >> str[i];
}
memset(dp_pre, 0, sizeof(dp_pre));
memset(dp_nxt, 0, sizeof(d... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, Base = 998244353;
const long long N = 6e5 + 7;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7LL;
const double pie = acos(-1.0);
double x[3], y[3], r[3], R[3], d;
long long Ways;
int32_t main() {
ios::sync_with_stdio(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int d[16] = {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0};
int n;
int main() {
scanf("%d", &n);
printf("%d\n", d[n - 1]);
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, HA = 19260817;
int n, m, a[N];
struct node {
int mxm, mxl, mxr, mim, mil, mir;
int bxml, bxmr, bxlr, bxrl;
int biml, bimr, bilr, birl;
int sum;
bool tag;
node() {
mxm = mxl = mxr = mim = mil = mir = bxml = bxmr = bxlr = bxrl = biml =
... | 20 |
#include <bits/stdc++.h>
using namespace std;
void tachyon() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
}
const int N = 50;
const int MAXE = 1e4 + 1;
int n, d, c[N];
bool was[N * MAXE + 1];
vector<int> a;
void solve() {
cin >> n >> d;
for (int i = 0; i < n; i++) cin >> c[i];
was[0] = 1;
for (int i = ... | 14 |
#include <bits/stdc++.h>
void sc(int &x) { scanf("%d", &x); }
void sc(int &x, int &y) { scanf("%d%d", &x, &y); }
void sc(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void sc(long long &x) { scanf("%lld", &x); }
void sc(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void sc(long long &x, long lon... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 32768, N = 109;
char ch;
string s[N], t;
int ans, v, f[MOD + 9], num, p, pos;
int ex();
int gt() {
int ret = 0;
if (t[pos] == 'n') return pos++, v;
if (t[pos] == 'f') return pos += 2, ret = f[ex()], pos++, ret;
while (t[pos] >= '0' && t[pos] <= '9') ... | 16 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
unsigned int uintMax = 4294967295;
int intMax = 2147483647;
int intMin = -2147483648;
unsigned long long ullMax = 18446744073709551615;
long long Max = 9223372036854775807;
lo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int p[10000005];
char s[10000005];
int main() {
gets(s + 1);
int n = strlen(s + 1);
s[n + 1] = '#';
for (int i = 1; i <= n; ++i) {
s[n + i + 1] = s[n - i + 1];
}
n = 2 * n + 1;
for (int i = 2; i <= n; ++i) {
p[i] = p[i - 1];
while (p[i] && s[p[i] +... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, K, w;
int nxt[5005][1005], deg[1005], ed[1005][1005], col[1005], id[1005];
void dfs(int id, int a, int b) {
swap(ed[id][b], ed[id][a]);
swap(nxt[id][b], nxt[id][a]);
col[ed[id][b]] = b;
if (nxt[id][b]) dfs(nxt[id][b], b, a);
}
int main() {
scanf("%d %d %... | 23 |
#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 ^ 48);
ch = getchar();
}
return x * f;
}
const long... | 15 |
#include <bits/stdc++.h>
using namespace std;
int spend[60 + 5][60 + 5][60 + 5];
int best[1005][60 + 5][60 + 5];
int n, m;
int res(int fr, int to, int k) {
fr -= 1;
to -= 1;
return best[k][fr][to];
}
int main() {
int R;
cin >> n >> m >> R;
for (typeof(m) car = 0; car < (m); ++car) {
for (typeof(n) fr = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void solve() {}
signed main() {
ios_base ::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, e;
cin >> n >> e;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline long long int max(long long int a, long long int b) {
return (a < b) ? b : a;
}
inline long long int min(long long int a, long long int b) {
return (a < b) ? a : b;
}
long long int a[1000005];
int main() {
int i;
long long int n, b, d;
scanf("%lld", &n);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int M = 20;
int N, compN;
bool adj[M][M];
string A, B;
vi comps[M];
bool vis[M];
void findComp(int n) {
vis[n] = true;
comps[compN].push_back(n);
for (int e = (0); e < (M); e++) {
if (vis[e]) continue;
if (ad... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
int cnt = 0;
int sum = 0;
int mi = 110;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int a;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(int agrc, char *argv[]) {
float n = 0;
float sum = 0;
cin >> n;
while (n > 0) {
sum += 1 / n;
n--;
}
cout << sum << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5001, MOD = 1e9 + 7;
int Pre[MAXN][2];
int get(int l, int r, int cur) {
return (Pre[r][cur] - Pre[l - 1][cur] + MOD) % MOD;
}
int main() {
int N, k, a, b, ans = 0;
cin >> N >> a >> b >> k;
Pre[a][0] = 1;
for (int K = 1; K <= k; K++) {
int nxt ... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.