solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 1; i < n; i++) v[i] += v[i - 1];
long long ma = 0, mi = 10e17;
for (int i = 0; i < n; i++) m... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n >= 0) {
cout << n;
return 0;
} else {
n = n * (-1);
if (n <= 10) {
n = 0;
cout << n;
return 0;
} else {
int a = n % 10, b = n % 100;
if (a == b) {
n = n / 10;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int check(int y) {
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
return 1;
} else
return 0;
}
int main() {
int y;
scanf("%d", &y);
int d = 0, is_leap = check(y);
while (1) {
d++;
if (check(y)) d++;
y++;
d %= 7;
if (d == 0 && is_... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f3f;
const double esp = 1e-8;
const int msz = 1000;
int dp[msz + 1][msz + 1];
char s1[msz + 1], s2[msz + 1];
int l1, l2;
int main() {
scanf("%s %s", s1, s2);
l1 = strlen(s1);
l2 = strlen(s2);
for (int i = 0; i <= l1; ++i) dp[i][0] = i;
for... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, a[55][55], tmp[55], c;
bool mark[55][55];
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
cin >> c;
a[i][j] = c;
if (!mark[i][c] && c != 0) {
++tmp[i];
mark[i][c] = 1;
}
}
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 11;
int n;
int mi[N], f[N];
int head[N], nex[N << 1], to[N << 1], wei[N << 1], size;
int id[N], dep[N], fa[N];
int U[N], V[N], X[N];
void add(int x, int y, int z) {
to[++size] = y;
nex[size] = head[x];
wei[size] = z;
head[x] = size;
}
void dfs(in... | 13 |
#include <bits/stdc++.h>
using namespace std;
int in() {
int n;
scanf("%d", &n);
return n;
}
long long Lin() {
long long n;
scanf("%lld", &n);
return n;
}
double Din() {
double n;
scanf("%lf", &n);
return n;
}
const long long inf = 1e17;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<int> a, b... | 3 |
#include <bits/stdc++.h>
using namespace std;
constexpr int kN = int(5E2 + 10);
string s, t;
int n, dp[kN][kN], m;
vector<int> v[26];
bool can(int pos) {
int npos = -1, lnxt, rnxt, l = 0, r = pos;
for (int i = 0; i <= pos; i++)
for (int j = pos; j <= m; j++) dp[i][j] = n;
dp[0][pos] = -1;
for (int i = 0; i ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int seed = 131;
const long long LLMAX = 2e18;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 5e3 + 10;
const int hmod1 = 0x48E2DCE7;
const int hmod2 = 0x60000005;
inline long long sqr(long long x) { return x * x; }
inline int sqr(int x) { return x ... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umax(T &x, T y) {
return (x < y) ? x = y, true : false;
}
template <class T>
bool umin(T &x, T y) {
return (x > y) ? x = y, true : false;
}
struct SAM {
struct state {
int fa, len;
vector<int> nxt;
};
vector<state> m;
vector<int> ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int dp[30005][500];
int gem[30005];
int d;
int f(int x, int y) {
if (dp[x][y] != -1) return dp[x][y];
int res = gem[x];
int step = y - 250 + d;
if (step - 1 > 0 && x + step - 1 <= 30000) {
res = max(res, gem[x] + f(x + step - 1, y - 1));
}
if (x + step <= 30... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, que, a[2005][2005], f[2005][2005], a1, a2, b1, b2, ans, nn, mm;
char ch[2005];
long long gets() {
long long v = 0;
char ch;
bool f = 0;
while (!isdigit(ch = getchar()))
if (ch == '-') f = 1;
v = ch - 48;
while (isdigit(ch = getchar())) v = (v... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2 * 1e3 + 20;
int dp[maxn][maxn];
int main() {
int n, k;
cin >> n >> k;
long long res = 0;
dp[0][1] = 1;
for (int i = 0; i <= k; i++) {
for (int j = 1; j <= n; j++) {
for (int l = j; l <= n; l += j) {
dp[... | 6 |
#include <bits/stdc++.h>
using namespace std;
double _eps = 1e-6;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
vector<int> adj[2000 + 100];
int arr[2000 + 100];
int f = 1;
void dfs(int root, vector<int> &v) {
vector<int> nv;
for (int x : adj[root]) {
dfs(x, nv);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
const double eps2 = 1e-7;
const int INF = 0x3f3f3f3f;
vector<int> v[300005], d[300005], val[300005];
long long ans[300005];
long long sub[300005];
int n;
void dfs(int a, int nowd, int pa) {
for (int i = 0; i < d[a].size(); i++) {
int k = min(... | 11 |
#include <bits/stdc++.h>
char str[500002], op[500001];
int left[500001], right[500001], corr[500001];
int stack[500000], sp;
int main(void) {
int i;
int n, m, p;
for (i = 0; i < 500001; i++) {
left[i] = i - 1;
right[i] = i + 1;
}
scanf("%d %d %d %s %s", &n, &m, &p, str + 1, op);
for (i = 1; i <= n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch = getchar();
long long x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct node... | 12 |
#include <bits/stdc++.h>
using namespace std;
int v[510][510], sol[510];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &v[i][j]);
for (int i = 1; i <= n; i++) {
int rez = 0, s = 0;
for (int j = 1; j <= m; j++) {
if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r, avg;
cin >> n >> r >> avg;
vector<pair<int, int> > v;
int a, b;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a >> b;
v.push_back(pair<int, int>(b, a));
sum += a;
}
sort(v.begin(), v.end());
long long req = 1ll ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 50010;
const int Maxs = 35;
int tot;
int n, P;
int F[Maxs][Maxs][Maxn];
int hIndex, hXor, hMod;
int toHash(int i0, int x0, int m0) {
int Ret = 0;
Ret = i0 * (P + 10) * 35 + x0 * (P + 10) + m0;
return Ret;
}
void getHash(int Hash) {
hIndex = Hash / (... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, cost[5], dp[4][1000][1 << 12];
char g[4][1001];
int who[4][4], col[1000];
int calc(int r, int c, int mask) {
if (r == 4) {
if (col[c] & ~mask) return 1e9;
return calc(0, c + 1, mask >> 4);
}
if (c == n) return 0;
int &ret = dp[r][c][mask];
if (ret !... | 14 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int n, k;
int a[200005], b[200005], c[200005];
int main() {
while (~scanf("%d", &n)) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) scanf("%d",... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6;
const int M = 4e3;
int a[N], b[N], k[N], r[N];
bool cmp(int x, int y) { return b[x] > b[y]; }
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long Inf = LONG_LONG_MAX;
const double long PI = 3.1415926535;
long long sqr(long long a) { return a * a; }
long long qb(long long a) { return a * a * a; }
long long max(long long a, long long b) {
if (a > b) return a;
return b;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int cu = 0, cg = 0;
string s;
cin >> s;
map<char, int> mp;
for (int i = 0; i < s.length(); i++) {
mp[s[i]]++;
}
for (auto i : mp) {
if (i.second > 1) {
cg++;
} else if (i... | 0 |
#include <bits/stdc++.h>
using namespace std;
void output(long long x) {
if (x < 0) putchar('-'), x = -x;
if (x == 0) {
putchar('0');
return;
}
int a[20], num = 0;
while (x) a[++num] = x % 10, x /= 10;
while (num > 0) putchar('0' + a[num--]);
}
inline long long myInt() {
char c = getchar();
whil... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000006;
const int mod = 1000000007;
long long dp[MaxN][2];
int num[MaxN];
int N;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) scanf("%d", num + i);
dp[1][0] = num[1] - 1;
dp[1][1] = num[2] - 1;
long long ans = dp[1][0];
for (int i... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int maxn = 1e5 + 3;
int n, m, k;
vector<int> adj[maxn];
void read() {
cin >> n >> m >> k;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
}
int depth[maxn], par[maxn];... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 111111;
int n, d;
long long x;
int a[NMAX];
int ag[NMAX];
int b[NMAX];
int bg[NMAX];
int c[NMAX];
int cg[NMAX];
long long getNextX() {
x = (x * 37 + 10007) % 1000000007;
return x;
}
void myswap(int &x, int &y) {
int tmp = x;
x = y;
y = tmp;
}
void... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000009;
const int Mod = 1e9 + 9;
int n, f[maxn], g[maxn];
int main() {
scanf("%d", &n);
f[0] = 0;
f[1] = 4;
for (int i = 2; i <= n / 2 - 2; i++) f[i] = (4 + 2 * f[i - 1]) % Mod;
g[n / 2] = 1;
for (int i = n / 2 - 1; i >= 1; i--)
g[i] = (3LL... | 18 |
#include <bits/stdc++.h>
using namespace std;
void func(void) {
freopen("input.c", "r", stdin);
freopen("output.c", "w", stdout);
}
struct trie {
trie *left, *right;
bool endMark;
trie() {
left = NULL;
right = NULL;
endMark = false;
}
} * root;
int f, A, yo, id;
vector<pair<int, string> > ans;
v... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f = ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
const int N = 300005;
int n, m, q, k;
int bh[N], bel[N... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
const int vx[4] = {1, -1, 0, 0};
const int vy[4] = {0, 0, 1, -1};
int n, m, a[N][N], s[N][N], id[N][N], cnt, ans[N * N / 100];
bool ry[N][N];
int area(int x1, int y1, int x2, int y2) {
return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long countDig(long long s) { return floor(log10(s) + 1); }
int main() {
long long num;
int luckyNums = 0;
string n;
cin >> num;
int digits = countDig(num);
n = to_string(num);
for (int i = 0; i < digits; i++) {
if (n[i] == '4' || n[i] == '7') luckyNum... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mark[1000016];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i, p, flag = 0, n;
string second;
cin >> n >> p >> second;
for (i = 0; i < second.size() - p; i++) {
if ((second[i] == '.' || second[i + p] == ... | 4 |
#include <bits/stdc++.h>
const int LEN = 2000100 * 3;
int r[LEN], sa[LEN];
int wa[LEN], wb[LEN], wv[LEN], ss[LEN];
int c0(int *r, int a, int b) {
return r[a] == r[b] && r[a + 1] == r[b + 1] && r[a + 2] == r[b + 2];
}
int c12(int k, int *r, int a, int b) {
if (k == 2) return r[a] < r[b] || r[a] == r[b] && c12(1, r, ... | 19 |
#include <bits/stdc++.h>
using namespace std;
unsigned long int min(unsigned long int a, unsigned long int b) {
if (a < b)
return a;
else
return b;
}
unsigned long int max(unsigned long int a, unsigned long int b) {
if (a > b)
return a;
else
return b;
}
unsigned long int func(unsigned long int a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
long long x, y, cost = 0, seg = 0;
string str;
cin >> n >> x >> y;
cin >> str;
for (int i = 0; i <= n - 1; i++) {
if (str[i] == '0' && (i == n - 1 || str[i + 1] == '1')) seg... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<string, int>> v;
for (int i = 0; i < n; i++) {
string a;
int b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end(), [](pair<string, int> a, pair<string, int> b) {
return a.second < b.second... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 666013;
const long long int mod2 = 1e9 + 9;
const long long int maxn = 1e6 + 5;
const long long int maxn1 = 1e7 + 1;
const int root = 1e5 + 5;
const long long inf = 1e18 + 18;
double pie4 = 3.1415926535;
long long int a[maxn], b[maxn];
int main() {... | 11 |
#include <bits/stdc++.h>
using namespace std;
int N, deg[100010], cnt[100010];
;
vector<int> g[100010];
bool v[100010];
bool ans = 1;
void dfs1(int nod, int p) {
int i;
for (i = 0; i < g[nod].size(); i++)
if (g[nod][i] != p) dfs1(g[nod][i], nod);
cnt[nod] = 0;
for (i = 0; i < g[nod].size(); i++) {
if (g... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int n, m;
bool used[MAXN];
pair<pair<int, int>, int> interval[MAXN];
bool cmp(const pair<pair<int, int>, int> &a,
const pair<pair<int, int>, int> &b) {
return a.first.first < b.first.first ||
(a.first.first == b.first.first && a.... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[5123456];
int main(int argc, char *argv[]) {
scanf("%d%d", &n, &m);
fgets(s, 5123456, stdin);
vector<time_t> lgs;
while (fgets(s, 5123456, stdin)) {
tm shijian;
shijian.tm_year = 2012 - 1900;
shijian.tm_mon = ((s[5] - '0') * 10 + s[5 + 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long answer = 0;
struct state {
int len, link;
map<char, int> next;
int c = 0;
int d = 0;
};
const int MAXLEN = 200005;
state st[MAXLEN * 2];
int sz, last;
void sa_init() {
sz = last = 0;
st[0].len = 0;
st[0].link = -1;
++sz;
}
void... | 16 |
#include <bits/stdc++.h>
int reverse(int c) {
int rev = 0;
for (int i = 0; i < 7; ++i) {
rev |= (c >> i) & 1;
rev <<= 1;
}
return rev;
}
int main() {
std::string text;
std::getline(std::cin, text);
int prev = 0;
for (int i = 0; i < text.size(); ++i) {
int c = reverse(text[i]);
if (prev -... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct pi {
double x, y;
} q[10];
int a[12];
double dis(int x, int y) {
return (q[x].x - q[y].x) * (q[x].x - q[y].x) +
(q[x].y - q[y].y) * (q[x].y - q[y].y);
}
double ver(int x, int y, int z) {
double k1 = q[x].x - q[y].x;
double k2 = q[x].y - q[y].y;
dou... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const long long MOD = 998244353;
const int INF = 0x3f3f3f3f;
long long read() {
long long x = 0, f = 1;
char ch;
do {
ch = getchar();
if (ch == '-') f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - 48;
ch = ... | 16 |
#include <bits/stdc++.h>
#pragma GCC omptimize("unroll-loops")
#pragma optimize("SEX_ON_THE_BEACH")
#pragma GCC optimize("no-stack-protector")
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
using ll = unsigned long long int;
using ull = unsigned long long int;
using dd = long double;
using ldd = long... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
char ch;
bool flag = false;
while (ch = getchar(), ch < '!')
;
if (ch == '-') ch = getchar(), flag = true;
while (x = 10 * x + ch - '0', ch = getchar(), ch > '!')
;
if (flag) x = -x;
}
inline int cat_max(const int &a, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y;
long long dp[3];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> x;
long long ans = 0;
for (int i = 0; i < n; i++) {
cin >> y;
dp[0] = max(dp[0] + y, 0ll);
dp[1] = max(dp[1] + x * y, dp[0]);
dp[2] = max(dp[2] + y, dp[... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
const int N = 500000;
int n, ans;
multiset<int> s0, sn, sp;
multiset<int>::iterator it;
struct pii {
int x, v;
pii() {}
pii(int a, int b) { x = a, v = b; }
bool operator<(const pii &a) const {
return (v == a.v) ? (x < a.x) : (v < a.v);
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int *a, *b;
a = new int[n];
b = new int[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (... | 0 |
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = (a - 1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
typedef long long int ll;
using namespace ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 200200;
void Fix(string& s) {
reverse(s.begin(), s.end());
s.resize(N, '0');
for (long long i = N - 1; i > 0; i--)
while (i < N - 1 && s[i] == '1' && s[i - 1] == '1')
s[i] = s[i - 1] = '0', s[i + 1] = '1', i++, i++;
reverse(s.begin(), s... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 10;
const double pi = acos(-1);
int n, m, k;
int r[N];
int a, b;
complex<double> A[N], B[N];
int c[N], p[N], ans[N];
void FFT(complex<double> A[], int n, int inv) {
for (int i = 0; i < n; ++i) {
if (i < r[i]) swap(A[i], A[r[i]]);
}
for (int mid... | 20 |
#include <bits/stdc++.h>
using namespace std;
int di[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const long long N = 1e5 + 5, MOD = 1e9 + 7, oo = 1e18;
int t, i, j, n, m, k, mex, mey, curx, cury;
string s;
map<char, int> mpx, mpy;
bool valid(int x, int y) { return (x >= 1 && x <= n && y >... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 2010;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int n;
vector<int> a;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
a.push_back(x);
}
if (n == 1 && a[0... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
if (a < b) a = b;
}
int read() {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch... | 26 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
double tick() {
static clock_t oldt;
clock_t newt = clock();
double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
oldt = newt;
return diff;
}
long long int powP(long long int a, long long int b) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
long long ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n * 2; i++) scanf("%d", &a[i]);
sort(a + 1, a + n * 2 + 1);
ans = 1ll * (a[n * 2] - a[n + 1]) * (a[n] - a[1]);
for (int i = 2; i <= n; i++)
ans = min(ans, 1ll * (a[n * 2] -... | 7 |
#include <bits/stdc++.h>
using namespace std;
double dp[202][202][402];
vector<pair<int, int> > tourList;
int n, l, k;
void solve(int tourId, int needToWin, int Bag) {
int bag = Bag - 200;
if (tourId == n) {
if (needToWin == 0 && bag >= 0) {
dp[tourId][needToWin][Bag] = 1.0;
} else {
dp[tourId][... | 10 |
#include <bits/stdc++.h>
using namespace std;
double prob[20][20];
double dp[(1 << 19)];
double pmove(int previous_bitmask, int must_die, int &n) {
int total_fishes = __builtin_popcount(previous_bitmask);
long long deno = ((total_fishes) * (total_fishes - 1)) / 2;
double move_prob = 0;
for (int fish = 0; fish <... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, p;
cin >> a >> b >> p;
string s;
cin >> s;
long long start = 0;
long long ans = -1;
long long end = s.length() - 1;
while (start <= end) {
long long mid = (start + end) / 2;
... | 5 |
#include <bits/stdc++.h>
struct node {
int x, y;
};
long long fac[200005], inv[200005], ans[2005];
int n, m, k;
node f[2005];
long long fp(long long x, int y) {
return (y % 2 ? x : 1ll) * (y / 2 ? fp(x * x % 1000000007, y / 2) : 1ll) %
1000000007;
}
void pre(int n) {
fac[0] = inv[0] = 1;
for (int i = 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
void sc(char &c) {
char temp[4];
scanf("%s", temp);
c = temp[0];
}
void debugvi(vector<int> arr, int n = (int)1e9) {
for (int i = 0; i < min(((int)(arr.size())), n); i++) printf("%d ", arr[i]);
printf("\n");
}
int testnum;
char temp[100005];
int m, n;
int freq[2][... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int n;
char s[maxn], p[maxn];
struct Suffix_Automaton {
int nxt[maxn * 2][26], fa[maxn * 2], l[maxn * 2];
int last, cnt;
int cntA[maxn * 2], A[maxn * 2];
long long num[maxn * 2];
Suffix_Automaton() { clear(); }
void clear() {
last... | 16 |
#include <bits/stdc++.h>
using namespace std;
void find(string A, string B, int n) {
int same0 = 0;
int same1 = 0;
int dif0 = 0;
int dif1 = 0;
if (A == B) {
cout << "0\n";
return;
}
for (int i = 0; i < n; i++) {
if (A[i] == B[i]) {
if (A[i] == '0') {
same0++;
} else {
... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
const double eps = 1E-9;
const double Exp = 2.718281828459045;
const double Pi = 3.1415926535897932;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int INF = 1000000000;
const int BS = 1000000007;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
set<long long> v;
char str[10];
const int M = 1000000000 + 7;
int main() {
int n;
scanf("%d", &n);
long long x;
long long m = -1;
const long long MX = 308983067;
long long u = MX, d = -1;
set<long long>::iterator it;
int c = 0;
for (int i = 0; i < n; ++i) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int a[n], b[n];
long long int sum = 0;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
su... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, M, ans;
int fr, to, cnt;
int fa[1000005], pp[1000005];
int out[1000005], sum[1000005], num[1000005];
int find(int x) {
if (fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
int main() {
int i, j;
scanf("%d %d", &N, &M);
for (i = 1; i <= N; i++) fa[i] = i;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 2e5 + 5;
template <class T>
inline void In(T &ret) {
char c;
ret = 0;
while ((c = getchar()) < '0' || c > '9')
;
while (c >= '0' && c <= '9') {
ret = ret * 10 + (c - '0'), c = getchar();
}
}
int add(int x, int y)... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int len;
long long sum;
long long lmax, rmax;
long long dmax;
friend node operator+(const node &a, const node &b) {
node ret;
ret.len = a.len + b.len;
ret.sum = a.sum + b.sum;
ret.lmax = max(a.lmax, a.sum + b.lmax);
ret.rmax = max... | 14 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
struct node {
long long v;
int id;
node(long long v = 0, long long id = 0) : v(v), id(id) {}
bool operator<(const node &b) const { return v < b.v; }
};
bool cmp(node a, node b) { return a.id < b.id; }
node p[20... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
using ll = long long;
struct Cmp {
int m, d[N], ds[N], dt[N], nd[N], nds[N], ndt[N];
void proc(int d[], int n, int nd[]) {
for (int i = 0; i < n; i++) nd[i] = n;
for (int i = n - 1; i >= 0; --i) {
if (i < n - 1) nd[i] = nd[i + 1];
... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long base = 31;
const long long maxn = 3e5 + 9;
const long long mod = 1e9 + 7;
long long n, A, B, i, a[maxn], sum;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> A >> B;
for (i = 1; i <= n; i++) {
cin >> a[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> arr[110];
int n;
int find(int x) {
for (int i = 0; i < n; i++)
if (arr[i].first == x) return i;
return -1;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &arr[i].first, &arr[i].second);
bool b = 0;
for (int i = 0; i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1... | 17 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > q;
set<pair<int, int> >::iterator it;
int x[200100], y[200100];
int i, j, n, m;
char s[5];
int main() {
scanf("%d%d", &n, &m);
x[0] = 0;
y[0] = 0;
x[m + 1] = 0;
y[m + 1] = 0;
q.insert(make_pair(0, m + 1));
q.insert(make_pair(n + 1, m + 1))... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int from;
int to;
double length;
Edge(int f, int t, double l) : from(f), to(t), length(l) {}
};
struct Node {
vector<int> out;
};
struct Graph {
vector<Node> nodes;
vector<Edge> edges;
Graph(int nr_nodes, int nr_edges) {
nodes.resize(nr_nod... | 14 |
#include <bits/stdc++.h>
using namespace std;
short n, m, k;
int main() {
scanf("%hd%hd%hd", &n, &m, &k);
(n <= m && n <= k ? puts("Yes") : puts("No"));
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string a[12] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
int main() {
string s;
cin >> s;
int n;
cin >> n;
int i;
for (i = 0; i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 20, M = 1e4 + 20;
const long long int OO = 1e15;
long long int n, m, l, s, t, adj[N][N], bestTS[N], bestST[N], U[M], V[M], W[M];
void solve() {
priority_queue<pair<long long int, long long int>,
vector<pair<long long int, long long int... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> k;
string s;
getline(cin, s);
vector<vector<string> > str;
for (int i = 0; i < k; ++i) {
vector<string> tmp;
getline(cin, s);
int u = s.find("void") + 4;
string t = "";
while (u < s.length()) {
if ((s[u] ==... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[N];
vector<int> vi;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, m, ans1 = 0, ans2 = 0;
cin >> n >> m;
for (;;) {
if (n >= 1 && m >= 1) {
n--;
m--;
ans1++;
} else if (n >= 2 && m == 0) {... | 0 |
#include <bits/stdc++.h>
const long long mod = 998244353;
using namespace std;
const long long N = 2005;
long long n, a[N], cnt[5005], suf[5005];
vector<long long> v;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
scanf("%d %d", &n, &m);
int i, j, k;
string passStrings[n];
for (i = 0; i < n; i++) {
cin >> passStrings[i];
}
int nearestOnes[n][3];
memset(nearestOnes, -1, sizeof(nearestOnes));
for (i = 0; i < n; i++) {
for (j = 0; j < m; j+... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long base = 1e9;
const double PI = acos(-1);
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 10;
void logic() {
long long v1, v2, v3, vm;
cin >> v1 >> v2 >> v3 >> vm;
for (long long i = v1; i <= 2 * v1; i++) {
f... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
static int N, K, deg[MAXN], vis[MAXN];
static vector<int> edge[MAXN];
int main() {
scanf("%d%d", &N, &K);
for (int i = 0, u, v; i < N - 1; i++) {
scanf("%d%d", &u, &v);
edge[u].push_back(v);
edge[v].push_back(u);
deg[u]++;
de... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, x, k, m;
vector<int> arr;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> x;
arr.push_back(x);
}
sort(arr.begin(), arr.end());
int64_t a, b;
a = m / (k + 1);
b = m % (k + 1);
cout << a * (k * arr[n - 1] + arr[n - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, a[N];
pair<int, int> b[N];
map<int, int> init_pos, fin_pos;
bool covered[N];
vector<vector<int> > seqs;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> b[i].first;
b... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
long long a[n + 1], b[n + 1], k, cnt = 0, sum = 0, res = 0;
bool vis[n + 1];
memset(vis, false, sizeof(vis));
for (long long i = 1; i <= n; ++i) cin >> a[i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 3e6 + 10, MOD = 1e9 + 7;
long long n, q, F[M], I[M];
long long A[M], B[M];
long long _pow(long long a, long long x = MOD - 2) {
long long ret = 1;
while (x) {
if (x & 1) ret = ret * a % MOD;
x /= 2;
a = a * a % MOD;
}
return ret;
}
in... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[110], b[110], res;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
}
res = -1;
for (int i = 1; i <= 100; i++) {
bool isOK = true;
for (int j = 0; j < m; j++) {
if ((a[j] / i) + (a[j] % i > 0) != b[j]) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, k;
cin >> m >> n >> k;
int a, b;
b = 1 + (k - 1) / (2 * n);
a = 1 + ((k - 1) % (2 * n)) / 2;
cout << b << " " << a << " ";
if (k % 2 == 0)
cout << "R";
else
cout << "L";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int s[1000006];
int c[1000006];
int e[1000006];
long long cost[100006];
vector<vector<long long>> O, E, A;
int N, L, M;
vector<vector<long long>> operator*(const vector<vector<long long>> &A,
const vector<ve... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[1010];
for (int i = 0; i < n; i++) {
cin >> s[i];
string ss;
cin >> ss;
s[i] += ss[1];
s[i] += ss[0];
cin >> ss;
}
int st[1111] = {};
bool used[1111] = {};
int res = 0;
for (int i = 0; i < n; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, N, K, M, tc;
int main() {
int ans = 0;
scanf("%d", &N);
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
int x = 0, y = 0;
for (int j = i; j < s.size(); j++) {
if (s[j] == 'U') y++;
if (s[j] == 'D') y--;
if (s[j] == 'L') x-... | 2 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int v = 0, f = 1;
char c = getchar();
while (c < 48 || 57 < c) {
if (c == '-') f = -1;
c = getchar();
}
while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
return v * f;
}
const int N = 301000;
int n, q;
char ch[N];
stru... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> graph[26];
map<char, long long int> charToint;
map<long long int, char> intTochar;
long long int cnt;
void find(string &a, string &b) {
long long int n = min(a.size(), b.size());
for (long long int i = 0; i < n; i++)
if (a[i] != b[i]) {
g... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.