solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const long long MOD = 1000000007;
int main() {
int n;
cin >> n;
vector<int> fem(370, 0);
vector<int> mal(370, 0);
for (long long i = 0; i < (int)n; i++) {
char c;
int a, b;
cin >> c >> a >> b;
for (int j =... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
;
}
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, cons... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int getChar() {
static char buf[1 << 16];
static int pos = 0, size = 0;
if (pos == size) {
pos = 0;
size = (int)fread(buf, siz... | 20 |
#include <bits/stdc++.h>
const long long int M = 998244353;
const long long int inf = 1e18 + 5;
using namespace std;
long long int power(long long int a, long long int n, long long int p) {
long long int res = 1;
a = a % p;
while (n > 0) {
if (n & 1) res = (res * a) % p;
n = n >> 1;
a = (a * a) % p;
... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 111031;
int tests;
string st1, st2;
int get_val(char c) {
if (c >= '0' && c <= '9') return c - '0';
return c - 'a' + 10;
}
long long parse_num(string st) {
long long res = 0;
for (int i = 0; i < st.size()... | 21 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > Q;
pair<int, int> ar[200005];
set<int> vals;
map<int, int> freq;
long long getmin() { return *vals.begin(); }
void add(int x, int v) {
if (freq[x] == 0) vals.insert(x);
freq[x] += v;
if (freq[x] == 0) vals.erase(x);
}
int main() {
int... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[305], g[305][305], h[305], f[305];
long long DP[100020];
int n, q, t, x, y, i, j, z[305];
void go(int p, int u, int tmp) {
if (f[u]) {
cout << 0 << endl;
exit(0);
}
f[u] = 1;
int ans = 0;
for (int i = 1; i <= n; i++)
if (i != u && i != p && g[u][... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 1;
bool visit[maxn] = {false};
vector<int> vc;
int main() {
int i, j, k;
int n;
scanf("%d", &n);
while (n--) {
scanf("%d", &k);
visit[k] = true;
}
n = maxn - 1;
int cnt = 0;
for (i = 1; i <= n / 2; ++i) {
if (visit[i]) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
string ter(int n) {
if (!n) return "";
return ter(n / 3) + string(1, n % 3 + '0');
}
int main() {
int a, c;
scanf("%d %d", &a, &c);
string A = ter(a);
string C = ter(c);
string B;
while (A.size() < C.size()) A = "0" + A;
while (C.size() < A.size()) C = "0"... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int id(int x) { return (x < 0) ? (200000 - x) : x; }
int ori(int x) { return (x > 200000) ? 200000 - x : x; }
vector<long long int> cnt(N, 0);
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int MOD = 1e9 + 7;
int n, q, k;
int a[N][10], t[4 * N][32];
void update(int id, int x, int y, int l) {
if (x > l or y < l) return;
if (x == y) {
for (int i = 0; i < (1 << (k - 1)); i++) {
int v = 0;
for (int j = 0; j < k; j++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unsigned long long arr[n];
unsigned long long res[n];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
if (arr[i] % 2 != 0) {
int z = arr[i] + 1;
res[i] = z;
} else
res[i] = arr[i];
}
for (int i = 1; i <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
const int M = 1 << 12;
const int mod = 1000000007;
struct E {
int to, next;
};
bool flag;
struct Tree {
int n, x, y, num;
E mem[N << 1];
int head[N], bit[N], sz[N], son[N][N];
inline void add(int x, int y) {
num++;
mem[num].to = y;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 9, p = 998244353;
long long f[N] = {0, 0, 0, 24, 4, 240, 204, 1316,
2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404};
const long long a[] = {0, 0, 4, 8, -1, 16, -10, 4, -12,
... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int l;
cin >> l;
string a;
cin >> a;
int n = a.size();
if (n % l) {
int m = ceil((1.0 * n) / l);
string x(m * l, '0');
x[0] = '1';
for (int i = l; i < m * l; i++) {
x[i] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dp[19][4][2];
long long solve(long long pos, long long cnt, bool tight, string first) {
if (pos == first.size()) {
return 1;
}
if (dp[pos][cnt][tight] != -1) {
return dp[pos][cnt][tight];
}
long long ret = 0;
long long en;
if (tight == 1) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int inti(int a, int b) { return ((a - b) < 0 ? (b - a) : (a - b)); }
int main() {
int x, y, z, t1, t2, t3;
cin >> x >> y >> z >> t1 >> t2 >> t3;
if ((inti(x, y)) * t1 < (3 * t3 + t2 * (inti(x, z) + inti(x, y))))
cout << "NO";
else
cout << "YES";
return 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(
(unsigned int)chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b) {
long long result = 1;
while (b > 0) {
if (b % 2 == 1) {
result *= a;
}
a *= a;
b /= 2;
}
return result;
}
long l... | 9 |
#include <bits/stdc++.h>
using namespace std;
int arr[100000];
map<int, bool> mp;
long long solve(int n, int l, int k) {
long long sum = 0, mx = LLONG_MIN;
set<pair<int, int> >::iterator it;
set<pair<int, int> > s1, s2;
for (int i = 0; i < n; i++) {
if (arr[i] >= 0)
sum += arr[i];
else if (k == 0)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int ms = 1e7;
int trie[ms][2], cnt[ms][2], sz = 0, a[ms], p[ms];
void insert(string s) {
int node = 0;
for (int i = 0; i < 64; i++) {
if (trie[node][s[i] - '0'] != -1) {
cnt[node][s[i] - '0']++;
node = trie[node][s[i] - '0'];
} else {
tri... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1000006;
long long n, a[N], f[N], h[N], x, y, ans;
map<long long, int> m;
vector<long long> v[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[i] = ((long long)rand() << ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 100005, inf = 1000000005, MOD = 1000000007;
const long long INF = 1000000000000000005LL;
int ile[MN], co[MN];
long long dp[2][MN];
long long koszt;
int n;
inline void wrzuc(int x) {
x = co[x];
koszt += ile[x];
++ile[x];
}
inline void wyrzuc(int x) {
x... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, i, ans, flag = 0;
map<char, char> mp;
string st, st1;
cin >> n >> st;
for (i = '1'; i <= '9'; i++) {
cin >> a;
mp[i] = a + 48;
}
st1 = st;
for (i = 0; i < st.size(); i++) {
char ch = st[i];
char best = mp[ch];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
vector<int> v[200500], ans;
int n, m, pre[200500]... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int maxN = 1e3 + 10;
const int oo = 1e9 + 10;
int n, m, Q, a[maxN][maxN], p[maxN][maxN], res = oo, d[maxN];
pair<int, int> q[maxN];
int ok[maxN][maxN];
bool vst[maxN];
vector<pair<int, int> > adj[maxN];
struct iii {
int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum = 0, res = 0, n, k, i, item, answer = -1;
cin >> n >> k;
for (i = 0; i < n; ++i) {
cin >> item;
if (item > 8) {
sum += 8;
res += (item - 8);
} else {
sum += item;
int t = 8 - item;
if (res > t) {
s... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool aaa(string s, string l, string m) {
int b = -1;
for (int i = 0; i < s.size(); i++) {
int d = 0;
if (b == -1) {
if (l.size() + i == s.size() + 1) {
return false;
}
for (int j = 0; j < l.size() && d == 0; j++) {
if (s[i + j] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void sci() {}
template <typename... Args>
void sci(int &x, Args &...args) {
scanf("%d", &x);
sci(args...);
}
const int N = 5e3 + 10;
const int mod = 1e9 + 7;
int a[N], f[N][N << 1];
int c[N], inv[N];
int ans[N << 1];
int n;
int ksm(int a, int b) {
int ret = 1;
while... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t, a, b, c;
int main() {
cin >> t;
while (t--) {
cin >> a >> b >> c;
int ans = 0x7fffffff;
int A = -1, B = -1, C = -1;
for (int aa = 1; aa <= 2 * a; aa++) {
for (int bb = aa; bb <= 2 * b; bb += aa) {
for (int i = 0; i <= 1; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int n, m;
int a[maxn];
char mp[10][maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= 4; i++) {
if (i <= 2) {
cout << 'a';
for (int j = 1; j <= (n - 1) / 2; j++) {
printf("%c", ('a' + (i + j - 1) % 24)),
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a, b;
int l;
long long t, m;
int n;
long long term(int i) { return a + (i - 1) * b; }
bool is_ok(int x) {
long long sum = (term(l) + term(x)) * (x - l + 1) / 2;
return (sum <= m * t && term(x) <= t);
}
int solve() {
int beg = l;
int fi = 1000000000;
whil... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int vis[100005], lowPrime[100005], prime[100005], cnt, p, pos;
struct node {
int x, y;
} e[100005];
void getPrime() {
for (long long i = 2; i < 100005; i++) {
if (prime[i] == 0) {
lowPrime[i] = i;
for (long long k = i * i; k < 100005; k ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ar[10000], i;
long long int sum = 0;
map<int, int> mp;
cin >> n;
for (i = 0; i < n; i++) {
cin >> ar[i];
}
for (i = 0; i < n; i++) {
if (mp.find(ar[i]) != mp.end()) {
while (mp.find(ar[i]) != mp.end() && ar[i] > 0) {
a... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(const T &x) {
return x * x;
}
template <typename T>
T my_abs(const T &x) {
return x < 0 ? -x : x;
}
const int INF = (int)1e9;
const long long LINF = (long long)4e18;
const long double EPS = 1e-9;
const long long MOD = (int)1e9 + 7;
const int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i = 3;
cin >> n;
while (n % i == 0) i *= 3;
cout << (n / i) + 1 << endl;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
long... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (a > b) swap(a, b);
int diff = b - a;
int q = diff / 10;
int rem = diff % 10;
if (rem != 0) ++q;
cout << q << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
basic_string<int> wins[12345];
int sell[12345], win[12345];
bool used[5005];
int pows[2001][1234];
int ans[1234];
int tmp[1234];
void reg(int* tmp) {
for (int j = 0; j < 1233; j++) {
tmp[j + 1] += tmp[j] / 10;
tmp[j] %= 10;
}
}
void add(int i) {
for (in... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
long long a[MAX];
long long sum[MAX];
int main() {
ios::sync_with_stdio(false);
long long N, ret = 0;
cin >> N;
for (int i = 0; i < N; ++i) cin >> a[i];
sort(a, a + N, greater<long long>());
for (int i = 1; i < N; ++i) {
ret += a[i] *... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
long long t, n, i, j, k, p, l, mn = 0, mx = 0, m;
string a, b;
scanf("%lld", &t);
while (t--) {
v.clear();
scanf("%lld", &n);
cin >> a >> b;
int sz = b.size();
for (int i = b.size() - 1; i >= 0; i--) {
if (... | 5 |
#include <bits/stdc++.h>
long long read() {
long long res = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') flag = -1;
ch = getchar();
}
while (isdigit(ch)) res = res * 10 + ch - 48, ch = getchar();
return res * flag;
}
void print(long long x) {
if (x < 0) putchar('-'), x =... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 1;
const double pi = acos(-1.0);
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
char a[n + 1][m + 1];
for (long long i = 0; i < n;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int si = 0, n, x, sp = 0, nri = 0, mn = 1000;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x % 2 == 0) {
sp += x;
} else {
nri++;
si += x;
if (x < mn) mn = x;
}
}
if (nri == 0) {
cout << 0;
ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, res = 0, i, j;
cin >> n;
for (i = 1; i < n; ++i) {
for (j = i + 1; j < n; ++j) {
int hy = i * i + j * j;
int root = sqrt(hy);
if (root * root == hy and root <= n) res += 1;
}
}
cout << res;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e14;
const long long N = 3e3 + 1;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
long long a[N], b[N], used[N], n, m, k, x, y, z, h, cnt, ans;
string s, t, TEQ = "AVMHIUOWXTY";
pair<long long, long long> p[3];
int main() {
ios_base::sy... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 51123987;
const int maxn = 152;
const int maxs = 5005;
const int maxa = 52;
string st;
int f[maxs][maxa][maxa];
int P[maxn][maxn];
int la[maxn], lb[maxn], lc[maxn];
int Q[maxs];
int n, ret, Qs = 0, Ps = 0;
inline void Add(int &x, int y) {
x += y;
if (x >... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const ui... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int ocho = a / 2;
if (ocho > 18 || (ocho > 17 && (a % 2 != 0))) {
cout << -1 << '\n';
return 0;
}
string resp;
for (int i = 0; i < ocho; ++i) {
resp += '8';
}
if (a == 1)
resp += '4';
else if (a % 2 != 0)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ui = unsigned int;
using ii = pair<int, int>;
using ull = unsigned long long;
using vi = vector<int>;
using vii = vector<ii>;
using llp = pair<ll, ll>;
const ll MAXN = 1e3 + 100, MAXM = 100 + 100, LOG_MAXN = 20, MAXVAL = 2e6 + 100,
MOD =... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> v;
int numOfDigits(int n) {
int ret = 0;
while (n > 0) {
n = n / 10;
ret++;
}
return ret;
}
int sumOfDigits(int n) {
int ret = 0;
while (n > 0) {
int a = n % 10;
n = n / 10;
ret += a;
}
return ret;
}
void... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const long long inf = 1e18 + 5;
const int offset = 3000;
int main() {
int n;
scanf("%d", &n);
int arr[55], dp[55][2];
for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
dp[n][1] = arr[n];
dp[n][0] = 0;
for (int i = n - 1; i > 0; i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, s, e;
long long x[N], a[N], b[N], c[N], d[N];
long long dp[2][N + N][5];
inline void assign(int idx, int tmp1, int tmp2, long long val) {
if (abs(tmp1 - tmp2) > 2 || tmp1 < 0 || tmp2 < 0) return;
dp[idx & 1][tmp1][tmp1 - tmp2 + 2] = val;
}
inl... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int n, ans, top, ttt;
int a[100100], d[100100], tot[100100], p[100100];
int main() {
while (scanf("%d", &n) != EOF) {
memset(tot, 0, sizeof(tot));
top = 0;
d[0] = 0;
a[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i])... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a, d, t[100100], v[100100];
double ans[100100];
int main() {
scanf("%d %d %d", &n, &a, &d);
for (int i = 0; i < n; i++) scanf("%d %d", &t[i], &v[i]);
for (int i = 0; i < n; i++) {
double tt = v[i] * 1.0 / a;
double dt = a * tt * tt / 2;
if (d > dt)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
struct vec {
long long x, y;
vec() {}
vec(long long x, long long y) : x(x), y(y) {}
vec operator-(const vec &v) const { return vec(x - v.x, y - v.y); }
long long operator*(const vec &v) const { return x * v.y - y * v.x; }
};
int p[maxn];
i... | 23 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
return a * b / gcd(a, b);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long int n, t;
cin >> n >> t... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> d = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
void bfs(vector<vector<int>> arr, vector<vector<long long>> &dist, int n,
int m) {
queue<pair<int, int>> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 314000000;
int n, m, deg[100005];
long long dist[100005], mx[100005];
vector<int> g[100005];
struct Edge {
int id;
long long cnt;
vector<int> g;
} e[100005];
vector<int> G[100005];
int dfn[100005], low[100005];
int instk[100005], scc[100005];
int... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long T, N, M;
set<long long> s;
void pre() {
long long sum = 1;
long long valor = 1;
long long sumA = 1;
s.insert(0);
s.insert(2);
int i = 2;
while (sum * 2 + 1 <= 1000000000) {
sum = sum + i;
s.insert(sum * 2 + valor);
valor = sum;
i++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) {
if (vi != v.begin()) os << ", ";
os << *vi;
}
os << "}";
return os;
}
template <typename ... | 22 |
#include <bits/stdc++.h>
inline int read() {
int x = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x;
}
const int N = 210;
int a[N], c[N], pre[N], lst[N];
struct Graph {
const int inf = 1073741823;
static const int N = 210, M... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2][505][505];
long long w[505];
long long n, m, b, mod;
int32_t main() {
cin >> n >> m >> b >> mod;
for (long long i = 1; i <= n; i++) {
cin >> w[i];
}
for (long long i = 0; i <= m; i++) {
for (long long j = 0; j <= b; j++) {
dp[0][i][j] =... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8;
const int MAXR = 1;
const int MAXC = 1;
const int MAXBITS = 64;
const int INF = (int)1e9;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
priority_queue<int, vector<int... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, next;
} road[100005 * 2];
struct nodd {
int max1, max2, num;
} msg[100005];
int m, n, d, start[100005], tot = 0, f[100005];
bool mark[100005];
void build(int x, int y) {
tot++, road[tot].x = x, road[tot].y = y, road[tot].next = start[x];
star... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct fenwick_tree {
vector<int> t;
int n;
fenwick_tree(int nn) : t(nn) { n = nn; }
fenwick_tree(const vector<int>& a) : fenwick_tree((int)a.size()) {
for (unsigned i = 0; i < a.size(); i++) inc(i, a[i]);
}
int sum(int r) {
int result = 0;
for (; r ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c;
cin >> a >> b >> c;
long long ans = abs(a - b) + abs(a - c) + abs(b - c);
cout << max(0ll, ans - 4) << "\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int xd1(int i, int n1, int n2) {
if (n1 == n2) {
return n1;
}
cout << '?' << ' ' << i << ' ' << n1 << ' ' << i << ' ' << (n1 + n2) / 2
<< endl;
int t1;
cin >> t1;
if (t1 == -1) {
exit(0);
}
if (t1 % 2 == 1) {
return xd1(i, n1, (n1 + n2) / ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<long long>> A;
long long n;
cin >> n;
long long N[n];
for (long long i = 0; i < n; i++) {
cin >> N[i];
}
A.resize(1);
A[0].push_back(N[0]);
for (long long i = 1; i < n; i++) {
if (*(A[0].end() - 1) < N[i])
A[0].push... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
return os << pai.first << ' ' << pai.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0, _i = (((int)(v).size())); i < _i; i++) c... | 0 |
#include <bits/stdc++.h>
using namespace std;
char S[(long long)1e5 + 2];
int main() {
int N, M;
scanf("%d ", &M);
fgets(S, (long long)1e5 + 2, stdin);
N = strlen(S) - 1;
S[N] = 0;
int k = 0;
for (k = 1; k <= 26; k <<= 1)
;
k >>= 1;
int i = -1;
for (i = -1; k; k >>= 1)
if (i + k < 26) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
vector<long long> a;
long long BSRight(long long x) {
long long l = 0, r = a.size() - 1, mid, vt = 1003332;
while (l <= r) {
mid = (l + r) / 2;
if (a[mid] < x)
l = mid + 1;
else {
if (a[mid] == x)... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long ans = n;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
n /= i;
ans += n;
}
}
a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int col[100005][2], par[100005];
int t[100005][2];
int vis[100005];
vector<vector<int> > adj;
vector<int> P, Q;
int N, M, K;
int ctr;
void init() {
for (int i = 0; i <= N; ++i) par[i] = i;
}
int find(int u) { return (par[u] == u ? u : (par[u] = find(par[u]))); }
void dfs(... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100003;
int n, m;
struct triple {
int x, y, k;
triple(int a, int b, int c) : x(a), y(b), k(c) {}
};
vector<triple> queries;
int a[MAXN], b[MAXN];
int tree[4 * MAXN];
int get(int tr[4 * MAXN], int pos, int needPos, int lcur, int rcur) {
if (tr[pos] >= ... | 11 |
#include <bits/stdc++.h>
using namespace std;
string num(int n) {
string s = "";
while (n) {
s = (char)(n % 3 + '0') + s;
n /= 3;
}
return s;
}
int calc(int c, int a) {
string s2 = num(a);
string s1 = num(c);
string resp;
while (s2.size() < s1.size()) s2 = '0' + s2;
while (s2.size() > s1.size(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int read() {
int kkk = 0, x = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') c = getchar(), x = -1;
while (c >= '0' && c <= '9')
kkk = (kkk << 3) + (kkk << 1) + (c - '0'), c = getchar();
... | 10 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT
using ll = long long;
using ii = pair<in... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long binexp(long long a, long long b, long long m) {
long long res = 1;
a = a % m;
while (b) {
if (b & 1) res = (a * 1ll * res) % m;
a = (a * 1ll * a) % m;
b >>= 1;
}
return res;
}
struct point {
long double x, y;
point(long double x, long dou... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
int n;
cin >> S >> n;
int Size = S.size();
if (Size % n != 0) {
cout << "NO";
return 0;
}
int Sub = Size / n;
for (int i = 0; i < Size; i++) {
if (S[i] != S[(i / Sub) * Sub + Sub - 1 - (i % Sub)]) {
cout << "NO";
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p);
template <class T>
ostream &operator<<(ostream &os, vector<T> &v);
template <class T>
ostream &operator<<(ostream &os, set<T> &v);
template <class T1, class T2>
ostream &operator<<(ostream &os,... | 15 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#define _USE_MATH_DEFINES
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 4;
int n, m, q;
set<pair<int, int>> st;
multiset<int> ss, tt;
char c[MAXN][MAXN];
int d[MAXN][MAXN], dn[MAXN][MAXN], ri[MAXN][MAXN], ans[MAXN];
pair<int, int> query[MAXN];
pair<int, int> get(int x, int y) {
auto it = st.lower_bound({x, y});
int l,... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, q;
scanf("%d", &n);
scanf("%d", &p);
scanf("%d", &q);
string s;
cin >> s;
bool done = false;
int i = 0;
while (i <= n && !done) {
if ((n - i) % q == 0) {
printf("%d\n", i / p + (n - i) / q);
int j = 0;
for (int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long turtle(long long a, long long b) {
long long ret = 1, tmp = a;
while (b) {
if (b & 1) ret = ret * tmp % 998244353;
tmp = tmp * tmp % 998244353;
b >>= 1;
}
return ret;
}
long long inv[5005], n, m, k, st[5005], cnt, mi[5005];
bool u[5005];
long l... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
const int PI = acos(-1.0);
int main() {
double x, y;
scanf("%lf%lf", &x, &y);
double r = sqrt(x * x + y * y);
if (r - (int)r < 1e-6)
printf("black\n");
else if (x == 0 || y == 0)
printf("black\n");
else {
if (x * y > 0) {
... | 5 |
#include <bits/stdc++.h>
int main() {
const int N = 26;
std::vector<std::pair<long, long> > countVec(N);
for (int p = 0; p < N; p++) {
countVec[p].first = 0;
countVec[p].second = p;
}
std::string word;
getline(std::cin, word);
int k;
scanf("%d\n", &k);
for (int p = 0; p < word.size(); p++) {
... | 4 |
#include <bits/stdc++.h>
bool v[1000020];
int n;
void F(int x) {
v[x] = 1;
if (x == 1) {
printf("0 1");
return;
}
if (v[n + x >> 1])
F(x >> 1);
else
F(n + x >> 1);
printf(" %d", x);
}
int main() {
scanf("%d", &n);
if (n & 1)
puts("-1");
else
F(0);
}
| 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 50000 + 5;
int N;
double suf[maxN];
struct songTp {
int l, p;
bool operator()(const songTp &a, const songTp &b) const {
return a.l * a.p * (100 - b.p) > b.l * b.p * (100 - a.p);
}
} song[maxN];
int main() {
scanf("%d", &N);
for (int i = 1; i <... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int a[N];
int dfs(int l, int r, int d) {
if (d == -1) return 0;
int i = l;
for (; i <= r; i++) {
if (a[i] & (1 << d)) break;
}
if (i == l || i == r + 1) return dfs(l, r, d - 1);
return min(dfs(l, i - 1, d - 1) + r - i, dfs(i, r, d - 1) + i... | 13 |
#include <bits/stdc++.h>
using namespace std;
char O[15][15];
void Wolves(int n, int m) {
int ans = 0, an = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (O[i][j] == 'W') {
if (i != 0 && O[i - 1][j] != '.' && O[i - 1][j] != 'W') ++an;
if (i != n - 1 && O[i + 1][j] != '.... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
namespace SegmentTree {
typedef struct Node *pnode;
pnode null;
struct Node {
int cnt;
pnode l;
pnode r;
};
void seed() {
null = new Node();
null->cnt = 0;
null->l = null;
null->r = null;
}
void pointUpdate(pnode &u, int x, int v, i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 30025, Mmax = 310005;
int S, D, weapon[Nmax], K, N, M, Nodes, i;
class Floow {
vector<int> v[Nmax];
int go[Mmax], c[Mmax], e = 0, dist[Nmax];
int taken[Nmax], used[Nmax];
bool bfs() {
memset(dist, -1, sizeof(dist));
queue<int> q;
dist[S]... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a[100007];
int main() {
int n, l, x, y;
scanf("%d %d %d %d", &n, &l, &x, &y);
int b, g;
b = g = 0;
for (int i = 0; i <= n - 1; ++i) {
scanf("%d", a + i);
if (binary_search(a, a + i, a[i] - x)) b = 1;
if (binary_search(a, a + i, a[i] - y)) g = 1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4 + 1, maxk = 200 + 1, inf = 1e9;
int n, k, a[maxn], dp[maxn][maxk][4][2];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < maxn; i++) {
for (int j = 0; j < maxk; j++) {
for (int t1 = 0; t... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a[110000];
vector<int> aa;
map<int, int> mp;
int d[140000];
int lowbit(int x) { return (x & (x - 1)) ^ x; }
void add(int x, int y) {
int i;
for (i = x; i <= (1 << 17); i += lowbit(i))
if (y < d[i]) d[i] = y;
}
int get(int x) {
int i, ans;
ans = 2000000000;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 15000;
const int maxn = 55;
const int MXFLOW = 1e6;
struct edge {
int a, cup, flow;
};
int s, t, n, m;
int qa[N], qb[N], len[N];
vector<int> d[N];
vector<edge> edges;
void add_edge(int a, int b, int cup) {
edge x1 = {b, cup, 0};
edge x2 = {a, 0, 0};
d[... | 16 |
#include <bits/stdc++.h>
const int MXN = 5e5 + 100;
const int MOD = 1e9 + 7;
using namespace std;
int n, m, k, fus[MXN];
map<long long, vector<pair<int, int> > > h;
long long c[MXN], pw2[MXN], ans, conn;
int F(int x) { return x == fus[x] ? x : fus[x] = F(fus[x]); }
int main(int argc, char const* argv[]) {
ios_base::s... | 14 |
#include <bits/stdc++.h>
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 5e1 + 5;
const double eps = 1e-9;
using namespace std;
int a[MAXN], w[MAXN][MAXN], dp[MAXN][MAXN][MAXN][MAXN];
int dfs(int i, int j, int l, int r) {
if (j > r || i + j - 1 < l || l > r) return dp[i]... | 17 |
#include <bits/stdc++.h>
using namespace std;
int c[100001];
list<int> p;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) scanf("%d", c + i);
sort(c, c + n);
n = unique(c, c + n) - c;
for (int i = 0; i < n; ++i) p.push_back(c[i]);
int a, b;
int res = 0;
cin >> a >> b;
while (a > b) {
i... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.