solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, ans = 0;
cin >> x;
int t = x;
if (x == 1) {
cout << 0 << endl;
return 0;
}
int len = log2(x);
vector<int> ve;
for (int i = len; i >= 0; i--) {
int flag = 0;
if ((x >> (i - 1)) % 2 == 0) {
ve.push_back(i);
x ^= ... | 5 |
#include <bits/stdc++.h>
void nop();
using namespace std;
const int inf = (int)1e9;
const long long infl = (long long)2e18;
const int mod = 1000000007;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
multiset<int> a;
long long ans = 0;
for (int i = 0; i <... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int t[N << 2], lzy[N << 2], a[N];
void push(int v, int l, int r) {
if (lzy[v]) {
t[v] += lzy[v];
if (l != r) {
lzy[v * 2] += lzy[v];
lzy[v * 2 + 1] += lzy[v];
}
lzy[v] = 0;
}
}
void modify(int v, int l, int r, int b, in... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, a1, c1, h2, a2;
cin >> h1 >> a1 >> c1 >> h2 >> a2;
vector<string> res;
while (h2 > 0) {
if (h1 > a2 || h2 <= a1) {
res.push_back("STRIKE");
h2 -= a1;
} else {
res.push_back("HEAL");
h1 += c1;
}
h1 -= a2;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Trie {
int ch[800005][26], Size;
vector<int> val[800005][2];
void clear() {
Size = 1;
memset(ch[0], 0, sizeof(ch[0]));
}
Trie() { clear(); }
void insert(char* s, int id, int v) {
int u = 0, n = strlen(s);
val[u][id].push_back(v);
for (... | 15 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000001];
vector<pair<int, int> > v[10000];
int ma = 0, ma1 = 0, ma2 = 0;
int ans = 0;
int dfs(int x, int co) {
if (v[x].size() == 0) return co;
vector<pair<int, int> >::iterator it = v[x].begin();
vector<pair<int, int> >::iterator it1 = it;
it++;
int a = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
pair<int, int> r[100100];
int lx, cr;
vector<pair<int, int> > p, np;
int main() {
cin >> M >> N;
for (int i = 0; i < N; i++) cin >> r[i].first >> r[i].second;
sort(r, r + N);
p.push_back(make_pair(1, 1));
lx = cr = 0;
while (cr < N) {
if (r[cr].fir... | 17 |
#include <bits/stdc++.h>
using namespace std;
int K[3][3] = {{0, 3, 4}, {3, 0, -1}, {4, -1, 0}};
int a[101];
int main() {
int n, d = 0;
bool ok = true;
scanf("%d", &n);
for (int i = (0), _b = (n); i < _b; ++i) {
scanf("%d", &a[i]);
if (i == 1) {
if (K[a[i] - 1][a[i - 1] - 1] >= 0) {
d += K... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, q, r;
long long qu;
int op;
int main() {
cin >> n >> k >> q;
if (n > k) swap(n, k);
while (k < q) {
op++;
if (k) r = n / k;
if (r < 0) {
r *= -1;
qu += r;
n += r * k;
} else {
qu++;
n += k;
}
if (n ... | 8 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.fi... | 13 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
template <typename T>
void mini(T& x, T y) {
x = min(x, y);
}
template <typename T>
void maxi(T& x, T y) {
x = max(x, y);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b, e / 2);
return power(b * b, e / 2);
}
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long mod_pow(long long b) {
long long a = 2, c = 1000000007;
long long ans = 1;
while (b != 0) {
if (b % 2 == 1) ans = (ans * a) % c;
a = (a * a) % c;
b /= 2;
}
return ans;
}
int main() {
long long n, i, j, k;
scanf("%lld", &n);
long long po... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1LL << 41;
vector<int> kmppre(string& t) {
vector<int> r(t.size() + 1);
r[0] = -1;
int j = -1;
for (int i = 0, qwerty = t.size(); i < qwerty; i++) {
while (j >= 0 && t[i] != t[j]) j = r[j];
r[i + 1] = ++j;
}
return r;
}
const int N ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000;
const int N = 100 * 1000;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> a(n), maxx(n);
for (int i = (0); i < (n); i++) cin >> a[i];
maxx[0] = a[0];
for (int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> c;
vector<long long> st;
long long sum = 0, s = 0;
vector<vector<long long> > Gr;
struct Ver {
Ver() {}
Ver(long long a, long long b, long long c) {
now = a;
pre = b;
dist = c;
}
long long now;
long long pre;
long long dist;
};
vect... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, p[6], res = 1e9;
int main() {
scanf("%d%d%d", &n, &a, &b);
p[4] = p[5] = 1;
do {
int cnt = 1, remain = n;
for (int i = 0; i < 6; i++) {
int currLen = 0;
if (p[i])
currLen = b;
else
currLen = a;
if (remain - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1007;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int t;
int n;
vector<int> G[maxn];
vector<int> a, b;
int ret, nnow = 0;
int dfs(int now, int p) {
if (now == ret) return 1;
int rr = 0;
for (int i : G[now]) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[10005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < 100; i++) b[i] = 30;
b[1] = 31;
b[2] = 28;
b[3] = 31;
b[5] = 31;
b[7] = 31;
b[8] = 31;
... | 4 |
#include <bits/stdc++.h>
char s[300300], in[100100], t[300300];
inline bool disc(char c) {
return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) ||
(c == '>') || (c == '<');
}
int main() {
int n, i, l, sl, j;
bool ok;
while (scanf("%d", &n) != EOF) {
s[0] = '<';
s[1] = '3';
sl = 2... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> l(20);
vector<int> r(20);
char s[100005];
int n, m;
int amt[21][21];
long long mx = 1LL << 60;
int main() {
scanf("%d %d %s", &n, &m, s);
int sz = 1 << m;
vector<long long> dp(sz, mx);
dp[0] = 0;
for (int i = 0; i < n - 1; ++i) {
++amt[s[i] - 'a'][... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
while (cin >> n) {
if (n % 2 != 0)
cout << "0" << endl;
else
printf("%.0lf\n", ceil((n / 4.0)) - 1.0);
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, tot[26], p[maxn];
char s[maxn], t[maxn];
vector<int> pos[26];
int val[maxn];
inline void Add(int x) {
for (; x <= n; x += x & -x) ++val[x];
}
inline int Ask(int x) {
int res = 0;
for (; x; x -= x & -x) res += val[x];
return res;
}
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, D = 350;
int n, w, a, b, mx = 0;
long long coe[N];
vector<int> eve[N];
struct line {
int a;
long long b;
line(int _a = 0, long long _b = 0) : a(_a), b(_b) {}
long long at(int x) { return 1LL * a * x + b; }
double intersect(const line &oth) co... | 22 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long s[n], c[n];
for (long long i = 0; i < n; ++i) cin >> s[i];
for (long long i = 0; i < n; ++i) cin >> c[i];
long long dp1[n];
for (long long i = 0; i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, p, b[50005], a[32], c[32];
int dp[32][32][50000];
int main() {
scanf("%d%d", &n, &p);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
for (int i = 1; i <= n; i++)
if (b[i] < 32) a[++a[0]] = b[i], c[a[0]] = i;
n = a[0];
for (int i = 1; i <= n; i++) dp[i... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int tc;
cin >> tc;
while (tc--) {
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 MOD = 1e9 + 7;
const int MX = 1e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<int> U;
int B[5010], N;
vector<long long> old, dp;
int main() {
cin >> N;
for (int i = 0; i < N; ++i) cin >> B[i];
U = vector<int>(B, B + N);
sort(U.begin(), U.end());
U.erase(unique(U.begin(), U.end()), U.end());
old = vector<long long>(((int)(U).size())... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long n = a + b + 1;
if (a == 0) {
for (int i = n; i > 0; i--) {
cout << i << " ";
}
return 0;
}
if (b == 0) {
for (int i = 0; i < n; i++) {
cout << i + 1 << " ";
}
return 0;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1, M = 1e9 + 7;
int seg[4 * N], n, q, in[N], out[N], lazy[4 * N], rem, v[N], ans, dp[18][N],
depth[N], bef, dp1[N][302], par[N];
vector<int> g[N];
void add(int &a, int b) {
a += b;
if (a >= M) a -= M;
if (a < 0) a += M;
}
void fix(int c, int l,... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int lim = 1e6 + 5;
int b[lim];
void solve() {
string s;
cin >> s;
if (int((s).size()) < 3) {
cout << "Just a legend";
return;
}
int i = 0, j = -1;
b[0] = -1;
while (i < int((s).size())) {
while (j >= 0 && s[i] != s[j]) j = b[j];
i++;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN();
int main() {
int n;
scanf("%d", &n);
int cnt = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
cnt += x;
}
if (n == 1) {
printf("%s", cnt == 1 ? "YES" : "NO");
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000000;
template <typename T>
T read(T& x) {
T f = 1;
x = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
return x *= f;
}
int n;
long long k, ans;
l... | 21 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return (gcd(b, a % b));
}
int com(int m, int n) {
int a[16], b[16];
int cs;
long long e;
n = min(n, m - n);
if (n >= 20) return 2147483647;
for (int i = 1; i <= n; i++) a[i] = m - i + 1, b[i] = i;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
int size(T& a) {
return (int)a.size();
}
template <typename T>
T sqr(T a) {
return a * a;
}
int a[21];
bool w[1010];
int main() {
memset((w), (false), sizeof(w));
w[0] = 1;
int n;
scanf("%d", &n);
for (int i = 1; i < n; ++i) {
for (in... | 15 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, k;
cin >> n >> k;
long long int maxi = 1;
for (long long int i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i <= k) {
maxi = max(maxi, i);
}
if ((n / i) <= k) {
maxi = max(maxi, n / i);
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ans[2000006];
long long lans[30];
long long mod = 1e9 + 7;
priority_queue<pair<int, int> > pq;
int a[26];
string s;
int n, k;
long long mx;
void calc() {
memset(lans, 0, sizeof(lans));
memset(ans, 0, sizeof(ans));
n = s.size();
for (int i = 0; i < n; i++) ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
string second, t, x, y;
int n;
int main() {
cin >> second >> t;
string cur1 = second, cur2 = t;
cin >> n;
cout << second << " " << t << endl;
for (int i = 0; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int x, y;
long long ans = 0;
vector<pair<int, int> > dv;
long long pow2(int p) {
long long rt = 1, cur = 2;
while (p) {
if (p & 1) {
rt *= cur;
rt %= mod;
}
cur *= cur;
cur %= mod;
p >>= 1;
}
return rt;
}
void... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char vet[20];
vector<char> res;
scanf("%d", &n);
scanf("%s", vet);
int i;
for (i = 0; i < n; i++) {
if (vet[i] > '1') {
if (vet[i] == '4') {
res.push_back('2');
res.push_back('2');
res.push_back('3');
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 100005;
struct node {
int num, y;
};
node A[N], B[N];
int a, b;
double len(int y1, int y2) {
return sqrt(1.0 * y1 * y1 + 1.0 * a * a) +
sqrt(1.0 * (y2 - y1) * (y2 - y1) + 1.0 * (a - b) * (a - b));
}
bool cmp(node a, node b) {... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> m(5, vector<int>(5));
void checkRow(int i) {
if (m[i][0] == 4) {
m[i][0] = 0;
for (int k = 1; k <= 4; k++) {
m[i][k] = 0;
}
}
}
void checkCol(int i) {
if (m[0][i] == 4) {
m[0][i] = 0;
for (int k = 1; k <= 4; k++) {
m... | 6 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long int>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vld = vector<long double>;
using pii = pair<long long int, long long int>;
using psi = pair<string, long long int>;
using pci = pair<... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
scanf("%d", &n);
string s;
cin >> s;
int ans = 0;
bool next = true;
int current = 0, multiple = 1;
for (int i = s.size() - 1; i >= 0; i--) {
if (next) {
if (s[i] == '0') {
multiple *= 10;
} else if (s[i] == '1') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int left = 0, up = 0;
if (s.length() % 2) {
cout << -1;
return 0;
}
for (char u : s) {
if (u == 'R')
left--;
else if (u == 'L')
left++;
else if (u == 'U')
up++;
else
up--;
}
if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[200005];
int main() {
int n, i, w, x, s = 0, l = -(1 << 31);
cin >> n;
for (i = 0; i < n; i++) cin >> x >> w, p[i] = make_pair(x + w, x - w);
sort(p, p + n);
for (i = 0; i < n; i++)
if (p[i].second >= l) l = p[i].first, s++;
cout << s;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (islower(s[0])) {
s[0] = toupper(s[0]);
}
cout << s;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void p(long long a[], long long n) {
for (long long i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) {
long long i, j, k, n, m, x, y;
char... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans[100010], cnt = 0;
pair<pair<int, int>, int> a[100010];
pair<int, int> b;
double dis(int x1, int y1, int x2, int y2) {
return (sqrt(abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2)));
}
bool zai(int ji, int x, int y) {
return dis(a[ji].first.first,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m, d;
cin >> n >> m >> d;
vector<long long> a(n, 0);
set<long long> s;
for (long long i = 0; i < n; ++i) {
cin >> a[i];
s.insert(a[i]);
}
map<long long, long lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
long double a[3];
char ch[3] = {'x', 'y', 'z'};
const long double eps = 1e-15;
struct Node {
int form;
int ord[3];
long double x, y, z;
Node(int o0, int o1, int o2, int _form) {
ord[0] = o0;
ord[1] = o1;
ord[2] = o2;
x = a[o0];
y = a[o1];
z =... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int x, u1, v1;
Node(int x = 0, int u1 = 0, int v1 = 0) : x(x), u1(u1), v1(v1) {}
};
int N, M;
vector<int> adj[100005];
bool vis[100005];
int depth[100005], size[100005];
int anc[100005][25];
void dfs(int u) {
vis[u] = 1;
for (int j = 1; j <= 20; j++) {... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int const N = 2 * 1e5 + 2;
int frq[1001];
vector<int> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, mx = -1;
cin >> n;
for (int i = 0; i < (int)(n); ++i) {
int x;
cin >> x;
frq[x]++;
mx = max(mx, frq[x]);
}
cout << n - mx << endl;... | 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;
if (n < 4)
cout << n + 1;
else if (n == 4)
cout << n;
else {
int ans = 4, r = 2, c = 2, ch = 0;
n -= 4;
while (n > 0) {
if (r <= c) {
n -= ... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
const long long int MAX = (long long int)(1e18 + 1);
const long long int MIN = (long long int)(-1e18 - 1);
const long long int mod = (long long int)(... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000], b[100000], c[100000];
int t[100000];
int main() {
for (int i = 0; i < 100000; i++) t[i] = 0;
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%I64d", a + i);
for (int i = 0; i < n; i++) scanf("%I64d", b + i);
if (n == 1) {
prin... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long T = 1;
while (T--) {
long long n;
cin >> n;
vector<vector<long long> > adj(n + 1);
long long r = -1;
for (long long i = 0; i < n - 1; i++) {
long long a, b;
cin >... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, l, r, i, j;
cin >> t;
while (t--) {
cin >> l >> r;
cout << l << " " << 2 * l << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long ara[100010], soso[100010], d, pa[100010];
int tree[100010 * 4], n;
void update(int idx, int b, int e, int p, int v) {
if (p > e || p < b) return;
if (b == e) {
tree[idx] = v;
return;
}
int m = (b + e) >> 1;
update((idx << 1), b, m, p, v);
updat... | 12 |
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int t;
cin >> t;
while (t)
{
long long n, c, have = 0, day = 0, ans;
cin >> n >> c;
vector<long long> a(n), b(n - 1);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n - 1; i++)
{
cin >> b[i];
}
ans =... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Rectangle {
int X0, X1, Y0, Y1;
};
int Get() {
char c;
while (c = getchar(), c < '0' || c > '9')
;
int X = 0;
while (c >= '0' && c <= '9') {
X = X * 10 + c - 48;
c = getchar();
}
return X;
}
char GetDirection() {
char c;
while (c = getch... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int mod1 = 19491001;
const int mod2 = 1526024417;
const int p = 131;
map<pair<unsigned long long, unsigned long long>, int> m;
set<int> se;
unsigned long long Hash1[2000000], Hash2[2000000];
int n, k, g;
int len1, len2;
unsigned long long Pow1, Pow2;
int ans[2000000];... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 80;
struct minion {
int a, b, ind;
bool operator<(const minion &other) const { return b < other.b; }
} minions[N];
int n, k;
int memo[N][N], vis[N][N], vid;
int solve(int i, int cnt) {
if (i == n) return cnt == k ? 0 : -1e9;
int &ret = memo[i][cnt];
... | 17 |
#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 = 2e3 + 10;
const long long int inf = 1e18 + 10;
long long int n, d... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
string s;
cin >> s;
long long n = s.size();
long long a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A') {
a++;
} else if (s[i] == 'B') {
b++;
} el... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
o << "sz = " << vc.size() << endl << "[";
for (const T&... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T mx(T X, T Y) {
if (X < Y)
return Y;
else
return X;
}
int main() {
long long a, b, c, d;
while (cin >> a >> b >> c >> d) {
long long m = mx(3 * a / 10, a - a / 250 * c);
long long v = mx(3 * b / 10, b - b / 250 * d);
if (m < v... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int N;
int A[maxn];
int cnt[maxn][2];
int dp[maxn][maxn];
int ans[maxn];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
memset(cnt, 0, sizeof(cnt));
for (int i = 1; i <= N; i++) {
if (A[i] == 1) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200001];
long long col[200001];
long long compute(long long index, long long flag, long long n) {
if (index == n - 1) return 1;
if (flag) {
return n - index;
} else {
return ((n - index) * (n - index - 1)) / 2;
}
}
int main() {
long long t;
... | 10 |
#include <bits/stdc++.h>
const int P = 998244353;
inline int mul(const int &a, const int &b) { return 1ll * a * b % P; }
inline int sub(int a, const int &b) {
a -= b;
return (a < 0) ? a + P : a;
}
inline int add(int a, const int &b) {
a += b;
return (a >= P) ? a - P : a;
}
int n, a[2001][2001];
int _mul[2001], ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int a[N + 1];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
for (int i = 1; i <= N; i++) {
a[i] += a[i - 1];
}
for (int ans = N; ans >= 1; ans--) {
int sum = 0;
for... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 201;
const int X = 2001;
const int Y = 2001;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
int n;
int n_pages[7];
bool read() {
if (!(cin >> n)) {
return false;
}
for (int i = 0; i < 7; i++) {
cin >> n_pages[i];
}
return tru... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, numStair, numLift, speedLift;
cin >> n >> m >> numStair >> numLift >> speedLift;
vector<int> stair(numStair, 0), lift(numLift, 0);
for (auto &i : stair) cin >> i;
for (auto &i : lift) cin >> i;
int q;
cin >> q;
while (q--) {
int x1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000011;
const int full = (1 << 22) - 1;
int dp[full] = {-1}, a[maxn];
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; ++i) {
cin >> a[i];
dp[full ^ a[i]] = a[i];
}
for (int i = full - 1; i >= 0; --i)
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int chkmax(T &a, T b) {
if (b > a) {
a = b;
return 1;
}
return 0;
}
template <class T>
int chkmin(T &a, T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class iterator>
void output(iterator begin, iterator end, ostr... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 7;
vector<long long> v[MX];
bool vis[2][MX], ans;
string s[2];
long long n, k;
void DFS(bool UD, long long i, long long flood) {
if (s[UD][i] == 'X' || i <= flood || vis[UD][i]) return;
if (i >= n - k) {
ans = 1;
return;
}
vis[UD][i] = 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 MOD = 1e9 + 7;
const int N = 2e6 + 5;
int n, k;
i64 pwr[N], ant[N];
int mobius[N];
static i64 expow(i64 base, i64 exp) {
i64 ant(1);
for (; exp > 0; exp /= 2) {
if (exp % 2) ant = ant * base % MOD;
base = base * base % MOD;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int t2[27], u2[27];
int s2[27];
int main() {
string s;
cin >> s;
for (char c : s) s2[c - 'a']++;
string t, u;
cin >> t >> u;
for (char c : t) t2[c - 'a']++;
for (char c : u) u2[c - 'a']++;
int min1 = (int)1e9;
int max1 = (int)-1e9;
for (int x = 0; x <= 2... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
void solve() {
long long n;
cin >> n;
long long div = 1;
long long ans = 0;
for (long long i = 1; i <= 60; i++) {
ans += (n / div);
div = div << 1;
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false... | 6 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int deg[100001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, s;
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
deg[u]++;
deg[v]++;
}
int l = 0;
for (int u = 1; u <= n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1000000], x, r;
int main() {
cin >> n;
r = n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == r) {
cout << x << " ";
r--;
while (a[r] == 1) {
cout << r << " ";
r--;
}
cout << endl;
} else {
a[x]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int limN = 18;
const int limB = 1 << limN;
int N;
double mat[limN][limN];
bool usd[limN][limB];
double probWMemo[limN][limB];
double probW(int pos, int msk = (1 << N) - 1) {
if (msk == 1) return 1.0;
if ((msk & 1) == 0) return 0.0;
if (usd[pos][msk]) return prob... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, nxt, flow;
} e[2000005];
int head[300000], cnte, cur[300000];
void insert(int u, int v, int f) {
e[cnte] = (edge){v, head[u], f};
head[u] = cnte++;
}
void adde(int u, int v, int f) {
insert(u, v, f);
insert(v, u, 0);
}
int g[300000], d[300000... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long n;
cin >> n;
long arr[n];
for (long i = 0; i < n; ++i) cin >> arr[i];
long psum[n];
psum[0] = arr[0];
for (long i = 1; i < n; ++i) psum[i] = psum[i - 1] + arr[i];
long dp[n];
for (long i = 0; i < n; ++i... | 14 |
#include <bits/stdc++.h>
using namespace std;
string add(string& s) {
string s1 = "";
int n = s.size();
int more = 1;
for (int i = n - 1; i >= 0; i--) {
int val = (s[i] - '0') + more;
if (val >= 10) {
more = 1;
val = 0;
} else {
more = 0;
}
s1 += (char)('0' + val);
}
if... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c;
scanf("%d%d", &n, &c);
int ans = 0;
int last = 0;
int tmp;
while (n--) {
scanf("%d", &tmp);
if (tmp - last <= c) {
last = tmp;
ans++;
} else {
last = tmp;
ans = 1;
}
}
printf("%d\n", ans);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i;
scanf("%d", &t);
double r, a, b;
for (i = 0; i < t; i++) {
cin >> a >> b;
if (a < 0.5) {
if (b > 0.5)
printf("0.500\n");
else
printf("1.000\n");
continue;
}
if (a >= 4 * b)
r = 0.5 + 0.5 ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + ch - '0', ch = getchar();
return f * s;
}
long long a, b, c, d;
int m... | 13 |
#include <algorithm>
#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <cmath>
//#include <bits/stdc++.h>
#include<queue>
#include <iomanip>
#include <climits>
#include <cstring>
#include <unordered_map>
using namespace std;
#define ff first
#define ss second
#define int long... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.1415926535897932384626433832795028841;
map<string, int> ssol;
void checkAdd(string vs) {
if (ssol.find(vs) != ssol.end()) {
return;
}
ssol[vs] = 1;
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
typedef struct alphabet {
char ch;
int freq;
} alpha;
int main() {
int n, j, i, min_index = 0, min = 266, flag = 1;
string s;
cin >> n >> s;
if (n % 4 != 0) {
cout << "===" << endl;
return 0;
}
alpha u[4];
u[0].ch = 'A';
u[1].ch = 'C';
u[2].ch ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n;
bool vis[maxn];
vector<int> G[maxn];
int bfs(int d[], int k) {
memset(vis, 0, sizeof(vis));
queue<int> q;
int res = k, mx = 0;
q.push(k);
d[k] = 0;
vis[k] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3], b[3];
int sum = 0, sumn = 0, temp;
for (int i = 0; i < 3; i++) cin >> a[i];
for (int i = 0; i < 3; i++) cin >> b[i];
for (int i = 0; i < 3; i++) {
temp = a[i] - b[i];
if (temp > 0) {
sum = sum + temp / 2;
}
if (temp < 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, block, R, L, k, N, i, j, hooh, a[200001], Right[501],
m1[1000001], c[1000001];
vector<pair<pair<int, int>, int> > t[501];
long long cnt, sum, ans[200001];
int in() {
int xxxx;
scanf("%d", &xxxx);
return xxxx;
}
void process() {
for (j = 1; j <= 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
int main() {
int n, p1 = 0, p2 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (!a[i]) i--, n--;
if (a[i] == 1) p1 = i;
}
n++;
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
if (!b[i]) i--, n--... | 5 |
#include <bits/stdc++.h>
using namespace std;
int grps = 0;
int current_grp[2000009], grp_size[2000009], freq[2000009];
vector<int> v, uniques, fre_v[2000009], unique_f;
vector<vector<int> > fgrps, grops;
void divide_by_frequency(vector<int> v) {
uniques.clear();
unique_f.clear();
fgrps.clear();
for (int i = 0;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int array[n];
for (int i = 0; i < n; i++) {
cin >> array[i];
}
sort(array, array + n);
for (int i = 1; i < n; i++) {
if (array[i] > array[i - 1]) {
cout << array[i] << endl;
return 0;
}
}
cout << "NO" <... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.