solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
const int N = 2e5 + 10;
using namespace std;
int n, q;
int num[N][9];
struct node {
int x, y, pos;
} Q[N * 9];
int bit[1 << 20];
pair<int, int> P[N];
inline long long C2(int x) { return 1LL * x * (x - 1) / 2; }
void add(int x) {
while (x <= n) {
++bit[x];
x += (x & -x);
}
}
int qu... | 13 |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
void primes() {
int n = 1000000;
s.insert(2);
for (int i = 3; i < n; i++) {
bool isprime = true;
for (int j = 2; j <= sqrt(i); j++) {
if (i % j == 0) {
if (s.find(j) != s.end()) {
isprime = false;
break;
}
... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll i, j, k;
ll t;
cin >> t;
while(t--){
ll n;
cin >> n;
vector<pair<ll,ll>> vt(n);
for(i=0; i<n; ++i){
cin >> vt[i].first;
vt[i].second=i;
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const double error = 1e-8;
const double MAXDIST = 3000;
const double e = 2.7182818284590452353602874713527;
double D[MAXN];
double prob[MAXN];
double dp[MAXN][MAXN];
double sqr(const double &x) { return x * x; }
int main() {
int n, k, eps, x0, y0;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
string succ(string s) {
for (int i = s.length() - 1; 0 <= i; --i) {
if (s[i] == 'z') {
s[i] = 'a';
} else {
s[i] += 1;
break;
}
}
return s;
}
int main() {
ios_base::sync_with_stdio(false);
string s, t;
cin >> s >> t;
s = succ(s);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int X[] = {0, 0, -2, 2, 1};
int Y[] = {-2, 2, 0, 0, 1};
int XX[] = {0, 1, 0, -1};
int YY[] = {1, 0, -1, 0};
int n, ttrue = 0, rs[2][55][55];
bool F[2][55][55][55][55], Free[2][55][55][55][55];
int Ask(int u1, int v1, int u2, int v2) {
if (u1 > u2) swap(u1, u2);
if (v1 >... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > G, LCA;
vector<int> pc(1 << 13);
void init() {
for (int i = 1; i < (1 << 13); ++i) {
int j = i;
while (j) {
if (j & 1) {
++pc[i];
}
j >>= 1;
}
}
}
int older(int mask) {
int ans = -1;
while (mask) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int x[100005], y[10 * 100005], n;
int a, b;
int main() {
int i, j, len, ans = 0, pos = 0, posds = -1;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", x + i);
scanf("%d %d", &a, &b);
for (i = 0; i < a - b; i++) y[i] = i + 1;
sort(x, x + n);
len = unique(x,... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c h, n;
};
template <class c>
rge<c> range(c h, c n) {
return rge<c>{h, n};
}
template <class c, class F>
struct rgm {
c h, n;
F f;
};
template <class c, class F>
rgm<c, F> map_range(c b, c e, F f) {
retur... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long dp[1000100][3];
int val[1000100];
long long a, b;
int prime[1000100];
int vis[1000100];
int n, cnt, fac[1000100];
void init() {
for (int i = 2; i < 1000100; i++) {
if (!vis[i]) prime[cnt++] = i;
for (int j = 0; j < cnt && prime[j] * i < 1000100; j++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200100], b[200100];
int ans;
int main() {
int kk;
long long lo = 0, hi = 10000000000000LL;
scanf("%d %d", &n, &kk);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
while (lo < hi - 1) {
int ok = 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > g[4];
int st[4], mid[4];
void out(pair<long long, long long> a) {
printf("(%I64d,%I64d)\n", a.first, a.second);
}
pair<long long, long long> operator+(pair<long long, long long> a,
pair<long long, lo... | 18 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long b[n], a[n], x[n];
for (long long i = 0; i < n; i++) {
cin >> b[i];
}
a[0] = b[0];
long long cur = 0;
cur = max(cur, a[0]);
for (long long i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MO = 1e9 + 7;
template <class T>
inline bool Chkmin(T &x, T y) {
return x > y ? x = y, true : false;
}
template <class T>
inline bool Chkmax(T &x, T y) {
return x < y ? x = y, true : false;
}
template <class T>
inline T read(T &x) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 1010;
struct fen {
long long t[maxn][maxn];
fen() { memset(t, 0, sizeof(t)); }
void modify(int x, int y, long long val) {
for (int i = x; i < maxn; i |= (i + 1))
for ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, s, d;
scanf("%d%d%d%d", &n, &m, &s, &d);
vector<int> a(n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
a.push_back(-1);
sort(a.begin(), a.end());
vector<pair<int, int>> segments;
for (int i = 1; i < a.size(); i++)
if (a[i] - a[... | 8 |
#include <bits/stdc++.h>
using namespace std;
set<int> alive;
int main() {
int n, m;
cin >> n >> m;
int ans[n + 2];
for (int i = 0; i < n; i++) {
alive.insert(i);
ans[i] = -1;
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
vector<int> willerase;
auto it =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long seed, vax;
long long Pow(long long a, long long b, long long mod) {
if (!b) return 1LL % mod;
long long r = Pow(a, b / 2, mod);
r = (r * r) % mod;
if (b & 1) r = (r * (a % mod)) % mod;
return r;
}
long long pot(long long a, long long b, long lo... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, x, fir, sec, now, nxt, t, tot, tot1;
long long sum;
map<int, int> m;
multiset<int> ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
sum += x, ++m[x];
}
map<int, int>::reverse_iterator it;
for (it = m.rbegin(); it !=... | 22 |
#include <bits/stdc++.h>
const double pi = 4.0 * atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = 1005000;
const int mod = 1e9 + 7;
using namespace std;
int n, m;
int T, tol;
int cnt[4][11][10][maxn];
char s[maxn];
int mx;
int getid(char c) {
if (c == 'A') return 0;
if (c == 'T') re... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x = 1, y = 4 * n / 2 + 1;
while (x <= m) {
while (y <= m) {
cout << y << " " << x << " ";
x++;
y++;
}
if (x > 2 * n) break;
cout << x << (x == 2 * n ? "\n" : " ");
x++;
}
return 0;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
long long dp[5000][2];
long long c[5000][5000];
int main() {
c[0][0] = 1;
for (int i = 1; i < 5000; i++) {
c[i][0] = c[i][i] = 1;
for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % p;
}
int n;
cin >> n;
... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
inline long long read() {
long long f = 0, x = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x... | 4 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int N = 1005;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
template <class T>
bool read(T& x) {
char c;
while (!isdigit(c = getchar()) && c != '-' && c != EOF)
;
if (c == EOF) return false;
T flag = 1;
if ... | 18 |
#include <bits/stdc++.h>
inline int pidorand() { return ((rand() & 32767) << 15) | (rand() & 32767); }
using namespace std;
inline int nxt() {
int x;
scanf("%d", &x);
return x;
}
int main() {
int n = nxt();
cout << (n - 1) / 2 << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
string field[2001];
int main() {
int n;
cin >> n;
for (int a = 0; a < n; a++) cin >> field[a];
int ans = 0;
int taikaku[2001];
for (int a = 0; a < n; a++) taikaku[a] = 0;
int koshin[2001];
for (int a = 0; a < n; a++) koshin[a] = 0;
for (int i = 0; i < n; i... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
long long ans = 0;
long long dp[maxn];
struct node {
int v;
long long w;
} q;
bool cmp(long long i, long long j) { return i > j; }
vector<node> l[maxn];
int n;
int a[maxn];
void dfs(int x, int fa) {
int i, v;
vector<long long> s;
dp[x] =... | 10 |
#include <bits/stdc++.h>
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T> v) {
os << "{";
for (auto el : v) {
os << el << ", ";
}
return os << "}";
}
int main() {
int n, k;
std::cin >> k >> n;
std::vector<int> v(k), u(n), sums(k);
std::unordered_map<int, int> m;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long nax = 125, mod = 1e9 + 7;
long long add(long long x, long long y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
long long mul(long long x, long long y) { return x * y % mod; }
vector<long long> g[nax];
long long vis[nax], cnt[nax], dp[nax][nax];
long l... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0);
int n, ans = 0;
cin >> n;
string s;
cin >> s;
for (int i = 1; i < s.size(); i += 2) {
if (s[i] == s[i - 1]) {
if (s[i] == 'a') {
s[i] = 'b';
ans++;
} else {
s[i] = 'a';
a... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e9 + 7;
int add(int a, int b) {
a += b;
if (a >= M) return a - M;
if (a < 0) return a + M;
return a;
}
int mul(int a, int b) { return a * (long long)b % M; }
void addup(int &a, int b) { a = add(a, b); }
const int N = 1000;
int n, m, sz[N];
bool v... | 20 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int px[1010], py[1010];
int n, m;
memset(px, 0, sizeof(px));
memset(py, 0, sizeof(py));
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
px[x] = 1;
py[y] = 1;
}
int ans = 0;
for (int i = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool b[1001];
int main() {
long long t, l, r, ans1, ans2, n, q, a, mid, tmp1, tmp2;
long long ans = 0, cnt;
cin >> n;
string s;
cin >> s;
int i;
for (i = 0; i < n - 2; i++) {
if (s[i] == 'x') {
if (s[i + 1] == 'x' && s[i + 2] == 'x') {
cnt = ... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
long long k, b, n, t;
int main() {
cin >> k >> b >> n >> t;
int res = 0;
long long cur = 1;
while (cur < t) {
cur = cur * k + b;
res++;
}
if (cur == t)
cout << max(n - res, 0ll) << endl;
else
cout << m... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long int n, m, k, x, y;
cin >> n >> m >> k >> x >> y;
if (n == 1 || n == 2) {
long long int maxi = 0, tot = n * m;
maxi += (k / tot);
long long int rmd = k % tot;
if (rmd > 0) {
maxi++;
}
l... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > sas;
vector<int> color;
void dfs(int a, int col = 0) {
color[a] = col;
col++;
col %= 2;
for (auto i : sas[a]) {
if (color[i] == -1) dfs(i, col);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >... | 18 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int &i : a) cin >> i;
int child = 0;
int inc_seq_allowed = 1;
int next_inc_seq_allowed = 0;
int height = 2;
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i]) {
child++;
} else {
ne... | 8 |
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
void solve() {
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
if (n1 > n2) {
cout << "First";
} else {
cout << "Second";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
struct Person {
int to, in;
};
int n, m;
Person p[MAXN];
int ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
p[a].to += c;
p[b].in += c;
}
for (int i = 1; i <= n; i++) ans ... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsi... | 13 |
#include <bits/stdc++.h>
using namespace std;
int movei[] = {0, 0, 1, -1, 1, 1, -1, -1};
int movej[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int MXN = 3e3 + 7;
const int MOD = 998244353;
string s, t;
int dp[MXN][MXN];
int add(int a, int b) { return (a + b) % MOD; }
int solve(int l, int r) {
if (l > r) return 1;
int &r... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n, m, c[505];
long long dp[505][505];
bool vis[505][505];
long long DP(int l, int r) {
if (l >= r) return 1;
if (vis[l][r]) return dp[l][r];
vis[l][r] = true;
int mmin = l;
for (int i = l + 1; i <= r; ++i)
if (c[i] < c[mmin... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int w, b;
string s;
w = b = 0;
for (int t = 0; t < 8; t++) {
cin >> s;
for (int i = 0; i < 8; i++) {
if (s[i] == 'Q')
w = w + 9;
else if (s[i] == 'R')
w = w + 5;
else if (s[i] == 'B' || s[i] == 'N')
w = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[444];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int mn = 1111111;
for (int i = 0; i < n; i++) {
int vsum = 0;
for (int j = i; j < n; j++) {
vsum += a[j];
mn = min(mn, abs(360 - 2 * vsum));
}
}
cout << mn... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
int prev = 1e9 + 1;
for (int i = 0; i < n; i++) {
if (max(a[i].fir... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, deque<T> const& v) {
s << '{';
for (int i = 0; i < int(v.size()); i++) s << (i ? "," : "") << v[i];
return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T> const& p) {
retu... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
int n;
string s;
char a[1000007];
int main() {
int t;
scanf("%s", a);
s = a;
n = s.size();
int kh = 0;
long long sol = 0;
for (int i = (4); i < (n); ++i) {
if (s[i - 4] == 'h' && s[i - 3] == 'e' && s[i - 2] == 'a... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 15;
int n, a;
string solve() {
map<int, int> m;
cin >> n;
for (int i = 0, ggdem = n; i < ggdem; i++) cin >> a, m[a]++;
for (int i = 0, ggdem = 20; i < ggdem; i++) {
if ((1 << i) == 2048) {
if (m[1 << i]) return "YES";
return "NO";... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct inter {
int l, r, t;
};
int n, m, s, f;
vector<inter> V;
bool pro(inter a, inter b) { return a.t < b.t; }
int main() {
scanf("%d %d %d %d", &n, &m, &s, &f);
for (int i = 0; i < m; i++) {
inter p;
scanf("%d %d %d", &p.t, &p.l, &p.r);
V.push_back(p);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int maxn = 100000 + 5;
int n, a[maxn], l[maxn], r[maxn];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
l[0] = 1;
r[n - 1] = 1;
for (int i = 1; i < n; i++) {
l[i] = min(l[i - 1] + 1, a[i]);
}
for (int i = n - 2; i >= 0; i--) {
r[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
if (N % 4 == 2 || N % 4 == 3) {
cout << -1 << '\n';
return 0;
}
vector<int> ans(N);
ans[N / 2] = N / 2;
for (int i = 0; i < N / 2; i += 2) {
ans[i] = i + 1;
ans[i + 1] = N - i - 1;
ans[N - i - 1] = N - i - 2;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
long long ar[n];
long long carry = 0;
for (long long i = n - 1; i >= 0; i--) {
ar[i] = (s1[i] + s2[i] - 'a' - 'a' + carry);
if (i !=... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, A, B;
int a[N];
long long f[N], g[N];
long long gao(int p) {
int pos = -1;
for (int i = 1; i <= n; ++i) {
if (a[i] % p == 0)
g[i] = g[i - 1]... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
set<int> ist;
map<string, int> msi;
map<string, string> mss;
map<int, string> mis;
map<int, int> mii;
pair<int, int> pii;
vector<int> v;
vector<pair<int, int> > vv;
int cc[] = {1, -1, 0, 0};
int rr[] = {0, 0, 1, -1};
void LIFT_OFF_SHARK_AP20() {
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, cur = 0;
cin >> t;
string s;
while (t--) {
long long res = 0, cur = 0;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '+') {
cur += 1;
} else {
cur -= 1;
if (cur < 0) {
res +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int mn[1111];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
for (int i = 0; i <= n; i++) mn[i] = 1e8;
for (int i = 0; i <= n; i++) cin >> m;
for (int i = 0; i < m; i++) {
int q, w, c;
cin >> q >> w >> c;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[1000010], s[1000010];
long long b, n, m;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], b += a[i];
sort(a + 1, a + 1 + n);
for (int i = n; i > n / 2; i--) m += a[i];
cout << m * m + (b - m) * (b - m);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
vector<int> v;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
int value = 0;
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) value++;
if (value... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
double x, y, r;
int num;
} a[1005];
bool cmp(Node p, Node q) { return p.r > q.r; }
bool judge(Node u, Node v) {
return (u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y) <
(u.r + v.r) * (u.r + v.r);
}
double cal(Node u) { return u.r * u.r * a... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
const long long mod = 1e9 + 7;
void faster() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const long long M = 10 + 10;
const long long N = 200 * 1000 + 10;
int main() {
faster();
int q;
cin >> q;
while (q--) ... | 0 |
#include <bits/stdc++.h>
int main() {
int k, a, b;
while (~scanf("%d%d%d", &k, &a, &b)) {
int ans = a / k + b / k;
if ((b % k != 0 && a < k) || (a % k != 0 && b < k)) {
printf("-1\n");
} else {
printf("%d\n", ans);
}
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
long long n, x, ans = 0;
cin >> n >> x;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
ve... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
vector<int> a;
for (int i = 0; i < n.size(); i += 2) {
a.push_back(n[i] - 48);
}
sort(a.begin(), a.end());
for (int i = 0; i < a.size() - 1; ++i) {
cout << a[i] << "+";
}
cout << a[a.size() - 1];
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long lar = 1e16;
const long long nlar = -1e16;
const long long INF = LLONG_MAX;
const long long NINF = LLONG_MIN;
const long long mod = 998244353;
const long long N = 1e6 + 100;
long double sqrtBinarySearch(long long num, long long p) {
long long left = 0, righ... | 10 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
std::vector<int> a, b, c;
a.reserve(n);
b.reserve(n);
c.reserve(n);
int mina = 0x7fffffff;
for (int i = 0, x; i < n; i++) {
scanf("%d", &x);
a.push_back(x);
b.push_back(x);
mina = std::min(mina, x);
}
std::sort(a.begin(), ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
template <class T>
void read(T &x) {
char ch;
bool neg = false;
for (ch = getchar(); !isdigit(ch); ch = getchar()) neg = ch == '-';
x = ch - '0';
for (ch = getchar(); isdigit(ch); ch = getchar()) (x *= 10) += ch - '... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int w, b;
double dp[maxn][maxn];
int main() {
scanf("%d%d", &w, &b);
for (int i = 1; i <= w; i++) dp[i][0] = 1.0;
for (int i = 0; i <= b; i++) dp[0][i] = 0.0;
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= b; j++) {
dp[i][j] += ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n % 4 == 0) {
for (int i = 0; i < n - n / 4; i++) cout << 9;
for (int i = 0; i < n / 4; i++) cout << 8;
cout << endl;
} else {
int temp = n / 4 + 1;
for (int... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long powermod(long long x, long long n, long long M) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
long long modinv(long long n, long long p) { return powermod(n, p ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, f;
cin >> n;
vector<int> liked_by(n + 1);
for (int i = 1; i <= n; i++) {
cin >> liked_by[i];
}
int triangle_exist = 0;
for (int i = 1; i <= n; i++) {
int a = i;
int b = liked_by[a];
int c = liked_by[b];
if (a == liked_by... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long a[n + 5][n + 5];
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= n; j++) {
cin >> a[i][j];
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > mass;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
mass.push_back(make_pair(a, b));
}
sort(mass.begin(), mass.end());
int cur = 0;
for (int i = 0; i < n; i++) {
int a = m... | 6 |
#include <bits/stdc++.h>
using namespace std;
void display(vector<int> v1) {
for (int i = 0; i < v1.size(); i++) {
cout << v1[i] << " ";
}
cout << endl;
}
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
using namespace std;
const int MAXN = (int)2e6 + 1000;
long long int fact... | 12 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, k, h;
cin >> n >> k >> h;
long long i, j;
pair<long long, pair<long long, long long>> p[n];
for (i = 0; i < n; i++) {
cin >> p[i].first;
}
for (i = 0; i < ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n;
if (n % 3 != 0) {
cout << n / 3 + 1;
return 0;
} else {
k = 3;
while (n % k == 0) {
k *= 3;
}
cout << n / k + 1;
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4000004;
int l, r, p;
int prime[111], js;
int n, a[N], f[N];
int b[N], ans;
bool cn[111];
void get_prime(int n) {
for (int i = 2; i <= n; ++i) {
if (!cn[i]) prime[++js] = i;
for (int j = 1; j <= js && prime[j] * i <= n; ++j) {
cn[prime[j] * i] ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int S = 0;
int L = 0;
int R = 0;
int maxx = 0;
const int sizee = 3e5 + 5;
int arr[sizee];
int n, k;
void fast() {
ios ::sync_with_stdio(false), cin.tie(0);
cout.tie(0);
}
int N() {
int C = 0;
int re = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == 1) {
+... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, M, X, flag[30], Q;
string T;
map<char, vector<pair<int, int> > > key;
vector<pair<int, int> > shift;
int dist(int x1, int y1, int x2, int y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
void init() {
for (int i = 0; i < 26; i++) {
char c = 'a' +... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)404;
const int ALPHA = 26;
bitset<N> b[ALPHA][N];
char a[N][N];
bitset<N> ans[N];
bitset<N> get(const bitset<N>& b, int len, int shift) {
assert(0 <= shift && shift < len);
return (b >> shift) | (b << (len - shift));
}
int main() {
int n, m, r, c;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long large = 2000000000000000000LL;
bool between(int le, int ri, int v) {
return (le == -1 || v > le) && (ri == -1 || v < ri);
}
int main() {
int n;
vector<string> w;
vector<int> p;
cin >> n;
set<int> s;
set<int>::iterator l = ... | 13 |
#include <bits/stdc++.h>
int main() {
char a[51];
scanf("%s", a);
int len = strlen(a);
int banyak_a = 0;
int bukan_a = 0;
int setengah = len / 2;
for (int i = 0; i < len; i++) {
if (a[i] == 'a') {
banyak_a++;
} else {
bukan_a++;
}
}
if (banyak_a == 1) {
printf("1\n");
} e... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> 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];
}
long long x = 0;
for (int i = 0; i < n; i++) {
x += a[i];
}
sort(b, b + n);
int y = b[n - 1] + b[n - 2... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 8, Base = 12345;
int n, Pre[N][26], Suf[N][26];
bool f[22][N];
char s[N];
long long ans0, ans, gain[N][26], pE[N];
inline void cover(int l, int r, long long d) {
pE[l] += d;
pE[r + 1] -= d;
}
struct Hash {
int mod, h[N], b[N];
void init() {
b... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e7 + 5;
const int M = 500 + 5;
long long mod = 998244353;
long long inf = 1e18;
long double eps = 1e-12;
long double pi = 2 * acos(0);
long long mul(long long a, long long b) {
a %= mod;
b %= mod;
return (a * b) % mod;
}
long long add(long long a, long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
int allHouses = 0;
int lastHouse = 0;
string street;
void precalc() {
for (int i = 0; i < street.size(); ++i)
if (street[i] == 'H') lastHouse = i;
allHouses = std::count(street.begin(), street.end(), 'H');
}
bool isSolution(int k) {
int theEndIdx = 0;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool p[1000001];
vector<int> v;
void sieve() {
for (int i = 4; i <= 1000000; i += 2) p[i] = 1;
for (int i = 3; i <= sqrt(1000000); i += 2) {
if (p[i] == 0) {
for (int j = i * i; j <= 1000000; j += i) p[j] = 1;
}
}
for (int i = 2; i <= 1000000; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 2;
long long INF = 1e17;
long long dp[N][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t, n;
long long a, b;
string r;
cin >> t;
while (t--) {
cin >> n >> a >> b;
cin >> r;
dp[0][0] = 0;
dp[0][1] = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(NULL));
const long double eps = 1e-9;
const int inf = 1e9;
const int mod = 1e9 + 7;
const long long infinity = 2 * 1e18;
struct flow {
private:
struct edge {
int to, c, f, w;
};
vector<vector<int>> g;
vector<edge> e;
int n, m = 0;
vector<bo... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e9 + 7;
const long long INF = (long long)1e18;
long long power(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret *= a;
a *= a;
if (ret >= mod) ret %= mod;
if (a >= mod) a %= mod;
b >>= 1;
}
retu... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int mod = 1e9 + 7;
long long p, k;
vector<int> a;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> p >> k;
int lvl = 0;
while (p != 0) {
long long x = p % k;
while (x < 0) x += k;
a.push_back(x);
p = -(p - x) / k... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i;
cin >> t;
int a[1000] = {0};
int y = t;
while (t--) {
int r;
cin >> r;
int b[r];
for (i = 0; i < r; i++) {
cin >> b[i];
a[b[i]]++;
}
}
for (i = 0; i < 1000; i++) {
if (a[i] == y) cout << i << " ";
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) { re... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 2147483646;
const int mod = 998244353;
int grid[2010];
void solve() {
int n;
cin >> n;
int a = 0;
int b = 0;
int c = 0;
if (n == 1 || n == 4 || n == 2) {
cout << -1 << "\n";
return;
}
a = n / 3;
if (n % 3 == 2) {
b = 1;
a -=... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e7 + 5;
void solve() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
for (long long i = 0; i < N; i++) {
long long x = b + i * a;
double y = ((1.0) * (x - d)) / c;
if (ceil(y) == floor(y) && y >= 0) {
cout << x << "\n";
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
int k1, k2;
int dp[105][105][2];
int recur(int n, int m, int k) {
int sum = 0;
if (!k) {
if (n <= 0 && m <= 0) return 1;
if (n <= 0 && m > 0) return 0;
if (dp[n][m][k] != -1) return dp[n][m][k];
for (int i = 1; i <= min(k1, n); i++)
sum = (sum + re... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int b[100100];
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(a, a + n);
int s = 0;
for (i = 0; i < n; i++)
if (a[i] != b[i]) s++;
if (s > 2)
printf("NO\n");
else
... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<string> vs;
map<pair<int, int>, vector<int> > mapa;
vector<int> adj[1000005];
int used[100005], len[100005];
int main() {
cout.sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
vs.push_back(s);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int MAIN() {
int a, b, c, d, ans = 0;
cin >> a >> b >> c >> d;
ans = ((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d));
cout << ans;
return 0;
}
int lglj = MAIN();
int main() { ; }
| 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.