solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
istream& operator>>(istream& o, pair<T, TT>& v) {
o >> v.first >> v.second;
return o;
}
template <typename T, typename TT>
ostream& operator<<(ostream& o, pair<T, TT>& v) {
o << "(" << v.first << "," << v.second << ")";
return o;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, i, x[100005], h[100005], vis[100005], ans = 0;
memset(vis, 0, sizeof(vis));
cin >> n;
for (i = 0; i < n; i++) cin >> x[i] >> h[i];
vis[0] = 1;
vis[n - 1] = 2;
for (i = 1; i < n - 1; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
int lazj[MAXN * 4], st[MAXN * 4], mk[MAXN * 4];
int a[MAXN], ans[MAXN];
void chang(int v, int u) {
if (st[v] != -1) {
st[u] = st[v];
mk[u] = mk[v];
lazj[u] = 0;
}
lazj[u] += lazj[v];
}
void add(int v, int l, int r, int f, int e,... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (a == 0) return b;
return gcd(b % a, a);
}
template <typename T>
void read(T &x) {
register T c = getchar();
x = 0;
int t = 0;
if (c == '-') t = 1, c = getchar();
for (; (c < 48 || c > 57); c = getchar())
;
for ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int32_t main() {
cin >> n >> k;
if (n > k * (k - 1)) return cout << "NO", 0;
cout << "YES\n";
long long cnt = n;
for (long long i = 2; i <= k; i++) {
for (long long j = 1, now = i; j <= k && cnt; j++, cnt--) {
cout << j << ' ' << now << '... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y);
long long int mpower(long long int x, long long int y, long long int p);
long long int modInv(long long int a, long long int m);
long long int gcdExtended(long long int a, long long int b, long long int *x,
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
int x[8], y[8], order[8];
int dist(int a, int b) {
return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);
}
bool isRect(int a, int b, int c, int d) {
if (x[b] - x[a] != x[c] - x[d] || y[b] - y[a] != y[c] - y[d]) return false;
if (dist(a... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100001], b[100001], c[100001], i;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n - 1; i++) cin >> b[i];
for (i = 0; i < n - 2; i++) cin >> c[i];
int sm_a = 0, sm_b = 0, sm_c = 0;
for (i = 0; i < n; i++) sm_a += a[i];
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int tinf = (int)1e9 + 7;
const long long inf = (long long)1e18 + 7;
int main() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
vector<pair<int, int>> gr1, ones;
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i + 1;
if (a[i].first ... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int MAX = 2e5 + 10;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-8;
const long double PI = acos(-1);
inline long long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
v[i] = a;
}
sort(v.begin(), v.end());
int x = v[k - 1];
if (v[k - 1] == v[k]) x = -1;
if (k == 0) {
if (v[k] == 1)
x = -1;
else... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[100][100];
void sortMat() {
long long temp[n * m];
long long k = 0;
for (long long i = 0; i < n; i++)
for (long long j = 0; j < m; j++) temp[k++] = a[i][j];
sort(temp, temp + k);
k = 0;
for (long long i = 0; i < n; i++)
for (l... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 * 2 + 10;
long long dp[N][2], n, a[N], s[N], ans = 0;
int32_t main() {
cin >> n;
for (long long i = (1); i <= (n); ++i) cin >> a[i];
for (long long i = (1); i <= (n - 1); ++i) s[i] = abs(a[i] - a[i + 1]);
for (long long i = (1); i <= (n - 1);... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, x[100100], v[100100], t[100100];
int second;
vector<pair<pair<int, int>, int> > V;
vector<pair<int, pair<int, int> > >... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline int _Int() {
int x;
scanf("%d", &x);
return x;
}
long long int bigMod(long long int A, long long int P, int M) {
long long int R = 1;
for (A %= M; P; P >>= 1) {
if (P & 1) R = (R * A) % M;
A = (A * A) % M;
}
return R;
}
long long int bigMul(long... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e9, MOD = 1e9 + 7;
long long modPlus(long long a, long long b) {
return (a % MOD + b % MOD) % MOD;
}
long long modMul(long long a, long long b) { return (a % MOD * b % MOD) % MOD; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
... | 13 |
#include <bits/stdc++.h>
int mapp[105] = {0};
char map[105][105];
int main() {
int i, j, n;
char ch;
scanf("%d%*c", &n);
for (i = 0; i < n; i++)
for (j = 0; j <= n; j++) {
scanf("%c", &map[i][j]);
if (map[i][j] == '.') mapp[i] = j + 1;
}
for (i = 0; i < n; i++)
if (!mapp[i]) break;
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool possible = false;
int x, t, a, b, da, db;
cin >> x >> t >> a >> b >> da >> db;
for (int i = 0; i < t && !possible; i++)
for (int j = 0; j < t && !possible; j++)
if ((a - i * da) == x || (b - j * db) == x ||
((a - i * da) + (b - ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int p[110];
int m;
priority_queue<int> q;
int main() {
int i, j, k;
int n;
int x;
bool sw;
long long ciel = 0, jori = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &m);
for (j = 0; j < m; j++) {
scanf("%d", &p[j]);
}
if (m & 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
int H, Q, Res;
long long L, R, X, Y;
vector<pair<long long, long long> > Union, Segs;
inline bool Cross(pair<long long, long long> &A,
const pair<long long, long long> &B) {
if (A.first < B.first) {
if (A.second > B.second) {
puts("Data not suf... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
vector<string> parse(string s, string c) {
int len = c.length(), p = -len, np;
vector<string> ans;
do {
np = s.find(c, p + len);
ans.push_back(s.substr(p + len, np - p - len));
p = np;
} while (p != ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, C[10], REZ, j, i, ok, x;
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> x;
ok = 1;
while (x > 0) {
C[x % 10] = 1;
x /= 10;
}
for (j = 0; j <= k; j++)
if (C[j] == 0) ok = 0;
if (ok == 1) REZ++;
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int N = 200005;
int n, a, b, k, tab[N], wyn, res, akt, i;
char t[N];
int main() {
scanf("%d %d %d %d", &n, &a, &b, &k);
scanf("%s", t);
for (i = 1; i <= n; i++) tab[i] = (t[i - 1] == '1');
tab[0] = 1;
tab[n + 1] = 1;
n += 2;
a... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[200001];
long long int pow1[200001];
long long int pow2[200001];
long long int extgcd(long long int a, long long int b, long long int& x,
long long int& y) {
long long int d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
double a[105];
double b[105];
double sum[105];
pair<double, double> dp[105][105];
double ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ans = max(ans, a[i]);
b[i] = (double)1 - a[i];
}
dp[0][0] = make_pair(0, 1);
for (in... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int row;
cin >> row;
bool check = false;
char ch[row][5];
for (int i = 0; i < row; i++)
for (int j = 0; j < 5; j++) cin >> ch[i][j];
for (int i = 0; i < row; i++)
if (ch[i][0] == 'O' && ch[i][1] == 'O') {
cout << "YES" << endl;
c... | 0 |
#include <bits/stdc++.h>
const int N = 1000000;
bool resolved[N];
std::vector<int> graph[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0, a, b; i < m; ++i) {
scanf("%d%d", &a, &b);
graph[a - 1].push_back(b - 1);
}
std::vector<int> candidates, result;
for (int i = 0; i < n; ++i) {
... | 22 |
#include <bits/stdc++.h>
#define sf(x) scanf("%d", &x)
#define lsf(x) scanf("%lld", &x)
#define pf(x) printf("%d\n", (x))
#define lpf(x) printf("%lld\n",(x))
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repp(i,x,y) for(int i=x;i<=y;i++)
#define mem(a,x) memset(a,x,sizeof(a))
#define min(a,b) (((a) < (b)) ? (... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a(1);
long long ans;
int main() {
scanf("%lld", &a[0]);
for (int i = 1; i <= a[0]; ++i) {
a.push_back(0);
scanf("%lld", &a[i]);
ans += a[i] * i;
}
printf("%lld", ans);
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2100000;
int ch[maxn][26], len[maxn], fail[maxn], tail, cnt;
int ind[maxn], vis[maxn], num[maxn];
void ins(int c) {
int t = tail;
tail = ++cnt;
len[cnt] = len[t] + 1;
while (t && !ch[t][c]) ch[t][c] = cnt, t = fail[t];
if (!t && !ch[t][c]) {
c... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, l = 0, s = 0;
string t;
cin >> n >> m >> k;
if (k == 1) {
for (int i = 0; i < n; i++) {
cin >> t;
for (int i = 0; i < m; i++)
if (t[i] == '.') s++;
}
} else {
string *a = new string[n];
for (int i = 0; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
bool is_prime(int x) {
bool f = x > 1;
for (int i = 2; i * i <= x; i++)
if (x % i == 0) f = 0;
return f;
}
long long solve(long long a[], long long l, long long k) {
if (is_prime(k)) {
long long ans = 0;
for (int i = l; i <= l + k - ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long a, long long b, long long c, long long a_n, long long b_n,
long long c_n) {
return abs(a - a_n) + abs(b - b_n) + abs(c - c_n);
}
void solve() {
int a, b, c;
long long mini = 1E15, An, Bn, Cn;
cin >> a >> b >> c;
for (int A = 1; A ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, c = 1, big = (long long int)1e15;
long long int ans = big;
cin >> n;
long long int v[n];
for (long long int i = 0; i < n; i++) cin >> v[i];
sort(v, v + n);
while (1) {
long long int val = 0, pw = 1;
for (long long int i = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char ans[N];
int n;
int nodes;
int subtree[N];
set<int> gr[N];
void dfs(int ch, int par) {
subtree[ch] = 1;
nodes++;
for (auto i : gr[ch]) {
if (i == par) continue;
dfs(i, ch);
subtree[ch] += subtree[i];
}
}
int centroid(int ch, in... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec1;
int s, t;
int temp;
for (int i = 0; i < n; i++) {
cin >> temp;
vec1.push_back(temp);
}
cin >> s >> t;
int sum1 = 0, sum2 = 0;
if (s == t) {
cout << 0;
} else {
for (int i = min(s, t); i < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[300005];
cin >> str;
int n = strlen(str);
for (int i = 0; i < n; i++) str[i + n] = str[i];
int ans = 1, t = 1;
for (int i = 1; i < 2 * n; i++) {
if (str[i] != str[i - 1])
t++;
else
ans = max(ans, t), t = 1;
}
ans = m... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void fileio(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const long long INF = 4e18;
inline long long read() {
long long x = 0;
bool flag = 1;
char c = getchar();
while (... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, K, q, a[1000005];
int fac[1000005], inv[1000005], invf[1000005];
int C(int a, int b) {
if (a < 0 || b < 0 || a - b < 0) return 0;
return fac[a] * 1ll * invf[b] % 1000000007 * invf[a - b] % 1000000007;
}
int cnt[1000005], ans;
int pr[1000005], cnt_pr, vis[1000005]... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 234;
const long long inf = 1ll << 60;
long long a[N], b[N], c[N], sa[N], sb[N], d[N][N][N], g[N][N][N];
int n, t, k;
int main() {
scanf("%d %d %d", &n, &t, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d %d %d", &a[i], &b[i], &c[i]);
}
++n;
a[n] = ... | 26 |
#include <bits/stdc++.h>
using namespace std;
int const xn = 1e6 + 5, mod = 1e9 + 7;
int q, r, n, dp[xn][20], mnp[xn];
int rd() {
int ret = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
ret = (ret << 3) + (ret <... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > Trans(const vector<vector<int> >& first,
const vector<vector<int> >& second, int n) {
vector<vector<int> > result(2 * n, vector<int>(2 * n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
result[i][... | 10 |
#include <bits/stdc++.h>
using namespace std;
double ti[11][100006] = {0};
int main() {
int n, t, sum = 1;
cin >> n >> t;
if (t < 1) {
cout << 0;
return 0;
}
ti[1][1] = t - 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
ti[i][j] = ((ti[i - 1][j] + ti[i - 1][j - 1]) / 2) -... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int dy[5] = {-1, 0, 1};
int N;
int ret(int col, int row, vector<string> &A, vector<vector<int>> &mem) {
if (col >= N) return 1;
int &ans = mem[row][col];
if (ans >= 0) return ans;
ans = 0;
auto bad = [&](pair<int, int> X) {
if (X.first < 0 || X.first >= ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int s = 150;
int main() {
string n;
int sum = 0;
cin >> n;
for (int i = 0; i < n.length(); i++) sum += (n[i] - '0');
if (sum >= (int(n[0] - '1') + (n.length() - 1) * 9))
cout << n << endl;
else {
int i;
for (i = 1; i < n.length(); i++) {
... | 5 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b)... | 11 |
#include <bits/stdc++.h>
long double vect(long double x0, long double y0, long double x1,
long double y1) {
return x0 * y1 - x1 * y0;
}
long double abs1(long double x) { return x < 0 ? -x : x; }
long double len(long double x0, long double y0, long double x1,
long double y1) {
return... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
bool isPrime(long long n) {
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
signed main() {
long long n, m;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[200005], query[1000005], memo[200005];
class node {
public:
vector<pair<long long int, pair<long long int, long long int> > > link;
};
node dp[600];
inline long long int readInt(void) {
bool minus = false;
long long int result = 0;
char ch;
ch =... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j, l, m, max, x, xi, xj, y;
int a[201], b[201], c[201];
while (scanf("%d%d", &n, &k) != EOF) {
c[0] = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
c[i] = c[i - 1] + a[i];
}
max = -1001;
for (i = 0; i < n; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int re_ad() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
int n, k, q;
int a[400010], b[40001... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int na, nb, ma, mb, i, x, y;
cin >> na >> nb;
string s1[na];
for (i = 0; i < na; i++) {
cin >> s1[i];
}
cin >> ma >> mb;
string s2[ma];
for (i = 0; i < ma; i++) {
cin >> s2[i];
}
long long int ans = 0, x1, y1, j, sum = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4010;
int N, M;
short board[MAXN][MAXN];
int bm[MAXN][MAXN];
int bv[MAXN][MAXN];
int bh[MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin >> N >> M;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) {
char c;
cin >> c;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 3 * 1e8 + 10;
int li[100005], ei[100005];
int main() {
int n, m, cl, ce, v, q, x1, y1, x2, y2, tim = INF;
scanf("%d%d%d%d%d", &n, &m, &cl, &ce, &v);
for (int i = 0; i < cl; i++) scanf("%d", &li[i]);
for (int i = 0; i < ce; i++) scanf("%d", &ei[i]);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > d;
vector<int> ans;
int n, p, k, i, used[101010];
bool cmp(pair<pair<int, int>, int> b1, pair<pair<int, int>, int> b2) {
return b1.first.second > b2.first.second ||
(b1.first.second == b2.first.second &&
b1.first.first... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt1 = 0;
int cnt2 = 0;
bool f = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] < 97) {
cnt1++;
}
}
if (cnt1 == s.length()) {
for (int i = 0; i < s.length(); i++) {
s[i] += 32;
}
cout <... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[10005];
int main() {
int i = 1, len, ans = 0;
scanf("%s", s + 1);
len = strlen(s + 1);
while (i <= len) {
if (s[i] == 'D') {
if (s[i + 1] == 'a' && s[i + 2] == 'n' && s[i + 3] == 'i' &&
s[i + 4] == 'l') {
ans++;
i += 5;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int f[100010];
int main() {
while (cin >> n) {
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
int ans = 1;
f[1] = a[1];
for (int i = 2; i <= n; ++i) {
int pos = lower_bound(f, f + ans, a[i]) - f;
if (a[i] >= f[pos])
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1000000007;
long long gcd(long long a, long long b) {
long long c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
string operator*(string a, unsigned long long b) {
string output = "";
while (b--) output += a;
retu... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double eps = 1e-7;
const int mod = 1000;
const double pi = acos(-1);
struct node {
int p, id;
node(int _p, int _id) : p(_p), id(_id) {}
bool operator<(const node &b) const { return p > b.p; }
};
int n;
int p[200005];
int a[200005];
in... | 6 |
#include <bits/stdc++.h>
int B[2000];
using namespace std;
int main() {
int n, k, i, j, ans, pos, min;
int A[2000];
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &A[i]);
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
if (A[j] - A[i] != (j - i) * k && A[i] + (j - i) * k > 0)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, sum;
sum = 1;
cin >> n >> c;
int t[n];
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < n - 1; i++) {
if ((t[i + 1] - t[i]) <= c) {
sum++;
} else
sum = 1;
}
cout << sum;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], p[200010];
void Init() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
p[n] = n;
for (int i = n - 1; i; --i) p[i] = a[i] == a[i + 1] ? p[i + 1] : i;
}
void Query() {
int i, l, r, x;
for (i = 1; i <= m; ++i) {
sc... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, z, i, j, n, m, k, s1, s2, s3, s4, s5, s6, mod, l, r, t, maxx,
minn, sx, so, sum, ans, puk, par, chi, sz, choc1, choc2, len, depth;
double u, v, w, x1, x2, x3, x4, z1, z2, z3, h, huh;
string s;
string q;
string p;
string sq[145];
long long aa[2045][2045];... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c;
cin >> r >> c;
char a[r + 2][c + 2];
for (int i = 0; i <= r + 1; i++) {
a[i][0] = 'D';
}
for (int i = 0; i <= c + 1; i++) {
a[0][i] = 'D';
}
for (int i = 0; i <= r + 1; i++) {
a[i][c + 1] = 'D';
}
for (int i = 0; i <= c... | 1 |
#include <bits/stdc++.h>
#define free dfkjgfdg
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
struct Event {
int x;
int y;
int type;
};
bool cmp(Event &a, Event &b) {
return (a.x < b.x);... | 23 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int N = 200005;
const int M = N * 2;
const int MAXN = M * 27;
const int CHAR_SET = 26;
template <class T>
bool read(T& x) {
char c;
while (!isdigit(c = getchar()) && c != '-' && c != EOF)
;
if (c == EOF) return false;
T flag = 1;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 200000 + 5;
int n, m, cnt, sol;
int viz[Nmax];
vector<int> v[Nmax];
int ans[100005][5];
bool dfs(int nod, int par) {
vector<int> cand;
cand.clear();
viz[nod] = ++cnt;
for (auto i : v[nod])
if (!viz[i]) {
if (dfs(i, nod) == 0) cand.push_bac... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long ans[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
vector<long long> v[m + 1];
long long a, b;
for (int i = 0; i < n; i++) {
cin >> a >> b;
v[a].push_back(b);
}
for (int i = 1; i <... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n;
scanf("%d", &n);
char a[1001][1001];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &a[i][j]);
}
}
char sq = 0, sq_tmp;
for (int i = 0; i < n; i++) {
sq_tmp = 0;
for (int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 5;
const long long inf = 1000ll * 1000 * 1000 * 1000 + 5;
long long dis[N];
int par[N];
vector<pair<long long, int> > adj[N];
set<pair<int, int> > s;
map<pair<int, int>, int> mp;
int main() {
int n, m, c = 0;
cin >> n >> m;
for (int i = 0; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long res = n;
for (long long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
n /= i;
res += n;
}
}
if (n > 1) {
++res;
}
cout << res << endl;
}
| 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
int randll(int iter = 2) {
int res = 0;
while (iter--) res <<= 15, res |= rand();
return res;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k = 0;
cin >> n;
vector<int> v1(n), v2(n);
for (int i = 0; i < n; i++) cin >> v1[i];
for (int i = 0; i < n; i++) cin >> v2[i];
for (int i = 0; i < n; i++) {
if (v1[k] == v2[i]) k++;
}
cout << n - k << endl;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
void fun() {
int n;
cin >> n;
map<int, list<int>> m;
int v1, v2;
for (int i = 0; i < n - 1; i++) {
cin >> v1 >> v2;
m[v1].push_back(v2);
m[v2].push_back(v1);
}
bool v[n + 1];
int V[n + 1];
for (int i = 0; i < n + 1; i++) {
v[i] = false;
... | 5 |
#include <bits/stdc++.h>
#pragma optimize("O2")
using namespace std;
const int inf = 1e7;
int n, m, k, xx1, xx2, yy1, yy2;
int a, b, c, d;
const int N = 1004;
int dp[N][N][4];
bool vis[N][N][4];
char s[N][N];
bool safe(int r, int c) {
return (r >= 0 && c >= 0 && r < n && c < m && s[r][c] == '.');
}
struct Q {
int r... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], od[100005], ev[100005];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
if (x % 2)
od[++cnt1] = x;
else
ev[++cnt2... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxv = 2e5 + 5;
int b[maxv];
long long z;
bool cmp(int x, int y) { return x > y; }
int main() {
ios::sync_with_stdio(false);
int i, q = 0;
cin >> q;
while (q--) {
int n, a, t = 0;
cin >> n;
for (i = 1; i <= n; i++) b[i] = 0;
for (i = 1; i <... | 6 |
#include <bits/stdc++.h>
#pragma GCC target("popcnt")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while (T--) {
vector<std::pair<int, int> > A;
int ans = 0;
string s;
cin >> s;
int i = 0;
while (i < s.size()) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void read_file(bool b = 1) {}
int n, m;
vector<int> d, h;
int main() {
read_file(0);
while (cin >> n >> m) {
d.resize(m), h.resize(m);
for (int i = 0; i < m; i++) {
cin >> d[i] >> h[i];
}
if (d[0] != 1) {
int x = h[0] + d[0] - 1;
d.inse... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
tuple<ll, ll> t45(ll x, ll y) { return {x + y, x - y}; }
ll nsec(ll x, ll y, ll k) {
if (x > y) swap(x, y);
return int(floor(double(y) / k) - floor(double(x + k - 1) / k) + 1.2);
}
ll a, b, x[2], y[2];
int main() {
ios_base::sync_with_stdio(0);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long A, B, ans, X;
bool chk[1010101];
int main() {
scanf("%I64d %I64d", &A, &B);
for (ans = 0; A + B >= ans * (ans + 1) / 2; ans++)
;
ans--;
for (int i = ans; i > 0 && A > 0; i--) {
if (i <= A) A -= i, chk[i] = true, X++;
}
printf("%I64d\n", X);
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int T1, T2, X1, X2, T0;
int main(void) {
cin >> T1 >> T2 >> X1 >> X2 >> T0;
long long int SolX = 0LL, SolY = 0LL;
for (long long int i = 0LL; i <= X2; i++) {
long long int L = 0LL, R = X1;
if (!i) L = 1LL;
while (L < R) {
long long int M = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n, q, t, k, d, ans, num, A[maxn + 1];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> q;
while (q--) {
cin >> t >> k >> d;
ans = num = 0;
for (int i = 1; i <= n; i++)
if (A[i] <= t) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool horses(int x1, int y1, int x2, int y2) {
return ((abs(x1 - x2) == 1 && abs(y1 - y2) == 2) ||
(abs(x1 - x2) == 2 && abs(y1 - y2) == 1));
}
bool horse_and_ladia(int x1, int y1, int x2, int y2) {
return (horses(x1, y1, x2, y2) || (x1 == x2 || y1 == y2));
}
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
const int MAXN = 270000;
int M, T[MAXN];
int gm(int l, int r) {
int ans = 0;
for (l = l + M - 1, r = r + M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
if (~l & 1) ans = max(... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353, MX = 2e5 + 2;
long long p = 0, q = 1, m;
void add(long long a, long long b) {
assert((4 * m) % b == 0);
a *= (4 * m) / b;
p = (p + a) % MOD;
}
inline int lsb(int i) { return i & -i; }
struct BIT {
int n, tree[MX];
BIT(int _n) {
n = _... | 15 |
#include <bits/stdc++.h>
using namespace std;
void nikal_pehli_fursat_mai() {
int n;
cin >> n;
n *= 4;
map<int, int> mp;
vector<long long> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
mp[v[i]]++;
}
sort(v.begin(), v.end());
for (auto it : mp) {
if (it.second % 2) {
cout << "NO"
... | 4 |
#include <bits/stdc++.h>
using ll = long long;
const int N = 1010;
const ll MAX = (ll)1e18;
int n;
int rand(int n) { return rand() % n; }
ll ask(int id, ll pos) {
printf("? %d %lld\n", id + 1, pos);
fflush(stdout);
ll ret;
scanf("%lld", &ret);
return ret;
}
ll left[N], right[N];
void solve(std::vector<int> ve... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
pair<long long, long long> vet[7009];
map<long long, long long> freq;
for (long long i = 0; i < n; i++) {
cin >> vet[i].first;
freq[vet[i].first]++;
}
for (long long i = 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
void read(vector<int> &a, int n) {
for (int i = 0; i < n; i++) cin >> a[i];
}
void read(vector<long long> &a, int n) {
for (int i = 0; i < n; i++) cin >> a[i];
}
const int MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (long long)1e18;
const long do... | 11 |
#include <bits/stdc++.h>
using namespace std;
char nc() {
static char buf[1 << 25], *p = buf, *q = buf;
if (p == q && (q = (p = buf) + fread(buf, 1, 1 << 25, stdin), p == q))
return EOF;
return *p++;
}
template <class T>
void rd(T& x) {
short f = 1;
x = 0;
char ch = getchar();
while (!isdigit(ch)) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, p, L[20005], R[20005], cnt = 0;
vector<pair<int, int> > a[20005];
struct Dp {
int f[4005];
} dp[4005 << 1];
void operator+=(Dp &a, const pair<int, int> &x) {
for (int i = 4005 - 1; i >= x.first; i--)
a.f[i] = max(a.f[i], a.f[i - x.first] + x.second);
}
int ma... | 19 |
#include <bits/stdc++.h>
int main() {
puts("1");
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
queue<string> q;
q.push(s);
set<string> ans_set;
ans_set.insert(s);
while (!q.empty()) {
string v = q.front();
q.pop();
if ((int)ans_set.size() == k) break;
for (int i = 0; i < (int)... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
long long a[60], b[60];
long long mina = 0, minb = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (i == 0 || a[i] < mina) {
mina = a[i];
}
}
for (int i... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long l = 0, r = 2e9;
while (l + 1 < r) {
long long m = (l + r) / 2;
if (6 * m * (m + 1) / 2 <= n)
l = m;
else
r = m;
}
if (6 * r * (r... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int h[2000050], nxt[2000050], v[2000050], w[2000050], s, tt, dep[200005], ec, m,
n, a, b;
int x[1000], y[1000], ct, tx[4] = {1, 0, -1, 0}, ty[4] = {0, -1, 0, 1};
long long t[1000], d[1010][1010];
char st[30][30];
void add(int a, int b, int c) ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int dp[1000005][25];
int p[1000005];
int sum(long long a, long long b) {
long long ans = (a + b);
if (ans > 1000000007) ans %= 1000000007;
return int(ans);
}
int mul(long long a, long long b) {
long long ans = (a * b);
if (ans > 1000000007) ans %= 1000000007;
re... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> U;
int n;
UnionFind() {}
void init(int n) {
U = vector<int>(n, -1);
this->n = n;
}
int root(int x) {
if (U[x] < 0) return x;
return U[x] = root(U[x]);
}
int link(int x, int y) {
int p, q;
p = root(x);
... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.