solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
map<long long, int> mp;
map<pair<long long, long long>, int> ix;
map<pair<long long, long long>, int> iy;
map<pair<pair<long long, long long>, long long>, int> ico;
long long res = 0, a, b, x, vx, vy;
int n;
int main() {
ios_base::sync_with_stdio(0)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 600100;
const int M = 1000010;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
long long qpow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b /= 2;
}
return ans;
}
long l... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn][maxn], b[maxn][maxn], n, m;
int ra[maxn], ca[maxn], rb[maxn], cb[maxn];
int main() {
cin >> n >> m;
memset(ra, 0, sizeof(ra));
memset(ca, 0, sizeof(ca));
memset(rb, 0, sizeof(rb));
memset(cb, 0, sizeof(cb));
int flag = 1;
for ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e8 + 10;
const int inf = 0x7f7f7f7f;
const int inff = -1 * inf;
const int mod = 1e8;
const long double PI = 3.14159265358979323846;
int main() {
long long n;
while (cin >> n) {
int res = 0;
if (n >= 100) {
res += n / 100;
n %= 100;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
void check() {
long long int ans = 1;
for (int i = 1; i <= 32; i++) {
v.push_back(ans);
ans *= 2;
}
}
int main() {
long long int n;
scanf("%lld", &(n));
check();
int ck;
for (int i = 0; i < v.size(); i++) {
if (v[i] == n)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long a[n];
int i;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int count = 0;
long min = 2e9;
for (i = 0; i < n - 1; i++) {
if (a[i + 1] - a[i] < min) {
min = a[i + 1] - a[i];
count = 1;
} else if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[2005];
map<int, int> sh, sp, x;
int main() {
int i, j, k, n, m, p, a, t, flag = 0, ans = -1;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
;
sh[arr[i]]++;
sp[arr[i]]++;
}
for (i = 0; i < n; i++) {
x[arr[i]]++;
fla... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[5050][5050];
int last[5050][5050];
int a[5050];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
last[i][m + 1] = m + 1;
for (int j = m; j >= 1; j--)
if (s[i][j] == '0')
last[i][j] = j;
... | 8 |
/*
''''' ' ' '''' '''' '''' '''' '''' ''''
' ' ' ' ' ' ' ' ' '
' ' ' '''' '''' '''' '''' '''' ''''
' ' ' ' ' ' ' ' ' ' ' '
' '''' '''' '''' '''' '''' '''' ''''
*/
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <cstddef>
#include <vector>
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string str1, str2;
cin >> str1 >> str2;
int curr = 1;
bool flag = true;
for (int i = 0; i < n; i++) {
if (curr == 1) {
if (!(str1[i] == '1' || str1[i] == '2')) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> greedy_BM(int n, vector<int> &mt, const vector<vector<int>> &g){
vector<bool> used(n, false);
for(int v=0;v<n;++v) {
for(int to : g[v]) {
if(mt[to] == -1) {
mt[to] = v;
used[v] = true;
bre... | 20 |
#include <bits/stdc++.h>
using namespace std;
int a[60][60], ans[60];
long long rez;
int main() {
int n, x, y, k;
cin >> n;
k = n * (n - 1) / 2 - 1;
for (int i = 0; i < k; i++) {
cin >> x >> y;
a[max(x, y)][min(x, y)]++;
ans[x]++;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j < i; j++)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
unordered_set<string> ss;
queue<string> q;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
q.push(s);
ss.insert(s);
long long ans = 0;
while (ss.size() < k && !q.empty()) {
string s = q.front();
q.pop();
for (int i = 0; i < s.size(); i+... | 12 |
#include <bits/stdc++.h>
using namespace std;
string s[10];
int v[10];
int ten[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
int apply(string str, int *a, int m) {
int ret = 0;
for (int i = 0; i < m; i++) ret += (str[a[i]] - '0') * ten[i];
return ret;
}
int main(void) {
int a[10] = {0, 1, 2, 3, 4,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[9];
int orz(char c) {
if (c <= 'C') return 1 + (c == 'C');
return 3 + (c == 'T');
}
int pow_mod(long long di, int zhi) {
int ans = 1;
while (zhi) {
if (zhi & 1) ans = ans * di % 1000000007;
di = di * di % 1000000007;
zhi >>= 1;
}
return ans;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, a[500010], f[500010], res, p, q;
int main() {
ios::sync_with_stdio(0);
scanf("%d", &n);
for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &a[i]);
f[1] = 1;
for (int i = (2), _b = (n); i <= _b; i++) {
if (a[i] != a[i - 1])
f[i] = f[i - 1] + 1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> mul(vector<int> const& a, vector<int> const& b) {
vector<int> c;
size_t k = 0, z = 0;
while (k < a.size() && z < b.size()) {
if (a[k] < b[z]) {
c.push_back(a[k]);
k++;
} else {
c.push_back(b[z]);
z++;
}
}
while (k < ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e+5 + 5;
int a[N], p, n, tans[N], rem[N], prem[N];
bool isp(int x, int pr) {
for (int i = 0; i < p; i++) rem[i] = 0;
for (int i = 1; i <= n; i++) tans[i] = x + i - 1;
int g = n + 1;
for (int i = n; i >= 1; i--) {
int f = lower_bound(tans + 1, tans... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(false);
int t = 1;
while (t--) solve();
return 0;
}
int INF = 1000000000;
int d[101010];
int a[101010];
void solve() {
int n;
cin >> n;
if (n == 1) {
cout << 1 << endl;
return;
}
for (int i = 0; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct Fruit {
int height;
int mass;
Fruit(int height_ = 0, int mass_ = 0) : height(height_), mass(mass_) {}
bool operator<(const Fruit& a) const {
if (height != a.height)
return height < a.height;
else
return mass < a.mass;
}
};
int main() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[1016], b[1016];
int main() {
int N, ma = 0, mb = 0;
cin >> N;
for (int i = 0; i < N; i++) cin >> a[i];
for (int j = 0; j < N; j++) cin >> b[j];
for (int i = 0; i < N; i++) ma |= a[i];
for (int i = 0; i < N; i++) mb |= b[i];
cout << ma + mb;
return 0;
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 69;
const long double pi = 3.14159265358979323L;
const int N = 1e5 + 5;
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void unsyncIO() { cin.tie(0... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
int n;
cin >> n;
int aa[n], w = 0;
for (int i = 0; i <= n - 1; i++) cin >> aa[i], w += aa[i];
int x, y, sum = 0, q = 1;
cin >> x >> y;
for (int i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long f = 0;
long long searchmeth(long long p[], long long x, long long f, long long y) {
long long k = 0;
for (long long i = f; i < x; i++) {
if (y >= p[i] && y < p[i + 1]) {
f = i;
k = y - p[i] + 1;
break;
}
}
cout << f << " " << k <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e7;
bool comp[LIM];
vector<int> primes;
void init() {
for (int i = 2; i < LIM; i++) {
if (!comp[i])
for (long long j = (i * 1ll) * i; j < LIM; j += i) comp[j] = true;
}
}
bool is_prime(long long x) {
if (x < LIM) return !comp[x];
if (x % 2... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
inline int FIX(long long a) { return (a % Mod + Mod) % Mod; }
int n, k;
int main() {
scanf("%d %d", &n, &k);
string s;
cin >> s;
if (k <= n / 2) {
for (int i = 1; i < k; i++) {
printf("LEFT\n");
}
for (int i = 0; i < s.leng... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int i, j;
unordered_set<int> s;
vector<int> princess;
vector<int> vec;
for (i = 1; i <= n; i++) {
vec.push_back(i);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void UpdateMax(T& a, T b) {
if (a < b) a = b;
}
template <typename T>
void UpdateMin(T& a, T b) {
if (a > b) a = b;
}
template <typename T>
inline void read(T& x) {
x = 0;
char c = getchar();
int flag = 1;
while (!isdigit(c)) {
if (c ==... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
long long f[27] = {}, i, j, a, b, c = 0, n;
long long ans[27][27];
for (i = 0; i < 27; i++)
for (j = 0; j < 27; j++) ans[i][j] = 0;
cin >> s;
n = s.size();
f[s[0] - 'a']++;
for (i = 1; i < n; i++) {
for (j = 0; j < 27; j++) ans... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
if (n == 2 && x == 0) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
if (n == 1) {
cout << x << endl;
return 0;
}
int t = n;
int bitsn = 0, bitsx = 0;
while (t > 0) {
t /= 2;
bitsn++;
}
if... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(const T& v) {
cerr << v << ' ';
}
template <typename T1, typename... T2>
void print(const T1& first, const T2&... rest) {
print(first);
print(rest...);
}
long long BigMod(long long int a, long long int b, int M) {
long long remainder... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[105];
char t[105];
int n;
int cal(int l, int r) {
int res = 0;
int p1 = l;
int p2 = 1;
while (p1 <= r && p2 <= n) {
if (t[p1] == s[p2]) {
p1++;
p2++;
} else
p2++;
}
if (p1 == r + 1) return 1;
return 0;
}
int vis[2][30];
void te... | 14 |
#include <bits/stdc++.h>
const int MX = 300005;
using namespace std;
int n, k, d;
vector<pair<int, int> > v[MX];
int police[MX];
vector<int> ans;
int visit[MX];
int used[MX];
void bfs() {
deque<pair<int, int> > q;
for (int i = 1; i <= n; i++) {
if (police[i] == 1) {
q.push_back(make_pair(i, -1));
vi... | 13 |
#include <bits/stdc++.h>
const int MAX_N = 300000;
const long long MOD = 1000000007;
long long x[1 + MAX_N];
long long count[1 + MAX_N];
long long sum[1 + MAX_N];
long long ans[1 + MAX_N];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
std::sort(x + 1, x + n + 1);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
bool flag[100002];
int main() {
int n, m, l;
cin >> n >> m >> l;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] > l) {
flag[i] = true;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (flag[i]) {
if (!flag[i + 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
long long n, k;
cin >> n >> k;
long long q = k % 2;
long long r = k % (n - 2);
if (q == 0 && (k / 2) <= (n - 2)) {
cout << "YES" << endl;
for (int i = 0; i < 4; i++) {
long long rem = k /... | 8 |
#include <bits/stdc++.h>
using namespace std;
void quick_sort(int* array, int low, int high) {
if (low >= high) return;
int left = low;
int right = high;
int pivot = array[left];
while (right > left) {
while (right > left && array[right] >= pivot) right--;
array[left] = array[right];
while (right ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)3e5 + 5;
int A[MAX_N], dp[MAX_N], cnt = 0;
vector<int> G[MAX_N];
void dfs(int s) {
if (G[s].empty()) {
cnt++;
return;
}
if (A[s])
dp[s] = MAX_N;
else
dp[s] = G[s].size() - 1;
for (auto u : G[s]) {
dfs(u);
if (A[s])
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int TurnWhere(const pair<long long, long long>& p1,
const pair<long long, long long>& p2,
const pair<long long, long long>& p3) {
long long val = (p2.second - p1.second) * (p3.first - p2.first) -
(p2.first - p1.first) * (p3.se... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, q, nodes;
vector<vector<int>> adj, tree, sp;
vector<int> subsize, is_cent, par, close, idx2node, node2idx, lg{-1}, depth;
void init() {
adj.resize(n);
tree.resize(n);
subsize.resize(n);
is_cent.resize(n);
par.resize(n);
close.resize(n);
node2idx.resize(... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
string suffix(string s, long long k) {
long long l = s.length();
long long cnt = 0;
for (long long i = l - 1; i >= 0; i--) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'o' || s[i] == 'i' || s[i] == 'u')
cn... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[200002], res[200002];
vector<pair<int, int> > b;
int main() {
int m, tmp;
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d", &tmp);
b.push_back(make_pair(tmp, i));
}
sort(a, a + m);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
sort(a, a + n, greater<long long int>());
sort(b, b + n, greater<long long int>());
long long int scoreA = 0, scoreB = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 43;
int n;
bool G[N][N];
int maxc[N];
int ans;
int cur[N], opt[N];
int dfs(int u, int d) {
cur[d] = u;
for (int v = u + 1; v <= n; v++) {
if (d + maxc[v] <= ans) return false;
if (G[u][v]) {
int i;
for (i = 1; i < d; i++)
if (!G... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
long long r = 0;
for (int k = 0; k < n - 1; ++k) {
int t = 1;
while (k + 2 * t < n) t *= 2;
r += a[k];
a[k + t] += a[k];
cout << r << " ";
}
co... | 3 |
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int maxn = 3101;
vector<int> g[maxn];
int N, M;
int s1, t1, l1, s2, t2, l2;
int dis[maxn][maxn], vis[maxn];
void BFS(int st) {
queue<int> q;
for (int i = 1; i <= N; i++) dis[st][i] = INF, vis[i] = 0;
dis[st][st] = 0;
q.push(st);
w... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, a, ans;
set<long long> Set;
bool f1;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
set<long long>::iterator it = Set.find(a);
if (it != Set.end()) {
Set.erase(it);
Set.insert(i);
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<string> > lev;
vector<pair<string, int> > v;
int c;
void rec(int l) {
int t = c;
if (lev.size() <= l) lev.push_back(vector<string>());
lev[l].push_back(v[c++].first);
for (int i = 0; i < v[t].second; i++) rec(l + 1);
}
int main() {
ios_base::sync_wit... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
long long ctr1 = 0, ctr2 = 0, sum;
cin >> a >> b;
sum = 0;
for (int i = 1; sum <= a; i = i + 2) {
sum = sum + i;
ctr1++;
}
sum = 0;
for (int i = 2; sum <= b; i = i + 2) {
sum = sum + i;
ctr2++;
}
if (ctr1 > ct... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, inf = 1e9 + 10;
int a[maxn];
int main() {
ios_base::sync_with_stdio(false);
int n, t = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i]) {
if (t > 0 && a[i - 1] == 0) t++;
t++;
}
}
cout << t;
r... | 2 |
#include <bits/stdc++.h>
using namespace std;
char a[20];
int compare(char *s, int n, int len) {
char ch[20];
int cnt = 0;
while (n) {
if (n % 2 == 0)
ch[cnt++] = '0';
else
ch[cnt++] = '1';
n /= 2;
}
if (cnt < len)
return 1;
else {
for (int i = 0; i < len; i++) {
if (a[... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
map<int, vector<int> > numbers;
int main() {
ios::sync_with_stdio(0);
int n, m, t1, t2;
cin >> n >> m;
for (long long i = 0; i < m; ++i) {
cin >> t1 >> t2;
++cnt[t1], ++cnt[t2];
numbers[t1].push_back(t2);
numbers[t2].push_back(t1);... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, a[N], maxn, sign;
int main() {
cin >> n;
for (register int i = 1; i <= n; i++) cin >> a[i];
for (register int i = 1; i <= n; i++) {
if (a[i] > maxn) sign = i, maxn = a[i];
}
sort(a + 1, a + n + 1);
cout << sign << " " << a[n - 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
vector<int> lst[N], pos[N], adj[N];
int col[N];
struct DSU {
vector<int> p, sz;
vector<vector<int> > lst;
DSU(int n) {
p.resize(n + 1);
sz.resize(n + 1, 1);
lst.resize(n + 1);
for (int i = 1; i <= n; i++) {
p[i] = i;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int n;
int seq[N];
void solve() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &seq[i]);
seq[i]--;
}
int ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++) {
if (seq[i] == i)
ans1++;
else if (seq[seq[i]] == i)... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
int reqa = 0, reqb = 0;
int temp = n;
int ans = 1;
while (1) {
if ((temp >= a) && (reqa < 4)) {
temp = temp - a;
reqa++;
}
if ((temp >= b) && (reqb < 2)) {
temp = temp - b;
reqb++;... | 8 |
#include <bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int t; cin >> t;
while (t--) {
long long n; cin >> n;
vector<long long> h(n);
for (long long i = 0; i < n; ++i) {
cin >> h[i];
}
auto solve = [&]() {
for (int i = 1; i < n; ++i) {
h[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double dinf = inf;
const int N = 2e5 + 10;
const int M = 18 + 10;
const int mod = 998244353;
const double eps = 1e-10;
const double PI = acos(-1.0);
int n;
int a[N], b[N], c[N], nxt[N];
int vis[N]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int q[111111];
int a[111111];
int b[111111];
long long len[111111];
int dp[111111];
int query(long long x) {
int id = lower_bound(len + 1, len + n + 1, x) - len;
if (q[id] == 1) return a[id];
long long tp = len[id - 1];
long long w = x - tp;
long long z = w... | 8 |
#include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' &... | 25 |
#include <bits/stdc++.h>
using namespace std;
void Fast() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
Fast();
string str1, str2;
cin >> str1 >> str2;
if (str1.length() > str2.length())
cout << str1.length();
else if (str2.length() > str1.length())
cout << str2.length();
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char str[2011], res[2011], mres[2011];
double ans = 0, mans = 0;
char deal[2000];
int x = 0, shuo[2000], m[2000], sz;
int getten(int x) {
int ans = 1;
for (int i = 1; i <= x; ++i) ans *= 10;
return ans;
}
int main() {
scanf("%s", str);
int len = strlen(str);
for... | 8 |
#include <bits/stdc++.h>
using vi = std::vector<long long int>;
using vvi = std::vector<vi>;
using pii = std::pair<long long int, long long int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
using namespace std;
const long long int N = 1e6 + 10;
const long long int inf = 1e9 + 10;
const long double P... | 10 |
#include <bits/stdc++.h>
using namespace std;
int g[1001], i, j, k, l, p, n, m;
int main() {
cin >> n;
for (i = 1; i <= n - 1; i++) {
cin >> g[i];
g[i] += g[i - 1];
}
cin >> i >> j;
cout << g[j - 1] - g[i - 1] << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 18;
const int MOD = 1e9 + 7;
int n, m, k, t;
pair<long long, int> a[N];
long long p[N];
int ans[N];
long long sum(int l, int r) { return p[r] - p[l - 1]; }
bool check(int r, int mn, long long money) {
int j =
lower_bound(a + 1, a + n + 1 -... | 11 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
int n, a[N];
void code() {
cin >> n;
set<int> se;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int nxt = 1, ans = 0;
for (int i = 0; i < ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct node {
int x, y, z;
int pos;
} s[N];
bool cmp(node s1, node s2) {
if (s1.z == s2.z) {
return s1.y > s2.y;
if (s1.y == s2.y) return s1.x > s2.x;
}
return s1.z > s2.z;
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 20;
int n, K;
int a[N], ans = -2147483647;
void solve() {
priority_queue<int> big;
priority_queue<int, vector<int>, greater<int> > smal;
for (int l = 0; l < n; l++) {
for (int r = l; r < n; r++) {
while (smal.size()) smal.pop();
whi... | 7 |
#include <bits/stdc++.h>
using namespace std;
void printarr(int arr[], int n) {
for (int i = 0; i < n; ++i) cerr << arr[i] << (i < n - 1 ? ' ' : '\n');
}
template <typename T>
void printv(T &a) {
for (auto it = a.begin(); it != a.end(); ++it) cerr << *it << ' ';
cerr << '\n';
}
long long int ans;
int arr[300009];... | 2 |
#include <bits/stdc++.h>
using namespace std;
int f(vector<int>& a, int n) {
unordered_map<int, int> m;
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 4) {
m[8]++;
} else if (a[i] == 8 && m[8]) {
m[8]--;
m[15]++;
} else if (a[i] == 15 && m[15]) {
m[15]--;
m[16]++;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6;
const int M = 10010;
const int K = 510;
const int LIT = 2500;
const int INF = 1 << 30;
int n, m[N][N], tot, need;
vector<int> v, vis;
int row[N], col[N], dia1, dia2;
int cr[N], cc[N], cd1, cd2;
void init() {
memset(m, 0, sizeof(m));
memset(row, 0, sizeo... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool judge(long long a, long long b) {
if (a == 0 || b == 0) return false;
if (judge(b, a % b)) {
if ((a / b % (b + 1)) % 2 == 0)
return true;
else
return false;
}
return true;
}
int main() {
long long a, b, t;
cin >> t;
while (t--) {
c... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
struct State {
int len, par, to[26], sz, ls;
};
State T[maxn];
int p, q, last, st;
int belong[maxn];
void extend(char c, int cur) {
T[++st].len = T[last].len + 1;
p = last;
while (p && !T[p].to[c - 'a']) {
T[p].to[c - 'a'] = st;
p = ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
cin >> n;
long long a[n], b[n - 1], c[n - 2];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n - 1; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + n - 1);
for (i = 0; i < n - 1;) {
if (a[i] != b[i]) {... | 3 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 9e18;
long long n, m, x, ans = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
scanf("%lld %lld"... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 2e2 + 10;
int a[mn][mn], b[mn][mn], n, m;
void solve() {
int i;
printf("YES\n");
for (i = 0; i < n; i++) printf("%d", a[i][0] != b[i][0]);
int idk = 0;
if (a[0][0] != b[0][0]) idk = 1;
printf("\n");
for (i = 0; i < m; i++) printf("%d", (a[0][i] ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
struct edge {
int to, next;
} e[N * 2];
int head[N], tot, n, Q;
int sz[N], dep[N], fa[N], co[N];
int top[N], dfn[N], ed[N], pos[N];
void add(int x, int y) {
e[++tot] = (edge){y, head[x]};
head[x] = tot;
}
void dfs1(int x) {
sz[x] = 1;
dep[x] ... | 25 |
#include <bits/stdc++.h>
using namespace std;
struct queue {
int l, r;
friend bool operator<(struct queue a, struct queue b) { return a.l < b.l; }
} b[26];
int iv[26];
int main() {
int n, k, count1 = 0, count3 = 0, sum = 0;
char str;
cin >> n >> k;
memset(iv, -1, sizeof(iv));
for (int i = 0; i < n; i++) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> str(n);
vector<vector<pair<char, int>>> v(1000001);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
str[i] = s;
int k = 0;
char last = '.';
for (int j = s.length() - 1; j >= 0; j--) {
if ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
for (int tt = 0; tt < t; tt++) {
cin >> n;
int m = n;
int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
for (int i = 0; i <... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int ind = 0; ind < t; ind++) {
int n;
cin >> n;
int a, r = 0;
for (int i = 0; i < n; i++) {
cin >> a;
r += a;
}
if (r % n == 0)
cout << 0 << endl;
else
cout << 1 << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[16][10001], b[16][16], c[16][16], dp[1 << 16][16][16], ans = 0;
int main() {
int i, j, k, l, n, m;
cin >> n >> m;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> a[i][j];
}
}
if (n == 1) {
long long x = 1000000000000;
f... | 12 |
#include <bits/stdc++.h>
using namespace std;
void file() {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
void Abdo() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int dx[] = {1, 1, -1, -1};
int dy[] = {1, -1, -1, 1};
const long double EPS = 1e-9, PI = 3.14159265358... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
if (n == 1) {
cout << "0";
} else {
long long int g = n;
long long int p;
long long int g1 = 9 + 4 * (g + k) * 2;
g1 = sqrt(g1);
long long int g2 = -3 + g1;
g2 = g2 / 2;
cout << g - g2;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int op = 1e8;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int res = 2;
int n = s.length();
int ans;
for (int i = 0; i < 10; i++) {
ans = 0;
for (int j = 0; j < n; j++) {
if (s[j] - '0' ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50, MOD = 1e9 + 7, MXL = 1100;
int n, k, a[N], sumn, cnt[MXL];
long long ans, dp[MXL][MXL], fac[N], inv[N];
set<int> lks;
vector<int> lkv;
long long power(int a, int b) {
if (b == 0) return 1;
long long tmp = power(a, b / 2);
tmp *= tmp;
tmp %= M... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, p, k, ans, a[300010], t;
unordered_map<int, int> hp;
unordered_map<int, pair<int, int> > ph;
int cal(int x) {
long long t = (((1LL * x * x) % p) * ((1LL * x * x) % p)) % p;
t = (t - 1LL * x * k) % p;
t = (t % p + p) % p;
return t;
}
void readf() { cin >> n >>... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int N = 2e5 + 10;
int n, k, c[N];
long long a[3003][3003], ans;
long long dp[22][3003];
void gao(int l, int r, int d) {
if (l == r) {
for (int i = 0; i <= min(k, c[l]); i++) {
ans = max(ans, dp[d][k - i] + a[... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long ar[100007];
long long leftAr[100007];
long long leftCost[100007];
long long rightAr[100007];
long long rightCost[100007];
int main(void) {
std::ios::sync_with_stdio(false);
long long n, i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> ar[i];
}
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long dp[5010][5010];
int n, k, a, b, x, y, z[300010];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", z + i);
sort(z + 1, z + n + 1);
x = n / k;
y = n / k + 1;
b = n % k;
a = k - b;
dp[1][0] = z[y] - z[1];
dp[1][1] = z[x] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long int;
using ld = long double;
using pi = pair<int, int>;
const double PI = acos(-1.0);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int inf = 1e7;
const int MAXN = 1e5 + 5;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m;
long long int p[111101], l[111101], r[111101], sum;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
n--;
for (i = 1; i <= n; i++) {
cin >> p[i];
}
long long int now = 0;
for (i = 1; i <= n; i++) {
if (p[i] & 1) {
l[i] = l[i -... | 12 |
#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
if (!1) cerr << "\E[91m" << __s << "\E[0m";
return __m;
}
C_ merr;
struct __s {
__s() {
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const unsigned long long base = 2333;
const int maxn = 5e6 + 50;
const int maxm = 10 + 5;
const int maxv = 1e6 + 5;
const int mod = 1e9 + 7;
const int ba = 3e5;
unsigned long long a[maxn];
unsigned long long b[maxn];
unsigned long long pw[maxn];
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int arr[101];
for (int i = 0; i < n; i++) arr[i] = 10000;
int l, r, t, p;
int sum[101];
for (int i = 0; i < n; i++) sum[i] = 0;
for (int i = 0; i < m; i++) {
cin >> l >> r >> t >> p;
for (int j = l - 1; j <= r - ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], x, y, l, r;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int i = 1, j = n;
while (i < j) {
while (x <= y && i <= j) x += a[i], i++, l++;
while (y < x && j >= i) y += a[j], j--, r++;
}
if (l + r < n) l++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, u, v, q;
bool come[330000];
vector<long long> edge[330000];
long long parent[330000];
long long group[330000];
long long g_min[330000];
long long g_max[330000];
long long limit[330000];
long long l_sum[330000];
long long dep[330000];
void dfs(long long x, lo... | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.