solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
vector<int> mq[105];
int xf[105];
int main() {
int n, s, x;
int i, j;
int a, b;
while (cin >> n) {
for (i = 1; i <= 100; i++) mq[i].clear();
a = 0, b = 0;
for (i = 1; i <= n; i++) {
cin >> s;
while (s--) {
cin >> x;
mq[i].push... | 12 |
#include <bits/stdc++.h>
using namespace std;
int Mx(int a, int b) { return a > b ? a : b; }
int Mn(int a, int b) { return a < b ? a : b; }
const int N = 1e5 + 5, mod = 1e9 + 7;
int upt(int x) {
while (x >= mod) x -= mod;
while (x < 0) x += mod;
return x;
}
int pw(int x, int k) {
int ret = 1;
while (k) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
map<char, char> m;
char a[200100][2];
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
for (char i = 'a'; i <= 'z'; i++) m[i] = i;
for (int i = 0; i < k; i++) {
cin >> a[i][0] >> a[i][1];
}
char ch;
for (char i = 'a'; i <= 'z'; i++) {
ch =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
int n, a[200005], _x... | 2 |
#include <bits/stdc++.h>
const int maxn = 1000 * 1000 + 5, maxm = 105;
const long long Mod = 1000 * 1000 * 1000 + 7;
struct Mat {
long long m[maxm][maxm];
Mat() {
for (int y = 0; y < maxm; y++)
for (int x = 0; x < maxm; x++) m[y][x] = 0;
}
void iden() {
for (int i = 0; i < maxm; i++) m[i][i] = 1;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int inf = 2e9;
const int N = 1001;
int n, k, b[N], a[N], s;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
int s = 0;
for (int j = 0; j... | 10 |
#include <bits/stdc++.h>
using namespace std;
double n, i, b, h, c, a, x;
int main() {
cin >> n >> h;
b = h * h / n;
x = b;
c = n - 1;
vector<double> v;
while (c != 0) {
a = sqrt(b);
v.push_back(a);
b += x;
c--;
}
for (i = 0; i < v.size(); i++) {
cout << fixed << setprecision(15) << ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const string nameFile = "test";
ifstream in(nameFile + ".in");
ofstream out(nameFile + ".out");
const int oo = 2e9;
int dp[52][52][52][52];
int a[52][52];
char ch;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, oo, 52 * 52 ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long expo(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) {
long long ret = expo(a, b / 2);
ret = (ret * ret) % 1000000007;
return ret;
} else {
long long ret = expo(a, b / 2);
ret = (ret * ret) %... | 7 |
#include <bits/stdc++.h>
static const int MAXN = 100008;
static const int HASH_BASE = 2333;
static const long long HASH_MOD = 100000007;
template <typename T>
inline T max(const T a, const T b) {
return a > b ? a : b;
}
inline long long fpow(long long b, long long e) {
long long ans = 1;
while (e) {
if (e & 1... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
vector<vector<long lon... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 20;
const int INF = 1e9 + 7;
int n, m, k, num;
int a[N], fa[N], type[N], di[N], sz[N];
long long ans;
stack<pair<int, int> > st;
struct Node {
int u, v;
} e[N];
inline int read() {
int p;
scanf("%d", &p);
return p;
int x = 0, f = 1;
char ch =... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, s, t;
long long x[5010], a[5010], b[5010], c[5010], d[5010];
long long dp[5010][5010];
int main() {
scanf("%d%d%d", &n, &s, &t);
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= n; ++j) dp[i][j] = 1e18;
for (int i = 1; i <= n; ++i) {
scanf("%lld", &x[i... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lb = 1000;
void vrikodara(long long n = 12) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(n) << fixed;
}
double solve() {
long long m, R;
cin >> m... | 11 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
const int M = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
cin >> s >> t;
long long total = 1;
long long bigger = 1;
long long smaller = 1;
long long eq = 1;
for (int i = 0; i < n; i++) {
if (s[i] == '?' &&... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
string base((n - k) / 2, '0');
base += "1";
string ans;
while (ans.size() < n) ans += base;
while (ans.size() > n) ans.pop_back();
cout << ans << endl;
return 0;
}
| 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-5;
const int N = 1e5 + 10;
deque<int> dq;
int main() {
int a, b, c, d;
while (~scanf("%d%d%d%d", &a, &b, &c, &d)) {
bool flag = true;
dq.clear();
while (a && b) {
dq.push_back(0... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 100009;
int sum[SIZE * 30];
int query(int base, int idx, int l, int r, int s, int e) {
if (sum[base + idx] == (r - l))
return -1;
else if (!sum[base + idx])
return max(l, s);
else {
int m = (l + r) / 2;
if (s < m) {
int t = query... | 11 |
#include <bits/stdc++.h>
const int mod = 1000000007;
int n, x[100010], y[100010], xs[100010], ys[100010], xcnt, ycnt;
struct edge {
int to;
edge* next;
} E[200010], *ne = E, *first[200010];
void link(int u, int v) {
*ne = (edge){v, first[u]};
first[u] = ne++;
}
int vcnt, ecnt;
bool vis[200010];
void dfs(int i) ... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct edges {
int to, next;
};
edges edge[400010];
int n, head[200010], num;
int ru[200010];
long long dp[200010][3], efficiency[200010];
int root;
bool vis[200010];
void add(int u, int v) {
num++;
edge[num].to = v;
edge[num].next = head[u];
head[u] = num;
}
void... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double x, y;
cin >> x >> y;
long double ans1 = y * log(x);
long double ans2 = x * log(y);
if (x == y) {
cout << "=" << endl;
} else if (ans1 == ans2) {
cout << "=" << endl;
} else if (ans1 > ans2) {
cout << ">" << endl;
} else {... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename L>
bool smin(T& x, L y) {
return x > y ? x = y, true : false;
}
const int MAXN = 5e4 + 15, SQ = MAXN / 350;
unordered_map<string, vector<int>> mp;
map<pair<string, string>, int> dp;
int q;
string s;
int32_t main() {
ios_base::sync_with_std... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
struct mint {
int value;
mint() : value(0) {}
template <class T>
mint(T x) {
value = x % M;
if (value < 0) {
value += M;
}
}
mint &operator++() {
if (++value == M) {
value = 0;
}
return *this;
}
m... | 24 |
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
int up = -1, down = 200001;
string ans = "";
int n, i, fl = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
if (a[i] > up && a[i] < down) {
if (a[i] < a[i + 1])
up = a[i], ans += " 0";
... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <typename T>
T gcd(T m, T n) {
while (n) {
T t = m % n;
m = n;
n = t;
};
return m;
}
template <typename T>
T exgcd(T a, T b, T& sa, T& ta) {
T q, r, sb = 0, tb = 1, sc, tc;
sa = 1, ta = 0;
if (b) do
q = a / b... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool sortby(pair<long long, long long> &a, pair<long long, long long> &b) {
return a.first < b.first;
}
void solve() {
long long n;
cin >> n;
vector<pair<long long, long long> > v;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
v.push_back(make_p... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[300002], i, l, r, num, rl, ans[300002];
int main() {
cin >> n;
for (i = 1; i <= n; ++i) cin >> a[i];
i = 1;
while (i <= n) {
l = i;
r = i;
while ((l >= 1) && (a[l] % a[i] == 0)) l--;
while ((r <= n) && (a[r] % a[i] == 0)) r++;
l++;
r... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
int cnt[100005];
bool vis[100005];
vector<int> adj[100005];
map<pair<int, int>, bool> mp;
vector<int> v;
int main() {
cin >> n;
for (int i = 0; i < n - 2; ++i) {
int a[3];
cin >> a[0] >> a[1] >> a[2];
++cnt[a[0]];
++cnt[a[1]];
++cnt[a[2]];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1005;
int chk[N][2 * N];
int n, k;
int shift = 1000;
string x, y;
void foo(int p, int D) {
if (p == n) {
if (abs(D) == k) {
cout << y << endl;
exit(0);
}
}
if (abs(D) >= k) return;
int &rv = chk[p][D + shif... | 12 |
#include <bits/stdc++.h>
using namespace std;
int N;
int previous(int index) { return index == 0 ? N - 1 : index - 1; }
void answer(const vector<long long> &A) {
cout << "YES" << '\n';
for (int i = 0; i < N; i++) cout << A[i] << (i < N - 1 ? ' ' : '\n');
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullp... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
double Max[MAXN], Min[MAXN];
double aa[MAXN], bb[MAXN];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lf", Max + i);
for (int i = 0; i < n; i++) scanf("%lf", Min + i);
for (int i = 1; i < n; i++) Max[i] += Max[i ... | 16 |
#include <bits/stdc++.h>
const int N = 60;
int n, m;
long long f[N][N], g[N][N], t[N][N], INV[N];
void Inverse_Element() {
INV[1] = 1;
for (int i = 2; i <= 60; i++) {
INV[i] = (-1000000007 / i * INV[1000000007 % i]) % 1000000007;
}
}
int main() {
Inverse_Element();
scanf("%d%d", &n, &m);
f[0][1] = 1;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
int c[200005], f[200005];
int fin(int x) {
if (x != f[x]) {
f[x] = fin(f[x]);
}
return f[x];
}
void unit(int x, int y) {
int fx = fin(x);
int fy = fin(y);
if (fx != fy) {
f[fx] = fy;
}
}
vector<int> p[200005];
int main() {
int n, m, k;
int l, r;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-6;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
map<char, int> num;
num['R'] = 0;
num['G'] = 1;
num['B'] = 2;
str... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int n;
cin >> n;
n *= 2;
vector<char> f(n);
vector<int> a(n, 0);
for (int i = 0; i < n; i++) {
cin >> f[i];
if (f[i] == '-') cin >> a[i];
}
vector<int> cur;
for (int i = 0; i < n; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100010;
struct adjList {
int id, nxt;
} Lst[MaxN * 2];
int LCnt, Head[MaxN];
int N, w[MaxN], root;
void addEdge(int a, int b) {
Lst[LCnt].id = b;
Lst[LCnt].nxt = Head[a];
Head[a] = LCnt++;
}
pair<long long, long long> dfs(int id, int pre) {
vector... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> factorial(1001);
long long int binpow(long long int a, long long int b) {
a %= 1000000007;
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
b >>= 1;
}
return res;
}
long long in... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N;
signed long long B[202020];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N;
signed long long G = 0;
vector<signed long long> C[64];
int ma = 0;
for (i = 0; i < (N); i++) {
cin >> B[i];
x = 0;
while (((B[i] >> x) & 1) == 0) x++;
... | 11 |
#include <bits/stdc++.h>
int A, B;
void ask(int x, int y) {
printf("? %d %d\n", x, y);
fflush(stdout);
}
void succ(int x, int y) {
printf("! %d %d\n", x, y);
fflush(stdout);
exit(0);
}
int main() {
ask(0, 0);
int cmp;
scanf("%d", &cmp);
for (int i = 29; ~i; --i) {
ask(1 << i | A, 1 << i | B);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k;
int c = 0;
int arr[n][2];
for (int i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
cin >> k;
for (int i = 0; i < n; i++) {
if (k <= arr[i][1]) c++;
}
cout << c << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005, K = 4000005;
const char *XW = "Hamed", *HW = "Malek";
int n, m, k, tox, ans, out;
int a[N], b[N], c[N], d[N], dlt[K], ze[2 * N], now[K], num[K], nuk[K], dlk[K];
struct rg {
int d, id, tr;
} rt[2 * N];
bool cmpa(rg a, rg b) { return a.d < b.d; }
struc... | 24 |
#include <bits/stdc++.h>
using namespace std;
long long int i, j, n;
long long int s[100005], el[100005];
int main() {
long long int m, cl, ce, v;
cin >> n >> m >> cl >> ce >> v;
for (i = 0; i < cl; i++) {
cin >> s[i];
}
for (i = 0; i < ce; i++) {
cin >> el[i];
}
long long int q;
cin >> q;
whi... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 1e5 + 134, M = 1e9 + 7;
int64_t pr[MAXN], q[MAXN];
int64_t F(int64_t i) {
if (i == 0) return 1;
int64_t x = F(i / 2);
if (i % 2 == 0)
return (x * x) % M;
else
return (2 * x * x) % M;
}
int main() {
ios_base::sync_with_stdio(false);
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long fast_pow(unsigned long long a, unsigned long long n) {
unsigned long long result = 1;
unsigned long long power = n;
unsigned long long value = a;
while (power > 0) {
if (power & 1) {
result = result * value;
result = result % 1000000007;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
long long x = a + b;
if (x >= 1000000007) x -= 1000000007;
if (x < 0) x += 1000000007;
return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
set<int> st[26];
char str[N];
set<int>::iterator it;
int main() {
scanf("%s", str);
int len = (int)strlen(str);
for (int i = 0; i < len; i++) {
st[str[i] - 'a'].insert(i + 1);
}
int n, opt, l, r;
char chr[2];
scanf("%d", &n);
for ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, check, lg;
char input[300000];
int main(int argc, char** argv) {
int i, j, k;
while (scanf(" %d %d %s", &n, &k, input) == 3) {
check = 1;
i = 0;
while (i < n - 1) {
for (j = k; j > 0; j--) {
if (i + k >= n - 1) {
i = n - 1;
... | 1 |
#include <bits/stdc++.h>
using i64 = long long;
std::vector<std::deque<std::pair<int, int>>> g;
std::vector<int> c;
int mod;
void dfs(int v, int p, int nc) {
for (auto &el : g[v]) {
if (el.first == p) continue;
c[el.second] = (nc++) % mod;
dfs(el.first, v, nc % mod);
}
}
int main() {
int n, k;
scanf... | 11 |
#include <bits/stdc++.h>
using namespace std;
namespace Dango {
const int MAXN = 100005;
vector<int> e[MAXN], ans;
int n, fa[MAXN];
int d[MAXN], pos[MAXN];
int read() {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) {
f |= (ch == '-');
ch = getchar();
}
while (isdigit(ch)) {
x = x * 1... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010, M = 500100;
int n, m, x[M], y[M];
bitset<N + N> mat[N];
inline void guass(int n) {
for (int j = (1), _endtmp = (n); j <= (_endtmp); j++) {
int r = j;
while (r <= n && !mat[r].test(j)) ++r;
assert(r <= n);
swap(mat[j], mat[r]);
for (... | 20 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> a(n);
vector<int> b(n + 1);
vector<string> ans(n + 1, string(n, '0'));
for (int i = 0;... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long int const inf = 1e18;
long long int const maxn = 1e6 + 5;
long long int const mod = 1e9 + 7;
long long int solve(vector<long long int> brr) {
sort(brr.begin(), brr.end());
long long int sz = brr.size();
long long int ans = 0;
for (long long int i = 1; i < ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int matrix[24];
int n, p, k = 0, ok = 0;
for (int i = 0; i <= 24 && ok == 0; i++) {
cin >> n;
matrix[i] = n;
if (matrix[i] != 0) {
p = i;
ok = 1;
}
}
if (p == 12)
cout << 0;
else if (p == 7 || p == 11 || p == 17 || p ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s, t;
cin >> s >> t;
vector<vector<bool> > v(n, vector<bool>(m, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) v[i][j] = s[i] == t[j];
int ans_k = n + 1;
vector<int> ans;
for (int i = 0; i <= m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int MAX = 1e9;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
double c;
int cnt = 0;
for (int i = 1; i < n; i++) {
for (int j = 1; j < n; j++) {
c = i * i + j * j;
double t = floor(sqrt(c));
if (sqrt(c) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[10000010], z;
int getnum(int n) {
for (int i = 1;; i++) {
if (a[i] > z) {
z -= a[i - 1];
break;
}
}
return z;
}
int main(void) {
cin >> t;
int count = 5;
a[1] = 2;
for (int i = 2; a[i - 1] <= 1000000001; i++) {
a[i] += a[i -... | 3 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
double root3 = pow(3, .5);
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double r, h;
cin >> r >> h;
double a = 1.0;
if (r * (root3 / 2.0) <= h) {
a += 2 + 2 * (long long)max(0.0, (h - r * (root3 * .5)) / r);
}
do... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MAXN = 2e6 + 50;
const long long LINF = 2e9 + 1000, MOD = 998244353;
const double Pi = acos(-1), EPS = 1e-6;
void test() { cerr << "\n"; }
template <typename T, typename... Args>
void test(T x, Args... args) {
cerr << x << " ";
test(args...);... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
while (cin >> n >> m >> k) {
int num[200005];
for (int i = 1; i <= n; i++) cin >> num[i];
int cnt = n, nk = k;
m--;
for (cnt = n; cnt >= 1; cnt--) {
if (nk > num[cnt]) {
nk -= num[cnt];
} else if (nk == n... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
const double eps = 1e-12;
template <typename T>
inline void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (ch... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 20;
const int M = 1e6 + 20;
int main() {
cout.tie(0);
long long k;
scanf("%lld", &k);
string s = "codeforces";
long long ans[15];
for (int i = 0; i < 10; i++) {
ans[i] = 1;
}
long long num = 1;
while (num < k) {
for (int i = 0; ... | 7 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define Endl endl
#define lb lower_bound
#define up upper_bound
#define fi first
#define se second
ll mod=1e9+7;
int solve()
{
ll n;
cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++)
cin>>a[i];
vector<ll>b(a);
sort(b.begin(),b.end()... | 7 |
#include <bits/stdc++.h>
using namespace std;
static inline void faststream() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void pri(const vector<int> &v) {
cout << v.size() - 1 << '\n';
for (int c : v) cout << c << ' ';
cout << '\n';
}
int main() {
faststream();
int n;
ve... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, xl[N], xr[N], yl[N], yr[N], min_color[N << 2], max_color[N << 2];
bool seen[N], disappeared[N];
vector<int> x, y;
vector<pair<int, int>> event[N];
set<int> colors[N << 2];
void push_up(int o, bool leaf = false) {
while (colors[o].size() && d... | 25 |
#include <bits/stdc++.h>
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
int A[100010], B[100010];
bool wa[100010], wb[100010];
int fir[100010], dis[200010], nxt[2... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
vector<pair<int, int>> g[N];
long long a[N], dp[N], ans, n;
void dfs(int u, int p) {
dp[u] = a[u];
for (auto [v, w] : g[u]) {
if (v != p) {
dfs(v, u);
ans = max(ans, dp[u] + dp[v] - w);
dp[u] = max(dp[u], dp[v] + a[u] - w);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int c[50][50];
int main() {
int n, m, a, b, s = 25000, s1;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> c[i][j];
cin >> a >> b;
for (int h = 0; h <= n - a; h++)
for (int g = 0; g <= m - b; g++) {
s1 = 0;
for (in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int mult(int a, int b) { return a * (long long)b % mod; }
int bp(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) res = mult(res, a);
a = mul... | 26 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long mod = 1e9 + 7;
bool check_prime(int n);
bool check_palindrone(string b);
set<int> gen_factors(int a);
map<int, int> gen_pfactors(int a);
set<int> gen_primes(int a);
long long combination(int a, int b, long long mod);... | 7 |
#include <bits/stdc++.h>
using namespace std;
int M[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
int m, d, ans;
cin >> m >> d;
m--;
d--;
ans = 1;
while (M[m]) {
d++;
if (d == 7 && M[m] > 1) ans++;
d %= 7;
M[m]--;
}
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x;
long long y;
};
long long n, k, b;
point a[100009];
bool cmp(point a, point b) { return a.y > b.y; }
int main() {
cin >> n >> k;
cin >> b;
for (int i = 1; i <= n; i++) {
a[i].x = i;
cin >> a[i].y;
}
a[n].y = 0;
sort(a + 1, a + n... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, s[300005];
int em, e[300005 * 2], nx[300005 * 2], ls[300005];
void read(int &x) {
x = 0;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
void write(int... | 22 |
#include <bits/stdc++.h>
using namespace std;
char s[510][510];
int a, b, dpr[510][510], dpc[510][510], q, x_1, x_2, y_1, y_2, i, j;
long long ans;
int main() {
scanf("%d%d", &a, &b);
for (i = 0; i < a; i++) {
scanf("%s", s + i);
for (j = 1; j < b; j++) {
dpr[i][j] = dpr[i][j - 1];
if (s[i][j] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a[11000], n, T, Ans, Max_m, b[11000];
map<int, int> Map;
vector<int> A;
int main() {
int i, j, k;
cin >> n >> T;
for (i = 1; i <= n; ++i) {
cin >> a[i];
b[i] = a[i];
Map[a[i]]++;
}
sort(b + 1, b + n + 1);
for (i = n + 1; i <= min(T, n) * n;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, ans = 2000000000;
int gcd(int a, int b) {
if (b == 0 or a == 0) return 2000000000;
if (b == 1) return a - 1;
if (a == 1)
return b - 1;
else
return a / b + gcd(b, a % b);
}
int a, b;
int main() {
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, ans = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return f * ans;
}
const int MAXN = 10001;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0, ct = 0;
cin >> n;
char a[n];
int b[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == '.') b[i] = 0;
if (a[i] == 'L') b[i] = 1;
if (a[i] == 'R') b[i] = 2;
}
for (int i = 0; i < n; ++i) {
if (b[i] == 1) {... | 3 |
#include <bits/stdc++.h>
const int fin = 0, maxn = 100010;
int n, m;
struct rec {
int x, y;
} a[maxn], b[maxn];
inline int cmp(const rec &a, const rec &b) {
if (a.x == b.x)
return a.y < b.y;
else
return a.x < b.x;
}
int main() {
if (fin) {
freopen("t.in", "r", stdin);
freopen("t.out", "w", stdou... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, d1, d2, i;
int main() {
scanf("%d%d", &n, &m);
d1 = 1;
d2 = n;
for (i = 1; i <= m; i++) {
scanf("%d%d", &a, &b);
if (a > b) swap(a, b);
if (d1 >= b || d2 <= a) {
printf("0\n");
return 0;
}
d1 = max(d1, a);
d2 = min... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
for (int i = 2; i < (sqrt(n) + 1); i++)
if ((n % i == 0) && (n != i)) return 0;
return 1;
}
int main() {
int n, i = 0;
cin >> n;
while (1) {
if ((!isprime((n / 2) - i)) && (!isprime(n - ((n / 2) - i)))) {
cout << (n / 2) - i << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
inline T BigMod(T A, T B, T M = MOD) {
T ret = 1;
while (B) {
if (B & 1) ret = (ret * A) % M;
A = (A * A) % M;
B = B >> 1;
}
return ret;
}
template <typename T>
inline T EGCD(T a, T b, T &x, T &y) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string getStr() {
char ch[1000000];
scanf("%s", ch);
return ch;
}
const int MAX_N = 2e5 + 1;
int kl[MAX_N];
int res = 0;
int live[MAX_N];
int a[MAX_N];
int main() {
stack<int> st;
int n;
scan... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LLINF = numeric_limits<long long>::max();
const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();
struct pt {
long long x, y;
pt() = default;
pt(long long x, long long y) : x(x), y(y) {}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
double p[100010], f1[100010], f2[100010];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
f1[i] = p[i] * (f1[i - 1] + 1);
f2[i] = f2[i - 1] + p[i] * (2 * f1[i - 1] + 1);
}
printf("%lf\n", f2[n]);
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
struct piece {
int buy;
int cnt;
int sell;
int num;
};
piece a[maxn][maxn];
int sell[maxn][maxn];
bool operator<(const piece& a, const piece& b) { return a.buy > b.buy; }
int main() {
int n, m, k;
int i, j;
cin >> n >> m >> k;
string s;... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 1e9 + 7;
const int N = 4e5 + 7;
const int M = 5e6 + 7;
int vis[M], p[N];
signed main() {
int q, x, y;
scanf("%d", &q);
scanf("%d", &x);
int head = 0;
for (int i = 0; i <= x; i++) p[i] = i;
while (q--) {
scanf("%d", &y)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
int months[12];
for (int i = 0; i < 12; i++) cin >> months[i];
if (k == 0) {
cout << "0" << endl;
return 0;
}
sort(months, months + 12);
if (months[11] >= k) {
cout << "1" << endl;
return 0;
}
int count = 1, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct huochai {
int num;
int num1;
} a[30];
bool cmp(struct huochai a, struct huochai b) { return a.num1 > b.num1; }
int main() {
int n, m, i;
while (~scanf("%d%d", &n, &m)) {
for (i = 1; i <= m; i++) {
scanf("%d%d", &a[i].num, &a[i].num1);
}
sort... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isSubSequence(string str1, string str2, int m, int n);
int CEIL(int a, int b);
bool isPrime(int x);
int mod_exp(long long x, unsigned int y, int p);
int gcd(int a, int b);
vector<int> Divisors(int n);
int getMSB(int n);
void sayyes() { cout << "YES" << '\n'; }
void say... | 0 |
#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
return n * n;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a,... | 2 |
#include <bits/stdc++.h>
using namespace std;
char que(int x, int y) {
printf("1 %d %d\n", x, y);
fflush(stdout);
char s[4];
scanf("%s", s);
return s[0];
}
int get(int l, int r) {
if (r - l <= 1) return l;
int m = (l + r - 1) / 2;
if (que(m, m + 1) == 'T')
return get(l, m + 1);
else
return get... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline bool bit(int x, int b) { return (x >> b) & 1; }
string s[60];
int n, m;
double prob[1 << 21];
long long not_can[1 << 21];
int main() {
scanf("%d\n", &n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
m = s[0].size();
for (int i = 0; i < n; ++i) {
for... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long W(long long a[], long long n, long long C, long long l, long long r,
long long ql, long long qr) {
long long R = 0;
long long B = 10000000000;
for (long long i = n - 1; i >= 0; i--) {
if ((n % 2 == 0 && i > n / 2) || (n % 2 == 1 && i > n / 2)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int find(long long u, long long v) {
if (u > v) swap(u, v);
if (u == 0) return 0;
if (!find(u, v % u)) return 1;
long long d = v / u;
return !(d % (u + 1) % 2);
}
int main() {
long long tt, n, m;
cin >> tt;
while (tt--) {
scanf("%lld%lld", &n, &m);
p... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1 << 30;
const int MAX = 512;
const int MAX2 = 1 << 20;
const int ADD = 100000;
int n;
bool B[MAX][MAX][32];
bool R[MAX][32];
int A[MAX];
int Res[MAX];
int main() {
cin >> n;
for (int i = (0); i < (n); ++i)
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, f[N][N], s[N][N][N];
int main() {
scanf("%d%d", &n, &m);
for (int i = (int)(1); i <= (int)(n); i++) {
int x, l, r;
scanf("%d", &x);
for (int j = (int)(1); j <= (int)(x); j++) {
int l, r;
scanf("%d%d", &l, &r);
f... | 21 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
using Long = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using Vv = V<V<T>>;
using Vb = V<bool>;
using Vvb = V<Vb>;
using Vi = V<int>;
using Vvi = V<Vi>;
using Vl = V<Long>;
using Vvl = V<Vl>;
using Vd = V<doub... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.