solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
using LL = long long;
vector<int> G[100005];
bool check(int from, int id) {
if (G[id].size() != 2) return true;
return G[id][0] != from && G[id][1] != from;
}
bool dfs(int from, int id) {
for (auto c : G[id]) {
if (c == from) continue;
... | 8 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
int flag = 0;
for (int i = 0; i < n; ++i) {
std::string name;
int before;
int after;
std::cin >> name >> before >> after;
if (before >= 2400 && after > before) {
flag = 1;
break;
}
}
if (flag) {
std::cout << ... | 0 |
#include <bits/stdc++.h>
int a[30];
int main() {
int n;
scanf("%d%d%d", &a[0], &a[1], &n);
for (int i = 2; i <= n; i++) a[i] = a[i - 1] + a[i - 2];
printf("%d\n", a[n]);
return (0);
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e3 + 10;
const int ch[5] = {0, 1, 2, 1, 2};
int n, dp[5][MX], a[MX];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= 4; ++j) {
dp[j][i] = max(dp[j - 1][i], dp[j]... | 10 |
#include <bits/stdc++.h>
using namespace std;
int N, R;
long double ans;
long double u;
int f[1 << 18];
int main() {
scanf("%d %d", &N, &R);
u = 1;
for (int i = 1; i <= N; i++) {
u /= 2;
}
for (int i = 0; i < (1 << N); i++) {
int val;
scanf("%d", &f[i]);
ans += u * f[i];
}
printf("%.7f\n",... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e7 + 1;
void solve() {
long long int n;
cin >> n;
vector<long long int> v(39, 0);
vector<long long int> v1(39, 0);
v[0] = 1;
v1[0] = 1;
for (long long int i = 1; i < 39; i++) v[i] = v[i - 1] * 3;
for (long long int i = 1; i < 39; i++... | 7 |
#include <bits/stdc++.h>
const int m = 250;
int n, a[m];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int i = 0; i < m; i++) scanf("%d", a + i);
double mean = 0.0;
for (int i = 0; i < m; i++) {
mean += a[i];
}
mean /= m;
double var = 0.0;
for (int i = 0; i < m; ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int _N = 510;
int n, s[_N], f[_N][_N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", s + i);
for (int j = 1; j <= n; j++)
for (int i = 1; i <= j; i++) {
f[i][j] = f[i][j - 1] + 1;
for (int k = i; k < j; k++)
if (s... | 11 |
#include <bits/stdc++.h>
using namespace std;
char g[2222][2222];
int main() {
ios::sync_with_stdio(false);
int R, C, K;
cin >> R >> C >> K;
for (int r = 0; r < R; r++) cin >> g[r];
for (int c = 0; c < C; c++) {
int res = 0;
for (int r = 0; r < R; r++) {
if (c - r >= 0 && g[r][c - r] == 'R') res... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
int r = (n - k) / 2 + 1;
for (int i = 0; i < n; i++) {
printf(i % r == r - 1 ? "1" : "0");
}
printf("\n");
return 0;
}
| 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m >> a >> b;
int oneride = n * a;
int seconedride;
if (m * a <= b) {
cout << n * a;
} else {
if (n % m == 0) {
seconedride = (n / m) * b;
} else {
if (m > n) {
seconedride = b;
} else... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
int x, y, v;
} d[5200];
inline bool cmp(node a, node b) { return a.v < b.v; }
int fa[5200], sz[5200], sum[5200], SUM;
inline int getroot(int x) {
if (fa[x] == x) return x;
return fa[x] = getroot(fa[x]);
}
int main() {
ios::sync_with_stdio(false)... | 19 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
string str;
cin >> str;
std::deque<char> dq;
int len = str.size();
int l = 0, r = 0;
int mid = 0;
for (int i = (0); i < (len); ++i) {
if (mid == 0 && str[i] != '|') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 6;
int nextt[N];
int n;
int deg[N];
int exists[N];
string ans = "";
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
string x;
cin >> x;
for (int j = 0; j < x.length() - 1; j++) {
exists[x[j] - 'a' + 1] = 1;
if (nextt[x[j]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int intmax = 0x7fffffff;
vector<pair<int, int> > f;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < 2 * n; i++) {
int a;
scanf("%1d", &a);
f.push_b... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, k;
cin >> n >> m >> k;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int mii = a[n - 1];
long long int mi = a[n - 2];
long long int h = m / (k + 1);
if (m % (k + 1) == 0)
cout <<... | 2 |
#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 x = 1000000007, y = 1000000007, x1 = -1000000007, coci = -1000000007;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e5 + 10;
int sz[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
if (m & 1) {
puts("No");
return 0;
}
int maxv = 0;
priority_queue<pair<int, int>> pq;
vector<pair<int, int>> ans;
for (int i = 1; i <= n; ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int k, l, ln, maxx;
char s[1000000];
int a[1010000], cnt, sm;
inline void read(int& x) {
char c = getchar();
x = 0;
while (c > '9' || c < '0') c = getchar();
while (c <= '9' && c >= '0') x = (x << 1) + (x << 3) + c - '0', c = getchar();
}
inline bool check(int x) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (1e9) + 7;
const double eps = 1e-6;
const int siz = 1e6 + 5, siz2 = 1e5 + 5;
stack<int> av, cur;
bool del[siz], q[siz];
int n, m;
vector<int> to[siz], from[siz], ans;
void solve() {
for (int i = 2; i <= n; i++) {
av.push(i);
}
cur.push(1);
del[1]... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int INF_MAX = 0x7FFFFFFF;
const int INF_MIN = -(1 << 30);
const double eps = 1e-10;
const double pi = acos(-1.0);
int toInt(string s) {
istringstream sin(s);
int t;
sin >> t;
return t;
}
template <class T>
string toString(T x) {
ostringstream sout;
sout <<... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, n2, m2, len;
long long str1[200010], str2[200010], str3[200010], f[200010];
long long ans;
char s[10];
void find() {
int i, j = 0, l, r;
for (i = 0; i < n; i++) {
while (j && str3[j] != str1[i]) j = f[j];
if (str3[j] == str1[i]) j++;
if (j == len) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
typedef long long ll;
typedef long double ld;
typedef vector... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void chmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <class T1, class T2>
void chmax(T1 &a, T2 b) {
if (a < b) a = b;
}
using Pi = pair<long long, long long>;
using Ti = tuple<long long, long long, long long>;
using vint = vector<long lon... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m;
string s;
map<char, int> fr;
vector<pair<long long int, char> > v;
int main() {
cin >> n >> m >> s;
for (int i = 0; i < s.size(); i++) fr[s[i]]++;
for (map<char, int>::iterator it = fr.begin(); it != fr.end(); it++)
v.push_back(make_pair(it->se... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long inf = 1e17 + 7;
struct node {
int to;
long long cost;
node() {}
node(int to, long long cost) {
this->to = to;
this->cost = cost;
}
friend bool operator<(node a, node b) { return a.cost > b.cost; }
};
long long di... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
string s[n];
set<string> st;
int sz = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = n - 1; i >= 0; i--) {
st.insert(s[i]);
if (st.size()... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2000005;
int N, R, MSol, Sol;
char Move[2] = {'T', 'B'}, String[MaxN];
int GCD(int X, int Y, int M) {
if (X == 1 && Y == 0) return M == N ? 0 : N + 1;
if (Y == 0) return N + 1;
M += X / Y;
return (X / Y - 1) - (Y == 1) + GCD(Y, X % Y, M);
}
void Bui... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100005;
const double EPSILON = 0.000001;
int n, m;
long long q[MAXM], w[MAXM];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) cin >> q[i] >> w[i];
sort(w, w + m, greater<int>());
int even, odd;
even = sqrt(2 * n) + EPSILON;
odd = (sqrt(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int a, b, c, m, x, resp = 0, aux;
long long mini = 0;
vector<int> usb, ps2, rest;
string s;
cin >> a >> b >> c >> m;
for (int i = (0); i < (m); i++) {
cin >> x >> s;
if (s[0] == 'U')
usb.push_back(x);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const double EPS = 1e-5;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
string s;
cin >> s;
int k;
cin >> k;
priority_queue<pair<stri... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
char s[maxn];
int main() {
scanf("%s", s);
int n = strlen(s);
bool flag = 0;
for (int j = 0; j < n; ++j) {
if (s[j] != 'a') {
flag = 1;
while (j < n) {
--s[j];
++j;
if (j == n || s[j] == 'a') break;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[100007];
long long t[100007];
long long c[100007];
long long ans = 0;
void ms(long long l, long long r) {
if (l == r) return;
long long mid = (l + r) / 2;
ms(l, mid);
ms(mid + 1, r);
long long cnt = l;
long long c1 = l, c2 = mid + 1;
while (c1 <= m... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int x, y, c;
} ee[110];
int n, m;
int cnt = 0;
int pa[110];
int vis[110];
int find(int x) {
if (pa[x] != x) pa[x] = find(pa[x]);
return pa[x];
}
void sert() {
for (int i = 0; i <= n; i++) pa[i] = i;
}
bool kru(int c, int s, int e) {
for (int i = 0; i... | 16 |
#include <bits/stdc++.h>
using namespace std;
long n;
vector<pair<long, long> > v;
long ar[300000];
long reach[300000][10];
long rspan, need1, need2;
long p, q;
long par[300000][10];
long ps, cur;
long tp, np, niters, m2, m1, qq;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
v.push_back(make_pair(0, 0));
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, k = 0, c = 0, a = 0;
scanf("%d%d", &n, &k);
scanf("%d", &c);
int res = 0, cur = 0;
for (int i = 0; i < c; ++i) {
scanf("%d", &a);
res += (a - cur - 1) / k;
++res;
cur = a;
}
res += (n - a) / k;
printf("%d", res);
ret... | 5 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int main() {
int n, k;
cin >> n >> k;
vector<int> v;
char c;
for (int i = 0; i < n; i++) {
cin >> c;
v.push_back(c - '0');
}
int preprevj = -1;
int prevj = -1;
for (int i = 0; i < k; i++) {
int j;
for (j = ma... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long inf = 1e18;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, k;
cin >> n >> m >> k;
vector<long long> lst(n);
for (long long& x : lst) cin >> x;
vector<long long> a;
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long sum, ways[N];
int n, parent[N], kids[N], dis[N], max_dis;
vector<pair<int, int> > adj[N];
vector<int> level[N];
bool seen[N];
bool lucky(int x) {
while (x > 0) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return ... | 11 |
#include <bits/stdc++.h>
using namespace std;
constexpr long long MAX_M = 1001005;
constexpr long long MOD = 1000000007;
long long fact[MAX_M];
long long mod_pow(long long b, long long p) {
long long out = 1;
while (p > 0) {
if (p & 1) {
out = (out * b) % MOD;
}
p >>= 1;
b = (b * b) % MOD;
}... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long n;
string s;
long long dp[2005][2005];
long long dp2[2005][2005];
long long ans = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long i, j;
cin >> s, n = s.length();
dp2[n + 1][0] = 1;
for... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct cage {
long long val;
int ind;
};
bool compare(cage X, cage Y) { return X.val > Y.val; }
struct element {
long long Size;
int father;
};
long long N;
int M;
vector<int> Sets, p[MAXN];
cage a[MAXN];
bool been[MAXN];
element d[MAXN];
lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
FILE* in = stdin;
FILE* out = stdout;
const int MAX = 200002;
int n;
long long a[MAX];
long long xp, xs, yp, ys, k;
long long gcd(long long x, long long y) {
while (y > 0) {
x %= y;
swap(x, y);
}
return x;
}
bool eval(int use) {
if (xp < yp) {
swap(xp, y... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, A[1000], B[1000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < n; i++) {
cin >> B[i];
}
bool Used[1001];
int P[1000], p1 = 0, p2 = 0;
memset(Used, false, sizeof(Used));
memset(P, 0, sizeof(P));
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void mult(const long long int* a, const long long int* b, long long int* c) {
for (int r = 0; r < 3; ++r) {
for (int j = 0; j < 3; ++j) {
int idx = j * 3 + r;
c[idx] = 0;
for (int i = 0; i < 3; ++i) c[idx] += a[i * 3 + r] * b[j * 3 + i];
}
}
}
... | 10 |
#include <bits/stdc++.h>
const long long mod = 1000000000 + 7;
const long long INF = 9000000000000000000;
using namespace std;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
long long gcd(long long a, long long b) { return (a == 0 ? b : gcd(b % a, a)); }
long long lcm(long long a, long long b... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y);
long long int gcd(long long int a, long long int b);
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
if (k % 2 == 0) {
cout << "YES\n";
for (long lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int ans = 10e12, n;
void rc(long long int s, int i, int k1, int k2) {
if (k1 == k2 && s >= n) {
ans = min(ans, s);
return;
}
if (i > 10) return;
rc(s * 10 + 4, i + 1, k1 + 1, k2);
rc(s * 10 + 7, i + 1, k1, k2 + 1);
}
int main() {
cin >> n;
rc... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {
return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const in... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a, b, c, d, n, t;
bool g[N][N] = {0};
int dir, x, y;
char ans[N][N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> a >> b >> c >> d >> n;
for (int i = 1; i <= a; ++i)
for (int j = 1; j <= b; ++j) g[i][j] = 1;
for (int i = a + ... | 11 |
#include <bits/stdc++.h>
using namespace std;
char num[200001];
int numLen, m, temp, answer = 0;
int stepArr = 1;
int main() {
cin >> num >> m;
numLen = strlen(num);
answer += (num[numLen - 1] - 48) % m;
for (int i = numLen - 2; i >= 0; i--) {
stepArr = (stepArr * 10) % m;
answer += ((num[i] - 48) * ste... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, heightmaks = 0, sum = 0;
map<int, int> data;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> k;
if (data[k] == 0) sum++;
data[k] += 1;
heightmaks = max(heightmaks, data[k]);
}
cout << heightmaks << " " << sum << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long val[300050];
long long power_mod(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret = ret * a % mod;
b >>= 1;
a = a * a % mod;
}
return ret;
}
int main() {
int n;
while (scanf("%d", &n) != EOF... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> mp;
mp["monday"] = 0;
mp["tuesday"] = 1;
mp["wednesday"] = 2;
mp["thursday"] = 3;
mp["friday"] = 4;
mp["saturday"] = 5;
mp["sunday"] = 6;
string a, b;
cin >> a >> b;
int x = mp[b] - mp[a];
x += 7;
x %= 7;
if (x == 0 ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int l[maxn], r[maxn];
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
long long r, g, b, w, zero = 0, odd = 0, even = 0;
cin >> r >> g >> b >> w;
if (r == 0) zero++;
if (g == 0) zero++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int t[N];
int main() {
int n, limit;
scanf("%d%d", &n, &limit);
for (int i = 1; i <= n; ++i) scanf("%d", &t[i]);
priority_queue<int> pq;
queue<int> q;
int sum = 0;
for (int i = 1; i <= n; ++i) {
sum += t[i];
int res = 0;
int prev... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, K;
cin >> n >> K;
string str;
cin >> str;
int size = str.size();
int ss = size - 1;
int p = 0;
bool sign = false;
for (int i = 0; i < ss; i++) {
if (str[i] == '4') {
if (str[i + 1] == '7') {
p = i;
sign = true;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
const int N = 3e5 + 5;
V<int> G[N];
int sz[N], fa[N], son[N];
void dfs(int u) {
sz[u] = 1;
for (auto& v : G[u]) {
dfs(v);
sz[u] += sz[v];
if (sz[v] > sz[son[u]]) son[u] = v;
}
}
int ans[N];
int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
string to_string(char s) {
string res = "'''";
res[1] = s;
return res;
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct Tpoint {
double x, y;
Tpoint() {}
Tpoint(double _x, double _y) {
x = _x;
y = _y;
}
inline void read() { scanf("%lf%lf", &x, &y); }
inline void show() { printf("%lf %lf\n", x, y); }
inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); }... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[8], cnt;
char s[30];
scanf("%d", &t);
while (t--) {
memset(s, 0, sizeof(s));
memset(a, 0, sizeof(a));
cnt = 0;
scanf("%s", s);
for (int i = 0; i < 12; i++) {
if (s[i] == 'X') a[0]++;
if (s[i] == 'X' && s[i + 6] =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, l, r;
int main() {
scanf("%d%d%d", &n, &l, &r);
int now = 1, ans1 = 0, ans2 = 0;
for (int i = 1; i <= n; ++i) {
if (i <= l)
ans1 += now;
else
ans1 += 1;
if (i < l) now = now * 2;
}
now = 1;
for (int i = 1; i <= n; ++i) {
ans2 +... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long a[n];
long long len[n];
unordered_map<int, int> rems[11];
bool validlen[11];
int temp;
for (int i = 0; i < 11; ++i) {
validlen[i] = false;
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
temp... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> adj[200005];
map<pair<long long, long long>, long long> pam;
long long c[200005];
bool visited[200005];
bool flg = true;
long long ans[200005];
void dfs(long long s, long long C) {
visited[s] = true;
c[s] = C;
for (long long i = 0; i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
void solve() {
string x;
cin >> x;
deque<long long> d;
for (long long i = 0; i < (long long)x.size();) {
long long j = i;
while (j < (long long)x.size() && x[i] == x[j]) j++;
d.push_back(j - i);
i = j;
}
if (x[0] == 'F') d.p... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct node {
node() { occ = 0; }
int occ;
map<char, node *> edge;
};
const int MAX_N = 2e5 + 5;
string t, s[MAX_N];
int n, sumlen;
node *trie;
int suf[MAX_N], pref[MAX_N], kmp[MAX_N];
void calcKMP(string str) {
int len = 0;
kmp[0] = 0;
int M = str.length();
i... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, a1, a2, b1, b2, i, j, mini, i_1, j_1, i_2, j_2;
char s[105];
int m[105][105], v[105][105];
void fil(int c1, int c2, int val) {
if (c1 <= 0 || c2 <= 0 || c1 > n || c2 > n) return;
if (m[c1][c2] == -1) return;
if (v[c1][c2]) return;
v[c1][c2] = val;
fil(c1 + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long f[110][2][2];
char s[110];
int main() {
scanf("%s", s + 1);
int len = strlen(s + 1);
s[++len] = s[1];
f[1][0][0] = 1;
f[1][1][1] = 1;
for (int i = 1; i <= len; i++)
for (int j = 0; j <= 1; j++) {
if (s[i] == 'A') {
if (s[i + 1] == 'A'... | 13 |
#include <bits/stdc++.h>
using namespace std;
char *fs, *ft, buf[1 << 15];
inline char getc() {
return (fs == ft &&
(ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
? 0
: *fs++;
}
inline int read() {
int x = 0, f = 1;
char ch = getc();
while (ch < '0' || ch > '9')... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long LINF = 1e17;
const double PI = 3.141592653589793238;
const int mod = 1000000007;
const double eps = 0.000001;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, m;
cin >> n >> h >> m;
int a[n + 3];
for (int i = 1; i <= n; i++) {
a[i] = h;
}
for (int i = 1; i <= m; i++) {
int l, r, x;
cin >> l >> r >> x;
for (int j = l; j <= r; j++) {
a[j] = min(a[j], x);
}
}
long long... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n == 0 && m == 0) {
cout << "0" << endl;
return 0;
}
if (n > m) {
cout << "-1" << endl;
return 0;
}
if (n == m) {
cout << 1 << endl;
cout << n << endl;
return 0;
}
if ((m - n) % 2 ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long linf = (long long)1e18;
const int mod = (int)1e9 + 7;
const long double eps = (long double)1e-8;
const int maxn = (int)1e5 + 5;
const long double pi = acos(-1);
int n, b[222][6], way[222];
pair<long double, long double> a[6];
vector... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1000001], ans = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
ans += a[n - 1] - a[i];
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
struct PT {
long long x, y;
PT(long long xx = 0, long long yy = 0) : x(xx), y(yy) {}
PT operator+(const PT &p) const { re... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036654775807;
long long dp[1 << 21];
int mnt[1 << 21], n, b, mt, mm;
struct fr {
int m, x, k;
} f[105];
bool comp(fr a, fr b) { return (a.k < b.k); }
int main() {
cin >> n >> mm >> b;
for (int i = 0; i < n; i++) {
cin >> f[i].x >> f[i]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
long long int sum = 0;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum +... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 1;
const int INF = 2e9 + 1;
const int MOD = (1e9 + 7);
void bye(string s = "") {
cout << s << '\n';
exit(0);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> arr(n);
set<pair<... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
struct Edge {
int t, nx, w;
} e[100010 << 1];
queue<int> g[100010];
long long d[100010], f[100010], y;
int i, j, k, n, m, q, x, h[100010];
struct Node {
int x;
Node(int x = 0) : x(x) {}
bool operator<(Node a) const { return d[x] > d[a.x];... | 26 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
istream &operator>>(istr... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long l, r;
int main() {
cin >> l >> r;
printf("YES\n");
for (long long i = l; i <= r; i += 2) {
cout << i << " " << i + 1 << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
static char _buf[1 << 16];
int _pos = 1;
int _cap = 1;
inline char nextChar() {
if (_cap == 0) return 0;
if (_pos == _cap) {
_cap = (int)fread(_buf, 1, 1 << 16, stdin);
if (_cap == 0) return 0;
_pos = 0;
}
return _buf[_pos++];
}
template <class T>
T next... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int a[N];
int n, k, ans;
int main() {
scanf("%d%d", &n, &k);
int p = n / 2 + 1;
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n / 2; ++i) {
for (; p <= n; ++p)
if (a[p] - a[i] >= k) b... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int ans = 0;
map<string, long long int> faces;
faces["Tetrahedron"] = 4, faces["Cube"] = 6;
faces["Octahedron"] = 8, faces["Dodecahedron"] = 12;
face... | 0 |
#include <bits/stdc++.h>
int main() {
long long int n, lcm;
scanf("%lld", &n);
if (n == 1) {
lcm = 1;
} else if (n == 2) {
lcm = 2;
} else if (n % 6 == 0) {
lcm = (n - 1) * (n - 2) * (n - 3);
} else if (n % 2 == 0) {
lcm = (n) * (n - 1) * (n - 3);
} else {
lcm = (n) * (n - 1) * (n - 2)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
unsigned long long n, k, i;
cin >> n >> k;
for (i = 1; n % i != 0 || n / i >= k; i++)
;
cout << i * k + n / i << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const long long prime = 1000000007;
const long long maxN = 1e6 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, sum = 0;
string s, s1, s2;
cin >> s;
n = s.length();
for (long long i = (long long)(0); i <= (long long)(n - 1); i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[200000 + 5];
int diff[200000 + 5];
int n, m, k;
vector<int> v;
long long dp[2][(1 << 8) + 5];
bool cnt[1 << 8];
int main(void) {
cin >> n >> m >> k;
for (int i = 0; i < (1 << 8); i++) {
int j = i;
int cnt_ = 0;
for (int t = 0; t < 8; t++) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
const int oo = 1e9, bpr = 1e9 + 7, N = 1e5 + 100;
inline long double dist2(long double x, long double y) {
return sqrt(x * x + y * y);
}
vector<pair<long double, int> > cc;
long double ans = 1e18, sum;
long double x[N],... | 10 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
long long a, b, q;
cin >> a >> b >> q;
auto sm = [&](long long n, long long f) {
return n * (2 * f + (n - 1) * b) / 2;
};
while (q--) {
long long l, t, m;
cin >> l >> t >> m;
long lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int main(int argc, char **argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long> stickers;
for (int i = 0; i < (int)(n); i++) {
long long sticker;
cin >> sticker;
stickers.push_back(sticker)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a = 0, b = 0;
for (char c : s) {
if (c == '0') {
if (a == 0) {
cout << "1 1\n";
} else {
cout << "3 1\n";
}
a = (a + 1) % 2;
} else {
if (b == 0) {
cout << "4 3\n";
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, t;
cin >> n;
for (long long k = 2; k <= 32; k++) {
if (n % ((1 << k) - 1) == 0) {
t = n / ((1 << k) - 1);
break;
}
}
cout << t << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.t... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct atom {
int x[31][31];
} dp[70], B;
int K, mo = 1e9 + 7, x[70], len, A[70];
long long n;
atom mul(atom k1, atom k2) {
memset(B.x, 0x00, sizeof B.x);
for (int i = 0; i < K; i++) {
B.x[i][K] = k2.x[i][K];
for (int j = 0; j < K; j++) {
B.x[i][K] = (B.... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
struct Point {
long long x, y;
int id, c;
inline Point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
inline bool operator<(const Point &oth) const {
return x < oth.x || (x == oth.x && y < oth.y);
}
inline Point operator+(const Poi... | 24 |
#include <bits/stdc++.h>
int main() {
int n, i, j;
scanf("%d", &n);
long int arr[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i == 0 || j == 0) {
arr[i][j] = 1;
} else {
arr[i][j] = arr[i - 1][j] + arr[i][j - 1];
}
}
}
printf("%ld", arr[n - 1][n - ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.