solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
int inf = 2e9;
map<int, int> ma;
bool flag = false;
void calc(long long n) {
long long del = 0;
string ans = "";
for (int i = 0; i < 63; i++) {
ans.push_back('0' + n % 2);
n /= 2;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p;
int *computeLPSArray(string &pat, int M) {
int len = 0, i;
int *lps = (int *)malloc(M * sizeof(int));
lps[0] = 0;
i = 1;
while (i < M) {
if (pat[i] == pat[len]) {
len++;
lps[i] = len;
i++;
} else {
if (len != 0) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, cur = 1;
cin >> n;
vector<vector<int>> d(n, vector<int>(3));
for (int i = 0; i < n; ++i) cin >> d[i][0];
for (int i = 0; i < n; ++i) cin >> d[i][1];
for (int i = 0; i <... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k;
int a[N];
bool cmp(int x, int y) {
if (x % 10 > y % 10) return 1;
return 0;
}
void answer() {
long long x = 0;
for (int i = 0; i < n; i++) {
x += a[i] / 10;
}
cout << x << endl;
}
int main() {
cin >> n >> k;
for (int i = ... | 6 |
#include <bits/stdc++.h>
inline long long gi() {
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 x * f;
}
long long A[1000010], B[1000010];
bool yes[1000010];
int _i[1000010... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int get(int x) {
if (k & 1) {
if (x < 4) return (x & 1);
if (x == 4) return 2;
if (x & 1) return 0;
int k = get(x / 2);
if (k == 1)
return 2;
else
return 1;
} else {
if (x <= 2)
return x;
else
return 1 ^ ... | 14 |
#include <bits/stdc++.h>
using namespace std;
class Solver {
public:
void test() {
{ this->solve(); }
}
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
if (n == 1) {
if (s[0] == '0') {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
... | 4 |
#include <bits/stdc++.h>
int N, p;
int a[1000], b[1000], d[1000];
int tank[1000], tap[1000], dim[1000];
int t;
void check_fwd(int check, int cur_min) {
if (!a[check - 1]) {
tap[t] = check;
dim[t] = cur_min;
return;
}
check_fwd(a[check - 1], d[check - 1] < cur_min ? d[check - 1] : cur_min);
}
int main(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N;
string S[100005];
int c[100005], lastSeen[10], nextOccur[10][100005];
long long amt[10][100005], ans[100005];
long long powMod(long long a, long long b) {
if (b == 0) return 1;
long long x = powMod(a, b / 2);
long long ret = (x * x) % 1000000007;
if (b % 2 ==... | 13 |
#include<bits/stdc++.h>
using namespace std;
const int N=510;
int n,mod;
int fact[N],comb[N][N];
int dp[2][N*N],Dp[2][N*N];
int FF[N*N];
int ans;
int A(int x,int y){return 1ll*comb[x][y]*fact[y]%mod;}
int rmd(int x){
x>=mod&&(x-=mod);
x<=-mod&&(x+=mod);
return x;
}
void mol(int &x){
x>=mod&&(x-=mod);
x<=-mod&&(x+=... | 19 |
#include <bits/stdc++.h>
using namespace std;
int N = 3e5 + 7;
int n;
vector<int> lef, rig, cnt, dp;
void solve() {
cin >> n;
int all = 0;
cnt.assign(n + 1, 0);
lef.assign(n + 1, N);
rig.assign(n + 1, -1);
dp.assign(n + 1, 0);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (cnt[x] == 0) all... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> A, B;
long long c1[25], c2[25];
int n;
long long merge1(vector<int>& a, int lev) {
int n = a.size();
if (lev == 0) return 0;
long long cnt = 0;
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
cnt += merge1(b, l... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, h, firs[maxn], ans[maxn], dep[maxn], k, x, y;
int len[maxn], f[maxn], t[maxn], sta[maxn], tp;
struct edge {
int too, nex;
} g[maxn << 1];
vector<int> v[maxn];
void add(int x, int y) {
g[++h].nex = firs[x];
firs[x] = h;
g[h].too = y;
}... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;
const long long int LINF = 1e18;
const long long int MOD = 1e9 + 7;
using namespace std;
int n;
int dp[MAXN];
set<int> MP[MAXN];
int main() {
cin >> n;
int ans = INF;
for (int i = 2; i <= n; i++) {
int r = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T cross(complex<T> a, complex<T> b) {
return imag(a * conj(b));
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void setmin(T &a, T b) {... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long po(long long x, long long n) {
long long ans = 1;
while (n > 0) {
if (n & 1) ans = (ans * x);
x = (x * x);
n /= 2;
}
return ans;
}
void func() {
string s;
cin >> s;
long long n = s.length();
long long a... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
map<int, int> vv;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
while (tmp % 2 == 0) tmp /= 2;
while (tmp % 3 == 0) tmp /= 3;
vv[tmp]++;
}
if (vv.size() =... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[20][110];
int n, m, mx[20], mn[20], f[20][2];
int main() {
scanf("%d%d", &n, &m), f[n + 1][1] = 0x3f3f3f3f;
for (int i = 1; i <= n; i++) {
mx[i] = 0, mn[i] = m + 2;
scanf("%s", s[i] + 1);
for (int j = 1; j <= m + 2; j++)
if (s[i][j] == '1') mx[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline long long int gcd(long long int a, long long int b) {
long long int r;
while (b) {
r = a % b;
a = b;
b = r;
}
return a;
}
inline long long int lcm(long long int a, long long int b) {
return a / gcd(a, b) * b;
}
inline long long int fpow(long lon... | 3 |
#include <bits/stdc++.h>
int x[200010], s[200010];
int main() {
int Case;
scanf("%d", &Case);
for (int T = 1; T <= Case; T++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
for (int i = 1; i <= a; i++) scanf("%d", &x[i]);
std::sort(x + 1, x + a + 1);
for (int i = 1; i <= c - 1; i++) s[i] = s[i - ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long dp[40][40];
int n, k;
int main() {
cin >> n >> k;
for (int i = 0; i <= n; i++) {
dp[0][i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int z = 0; z < j; z++) {
dp[j][i] += dp[z][i - 1] * dp[j - z - 1][i - ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
pair<long long, long long> origin;
pair<long long, long long> operator-(pair<long long, long long> A,
pair<long long, long long> B) {
return pair<long long, long long>(A.first - B.firs... | 18 |
#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;
int a[n];
int sum = 0;
int e = 1, o = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
for (int i = 0; i < n; i++) {
if (a[i] % 2 != 0) {
... | 3 |
#include <bits/stdc++.h>
int min(int a, int b) {
if (a > b)
return b;
else
return a;
}
int main() {
char b[] = "ACTG";
int n;
scanf("%d", &n);
char s[n + 1];
scanf("%s", s);
int ans = -1;
for (int i = 0; i < n - 3; i++) {
int sum = 0;
for (int j = i, k = 0; j < i + 4; j++, k++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, a...);
}
const lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
long double pi = 3.1415926535897932384626433832795;
long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long _gcd(long long a, long long b, long long& x, long long& y) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
if (a > b) {
return a;
}
return b;
}
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
long long int min(long long int a, long long int b) {
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int _SZIE = (1 << 21) + 1;
char ibuf[_SZIE], *iS, *iT, c, stk[46];
int tot;
template <class I>
inline void read(I &_x) {
I fl = 1;
for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, _SZIE, stdin),
(iS == iT ? EOF : *iS++)... | 21 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
void solve() {
double w, h;
cin >> w >> h;
double a1, b1, a2, b2;
cin >> a1 >> b1 >> a2 >> b2;
double w1, h1;
cin >> w1 >> h1;
double ans = 0x3f3f3f3f;
double ans1;
if (a2 - a1 + w1 <= w + eps) {
ans1 = w1 - a1;
if (ans1 <=... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int m = 0, p;
for (int i = 0; i < n; i++) {
if (m < a[i]) {
m = a[i];
p = i;
}
}
bool der = true;
for (int i = p; i < n - 1 && der; i++) {
de... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, l, j, k, a[110000], b[110000], c[110000];
int main() {
cin >> n >> m >> k;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < m; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
reverse(a, a + n);
reverse(b, b + m);
for (i = 0; i < n; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[100008];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, ans = 0;
cin >> n;
long long int* arr = new long long int[n + 1];
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int i = 1; i <= n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j = 0, k = 0;
cin >> n;
long int arr[n], a, f[n], s[n];
bool flag1 = false, flag2 = false;
long long int first = 0, second = 0;
for (i = 0; i < n; i++) {
cin >> a;
if (i == n - 1) {
if (a > 0)
flag1 = true;
else... | 6 |
#include <bits/stdc++.h>
int main() {
long n, a[100111], i, max = 1, count = 1;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
if (i == 0) continue;
if (a[i] > a[i - 1]) {
count++;
if (max < count) max = count;
} else
count = 1;
}
printf("%ld", max);
return... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 500;
int n, d, h, idx[maxn];
vector<pair<int, int> > e;
list<int> cap;
int get() { return *(cap.begin()); }
int main(int argc, char *argv[]) {
cin >> n >> d >> h;
if (d > 2 * h) {
cout << -1 << endl;
return 0;
}
for (int i = 2; i <= n;... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
return x * f;
}
void print(long long x) {
if (x < 0) x = -x, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, l = 0, j = 0;
int a[10000] = {0};
int b[10000] = {0};
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
b[a[i]] = 1;
if (a[i] > j) j = a[i];
}
for (i = 1; i <= j; i++) {
if (b[i] == 1) l++;
}
cout << l << endl;
retur... | 0 |
#include <bits/stdc++.h>
int n, m;
int x[100010], y[100010], px[100010], py[100010], sx, sy;
int flag, f[2][2];
long long ans;
int abs(int c) {
if (c < 0) return -c;
return c;
}
int main() {
int i, j;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%d%d", x + i, y + i);
px[i] = x[i];
py[i] = y[... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n, m, a[MAX], vis[MAX], vis2[MAX];
vector<int> g[MAX], gt[MAX];
void dfs(int v) {
for (auto u : g[v])
if (!vis[u]) vis[u] = true, dfs(u);
}
void dfs2(int v) {
for (auto u : gt[v])
if (!vis2[u]) {
vis2[u] = true;
if (a[u] ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int first, long long int n) {
if (n == 0)
return 1;
else if (n % 2 == 0) {
long long int second = power(first, n / 2);
return second * second;
} else
return first * power(first, n - 1);
}
int strTOint(string s) {
strings... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0) ret += m;
return ret;
}
struct node {
bool esq, dir;
};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, x;
cin >> n;
long long r... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long get() {
long long x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const long long N = 1005, S = 1000, P = 1e9 +... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400000 + 100;
int G[N], G2[N], to2[N], ne2[N], ne[N], to[N], sz[N], fa[N], dp[N], tp[N],
das[N * 2], n, m, q;
int hc[N], xb, xb2, cnt, w[N], dfn[N], dft[N], clk;
int q1, q2, ans;
void modify(int o, int l, int r) {
if (l == r) {
das[o] = w[dft[l]];
... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 35, m1 = 1e9 + 51, m2 = 1e9 + 123;
int hash1[N], hash2[N], a[N], pos[N], val[N];
int n, u, v;
string t;
vector<int> G[N];
set<pair<int, int> > s[N];
void dfs(int u, int p) {
pos[u] = u;
for (int i = 0; i < G[u].size(); ++i) {
int v = G[u][i];
... | 16 |
#include <bits/stdc++.h>
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int n, k;
long long f[37][71];
std::vector<int> a[71], b[71]... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70500;
const int M = 11;
char a[N][M];
int n, m = 9;
struct Info {
int belong;
int val;
} xu[5000000];
int ans[N];
int cc;
int find(int x, int y, int z) {
int i;
int res = 0;
for (i = z; i >= y; i--) res = res * 10 + (a[x][i] - '0');
return res;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr.w... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, P;
scanf("%d%d", &N, &P);
for (int i = 0; i <= 1000100; i++) {
int t = N - P * i;
int cnt = 0;
while (t) {
cnt += t % 2;
t /= 2;
}
if (cnt <= i && i <= N - P * i) {
printf("%d\n", i);
return 0;
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int rec[4002];
vector<int> v[4002];
int main() {
int n, m, minm = 1000000, a, b;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &a, &b);
rec[a]++;
rec[b]++;
v[a].push_back(b);
v[b].push_back(a);
}
int p, q, c = 0;
for (in... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long d[N];
long long dis[N], s[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> d[i];
sort(d + 1, d + n + 1);
long long res = 0;
for (int i = 1; i <= n; i++) s[i] = s[i - 1] + d[i];
for (int... | 6 |
#include <bits/stdc++.h>
typedef struct Lnode {
int t;
int v;
struct Lnode *next;
} node;
node *record[101];
int flag[100001];
int height(int t, int n) {
int result = 0, i;
node *p;
p = record[n];
while (t - p->t > 0) {
result += p->t * p->v;
t -= p->t;
p = p->next;
}
result += p->v * t;
... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimization("O3")
using namespace std;
template <typename T>
inline void Cin(T& first) {
char c;
T sign = 1;
first = 0;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
if (c == '-') sign = -1;
for (; c >= '0' && c <= '9'; c = getchar()) first = first * 10 + c -... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n + 1], p[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
struct N {
int x, y, mx, my;
};
queue<N> q;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int n, m;
char s[3020][3020];
int v[3020][3020][2];
int sx, sy;
int main() {
scanf("%d %d", &n, &m);
memset(v, 0x3f, sizeof v);
int ans = 0;
for (int i = 0; i < n; i+... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200023;
long long int power(long long int a, long long int b) {
long long int ans = 1;
while (b) {
if (b & 1) ans = (ans * a);
b /= 2;
a = (a * a);
}
return ans;
}
bool mysort(const pair<long long int, long long int> &a,
const p... | 7 |
#include <bits/stdc++.h>
int N;
int K[] = {0, 2, 1, 3};
int main() {
scanf("%d", &N);
int n = N / 4;
if (N % 4 == 0) {
printf("YES\n");
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = 0; k < 4; k++) {
for (int x = 0; x < 4; x++) {
printf("%d... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 1e7 + 100;
const int mod = 998244353;
long long t, n, m, dp[maxn];
void solve() {
cin >> n >> m;
int sum = 1;
dp[1] = 1;
for (int i = 2; i <= n; i++) {
dp[i] = sum;
for (long long l = 2, r; l <= i; l = r + 1) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long MODUL = 1000000007;
const long long MAXINT = 1000000010;
const long long MAXLL = 1000000000000000000;
template <typename T>
inline T MIN(T lef, T ri) {
return (lef < ri ? lef : ri);
}
template <typename T>
inline T... | 8 |
#include <bits/stdc++.h>
using namespace std;
double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, OO = 1e9;
int freq[N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
cout << fixed << setprecision(0);
int n, m, x;
cin >> n;
m = n >> 1;
for (int i = 0; i < m; +... | 10 |
#include <bits/stdc++.h>
long long check(int a, int b, int c, int l) {
if (a + b + l <= c) {
return 1ll * (l + 1) * (l + 2) / 2;
}
l = c - a - b;
if (l < 0) {
return 0;
}
return 1ll * (l + 1) * (l + 2) / 2;
}
int main() {
int a, b, c, l;
scanf("%d %d %d %d", &a, &b, &c, &l);
long long ans = 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l = 0;
string s;
cin >> s;
int n = s.size();
for (int i = 1; i < n; i++) {
if (s[l] < s[i]) l = i;
}
for (int i = 0; i < n; i++) {
if (s[l] == s[i]) cout << s[i];
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4000 + 23;
int n, k, t[MAXN], d[MAXN], dp[MAXN][MAXN], ans;
int main() {
cin >> n >> k;
if (n == 0) return cout << 86400, 0;
for (int i = 0; i < n; i++) cin >> t[i] >> d[i];
t[n] = 86401;
for (int i = 0; i < n; i++) dp[0][i] = max(t[i], dp[0][i - ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int vc = (1000000000 + 100) * 2;
int n, m;
int mp[100100];
pair<pair<int, int>, pair<int, int> > costB[(1 << 9)];
pair<int, pair<int, int> > costR[(1 << 9)];
int main() {
for (int i = 0; i < (1 << 9); ++i) {
mp[i] = vc;
costB[i] = make_pair(make_pair(vc, vc)... | 13 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
vector<long long int> commDiv(long long int a, long long int b) {
int n = gcd(a, b);
vector<long long int> ans;
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
ans.push_back(n /... | 8 |
#include <bits/stdc++.h>
using namespace std;
int sum[64];
int dp[64];
int main() {
ios::sync_with_stdio(false);
int n, x;
vector<int> a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
reverse(a.begin(), a.end());
sum[0] = a[0];
for (int i = 1; i < n; i++) {
sum[i] = s... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long a, long long p) {
if (!p) return 1;
long long t = bigmod(a, p >> 1);
t = t * t % 998244353;
if (p & 1) t = t * a % 998244353;
return t;
}
int n, a[600001];
long long sum[600001];
long long range(int l, int r) { return sum[r] - sum[l - 1]... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
ll p;
struct node {
node *l, *r;
ll offset;
vector<ll> dips;
};
ll apply_func(node* v, ll m) {
int s = -1;
int e = (int)v->dips.size();
while (s + 1 < e) {
int mid = (s + e) / 2;
if (v->dips[mid] <= m) {
s = mid;
... | 25 |
#include <bits/stdc++.h>
using namespace std;
bool ispallim(string s, int i, int j) {
while (i <= j) {
if (s[i] == s[j])
i++, j--;
else
return false;
}
return true;
}
pair<long long int, long long int> func(string s, set<long long int> st[]) {
long long int strt = 0, end = s.size() + 1, n;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, ans[10005], cnt[10005], nxt;
map<string, int> id;
vector<int> edge[10005];
vector<string> name;
bool used[10005];
void solve(int s) {
memset(cnt, 0, sizeof(cnt));
memset(used, 0, sizeof(used));
for (int k = 0; k < edge[s].size(); k++) used[edge[s][k]] = 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
int ab(int x) { return x < 0 ? -x : x; }
int n, s[2000], p[2000], sx[2001], px[2001], a[2][2000000], c, cost, i, t;
void sw(int x) {
if (s[x] == p[x]) return;
int y = sx[p[x]];
while (sx[p[y]] < x) y++;
a[0][c] = y;
a[1][c++] = x;
swap(p[x], p[y]);
swap(px[p[x... | 15 |
#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
int main() {
int n;
int min_cap = 0, pass = 0;
int a, b;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a >> b;
min_cap = max(min_cap, pass + b - a);
pass += b - a;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int x[1000100], y[1000100];
int main() {
int n, k;
while (cin >> n >> k) {
memset(x, 0, sizeof(x)), memset(y, 0, sizeof(y));
int z = 1;
for (int K = (int)1; K < (int)k + 1; K++) {
if (z > n) break;
x[z++] = K, y[K]++;
if (z > n) break;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long k;
long long c[1010];
long long s[1010];
long long ncr[1000][1000];
void init() {
ncr[0][0] = 1;
for (long long i = 1; i < 1000; i++)
for (long long j = 0; j <= i; j++) {
ncr[i][j] = ncr[i - 1][j];
if (j > 0) ncr[i][j] = ((ncr[i][j] + ncr[i - 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T Min(T x, T y) {
return x < y ? x : y;
}
template <class T>
inline T Max(T x, T y) {
return x > y ? x : y;
}
inline long long read() {
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
getline(cin, s);
int size = s.length();
char maxChar = 'a';
for (int i = 0; i < size; ++i) {
if (s[i] > maxChar) {
maxChar = s[i];
}
}
int count = 0;
for (int i = 0; i < size; ++i)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char a[1000][1000];
bool visited[1000][1000] = {false};
vector<pair<int, int> > v;
void dfs(int row, int col) {
if (row < 0 || row >= n || col < 0 || col >= m || visited[row][col] ||
a[row][col] != '.')
return;
visited[row][col] = true;
v.push_b... | 8 |
#include <bits/stdc++.h>
using namespace std;
const char INPUT[] = "HelloWorld.inp";
const char OUTPUT[] = "HelloWorld.outp";
long long a1, b1, a2, b2;
void swap3(long long& a, long long& b) {
long long temp = a;
a = b;
b = temp;
}
void swap2(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
long long tryD... | 11 |
#include <bits/stdc++.h>
const int S = 1 << 21;
char ibuf[S], *iS, *iT, obuf[S], *oS = obuf, *oT = oS + S - 1;
struct Flusher_ {
~Flusher_() { (fwrite(obuf, 1, oS - obuf, stdout), oS = obuf, void()); }
} flusher_;
template <class T>
inline void read(T &x) {
x = 0;
register char c = (iS == iT ? (iT = (iS = ibuf) +... | 25 |
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
void cmax(T& x, const T& y) {
if (x < y) x = y;
}
template <class T>
void cmin(T& x, const T& y) {
if (x > y) x = y;
}
temp... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct event {
int x, y, t, ans;
} E[1451550];
struct point {
int x, y;
} P[100050];
int M1[362900], M2[362900], M3[362900], M4[362900], cnt[362900];
int X[100050], Y[100050], sx[100050], sy[100050], c[100050];
int a[10], b[10];
bool vis[10];
int n, Tx, Ty, m, tot;
bool... | 17 |
#include <bits/stdc++.h>
using namespace std;
int r[200009];
int n, arr[200009];
long long a, b, c, k;
long long cost[200009];
int nt[200009];
int main() {
cin >> n >> k >> b >> c;
b = min(b, 5 * c);
for (int i = 0; i < n; i++) scanf("%d", arr + i);
sort(arr, arr + n);
for (int i = 0; i < n; i++) r[i] = (arr[... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
int a[100001];
map<int, int> mp;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int i, j;
int n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
sort(a, a + n);
int xx = 0;
for... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
long long arr[maxn];
long long dp[maxn];
int main() {
long long a, b, c, d, e, f, g, h;
ios::sync_with_stdio(0);
while (cin >> a) {
long long ans = -1e16;
for (int i = 1; i <= a; i++) {
cin >> arr[i];
}
g = 0;
e = 1;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long t, s[N], ans, tmp[N];
int n, a[N];
void mergeSort(int a, int b, long long s[]) {
if (a >= b) {
return;
}
int m = (a + b) / 2;
mergeSort(a, m, s);
mergeSort(m + 1, b, s);
int l = a, pl = a, r = m + 1, pr = m + 1;
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100004];
int l[1004], r[1004];
int s[100004];
vector<int> v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
int mi = INT_MAX;
int ma = INT_MIN;
for (int i = 1; i <= int(n); i++) {
cin >> a[i];
if (a[i... | 13 |
#include <bits/stdc++.h>
using namespace std;
namespace Dinic {
const int INF = 1e9 + 1e8;
const int N = 2200;
const int M = 11000;
int fst[N], nxt[M], to[M];
int cap[M];
int dis[N], q[N], ptr[N];
int V, E;
void init() {
memset(fst, -1, sizeof fst);
V = E = 0;
}
inline int add_node() {
V++;
return V - 1;
}
inli... | 16 |
#include <bits/stdc++.h>
int main() {
int n, count[5], i, temp, counts = 0;
for (i = 0; i < 5; i++) {
count[i] = 0;
}
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &temp);
count[temp]++;
}
counts = counts + count[4];
if (count[3] >= count[1]) {
counts = counts + count[3] + (cou... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int n, t, s[N];
int solvel(int l, int r) {
int tt, st = t;
bool fl = 0, fr = 0;
while (!fl || fr) {
printf("? %d %d\n", l, r), fflush(stdout), scanf("%d", &tt);
if ((tt ^ t ^ r) & 1)
fr ^= 1;
else
fl ^= 1;
swap(t, tt);
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename L>
bool smax(T &x, L y) {
return x < y ? (x = y, true) : false;
}
template <typename T, typename L>
bool smin(T &x, L y) {
return y < x ? (x = y, true) : false;
}
void dfs1(long long v = 0, long long p = -1);
void dfs2(long long v = 0, lon... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, j, a, k, b[102], l;
int main() {
cin >> n;
while (n--) {
cin >> a;
if (a < 0) k++;
if (k == 3) k = 1, b[j++] = l, l = 0;
l++;
}
b[j++] = l;
cout << j << endl;
for (int i = 0; i < j; i++) cout << b[i] << " ";
}
| 2 |
#include<bits/stdc++.h>
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int TT;scanf("%d",&TT);for(int tt=1;tt<=TT;tt++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define perr(i,a,b) for(int i=a;i>b;i--)... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr... | 2 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
template <class T>
int sgn(T x) {
return (x > 0) - (x < 0);
}
template <typename T>
inline void read(vector<T>& v) {
for (T& i : v) cin >> i;
}
long long int euclid(long long int a, long long int b, long long in... | 10 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
int gcds;
scanf("%d", &arr[0]);
gcds = arr[0];
for (int i = 1; i < n; i++) {
scanf("%d", &arr[i]);
gcds = gcd(gcds, ... | 5 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
vector<int> memo;
int kk = -1;
int dfs(const int now, const int from, const vector<vector<int>>& edges) {
int a = 0;
int b = 0;
int c = 0;
for (auto e : edges[now]) {
if (e == from)
... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline int read(void) {
int ans = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) ans = ans * 10 + ch - '0', ch = getchar();
return ans;
}
const int N = 1e6 + 10;
int a[N];
map<int, int> mp;
int main(void) {
int n = read(), k = r... | 15 |
#include <bits/stdc++.h>
using namespace std;
int Q[100000 + 10];
vector<int> A;
bool comp(int x, int y) { return x > y; }
int main() {
int m, n;
while (cin >> m) {
for (int i = 0; i < m; i++) scanf("%d", &Q[i]);
cin >> n;
A.assign(n, 0);
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
sort(Q, Q... | 6 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
int bsr(int x) { return 31 - __builtin_clz(x); ... | 25 |
#include <bits/stdc++.h>
using namespace std;
char a[100005], b[100005];
int la, lb, p[100005], f[100005], g[100005];
int main() {
scanf("%s", a + 1);
la = strlen(a + 1);
scanf("%s", b + 1);
lb = strlen(b + 1);
for (int i = 2, j = 0; i <= lb; ++i) {
while (j && b[j + 1] != b[i]) j = p[j];
if (b[j + 1]... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct Position {
int p;
int cost;
} pos, pre, now;
int cnt[200005];
int cost[200005];
int n, m;
int x, y;
int k;
int path[200005];
vector<vector<int>> edge;
int s, e;
queue<Position> q;
int len;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i <= n + 1; i+... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.