solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
const double pi = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int limit = 5e5;
int read() {
int s = 0;
char c = getchar(), lc = '+';
while (c < '0' || '9' < c) lc = c, c = getchar();
while ('0' <= c && c... | 10 |
#include <bits/stdc++.h>
using namespace std;
int posscount = 0, numh[3001], numnz[3001], n, k, numbu[3001][3002], p;
int main() {
cin >> n >> k;
numh[0] = 0;
numnz[0] = 0;
for (int i = 0; i < n; i++) {
cin >> p;
numh[i + 1] = numh[i];
numnz[i + 1] = numnz[i];
if (p == 100) numh[i + 1]++;
if... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
int n, m;
long long v[N];
int t[N];
int h[N];
int dad(int nod) {
if (nod == t[nod]) {
return nod;
} else {
t[nod] = dad(t[nod]);
return t[nod];
}
}
void uni(int a, int b) {
a = dad(a);
b = dad(b);
if (a == b) return;
if (h... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
return (out << "(" << a.first << "; " << a.second << ")");
}
template <typename T1>
ostream &operator<<(ostream &cout, vector<T1> &a) {
if ((int)a.size() == 0) return (cout << "()");... | 13 |
#include <bits/stdc++.h>
using namespace std;
void Fastio() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long fact[1000006], inv[1000006];
long long fp(long long base, long long exp) {
if (exp == 0) return 1;
long long ans = fp(base, exp / 2);
ans = (ans * ans) % 998244353;
if (exp % 2 != 0)... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[1000006], d[1000006], s, x, it, sl, st, minv, ans1,
sum[1000006], ans2, ans3;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> d[i];
s =... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
int lx, ly, rx, ry;
int lx2, ly2, rx2, ry2;
int go_query(int x1, int y1, int x2, int y2) {
int ret;
if (x1 > x2 || y1 > y2) return 0;
printf("? %d %d %d %d\n", x1, y1, x2, y2);
fflush(stdout);
scanf("%d", &ret);
return ret;
}
int main() {
scanf("%d", &n... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int main() {
int n, dp[2] = {1, 1};
scanf("%d", &n);
for (int i = 0; i < n; i++) dp[i & 1] = (dp[i & 1] + dp[~i & 1]) % INF;
printf("%d\n", ((dp[0] + dp[1]) % INF + INF - 2) % INF);
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> countSort(const string &s) {
vector<int> res(10, 0);
for (char c : s) {
++res[c - '0'];
}
return res;
}
int main() {
int n;
cin >> n;
string s1;
string s2;
cin >> s1;
cin >> s2;
auto v1 = countSort(s1);
auto v2 = countSort(s2);
int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, d1[3003][3003], d2[3003][3003];
vector<int> v[3003], f[3003];
pair<int, int> mv[3003][9], mf[3003][9];
int mx, a[9];
void bfs(int xi) {
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
q;
for (int i = 1;... | 12 |
#include <bits/stdc++.h>
using namespace std;
int vis[100010];
int num[100010];
int main() {
int n, m, a;
scanf("%d%d", &n, &m);
map<int, int> M;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
M[a] = 1;
}
int flag = 0, sum = 0, pos = 0;
for (int i = 1; i < 10000000; i++) {
if (M[i] == 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int maxk = 26;
struct node {
int next[maxk], flag, fail;
} tree[maxn];
char s[maxn], t[maxn];
int f[maxn][maxn], p[maxn][maxn], letter[maxn][maxn], v[maxn], n, m, root, size;
int ans[maxn];
void insert(char *s) {
int len = strlen(s), x = root... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s, t;
cin >> s >> t;
int x, y;
x = ((s[0] - '0') * 10 + (s[1] - '0')) * 60 + (s[3] - '0') * 10 +
(s[4] - '0');
y = ((t[0] - '0') * 10 + (t[1] - '0')) * 60 + (t[3] - '0') * 10 +
(t[4] - '0');
int u, v;
if (x - y >= 0) {
u... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream ff("file.txt");
int n, m;
cin >> n >> m;
vector<pair<int, int>> v(n);
set<int> s1;
map<int, int> m1;
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
s1.insert(v[i].first);
s1.insert(v[i].second);
}
if (m ==... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1000;
inline long long read() {
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 - 48;
ch = getchar();
}
return x * f;
}
lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 2e6 + 220;
int n, k;
set<long long> s;
long long sec[MAX_N], m[MAX_N];
map<long long, long long> mp;
void Init() {
cin >> n >> k;
for (int i = 1; i < n + 1; i++) cin >> sec[i] >> m[i];
}
void Solve() {
for (int i = 1; i < n + 1; i++) {
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int S = 100003;
const int MOD = 1e9 + 7;
const double pi = 2 * acos(0.0);
int _I() {
int x;
scanf("%d", &x);
return x;
}
long long _LL() {
long long x;
scanf("%lld", &x);
return x;
}
int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dirY[] = {0, 1, 0, -1, 1, -... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
const long long int INF = 1000111000111000111LL;
long long int modular_exp(long long int base, long long int exp,
long long int mod) {
long long int ans = 1;
while (exp) {
if (exp % 2) ans = ans % mod * ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct State {
int st, nd, val, prv;
State(int st_, int nd_, int val_, int prv_)
: st(st_), nd(nd_), val(val_), prv(prv_) {}
bool operator>(const State& other) const {
if (st != other.st) {
return st > other.st;
}
return nd > other.nd;
}
vo... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long int temp;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
cin >> temp;
if (temp % 2 == 0)
even++;
else
odd++;
}
cout << min(even, odd);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long binExp(long long x, long long n) {
long long r = 1;
while (n > 0) {
if (n % 2 == 1) r = r * x;
x = x * x;
n = n / 2;
}
return r;
}
long long modbinExp(l... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 1e6 + 10;
vector<int> a[maxn], b[maxn];
int f = 0;
int va[maxn], vb[maxn];
void dfs(int first) {
for (int i : a[first]) {
if (vb[i] != -1) continue;
vb[i] = 0;
va[i] = 1;
dfs(i);
}
}
void dfs2(int first) {
for (int i : b[firs... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1.1e5;
int n;
double dp[2][N], k;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 666; j++)
dp[i & 1][j] = ((dp[i - 1 & 1][j + 1] + j) / (j + 1) + j / 2.0 +
dp[i - 1 & 1][j] * j / (j + 1)) /
... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if ((a == 0) || (b == 0)) return a + b;
return gcd(b, a % b);
}
long long pow_mod(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % 1000000007;
a = (a * a) % 1000000007;
b >>... | 10 |
#include <bits/stdc++.h>
using namespace std;
int b[10000005];
int n, a;
long long ans;
int main() {
cin >> a >> n;
for (int i = 1; i * i <= 10 * 1000 * 1000; i++) {
int cur = i * i;
int j = 1;
while (cur * j <= a + n - 1) b[cur * j] = j++;
}
for (int i = a; i <= a + n - 1; i++) ans += b[i];
cout ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[2][2];
int main() {
int T;
scanf("%d", &T);
while (T--) {
a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0;
int n;
scanf("%d", &n);
int t;
for (int i(0); i < n; i++) {
scanf("%d", &t);
if (t % 2) {
a[0][0]++;
} else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long inf = 1e9, mod = 1e9 + 7, MAX = 1e3 + 1;
long long n, m, dp[21][MAX];
long long sol(int idx, int prev) {
if (idx == m) return 1;
long long &ret = dp[idx][prev];
if (~ret) return ret;
ret = 0;
for (int i = p... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
struct node {
int l;
int r;
long long co;
long long sum;
long long laz;
} tree[4 * N];
long long ac;
void pushup(int cur) {
tree[cur].sum = tree[cur * 2].sum + tree[cur * 2 + 1].sum;
if (tree[cur * 2].co == tree[cur * 2 + 1].co)
tr... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int ok[10];
memset(ok, 0, sizeof(ok));
if (c > 0 || b > 0) {
if ((a + b) % 2 == 0) {
ok[3] = 1;
} else {
ok[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t = 1;
while (t--) {
int n;
cin >> n;
n *= 2;
vector<long long> arr;
int x;
for (int i = 0; i < (int)(n); ++i) {
cin >> x;
arr.push_back((long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXV = 1e6;
int k;
int main() {
scanf("%d", &k);
vector<int> ans(1, -1);
int sum = -1, cnt = 1;
while (sum - cnt + MAXV < k) {
sum += MAXV;
cnt++;
ans.push_back(MAXV);
}
ans.push_back(k - sum + cnt);
printf("%d\n", ans.size());
for (aut... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct data {
int a, p;
inline bool operator<(const data& x) const { return a > x.a; }
} d[101];
double dp[101][101][101 * 10], base[101];
int main() {
int lsy;
scanf("%d", &lsy);
while (lsy--) {
int n, sp(0);
double c, t, cg;
scanf("%d%lf%lf", &n, &c,... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 45 + 4, MAX = 4e5 + 1, INF = 2e18, mod = 1743;
int n, mx, k;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
if (k == n || k == 0) {
cout << 0 << ' ' << 0;
return 0;
} else if (k > n / 3)
cout << 1 << ' ' << n - k;
else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, ans = 0;
scanf("%lld%lld", &a, &b);
while (a > 0 && b > 0) {
if (a < b) swap(a, b);
long long p = a % b;
ans += a / b;
a = p;
}
printf("%lld\n", ans);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, unsigned long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, x;
int sum = 0;
int main() {
scanf("%d%d", &n, &x);
if (n == 2 && x == 0)
printf("NO\n");
else if (n == 1) {
printf("YES\n%d\n", x);
} else {
printf("YES\n");
for (int i = 1; i <= n - 2; i++) {
sum ^= i;
}
int mx = 300000;
if... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, t;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int k;
cin >> k;
int all = k + (1 << 17);
int arr[3][3];
arr[0][0] = all;
arr[0][1] = k;
arr[0][2] = 0;
arr[1][0] = (1 << 17);
arr[1][1] = all;
arr[1][2] = k;... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epo... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000001];
int main() {
long long n;
cin >> n;
cout << n * (n + 1) << '\n';
for (int i = n; i >= 0; i--) {
int x = 0;
if (a[i]) continue;
for (int j = 0; j <= 32; j++) {
if ((1ll << (j)) > i) {
x = j;
break;
}
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 112;
int n, m;
char dp[N][N][26][2];
vector<pair<int, int> > g[N];
char solve(const int i, const int j, const int before, const bool current) {
if (dp[i][j][before][current] != -1) return dp[i][j][before][current];
int ans = 0;
int x = current ? j : i;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
long double PI = 3.14159265358979323846264338327950;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
vector<string> ans, v;
for (char i = 'A'; i <= 'Z'; i++) {
for (char j = 'a'; j <= 'z'; j++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
string tg;
int ct = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
getline(cin, tg);
getline(cin, s);
if (k == 0) {
for (int i = 0; i < n; i++) cout << s[i] - '0';
exit(0);
}
if (s.size() == 1) {
cout... | 2 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename Arg1>
void debug(const char* name, Arg1&& arg1) {
cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void debug(const char* names, Arg1&& arg1, Args&&.... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
const int N = 2 * 1e5 + 5;
const long long INF = 1e18;
const double EPS = 1e-6;
long long l, r, n;
pair<double, double> x[N];
double time(double m) {
double ans = double(0);
for (int i = 1; i <= n; i++) {
ans = max(ans, double(abs(x[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 17;
int n;
map<long long, vector<int> > v;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v[x].push_back(i);
}
vector<pair<int, long long> > ans;
for (auto &val : v) {... | 8 |
#include <bits/stdc++.h>
using namespace std;
double len(int x1, int stupid_cmath, int x2, int y2) {
return sqrt(0.0 + ((x1 - x2) * (x1 - x2)) +
((stupid_cmath - y2) * (stupid_cmath - y2)));
}
int main() {
int a, b, c, d, mm[4][3], i, j;
double l;
cin >> a >> b >> c >> d;
mm[0][0] = a;
mm[0][1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int s[100010], t[100010], l[100010], r[100010];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int u, v;
cin >> u >> v;
s[u]++;
s[v + 1]--;
}
for (int i = 1; i <= m; i++) s[i] =... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4000005;
int trie[N][2], sz[N], ts = 1;
void update(int p, int v) {
int r = 1;
sz[r] += v;
for (int i = 31; i >= 0; i--) {
bool c = (1 << i) & p;
if (!trie[r][c]) trie[r][c] = ++ts;
r = trie[r][c];
sz[r] += v;
}
}
int query(int p, int l... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100];
bool can[100][100];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
can[x][y] = can[y][x] = true;
}
int ans = -1;
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
int n, m, k;
vector<long long> c;
vector<pair<int, int> > e;
map<long long, set<int> > xv;
vector<int> pow2;
int add(int a, int b) { return (int)(((long long)a + (long long)b) % MOD); }
int sub(int a, int b) {
return (int)(((long long)a + MOD... | 14 |
#include <bits/stdc++.h>
using namespace std;
int N, Q;
int L[303030], R[303030], K[303030];
vector<int> C;
static signed long long const def = 0;
template <class V, int NV>
class SegTree_3 {
public:
vector<V> base, tot;
SegTree_3() {
int i;
base.resize(NV * 2, 0);
tot.resize(NV * 2, 0);
};
void up... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, k;
int a[1000005], maxx[1000005], minn[1000005];
set<int> st;
int main() {
scanf("%d%d", &n, &k);
int mx = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
auto iter = st.upper_bound(a[i]);
if (iter != st.end()) {
... | 13 |
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
const long long mod=998244353;
typedef pair<int,int> pii;
int n,x,y,s,t;
int a[maxn*2+5][maxn+5],b[maxn+5][maxn+5],f[maxn+5];
vector <pii> v;
vector <int> c[maxn+5][maxn+5];
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
vector<pair<int, int> > b;
vector<pair<int, int> > ans;
bool cmp(pair<int, int> x, pair<int, int> y) { return x.second > y.second; }
int main() {
int n, v, t, p;
scanf("%d%d", &n, &v);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &t, &p);... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, r1, r2;
int p[50005];
void rev(int at, int from) {
if (from == -1) return;
int temp = p[from];
p[from] = at;
rev(from, temp);
}
int main() {
memset(p, 0, sizeof(p));
cin >> n >> r1 >> r2;
for (int i = 1; i <= n; i++) {
if (i == r1)
p[i] = -1;
... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long N = 200000 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000010;
const long long LOG = 25;
long long mul(long long a, long long b) { return (a * 1ll * b) % MOD; }
long... | 17 |
#include <bits/stdc++.h>
int main() {
int t1, t2;
int ezaz, imran = 0;
int bijor;
int jor;
scanf("%d", &t1);
for (int i = 1; i <= t1; i++) {
imran = 0;
bijor = 0;
jor = 0;
scanf("%d", &t2);
for (int j = 1; j <= t2; j++) {
scanf("%d", &ezaz);
if (ezaz % 2 != 0 || ezaz == 1) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio();
long long a;
cin >> a;
long long num = 0, sm = 1;
long long b = a;
while (b > 0) {
num++;
sm *= 10;
b /= 10;
}
sm /= 10;
long long out = (a / sm + 1) * sm;
cout << out - a << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> g[100100];
map<long long int, bool> f;
long long int w[100100];
bool p[100100];
long long int n;
bool used[100100];
void dfs(int v, long long int mm, long long int mmax) {
used[v] = 1;
if (w[v] >= mm && w[v] <= mmax) f[w[v]] = 1;
if ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
stack<char> s;
char ch;
long long refresh = 0, ans = 0;
while (cin >> ch) {
if (s.empty())
s.push(ch);
else if (s.top() == '(') {
if (ch == '(')
s.push(ch);
else {
s.pop();
ans += 2;
}
} else {... | 6 |
#include <bits/stdc++.h>
using namespace std;
void customrun() {}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool isprime(long long n) {
for (long long i = 2; (long long)i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
long long fib(in... | 8 |
#include <bits/stdc++.h>
using namespace std;
char str[10000], src[10000];
int n;
int main() {
scanf("%d", &n);
scanf("%s %s", str, src);
int cnt = 0;
for (int(i) = 0; (i) < n; (i)++) {
int res = 0;
int st = min(str[i], src[i]);
int ed = max(str[i], src[i]);
int cou = ed - st;
cnt += min(cou... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
const long long mod = 1000000007;
int n;
int a[100010];
vector<vector<int> > p;
long long pw(long long a, int b) {
long long result = 1;
long long cur = a;
for (int i = 0; i < 18; i++) {
if ((b >> i) & 1) result = (resul... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a;
cin >> a;
while (a > 0) {
cout << a << " ";
--a;
}
cout << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int M = 5005;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, a[N], k;
long long dp[M][M];
int main() {
scanf("%d%d", &n, &k);
memset(dp, inf, sizeof(dp));
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
dp[0]... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
}
return os;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int num, f[11000][110], g[11000][110];
int p, m;
int n, flag;
char s[110000];
stack<int> st;
const int inf = 1e9;
void update(int x, int l, int r) {
if (flag) {
for (int i = 0; i <= p; i++)
if (f[l][i] == inf)
continue;
else {
for (int j = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int A1, A2, A3, A4;
int main() {
int i;
scanf("%d%d%d%d", &A1, &A2, &A3, &A4);
if (abs(A3 - A4) > 1)
printf("-1");
else {
if (A3 == A4) {
if ((((A1) > (A2) ? (A1) : (A2)) - A3 - 1 < 0) ||
(((A1) < (A2) ? (A1) : (A2)) < A3))
printf("-1... | 10 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector<lli> vi;
typedef vector<pair<lli,lli>> vii;
typedef vector<vector<lli>> vvi;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : fal... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
struct Sync_stdio {
Sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
} _sync_stdio;
struct FAIL {
FAIL() {
cout << "CHANGE!!!"
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum = 0, i, cur = 0, n, c, pre = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> c;
if (c > pre) {
if (c - pre <= cur) {
cur -= c - pre;
} else {
sum += c - pre - cur;
cur = 0;
}
} else {
cur +... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << n << "\n";
for (int i = 1; i <= n; i++) cout << i << " ";
cout << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 123;
void run();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
const int N = 80;
int n;
string s;
int a[N];
int dp[N][N][N][2];
vector<int> p[3];
int calc(int v, int k, int x, int pos) {
int res ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<long long int> v;
vector<long long int> a;
long long int sum = 0;
for (int i = 0; i < n; i++) {
long long int x;
cin >> x;
sum += x;
}
if (sum % n == ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
const long long mod = 1e9 + 7;
int f[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
f[0] = f[1] = 0;
int k = 0;
for (int i = 2; i <= s.length(); i++) {
while (k != 0 && s[i - 1] != ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long tong;
int n, k;
long long giaithua[20];
map<long long, int> sum[30];
int board[30];
long long ans = 0;
void dfs1(int a, int b, long long c) {
if (c > tong) return;
if (a == n / 2)
sum[b][c]++;
else {
dfs1(a + 1, b, c);
dfs1(a + 1, b, c + board[a]... | 13 |
#include <bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m;
cin >> n >> m;
if (n == 1 && m == 1) {
cout << 1;
} else if (n % 2 == 0) {
if (m - 1 > n - m) {
cout << m - 1;
} else {
cout << m + 1;
}
} else {
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[3];
cin >> arr[0] >> arr[1] >> arr[2];
sort(arr, arr + 3);
cout << max(0, arr[2] - (arr[0] + arr[1] - 1)) << "\n";
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2,avx")
#pragma GCC optimize("unroll-loops")
using namespace std;
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bo... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, x;
cin >> n >> x;
int a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
int dp[x + 1][x + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long aa[200200];
long long tree[600200];
long long tree_b[600200];
void init(int b, int e, int node) {
if (b == e) {
tree[node] = aa[b];
return;
}
int mid = (b + e) / 2;
int left = node * 2;
int right = node * 2 + 1;
init(b, mid, left);
init(mid +... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int table[2][110];
int main() {
int tmp;
memset(table, 0, sizeof(table));
cin >> n >> k;
n = n / k;
while (n--) {
for (int i = 1; i <= k; i++) {
cin >> tmp;
tmp == 1 ? table[1][i]++ : table[0][i]++;
}
}
tmp = 0;
for (int i = 1; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void min_self(long long &a, long long b) { a = min(a, b); }
void max_self(long long &a, long long b) { a = max(a, b); }
long long add(long long x, long long y) { return (x + y) % MOD; }
long long sub(long long x, long long y) { return add(x, M... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int c;
cin >> c;
string data;
cin >> data;
int count = 0;
for (int i = 0; i < c - 1; i++) {
if (data[i] == data[i + 1]) count++;
}
cout << count;
return 0;
}
| 0 |
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
using namespace std;
bool cmp(int a, int b) { return a >= b; }
int main() {
int k, cnt = 0, sum = 0, idx = 0;
cin >> k;
vector<int> a(12);
for (int i = (int)(0); i < (int)(12); ++i) cin >> a[i];
sort(a.begin(), a.end(), cmp);
whil... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 51, P = 1e9 + 7;
int a[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < n; j++) {
if (s[j] == '#')
a[i][j] = 1;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 203;
long long a[MAX];
long long f[MAX][MAX];
long long k, n, x;
signed main() {
long long best = 0, i;
cin >> n >> k >> x;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
if (x < n / k) {
cout << -1;
return 0;
}
for (long... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long c, sum;
long long a, b;
for (long long i = 0; i < n; i++) {
cin >> c >> sum;
a = sum / c;
b = sum % c;
cout << (a + 1) * (a + 1) * b + a * a * (c - b) << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6;
long long cnt[MAXN], pcnt[MAXN], pmx[MAXN];
void upd(long long &mx1, long long &mx2) {
if (mx2 > mx1) {
swap(mx1, mx2);
}
}
long long getPref(long long l, long long r) {
r = min(MAXN - 1, r);
return pcnt[r] - pcnt[l - 1];
}
long long ... | 24 |
#include <bits/stdc++.h>
using namespace std;
vector<int> L, R;
int n;
int ans;
int num[20], now[20];
bool has(int l, int r) {
for (int e = l; e <= r; e++)
if (num[e]) return true;
return false;
}
bool check(int cur, int lflag, int rflag) {
if (cur == n) return true;
int l = L[cur], r = R[cur];
if (lflag ... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long g(int x) {
if (x == 1) return 1;
if (x == 2) return 0;
if (x == 3) return 1;
if (x == 4) return 2;
long long ans = 0;
if (x % 2 == 1) return 0;
if (g(x / 2) != 1) return 1;
return 2;
}
int main() {
long long n, k;
cin >> n >> k;
vector<int> v... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct O {
int l, r, s, t, i;
} o[200005];
bool cmp(O a, O b) { return a.l < b.l; }
int n, m, Q, ans[200005], f[1005][1005], u[200005], v[200005];
int main() {
scanf("%d%d%d", &n, &m, &Q);
for (int i = 1; i <= m; ++i) scanf("%d%d", &u[i], &v[i]);
for (int i = 1; i <... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e4 + 7;
int n, m, timer = 0;
vector<int> g[MAXN], ans;
int tin[MAXN], tout[MAXN];
char used[MAXN];
void dfs(int v) {
used[v] = true;
tin[v] = ++timer;
for (size_t i = 0; i < g[v].size(); ++i) {
int to = g[v][i];
if (!used[to]) dfs(to);
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, a[N];
map<vector<int>, int> b;
int main() {
scanf("%d", &n);
vector<int> x(n - 1);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 0, u; i < 32768; i++) {
u = __builtin_popcount((a[1] & 32767) ^ i);
for (int j = 2; j <... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k, l, d[300005];
vector<int> isles;
bool possible(int idx) {
int start = isles[idx], end = isles[idx + 1];
if (end == start + 1) return true;
vector<pair<int, bool> > events;
for (int i = start + 1; i < end; i++) {
if (d[i] + k - l <= k - d[i] +... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed int main() {
signed long long d, k, a, b, t;
cin >> d >> k >> a >> b >> t;
signed long long ans;
if (d <= k)
ans = d * a;
else if (t + k * a > k * b)
ans = k * a + (d - k) * b;
else {
signed long long repair = d / k - 1;
signed long long r... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
double x = 0, result;
for (int i = 0; i < n; i++) {
double p;
cin >> p;
x += p;
}
result = x / n;
cout << result << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int q;
unsigned long long int n;
unsigned long long int ans, sum;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
unsigned long long int powe(unsigned long long int a,
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, l, m, n;
int a[1000];
int b[1000];
int sum;
int main() {
scanf("%i", &n);
for (i = 0; i < n; i++) {
scanf("%i", &m);
if (m % 2 == 0)
a[k++] = m;
else
b[l++] = m;
}
if (l == 0) {
printf("0");
return 0;
} else {
for (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
int rec[N][2], L, b, f, n;
set<int> s;
set<int>::iterator fir, sec;
int search_space(int i, int car) {
int len = car + b + f;
for (fir = s.begin(); fir != s.end(); ++fir) {
sec = fir;
++sec;
if (sec != s.end() && *sec - *fir >= len)... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.