solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 7;
int gcd(int x, int y) {
if (!x || !y) return x + y;
while ((x %= y) && (y %= x))
;
return x + y;
}
bool check(int x, int y, int z) {
vector<int> v = {x, y, z};
sort(v.begin(), v.end());
do {
if ((v[0] & 1) && (v[1] & 2) && (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long a[N];
long long s[N];
long long gt[20];
long long n, q, m = 15;
void sub1() {
long long cur = 1;
while (q--) {
long long typ;
cin >> typ;
if (typ == 1) {
long long l, r;
cin >> l >> r;
vector<bool> fla... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int F(long long int a) {
long long int i = 1;
for (; i * (i - 1) < 2 * a; i++)
;
if (i * (i - 1) != 2 * a)
return -1;
else
return i;
}
int main() {
long long int a, b, c, d;
while (scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d) == 4) {
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n, f[N], cnt;
double a[N], b[N];
struct node {
int l, r;
double sum;
};
double qs(node c) { return c.sum * (c.r - c.l + 1); }
stack<node> s;
void update(int x) {
node q = (node){s.top().l, x, (qs(s.top()) + a[x]) / (x - s.top().l + 1)};
s.... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int N, M, res;
int main() {
cin >> N >> M;
for (int i = 1; i <= N; i++) res += (M + i % 5) / 5;
cout << res;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
bool mark[2 * maxn];
struct Node {
set<int> s;
int ma, mi;
Node *ls, *rs;
Node(int l, int r) {
ls = rs = nullptr;
ma = mi = -1;
s.clear();
if (l + 1 == r) return;
ls = new Node(l, (l + r) >> 1);
rs = new Node((l + r)... | 12 |
#include <bits/stdc++.h>
const int INF = (int)(1e9);
const long long INFLL = (long long)(1e18);
const double EPS = 1e-13;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int w, h;
cin >> w >> h;
long long ans = 0;
for (int i = 2; i <= w; i += 2) {
for (int j = 2; j <= h; j += 2) ans = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
queue<int> q;
set<int> vals;
for (int i = 0; i < n; ++i) {
int id;
cin >> id;
if (!vals.count(id)) {
if (int(q.size()) >= k) {
int curr = q.front();
q.pop();
vals.erase(curr);
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, ans, f[120][120][2];
struct node {
int xb, fw;
bool operator<(const node p) const { return xb < p.xb; }
} a[120];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].xb, &a[i].fw);
sort(a + 1, a + n + 1);
a[0].xb = -2e9;
a[++n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int matr[500][500];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < n; j++) matr[i][j] = s[j];
}
int z = 0;
int r = matr[0][0];
if (n > 1) z = matr[0][1];
if (z == r) {
cout << "NO";
ret... | 1 |
#include <bits/stdc++.h>
enum { LEFT, RIGHT, BOTH };
const int INF = INT_MAX >> 1;
std::string virus, s1, s2;
std::vector<int> failure;
int solution[105][105][105];
bool solved[105][105][105];
int next[105][105][105];
void fill_failure(void) {
int candidate, pos;
failure.clear();
failure.resize(virus.size());
p... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55, M = 105, T = 40005;
const double pi = acos(-1.0);
int n, m, t, x;
int d[N][N], a[M], b[M], c[M];
double p[M][T], f[N][T], g[M][T];
struct cmplx {
double x, y;
cmplx(double xx = 0, double yy = 0) { x = xx, y = yy; }
};
cmplx operator+(cmplx &a, cmplx &b... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, k;
cin >> n >> k;
long long int arr[205] = {0};
long long int map1[205] = {0};
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
map1[arr[i]] = 1;
}
long long int ans = 0;
for (long long int i = 1; i < 204; i++) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[111][111];
int main() {
int n, m, d;
while (cin >> n >> m >> d) {
int s = 0x7fffffff, t = -0x7fffffff;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
s = s < a[i][j] ? s : a[i][j];
t = t > a[i][j] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
int print_value(A title, B val) {
cout << title << " = " << val << "\n";
return 1;
}
int break_point() {
char c;
while ((c = getchar()) != '\n')
;
return 0;
}
template <typename A>
int logg(A v) {
cout << v << "\n";
return... | 6 |
#include <bits/stdc++.h>
int main() {
int n, x1, x2, i, j;
scanf("%d", &n);
x1 = n % 10;
x2 = n / 10;
if (x1 == 0)
i = 2;
else if (x1 == 1)
i = 7;
else if (x1 == 2)
i = 2;
else if (x1 == 3)
i = 3;
else if (x1 == 4)
i = 3;
else if (x1 == 5)
i = 4;
else if (x1 == 6)
i = 2... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 12;
const int X[] = {0, 1, 0, -1, 0, 0};
const int Y[] = {1, 0, -1, 0, 0, 0};
const int Z[] = {0, 0, 0, 0, 1, -1};
struct coord {
int x, y, z;
};
char layers[MAXN][MAXN][MAXN];
bool done[MAXN][MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);
cin... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a, i, j;
string s;
cin >> n >> k >> s;
for (i = 0; s[i] != 'G'; i++)
;
for (j = 0; s[j] != 'T'; j++)
;
for (a = min(i, j); a < max(i, j); a += k)
if (s[a] == '#') break;
if (a == max(i, j)) {
cout << "YES";
} else {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
struct muchie {
int node, weight, degree;
bool operator<(const muchie &other) const { return weight < other.weight; }
muchie(int a, int b, int c) {
node = a;
weight = b;
degree = c;
}
};
vector<muchie> out... | 7 |
#include <bits/stdc++.h>
using namespace std;
void err() { cout << '\n'; }
template <typename T, typename... More>
void err(T arg, More... more) {
cout << arg << ' ';
err(more...);
}
const long long mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 250000;
int n, s[kMaxN * 2 + 1], t[kMaxN * 2 + 1];
namespace st {
const int kMaxM = kMaxN * 2;
int dp[19][kMaxM + 1], m, log2[kMaxM + 1];
void Init() {
m = n * 2;
log2[1] = 0;
for (int i = 2; i <= m; ++i) {
log2[i] = log2[i - 1];
if ((i & (i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<string, string>> lang(m);
for (int i = 0; i < m; i++) {
cin >> lang[i].first >> lang[i].second;
if (lang[i].first.size() > lang[i].second.size()) {
swap(lang[i].first, lang[i].second);
}
}
vecto... | 1 |
#include <bits/stdc++.h>
const int sed = 10;
char a[1000005];
int s[1000005], l;
int bas[1000005], inv[1000005];
int sum[1000005], len1, len2, len3, pos1, pos2, pos3;
int qmi(int a, int b) {
int ans = 1;
while (b) {
if (b % 2) ans = 1ll * ans * a % 1000000007;
a = 1ll * a * a % 1000000007;
b /= 2;
}
... | 7 |
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for( int i=(a); i<(b); ++i)
#define REP(i,a,b) for( int i=(a); i<=(b); ++i)
#define MOD 1000000007
#define mp(x,y) make_pair(x,y);
#define mem(a,val) memset(a,val,sizeof(a))
#define pb push_back
#define sz(x) (int(x.size()))
#define endl '\n'
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll s, x;
cin >> s >> x;
if (x > s) out(0);
l... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[10001];
bool Ok(int n) {
for (int i = 0; i < n; i++) {
if (!a[i]) return false;
}
return true;
}
int main() {
int n, m, c;
cin >> n >> m >> c;
while (m--) {
int q;
cin >> q;
int p = -1;
if (q > c / 2) {
for (int i = n - 1; i >= 0;... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int m;
vector<long long int> v;
vector<long long int> vv;
vector<long long int> rest;
long long int solve(long long int pat) {
rest = v;
vv.clear();
long long int cur = 0;
for (int i = 1; i <= n; i++) {
long long int star = i;
long... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int search(long long int k, long long int n, long long int b,
long long int a) {
long long int min = 1;
long long int max = n;
long long int med;
long long int ans = 0;
while (min <= max) {
med = (max - min) / 2 + min;
if (b ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> a >> b;
if (n % m == 0)
cout << "0";
else {
long long g = a * ((n / m + 1) * m - n);
long long x = b * (n % m);
if (g > x)
cout << x;
else
cout... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, k;
int t;
cin >> t;
while (t--) {
cin >> n >> m >> k;
n = n < 0 ? n * -1 : n;
m = m < 0 ? m * -1 : m;
if (max(n, m) > k) {
cout << -1 << endl;
continue;
}
if (n == 0 && m == 0 && k == 1) {
co... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct data {
int x, h, left, right;
};
data tree[100005];
int main() {
int n, ans = 2;
scanf("%d", &n);
if (n == 1) {
printf("1\n");
return 0;
}
for (int i = 0; i < n; i++) {
scanf("%d %d", &tree[i].x, &tree[i].h);
}
for (int j = 1; j < n - 1; j... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long a1[maxn], a2[maxn], a3[maxn], n, m, num1, num2, num3, ans, s2[maxn],
s3[maxn], am[maxn];
bool cmp(long long a, long long b) { return a > b; }
void add1(long long c) {
num1++;
a1[num1] = c;
}
void add2(long long c) {
num2++;
a2[... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const int maxn = 1e2 + 10;
int n, d;
int a[maxn];
int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> d;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = a[0]... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-2;
const int N = 1e5 + 50;
const double PI = acos(-1.);
const double E = 2.71828182845904523536;
const int MOD = 1e9 + 7;
char s[N];
int main() {
int n;
cin >> n >> s;
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int dpL[MAXN], dpR[MAXN];
string s, t;
vector<int> plc[30];
int main() {
cin >> s >> t;
int n = s.size(), m = t.size();
for (int i = 0; i < n; i++) {
dpL[i] = i > 0 ? dpL[i - 1] : 0;
if (dpL[i] < m && t[dpL[i]] == s[i]) dpL[i]++;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
char a[5000000], b[5000000];
int n, mtlian1, mtlian2, cnt;
int main() {
cin >> n;
for (int i = 1; i <= 2 * n; i++) {
cin >> a[i];
if (a[i] == '1') mtlian1++;
}
for (int i = 1; i <= 2 * n; i++) {
cin >> b[i];
if (b[i] == '1') mtlian2++;
}
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int j = 0; j < t; j++) {
int n, m, k;
bool r = false;
cin >> n >> m >> k;
int ar[n];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < n - 1; i++) {
ar[i] += m;
m = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005000;
char s[MAXN];
int z[MAXN];
int add[MAXN];
int n, k;
int main() {
scanf("%d%d %s", &n, &k, s);
int l = 0, r = -1;
z[0] = 0;
for (int i = 1; i < n; ++i) {
int len = 0;
if (i <= r) {
len = min(r - i + 1, z[i - l]);
}
whil... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long INF64 = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
long long n, m, a, b;
void Load() {
cin >> n >> m >> a >> b;
a--;
b--;
}
void Solve() {
if (a % m == 0 && n == b + 1) {
cout << 1;
return;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> m >> n;
char table[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table[i][j];
}
}
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
char a = table[i][j];
cout << a ... | 2 |
#include <bits/stdc++.h>
const double pi = 3.1415926535897932384626433832795, eps = 1e-10;
int N, M, i, j;
double Ax, Ay, Az, Vx, Vy, Vz, Ox, Oy, Oz, Bx, By, Bz, px, py, pz, R, r, Sin,
Sin1, Theta, Theta1, Theta2, l1, l2, mid1, mid2, h, s, Len, Ans, d, D, Cos;
double len(double x, double y, double z) { return sqrt(... | 8 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 2e5 + 10;
const long long MOD = 1e9 + 7;
int cases = 0;
using std::string;
const int dir[][2] = {{-1, 0}, {-1, -1}, {-1, 1}, {0, -1},
{0, 1}, {1, -1}, {1, 0}, {1, 1}};
st... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
set<char> st;
map<char, int> mp1;
map<char, int> mp2;
int main() {
string second, t;
cin >> second >> t;
int l = 0;
if (second.size() > t.size()) l = 1;
for (auto x : second) {
st.insert(x);
mp1[x]++;
}
int l1 = st.si... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int MOD = 1e9 + 7;
const int N = 1e3 + 10;
int n, m, mod, p10[2][N], f[N][110][10] = {0}, g[N][110][10] = {0};
int solve() {
long long ans = 0;
p10[0][0] = p10[1][0] = 1;
for (int i = 1; i <= n; i++) {
p10[0][i] = (1LL * p10[0][i - 1] * ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[5009];
int ans[5009], as;
int c[50009];
int tp[50009];
priority_queue<pair<int, int> > q;
void dubl() {
int i, t;
for (i = 1, t = 0; i <= tp[0] || t; ++i, t /= 1000)
tp[i] = (t += 2 * tp[i]) % 1000;
tp[0] = i - 1;
}
void ctp(int x) {
memset(tp, 0, sizeof(t... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long ans = 0, n, b, c, i, j, x, y;
int main() {
scanf("%lld%lld%lld%lld", &n, &x, &y, &c);
b = x / 2 + y;
for (i = 0; i <= b; i++)
for (j = 0; j <= c; j++)
if (i + j * 2 == n) {
if (j * 2 == n) {
ans++;
continue;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(long long x)... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<string> LIS;
vector<int> G[26];
int visited[26];
vector<int> TOPO_SORT;
bool dfs(int s) {
visited[s] = 1;
for (auto it : G[s]) {
if (visited[it] == 0 && !dfs(it))
return false;
else if (visited[it] == 1)
return false;
}
visited[s] = 2;
T... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
while (t--) {
int n;
cin >> n;
set<int> s;
int x;
int e = 0, o = 0;
for (int i = 0; i < n; i++) {
cin >> x;
s.insert(x);
if (x % 2 == 0)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int re_ad() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
int k, n, m, cnt;
long long a[10001... | 10 |
#include <bits/stdc++.h>
using namespace std;
int N;
double pEatenBy[18][1 << 18];
double a[18][18];
double dp[1 << 18];
double f(int mask) {
int ones = __builtin_popcount(mask);
if (ones == N) return 1;
double prob1 = 2.0 / ((double)ones * (ones + 1));
double& r = dp[mask];
if (r > -0.5) return r;
r = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n < 4)
cout << "NO\n";
else {
cout << "YES\n";
if (n % 2 == 0) {
cout << "1 * 2 = 2\n";
cout << "2 * 3 = 6\n";
cout << "6 * 4 = 24\n";
for (int i = 5; i <= n; i += 2) {
cout << i + 1 << " ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
long long v[N], to[N], k;
int f[N][40];
long long sum[N][40], mi[N][40];
void solve(int g) {
long long res = 0, mmin = 1e9 + 7;
for (int i = 34; i >= 0; --i) {
if (k & (1ll << i)) {
res += sum[g][i], mmin = min(mmin, mi[g][i]);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, mn = NULL, pos;
map<int, int> mp;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (mn == NULL) {
mn = x;
pos = i + 1;
}
if (mn > x) {
mn = x;
pos = i + 1;
}
mp[x]++;
}
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
vector<long long> times;
for (long long i = 0; i < n; i++) {
long long h, m;
char ch;
cin >> h >> ch >> m;
times.push_back(60 * h + m);
times.push_back(1440 + 60 * h + m);
}
sort(times.begin(), times.end... | 4 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mirror(pair<int, int> &p) { return {p.second, p.first}; }
void move_from_first_two_sets_to_other_two(set<pair<int, int>> &set1_1,
set<pair<int, int>> &set1_2,
set<pair<int, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int M = 200 + 10;
long long int GCD(long long int x, long long int y) {
return y == 0 ? x : GCD(y, x % y);
}
int main() {
long long int a, b, x1, y1, x2, y2;
cin >> a >> b >> x1 >> y1 >> x2 >> y2;
long long int gcd = GCD(2 * a, 2 * b);
long long int lcm = 2 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
string a, b;
cin >> a >> b;
long long x = 1, y = -1;
for (auto &c : a) {
if (c == '1' || c == '2') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100 + 10][100 + 10];
int main() {
int n, m;
while (cin >> n >> m) {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
int ansn = n;
bool ansmark = true;
while (1) {
if (ansn % 2 != 0 || ansmark == false) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "-O3"
const int mod = 1e9 + 7;
int sum(int a, int b) {
int c = a + b;
if (c >= mod) {
c -= mod;
}
return c;
}
int dif(int a, int b) {
int c = a - b;
if (c < 0) {
c += mod;
}
return c;
}
int mlt(int a, int b) {
long long c = a *... | 11 |
#include <bits/stdc++.h>
using namespace std;
set<int> a;
int n;
int main() {
int i, j, k, t;
while (cin >> n) {
for (i = 0; i < n; i++) {
scanf("%d", &k);
while (k % 2 == 0) k /= 2;
while (k % 3 == 0) k /= 3;
a.insert(k);
}
if (a.size() == 1)
cout << "Yes" << endl;
els... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
long double soma = 0;
for (int i = 1; i <= n; i++) {
soma += ((pow(i / (long double)n, m) - pow((i - 1) / (long double)n, m)) *
(long double)i);
}
printf("%.10Lf\n", soma);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long int t;
cin >> t;
while (t--) {
long long int n, a, b;
cin >> n >> a >> b;
double ca = (double)a;
double cb = (double)b / (double)2;
if (cb <= ca) {
if (n % 2 == 0)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> arr(n, 0);
for (int i = 0; i < n; i++) cin >> arr[i];
unordered_map<int, int> umap;
for (int i = 0; i < n; i++) {
if (umap.find(arr[i]) != umap.end())
umap[a... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long SUM = 0, ff = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') ff = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
SUM = (SUM << 3) + (SUM << 1) + (ch ^ 48);
ch = getchar();
}
ret... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int cuenta(map<int, int> v[500000], int tope) {
long long int c = 0;
for (int i = 0; i < tope; i++) {
map<int, int> &m = v[i];
map<int, int>::iterator it = m.begin();
if (it != m.end()) {
int pos = it->first;
it++;
while (it != m.... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> lcs(vector<int> &seq) {
int m = seq.size();
vector<int> ret(m);
vector<int> a;
for (int i = 0; i < m; ++i) {
if (a.size() == 0) {
a.push_back(seq[i]);
ret[i] = 1;
} else {
if (seq[i] >= a.back()) {
a.push_back(seq[i]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int cas = 1; cas <= t; cas++) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int star... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
pair<int, int> v[2022];
int t[2022];
vector<int> a;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < (n); i++) {
scanf("%d", &v[i].first);
v[i].second = i + 1;
}
sort(v, v + n);
for (int i = 1; i < (n); i++) {
if (v[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
fast_ios() {
cin.tie(nullptr), ios::sync_with_stdio(false),
cout << fixed << setprecision(20);
};
} fast_ios_;
template <class T>
auto add = [](T a, T b) -> T { return a + b; };
template <class T>
auto f_max = [](T a, T b) -> T { return max... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long v[1000], f[1000], n, vis[10000], anss, i, o;
struct node {
long long a[10];
} ans[100000];
long long calc(long long l, long long r) {
long long tmp = 0, p = 1;
for (long long i = r; i >= l; i--) {
tmp += v[i] * p;
p = p * 10;
}
return tmp;
}
bool... | 6 |
#include <bits/stdc++.h>
using namespace std;
set<char> data;
string s;
string ans = "";
bool ddddd = false;
int main() {
int n;
cin >> n;
cin >> s;
data.insert('a');
data.insert('y');
data.insert('i');
data.insert('o');
data.insert('u');
data.insert('e');
for (int i = 0; i < s.size(); i++) {
if... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n + 1];
map<long long int, vector<long long int>> m;
for (long long int i = 1; i <= n; i++) {
cin >> a[i];
m[a[i]].push_back(i);
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gi() {
char cc = getchar();
long long cn = 0, flus = 1;
while (cc < '0' || cc > '9') {
if (cc == '-') flus = -flus;
cc = getchar();
}
while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
return cn * flus;
}
const long long N ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1e8;
double arr[200001];
int t;
bool isok(double x) {
double pos = 0;
int tot = 0;
while (1) {
int idx = upper_bound(arr, arr + t, pos) - arr;
if (idx >= t) break;
tot++;
pos = arr[idx] + 2 * x;
}
return tot <= 3;
}
void build(d... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int MAXM = 3e5 + 10;
const int INF = 1e9 + 7;
int a[MAXN];
int b[MAXN];
int c[MAXN];
vector<pair<int, int> > portals[MAXN];
vector<pair<int, int> > real_portals[MAXN];
int reachable_by[MAXN];
int dp[MAXN][MAXN];
int main() {
int n, m, k;
cin... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long inf = 1e8;
const int MAXM = 1e5 + 5;
const int MAXN = 1e6 + 4;
long long pre[MAXM], a[MAXM];
int main() {
int n, m, i, j, k;
scanf("%d", &n);
scanf("%d", &m);
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort(... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long int, long long int> > > roads(1005);
vector<vector<pair<long long int, long long int> > > drivers(1005);
long long int dis[1005][1005], v[1005], st, n, en, fl;
void dfs(long long int stra, long long int rem, long long int cos) {
long long int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
const int N = 1e5 + 5;
char s[N], a[10], b[10];
int mp[500005], id, pos[8][N], h[N], cnt, f[510][N], len[N];
vector<int> g[N];
int getnum(char *s, int l) {
int num = 0;
for (int i = 0; i < l; i++) num = num * 26 + s[i] - 'a' + 1;
return num;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str, b;
cin >> str;
for (int i = 0; i < str.size(); ++i)
if ((str[i] == '[') || (str[i] == ']') || (str[i] == ':') ||
(str[i] == '|'))
b += str[i];
int i = 0, j = 0, k = 0, m;
int max_len = -1;
int cur_len = 0;
int str_len... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int tr[10005][2], fa[10005], dp[2][10005][105], minn;
int p, m;
void dfs(int id) {
if (!tr[id][0]) return;
int l = tr[id][0], r = tr[id][1];
dfs(l);
dfs(r);
for (int i = 0; i <= minn; i++) {
for (int j = 0;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
int t, ii, i, j, n, flag;
string s;
cin >> t;
for (ii = 0; ii < t; ii++) {
flag = 0;
cin >> n >> s;
i = 0;
j = s.length() - 1;
while (i < j) {
if (s[i] == s... | 1 |
#include <bits/stdc++.h>
using namespace std;
char _;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
string val;
cin >> val;
if (val.length() < 3) {
cout << "0\n";
continue;
}
vector<int> prefix;
prefix.p... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int mod = 1e9 + 7;
int n, k, l, r, mid, pos;
long long w;
bool f[N], vis[N];
vector<int> ans;
long long check(int mid) {
long long res = 0;
for (int i = (1); i < (mid + 1); i++) res += mid / i - 1;
return res;
}
int main() {
ios::sync_wit... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
long long modpow(long long a, long long n, long long mod = MOD) {
long long res = 1;
while (n > 0) {
if (n & 1) (res *= a) %= mod;
(a *= a) %= mod;
n >>= 1;
}
return res;
}
long long sum_power(long long r, long long n, long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t, n, c0, c1, h;
string s;
cin >> t;
while (t--) {
cin >> n >> c0 >> c1 >> h;
cin >> s;
int cant1 = 0, cant0 = 0;
for (int i = 0; i < n; ++i) {
cant1 += (s[i] == '1');
cant0 +... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, ans, cnt, maxn, minn;
int a[1010], dl[1010];
map<long long, int> Q;
int main() {
scanf("%d", &n);
maxn = -1000000000;
minn = 1000000000;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (!Q.count(a[i]))
Q[a[i]] = 1;
else
Q[a[i]]++... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long dx[4] = {-1, 1, 0, 0};
const long long dy[4] = {0, 0, -1, 1};
const long long MAX = 3e5;
const long long oo = 1e16;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long n, m, k, Q, l, x, y,... | 8 |
#include <bits/stdc++.h>
using namespace std;
void seif() { std::ios_base::sync_with_stdio(0); }
int fmp[30], smp[30];
int main() {
seif();
string s1, s2;
cin >> s1 >> s2;
if (s1.length() != s2.length()) return cout << "NO", 0;
for (int i = 0; i < s1.length(); i++) {
fmp[s1[i] - 'a']++;
smp[s2[i] - 'a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const unsigned M1 = 100007;
const unsigned M2 = 100021;
const unsigned P = 101;
long long fast_pow(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e == 1) return b;
if (e % 2 == 0) {
return fast_pow((b * b) % m, e / 2, m) % m;
}
return b * f... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
string a;
string s;
int n;
int m;
int dp[5001][5001];
int main() {
cin >> a;
cin >> s;
n = a.size();
m = s.size();
memset(dp, 0, sizeof(dp));
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
dp[i][j] = d... | 4 |
#include <bits/stdc++.h>
int a[1111], v[1111];
char hash[1111];
int main() {
int i, j, n, m, x, y, z, o = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d%d%d", &x, &y, &z);
a[x] = y;
hash[y] = 1;
v[x] = z;
}
for (i = 1; i <= n; i++) o += (!hash[i] && a[i]);
printf("%d\n", o);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int data[110][4];
bool outdated[110];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
scanf("%d", &data[i][j]);
}
outdated[i] = false;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n && !ou... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline bool happy(int x) {
while (x) {
int cnt = x % 10;
if (cnt != 4 && cnt != 7) return 0;
x /= 10;
}
return 1;
}
int main() {
int n;
while (scanf("%d", &n) >= 1) {
vector<int> a(n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
vector<... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned n, m;
cin >> n >> m;
vector<unsigned> a(n + 1, 0);
vector<unsigned> b(n + 1, 0);
for (auto i = 0; i < n; ++i) {
unsigned aa, bb;
cin >> aa >> bb;
a[i] = aa;
b[i] = bb;
}
if (a[0] != 0) {
cout << "NO" << endl;
retur... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int size = 110;
const int inf = 0x3f3f3f3f;
int n, a;
int dp[size][size];
int var[size], x[size], y[size];
bool vis[size];
int dist[size];
int Abs(int x) { return x > 0 ? x : -x; }
void work() {
for (int i = 1; i <= n; i++) {
dp[i][i] = inf;
for (int j = i +... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, cnt[5005], n1, n2, n3, ans1[5005], ans2[5005],
ccnt = 0, dp[5005][5005], vis[5005], d = 1, va[5005], ud[5005], pr[5005],
hi;
vector<long long> v[5005];
map<long long, long long> m1;
void dfs1(int x) {
if (vis[x] == 0) {
vis[x] = 1;
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
const int maxn = 150005;
int t[maxn];
int main(void) {
int n, k, q;
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
int type, a;
for (int i = 0; i < q; i++) {
cin >> type >> a;
if (type == 1) {
s.insert(t[a]);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mat[5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) cin >> mat[i][j];
}
int a[5] = {0, 1, 2, 3, 4};
int sum, mx = -1;
do {
sum = 0;
for (int j = 0; j < 3; j += 2)
sum += (mat[a[j]][a[j + 1]] + mat[a[j + 1]][a[j... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <class T, class U>
inline void add_self(T &a, U b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
template <class T, class U>
inline void min_self(T &x, U y) {
if (y < x) x = y;
}
template <class T, class U>
inline void ma... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.