solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, k;
bool checkSurvive(char f[], char s[], int pos, int flooded) {
if (pos < 0) {
return false;
}
if (flooded >= pos) {
return false;
}
if (pos > n - 1) {
return true;
}
if (f[pos] != '-') {
return false;
}
f[pos] = 'a';
bool jump = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, mod, m;
scanf("%d%d%d", &a, &b, &mod);
for (int i = 0; i <= a && i < mod; i++) {
m = (1000000000LL * i) % mod;
if ((m > 0) && (m + b < mod)) {
printf("1 %09d\n", i);
return 0;
}
}
cout << 2 << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long int GC(long long int a, long long int b) {
if (b == 0)
return a;
else
return GC(b, a % b);
}
long long int inv_gc(long long int a, long long int b) {
return a / GC(a, b) * b;
}
long long int Ceil(long long int a, long long int b) {
return a / b + (... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct A {
int i, j;
int x;
A() {}
A(int x, int i, int j) : x(x), i(i), j(j) {}
const bool operator<(const A &tmp) const { return this->x < tmp.x; }
const bool operator!=(const A &tmp) const { return this->x != tmp.x; }
} a[1010];
int mp[1010][1010];
int smaller... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
bool op = false;
char c = getchar();
while (!isdigit(c)) op |= (c == '-'), c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const long long N = 1e3 + 10;
long lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> A, RES;
map<long long int, set<long long int>> EDGES;
vector<long long int> E, P;
long long int SUM = 0;
long long int AA;
vector<long long int> STACK;
vector<long long int> SUMSTACK;
vector<long long int> STACKIDX;
vector<long long int> RETURN;
vector... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int arr[2 * 100000], l, r, n;
int main() {
cin >> n;
for (int i = (0), _b = (n - 1); i <= _b; i++) {
cin >> arr[i];
arr[n + i] = arr[i];
}
for (int i = (1), _b = (2 * n - 1); i <= _b; i++) {
if (arr[i] >= arr[i - 1])
r... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[30][30];
char st[110][110];
int in[30];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%s", st[i]);
memset(a, 0, sizeof(a));
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j) {
int l1 = strlen(st[i]);
int l2... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 262222, M = 19;
int n, K, mo, T, Fac[N], Inv[N], FInv[N], ans, a[M][N], c[M][N], cnt[N];
unsigned long long b[M][N];
int quick(int x, int y) {
int s = 1;
for (int i = 1; i <= y; i <<= 1, x = (long long)x * x % mo)
if (i & y) s = (long long)s * x % mo;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
int a[100003];
int sum[100003];
int sum2[100003];
int res = 0;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
res += a[i];
}
int cur = 0;
for (i = 1; i <= n; i++) {
cur -= a[i];
sum[i] = max(cur, sum[i - 1] + a[i]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
bool tab[910];
int res[40];
int main() {
int n, k;
int v;
cin >> n >> k;
for (int(i) = 0; (i) < (k); ++(i)) {
cin >> v;
tab[v] = 1;
res[i] = v;
}
int curr = 1;
for (int(i) = 0; (i) < (k); ++(i)) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, t, n, m, it, siz[5050], cur, res, it2;
char s0[5050];
string sb[5050];
struct trie {
int mp[30];
int f1, f2, len, fa;
} s[10050];
void build(int id, int dep, int l, int r) {
if (l == r) {
s[id].len += (siz[l] - dep + 2);
return;
}
int x[30], i... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int data;
int idx;
bool operator<(const node &n) const { return n.data > data; }
};
const int MAX = 310000;
struct node A[MAX];
priority_queue<struct node> pq;
int main(void) {
int n, k;
while (~scanf("%d %d", &n, &k)) {
for (int i = 1; i <= n; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 1;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tests, ind1, ind2;
cin >> tests;
string s, t, sorted;
char mn;
while (tests--) {
cin >> s >> t;
sorted = s;
sort(sorted.begin(), sorted.end()... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 105;
const int MAX_E = MAX_N * MAX_N * 2;
const int INF = 1 << 30;
int n, k, flow;
int e, head[MAX_N], from[MAX_E], to[MAX_E], c[MAX_E], w[MAX_E];
void add_edge(int u, int v, int cap, int cost) {
from[e] = head[u];
head[u] = e;
to[e] = v;
c[e] = ca... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<long long, long long> > a;
int main() {
scanf("%d", &n);
long long x, y;
for (int i = 0; i < n; i++) {
scanf("%I64d %I64d", &x, &y);
a.push_back(pair<long long, long long>(x, y));
}
sort(a.begin(), a.end());
for (int i = 0; i < n - 1; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct node {
int ch, l, r, sz, lb, rb, v;
bool operator<(const node& b) const {
if (sz == b.sz) return lb > b.lb;
return sz < b.sz;
}
};
node a[maxn];
priority_queue<node> q;
bool vis[maxn]... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Obj {
int money, size, id;
Obj(int m = 0, int s = 0, int i = 0) : money(m), size(s), id(i) {}
};
bool cmpSize(Obj a, Obj b) { return a.size < b.size; }
bool cmpMoney(Obj a, Obj b) { return a.money > b.money; }
vector<int> e[(100000 + 10)];
int _link[(100000 + 10)... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
map<vector<string>, int> m;
bool result;
int n;
void dfs(vector<string> v) {
if (m[v]) return;
m[v] = 1;
int x = v.size();
if (x == 1) result = true;
if (x > 1 && (v[x - 1][0] == v[x - 2][0] || v[x - 1][1] == v[x - 2][1])) {
vector<string> u ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7, N = 1e5 + 5;
long long n, m, a[N], b[N];
int main() {
scanf("%lld%lld", &n, &m);
if (n > m) swap(n, m);
a[1] = 2, a[2] = 4;
for (int i = 3; i <= n; i++) a[i] = (a[i - 1] + a[i - 2]) % Mod;
b[1] = a[n], b[2] = (b[1] + 2) % Mod;
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
long long a[n][m];
long long ck = 1;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < m; j++) {
cin >> a[i][j];
if ((i == 0 && (j == 0 || j == m - 1)) ||
(i == n - 1 && (j == 0 ||... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
int power(int a, int p) {
if (p == 0) return 1;
int ans = power(a, p / 2);
ans = (1LL * ans * ans) % M;
if (p % 2) ans = (1LL * a * ans) % M;
return ans;
}
const int N = 3e5 + 7;
int a[N], dp[N], ex[N];
int main() {
ios::sync_with_stdio(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int N;
char S[23][400005];
vector<int> zhi[23];
int vvv[23];
int dp[(1 << 20) + 3];
inline int countOne(const vector<int>& zhi, int x) {
auto iter1 = lower_bound(zhi.begin(), zhi.end(), x);
auto iter2 = upper_bound(zhi.begin(), zhi.end(), x);
int ret = iter2 - iter1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int NMax = 55;
int N, P;
int C[NMax];
int DP[NMax][NMax][NMax][NMax];
int Power[NMax], ans;
const int MOD = 1000000007;
void Add(int& x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
void Read() {
cin >> N >> P;
for (int i = 1; i <= N; i++) {
cin >> C[i];
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct Seg_tree {
int maxv, ori, lazy;
} tree[800005];
int dep[200005], nnum[200005], onum[200005], ttop[200005], f[200005],
siz[200005], son[200005];
struct Ques {
int p, t, num;
friend bool operator<(Ques a, Ques b) {
return dep[a.p] + a.t == dep[b.p] + b.t ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int n;
cin >> n;
vector<int> planks(n);
for (int j = 0; j < n; j++) {
int size;
cin >> size;
planks[j] = size;
}
sort(pl... | 0 |
#include <bits/stdc++.h>
using std::array;
using std::bitset;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::function;
using std::ios_base;
using std::list;
using std::map;
using std::max;
using std::min;
using std::multiset;
using std::next_permutation;
using std::pair;
using std::prior... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, s;
cin >> n;
s = (n + 1) / 2;
cout << s % 2 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int B = 317;
const int N = 4e3 + 7;
const long long mod = 998244353;
const int inf = 1e9 + 100;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) {
int x, y;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, nn, mm, x, y, r, a1, a2, p[1000000], q[1000000];
char s[1000000], t[1000000], ch;
int main() {
scanf("%s", s + 1);
scanf("%s", t + 1);
ch = 'a';
for (int i = (1); i <= (500000); i++) {
if (s[i] != ch) {
n++;
p[n] = x;
x = 0;
ch ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 321;
const int MOD = 1000 * 1000 * 1000 + 7;
int lps[MAXN], N, M, dp[MAXN], ps[MAXN], sp[MAXN];
bool good[MAXN];
char txt[MAXN], pat[MAXN];
void computeLPSArray();
void KMPSearch() {
M = strlen(pat);
N = strlen(txt);
computeLPSArray();
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename P, typename Q>
ostream& operator<<(ostream& os, const pair<P, Q>& p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename K, typename V>
ostream& operator<<(ostream& os, const map<K, V>& v) {
os << '[';
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 405;
int n, m, g[N][N], tag1, tag2, vis1[N], vis2[N];
vector<int> G[N], d[N], po, Le;
double Ans, P[N], Maxp[N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) g[i][j] = g[j][i] = N;
for (int i = 1, u, v; i ... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
using namespace std;
const long long maxn = 2e5 + 20;
const long long inf = (long long)2e9;
const long double pi = asin(1) * 2;
const long doub... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, out, rev;
getline(cin, s);
int i = 0;
int j = s.length() - 1;
while (j - i >= 3) {
if (s[i] == s[j]) {
out.push_back(s[i]);
i++;
j--;
} else if (s[i] == s[j - 1]) {
out.push_back(s[i]);
i++;
j -= 2... | 5 |
#include <bits/stdc++.h>
using namespace std;
set<long long> ss;
int main() {
int n;
cin >> n;
int k = 0;
long long x, y, a;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
x = n / i, y = x + x * (x - 1) / 2 * i;
ss.insert(y);
a = n / i, x = n / a;
y = x + x * (x - 1) / 2 * a;... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int s1[N], m1[N], r1[N];
struct Line {
int t;
long long a;
long long b;
bool operator<(const Line& x) const { return t < x.t; }
};
struct Node {
vector<Line> vec;
void init(int l, int r) {
vec.push_back({0, 0, 0});
for (int i = l; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
class dinic_flow {
public:
struct edge {
int to, rev, cap;
edge(int to = 0, int rev = 0, int cap = 0) : to(to), rev(rev), cap(cap) {}
};
vector<vector<edge> > g;
vector<vector<edge>::iterator> nowi;
vector<int> dist;
int nodes, src, dst;
queue<int> q;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, r, k;
cin >> n >> r >> k;
long long int a = n * k;
vector<pair<long long int, long long int>> ar(n);
for (int i = 0; i < n; i++) {
cin >> ar[i].second >> ar[i].first;
a -= ar[i].second;
}
sort(ar.begin(), ar.end());
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> x, v;
int idX(int val) { return (lower_bound(x.begin(), x.end(), val) - x.begin()); }
int idV(int val) { return (lower_bound(v.begin(), v.end(), val) - v.begin()); }
struct FenwickTree {
vector<long long> bit;
int n;
FenwickTree(int n) {
this->n ... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debugv(vector<vector<T>> v) {
for (auto x : v) {
for (auto y : x) {
cout << y << " ";
}
cout << "\n";
}
}
template <typename T>
T myMax(T x, T y) {
return (x > y) ? x : y;
}
long long maximum = numeric_limits<int>::max();
l... | 3 |
#include <bits/stdc++.h>
const int inf = 1 << 30;
int cnt[510][510], n, m;
struct Vector {
long long x, y;
Vector(long long _x = 0, long long _y = 0) {
x = _x;
y = _y;
}
inline friend Vector operator-(const Vector &u, const Vector &v) {
return Vector(u.x - v.x, u.y - v.y);
}
inline friend long l... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool check(char arr[200][200], int i, int j) {
bool d = 1;
if (arr[i][j] == '#' && arr[i - 1][j] == '#' && arr[i + 1][j] == '#' &&
arr[i][j + 1] == '#' && arr[i][j - 1] == '#') {
d = 0;
}
return d;
}
int main() {
char arr[200][200];
int x;
cin >> x;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, num;
long long g, r, p;
long long w[maxn], f[maxn];
struct SegmentTree {
int sum, ls, rs;
} empty;
vector<SegmentTree> tree;
int query(int k, long long l, long long r, long long x, long long y) {
if (x <= l && r <= y) return tree[k].... | 10 |
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std... | 9 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
int main() {
int T = read();
wh... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
struct Point {
int id;
int c;
double x, y;
Point(double x = 0, double y = 0, int c = 0, int id = 0)
: x(x), y(y), c(c), id(id) {}
};
const double EPS = 1e-8;
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Poin... | 9 |
#include <bits/stdc++.h>
double const PI = 4 * atan(1.0);
using namespace std;
int n, run;
vector<vector<int> > V;
int main() {
scanf("%d", &n);
for (run = 1;; run++)
if (run * (run + 1) / 2 > n) break;
V.resize(run + 2);
int m = run * (run - 1) / 2;
int chay = 0;
for (int i = 0; i < run; i++) {
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5, MOD = 1e9 + 7;
set<int> lower, upper, unknown;
int get_min(set<int> &s) { return s.empty() ? INF : *s.begin(); }
int get_max(set<int> &s) { return s.empty() ? -INF : *(--s.end()); }
void add(int price) {
if (price <= get_max(lower)) {
assert(l... | 6 |
#include <bits/stdc++.h>
const int MAXN = 110000;
const int INF = 1E9 + 233;
struct Node {
int c[2], fa;
int siz;
long long val, sum, ret;
Node() {}
Node(int k) {
c[0] = c[1] = fa = 0;
siz = 1;
sum = val = k;
ret = 0;
}
} tr[MAXN];
struct Splay {
int root;
void pushup(int x) {
tr[x].... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> mat(n, vector<int>(m, 0));
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i < n + 1; i++)
for (int j = 1; j < m + 1; j++) {
cin >> mat[i - 1][j - 1];
dp[i][j] =
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
long long cost[N][10], step[N][10], n;
int getMax(int x) {
int ret = 0;
while (x) {
ret = max(ret, int(x % 10));
x /= 10;
}
return ret;
}
void init() {
for (int i = 0; i < N; i++) {
int c = getMax(i);
for (int j = 0; j < 10; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 51123987LL;
const int ROWS = 2;
int pnext[1001][3];
int dp[ROWS][150][51][51];
int main() {
int n;
scanf("%d", &n);
char str[1001];
scanf("%s", str);
for (int c = 0; c < 3; ++c) pnext[n][c] = n;
for (int i = n - 1; i >= 0; --i) {
for (int c =... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 25, M = 300005;
int n, a[N][N];
long long f[M], g[N][M], d[N][M], dp[N][M];
map<long long, long long> mp;
string st;
inline int bp(int x) { return __builtin_popcount(x); }
void dfs(int p, int s, int x, long long m) {
if (s == n) {
long long w = 0;
fo... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long mpow(long long a, long long b) {
long long c = 1;
while (b) {
if (b & 1) c = c * a % 998244353;
a = a * a % 998244353;
b /= 2;
}
return c;
}
long long minv(long long a) { return mpow(a, 998244353 - 2); }
int n;
long long ans;
vector<int> g[5000... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[110], b[110], sco[10];
scanf("%d", &n);
memset(sco, 0, sizeof(sco));
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
sco[a[i]]++;
}
for (int i = 0; i < n; i++) {
scanf("%d", b + i);
sco[b[i]]--;
}
int sum1 = 0, sum2 = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long x[100005], y[100005];
int par[100005][30], lvl[100005];
long long cross(long long x1, long long y1, long long x2, long long y2,
long long x3, long long y3) {
long long x4 = x1 - x2;
long long x5 = x3 - x2;
long long y4 = y1 - y2;
long long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
long long int dp[MAXN][4];
long long int comb(int n, int k) {
if (k == n || k == 0) return 1;
if (k > n) return 0;
if (dp[n][k] > 0) return dp[n][k];
long long int ans = comb(n - 1, k - 1) + comb(n - 1, k);
return dp[n][k] = ans;
}
long l... | 6 |
#include <bits/stdc++.h>
using namespace std;
int b[500005], ans[500005];
struct Base {
int a[23], pos[23];
Base() {
for (int i = 0; i < 23; i++) a[i] = 0;
}
void up(int &a, int b) {
if (b > a) a = b;
}
void ins(int x, int r) {
for (int i = 22; ~i; i--)
if (x >> i & 1) {
if (a[i]) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long double ZERO = 1e-15;
const long double EPS = 1e-10;
const long long MAXN = 100500;
const long long INF9 = 2 * 1e9;
const long long INF = 4 * 1e18;
const long long L0 = 0;
const long double PI = acos(-1);
const long double sq2 = sqrt(2.0);
long long req(long long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a = "", aux;
for (int i = 1; i <= 1001; i++) {
stringstream ss;
ss << i;
ss >> aux;
a += aux;
}
int n;
cin >> n;
n--;
cout << a[n] << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, K, v[1000050], c[1000050], ans[1000050];
double Ans, ret;
int main() {
scanf("%d%d", &n, &K);
for (int i = 1; i <= n; ++i) {
scanf("%d", &v[i]);
v[i] *= 100;
}
for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
for (int i = n; i; --i) ans[i] = min(max... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, A[105];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
}
sort(A, A + n);
for (int i = 0; i < n; i++) {
cout << A[i] << " ";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
const int mod = 998244353;
int main() {
ios_base::sync_with_stdio(false);
long long int fact[N];
vector<pair<int, int> > seq;
map<int, long long int> freqA;
map<int, long long int> freqB;
map<pair<int, int>, long long int> freqSeq;
seq.cl... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXNN = 1E4 + 10;
int n, b, q;
pair<int, int> a[MAXNN];
int c[MAXNN][5];
const int MAXN = 22000, MAXM = 440000;
struct Dinic {
struct edge {
int x, y;
int c;
int f;
edge *next, *back;
edge(int x, int y, int c, edge* next)
: x(x), y(y)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool v = false, h = false;
for (auto &x : s) {
if (x == '0') {
if (v) {
cout << "3 4" << endl;
} else {
cout << "1 4" << endl;
}
v = !v;
} else {
if (h) {
cout << "4 3" <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long pow(long long a, long long b) {
long long ans = 1;
a %= mod;
while (b) {
if (b % 2) {
ans *= a;
ans %= mod;
}
b /= 2;
a *= a;
a %= mod;
}
return ans;
}
long long inv(long long a) { return pow(a, mo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1 << 21], ops[1 << 20];
int h, g;
int qq[24], qn;
int f(int id) {
int tmp = a[id];
a[id] = 0;
qn = 0;
qq[qn++] = id;
while (id * 2 < (1 << h) && a[id] < max(a[id << 1], a[(id << 1) | 1])) {
if (a[id << 1] > a[(id << 1) | 1]) {
swap(a[id << 1], a[id... | 8 |
#include <bits/stdc++.h>
long long XX, XY, YX, YY;
int bits[100005];
int n;
int readbit() {
char ch = getchar();
while (ch != '0' && ch != '1') ch = getchar();
return ch - '0';
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) bits[i] = readbit();
for (int i = 0; i < n; ++i) {
int x = readbit(... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, g[20][20], r, c, k, ans = 0, x, y;
bool chk(int a, int b, int c, int d) {
int cnt = 0;
for (int i = a; i <= a + c; i++) {
for (int j = b; j <= b + d; j++) {
cnt += g[i][j];
if (cnt >= k) return 1;
}
}
return 0;
}
int main() {
scanf("%d%d... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int inf = 1000000010;
const long long INF = 1000000000000001000LL;
const int mod = 1000000007;
const int MAXN = 300010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN], B[30];
void Main() {
memset(B, 0, sizeof(B))... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, N = 202, M = 1e9 + 7;
int nxt[N][2], dp[N][N][N][2];
int n;
string s;
int max_prifix(string t) {
for (int i = t.size(); i >= 1; i--)
if (s.substr(0, i) == t.substr(t.size() - i)) return i;
return 0;
}
void add(int &a, int b) {
a += b;
if... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long n, k;
cin >> n >> k;
vector<long> v;
long i, x;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
long long count = 0;
sort(v.begin(), v.end(), greater<long>());
for (i = 0; i < n; i++) {
if ((v... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1, INF = 1e9 + 1;
int arr[MAXN], tree[4 * MAXN];
void build(int v, int a, int b) {
if (b - a == 1) {
tree[v] = arr[a];
return;
}
build(v * 2, a, (a + b) / 2);
build(v * 2 + 1, (a + b) / 2, b);
tree[v] = min(tree[v * 2], tree[v * 2 + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
const long long INF = 1e12;
vector<long long> vec;
string X;
long long N, res, mx, ind, arr[MAX], beg[MAX], value[MAX], mark[MAX];
int main() {
ios_base::sync_with_stdio(false);
mx = -INF;
cin >> N;
for (int A = 1; A <= N; A++) {
cin >> X;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long T, a, n, p, h;
long long f(long long a, long long n, long long p) {
long long tmp = a * n / p;
if (!tmp) return max(a, p - a * n);
if (a * n % p < a * (p / a - 1)) --tmp;
return f(min(a - p % a, p % a), tmp, a);
}
int main() {
cin >> T;
while (T--) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class TT>
void read(register TT &x) {
x = 0;
register char ch = getchar();
register bool f = 0;
while (ch < 48 || 57 < ch) f |= ch == '-', ch = getchar();
while (47 < ch && ch < 58)
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
if (f) x = -x... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 200 * 1000 + 9;
const long long inf = 1e18;
const long long mod = 998244353;
void solve() {
long long n;
cin >> n;
long long x = sqrt(n);
long long mv = x - 1;
n = n - x;
long long y;
n % x == 0 ? y = n / x : y = (n / x) + 1;
mv = mv + y;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
struct ppp {
int k, l, r, v;
void mk(int _k, int _l, int _r, int _v) {
k = _k;
l = _l;
r = _r;
v = _v;
}
} a[1200000];
struct seg {
int ans, sign;
seg *lch, *rch;
seg() {
ans = sign = 0;
lch = 0;
rch = 0;
}
vo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int mod = 1e9 + 7;
long long fpow(long long x, long long p) {
if (!p) return 1;
long long sq = fpow(x, p ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[2005][2005];
int main() {
int n, k;
cin >> n >> k;
long long int s = 0;
dp[0][1] = 1;
for (int i = 0; i < k; i++) {
for (int j = 1; j <= n; j++) {
for (int p = j; p <= n; p += j) {
(dp[i + 1][p] += dp[i][j]) %= 1000000007;
... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define R(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int A[n];
if(n%2)
{
for(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long p, d;
unsigned long long num[20] = {0};
unsigned long long ten[20];
ten[0] = 1;
int i;
for (int w = 1; w <= 19; w++) {
num[w] = num[w - 1] * 10 + 9;
ten[w] = ten[w - 1] * 10;
}
while (cin >> p >> d) {
int a[20];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9, PI = acos(-1);
int n, k;
vector<int> a;
void solve() {
cin >> n >> k;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
int to = 1, ans = 0;
for (int i = 1; i < n; i++) {
if (a[i] != a[i - 1])
to++;
else
ans = max(a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int px[N], py[N];
vector<int> d[N], h[N];
int r, c, n, k;
int prv[N], nxt[N], f[N], la;
void push(int x) {
prv[x] = la;
nxt[la] = x;
la = x;
}
void delt(int x) {
prv[nxt[x]] = prv[x];
nxt[prv[x]] = nxt[x];
}
long long ans;
long long calc(int x)... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
pair<int, int> p[2000];
map<pair<int, int>, int> cnt;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf(" %d%d", &p[i].first, &p[i].second);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
int X = p[i].first + p[j].fir... | 5 |
#include <bits/stdc++.h>
long long int max(long long int a, long long int b) {
long long int m;
if (a < b) {
m = b;
} else
m = a;
return m;
}
int main() {
long long int x1, x2, y1, y2, i, j, k, m = 0;
scanf("%lld %lld", &x1, &y1);
scanf("%lld %lld", &x2, &y2);
i = abs(x2 - x1);
j = abs(y2 - y1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[102][102], mod = 1000000007, k;
long long int find(int n, int k) {
if (dp[n][k] != -1) return dp[n][k];
if (n == 0) return 1;
long long int sum = 0;
for (long long int i = 1; i < k + 1; i++) {
if (n - i >= 0) {
sum = (sum + find(n - i, k)) % mod;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1700;
int g[N][N], n, m, ng[N][N], bg[N][N];
int c[4][2] = {1, 0, 0, 1, -1, 0, 0, -1},
cc[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, -1, -1, 1, -1, -1, 1};
void xiao() {
int i, j, k;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (!g[... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long cost[100005][5], jaw[100005];
vector<int> hub[100005];
int ke[100005];
void dfs(int now, int par) {
for (int i = 0; i < hub[now].size(); i++) {
int cur = hub[now][i];
if (cur == par) continue;
ke[now] = cur;
dfs(cur, now);
}
}
int main() {
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
int n;
cin >> n;
int a[205];
for (int j = 1; j <= n; j++) cin >> a[j];
for (int j = 1; j <= n; j++) {
int t = a[j], total = 1;
while (t != j) {
total++;
t = a[... | 1 |
#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
void solve(... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
const int L = 20 + 5;
const int S = 2097152 + 5;
const int oo = 1000000000;
int n, p;
int f[N], g[N], v[S];
int z[N][L];
char s[N][L];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
p = strlen(s[1] + 1);
f... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e6 + 5;
char s[MAXN];
char Ma[MAXN * 2];
int Mp[MAXN * 2];
int dp[MAXN];
int len;
void Manacher(char s[]) {
int l = 0;
Ma[l++] = '$';
Ma[l++] = '#';
for (int i = 0; i < len; i++) {
Ma[l++] = s[i];
Ma[l++] = '#';
}
Ma[l] = 0;
int mx = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int c[n];
for (int i = 0; i < n; ++i) {
cin >> c[i];
}
for (int i = 0; i < n - 1; ++i) {
if (c[i] > 8) {
c[i + 1] += c[i] - 8;
c[i] = 8;
}
}
if (c[n - 1] > 8) {
c[n - 1] = 8;
}
int res = -... | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int _kReadBufferSize = 1 << 15;
char _readBuffer[_kReadBufferSize];
int _readPos;
int _readLength;
bool _ended = false;
inline void _loadBuffer() {
_readLength = static_cast<int>(
fread(_readBuffer, sizeof(char), _kReadBufferSize, stdin));
_re... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 5;
double dp[Maxn];
int First[Maxn], Next[Maxn * 2], to[Maxn * 2], cnt, WE[Maxn * 2], size[Maxn],
nmsl[Maxn];
inline void add(int z, int y, int w) {
Next[++cnt] = First[z];
First[z] = cnt;
to[cnt] = y;
WE[cnt] = w;
}
inline int R() {
cha... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long base, long long exponent, long long modulus) {
if (base == 0 && exponent == 0) return 0;
long long result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) result = (result * base) % modulus;
exponent = exponent >> 1;
base = (ba... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e9 + 1;
const double pi = 3.1415926535897932384626433832;
const long long M = 2e18 + 7;
long long bis(long long a[], long long l, long long r, long long x) {
while (l <= r) {
long long m = l + (r - l) / 2;
if (a[m] == x) return m;
if (a[... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 5;
const int N = 1e5 + 10;
const long long mod = 1e9 + 7;
const int Mx = 1e7;
const string t = "RGB";
void solve() {
int n;
cin >> n;
int tmp = n;
if (n % 4 == 0) {
cout << 0 << endl;
cout << n / 2 << " ";
for (int i = 1; i <... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.