solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec;
int n, m;
cin >> n >> m;
for (int x, i = 0; i < n; i++) {
cin >> x;
vec.push_back(x);
}
sort(vec.begin(), vec.end());
cout << vec[n - m];
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long p;
int k;
int cnt = 0;
int ans[107];
int get() {
int x = p % k;
if (x < 0) x += k;
return x % k;
}
int main() {
scanf("%lld%d", &p, &k);
while (p != 0) {
++cnt;
ans[cnt] = get();
p -= get();
p /= (-k);
}
printf("%d\n", cnt);
for (in... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
inline unsigned long long nim... | 26 |
#include <bits/stdc++.h>
using namespace std;
int num[30], len;
long long dp[30][2550][50];
int a[50], has[2520];
int gcd(int a, int b) {
if (!b)
return a;
else
return gcd(b, a % b);
}
int llcm(int a, int b) { return a / gcd(a, b) * b; }
long long dfs(int pos, int mod, int lcm, int limit) {
if (pos < 0) r... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
long long int INF = 1e18 + 10;
long long int MOD = 998244353;
long long int mod = 1e9 + 7;
inline long long int add(long long int a, long long int b, long long int m) {
if ((a + b) >= m) return (a + b) % m;
return a + b;
}
inline lo... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> final;
void seive(int n) {
vector<bool> prime(n + 1, true);
prime[0] = false;
prime[1] = false;
for (int i = 2; i <= (long long int)sqrt(n); ++i) {
if (prime[i]) {
for (int j = i * i; j <= n; j += i) prime[j] = false;
}
}
for (int i = 2... | 10 |
#include <bits/stdc++.h>
using namespace std;
char S[200010];
long long T, n, K, ans;
string s;
inline long long read() {
long long x = 0, tmp = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') tmp = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + (ch ^ 48);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct block {
int l, r, mx;
};
struct occ_str {
int l, r, sz;
};
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N, Q, B = 200, MX = 200000;
cin >> N >> Q;
vector<int> A(N);
vector<occ_str> occ(MX + 1, {0, 0, 0});
for (int i = 0; i < N; i++) {
A[... | 24 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, k;
cin >> n >> k;
if (k == 0) {
cout << n << "\n";
return;
}
long long int flag = 1;
if (n % 2 == 0) flag = 0;
long long int ans = n;
if (flag == 0) {
if (k % 4 == 1) {
ans = n - k;
} else if (k % 4 == 2)... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long check(long long arr[], long long num, long long value) {
long long count = 0;
for (int i = num - 1; i >= 0; i--) {
if (arr[i] >= value) {
count++;
} else
break;
}
if (count >= value)
return 1;
else
return 0;
}
long long Binary... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vn;
bool bs(long long n, long long len) {
long long low = 0, hi = len - 1, mid;
while (low <= hi) {
mid = (low + hi) / 2;
if (vn[mid] == n)
return true;
else if (n > vn[mid])
low = mid + 1;
else
hi = mid - 1;
}
ret... | 5 |
#include <bits/stdc++.h>
using namespace std;
int visi[300005] = {0}, tt = 0;
int in[300005], out[300005], h[300005] = {0}, tr[300005] = {0};
vector<vector<int> > gr;
void dfs(int node) {
visi[node] = 1;
in[node] = tt;
tt++;
int i;
for (i = 0; i < gr[node].size(); i++) {
int tn = gr[node][i];
if (!vis... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int e, s, n, m;
int t[N], x[N];
vector<int> v[4];
vector<int> len[4];
int get(int t, int x) {
int i = (int)(lower_bound((v[t]).begin(), (v[t]).end(), x) - v[t].begin());
return len[t][i] + max(v[t][i] - x - s, 0);
}
int main() {
scanf("%d%d%d%... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct Person {
string name, type;
int bonus;
string home;
Person(string _name, string _type, int _bonus, string _home)
: name(_name), type(_type), bonus(_bonus), home(_home) {}
};
struct Item {
string name, type;
int atk, def, res, size;
Item(string _na... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 1;
const int mod = 1e9 + 7;
int dp[maxn], g[maxn], ans = 1;
struct node {
int u, v, w, id;
} s[maxn];
bool cmp(const node &a, const node &b) { return a.w < b.w; }
int main() {
int n, m, u, v, w, j, t = 1;
scanf("%d %d", &n, &m);
for (int i = 1... | 11 |
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, k;
int a[200010];
int cnt = 0;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] & 1) cnt++;
}
if (cnt < k) {
printf("NO\n");
continue;
} else... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int A = 26;
set<int> adj[A];
bool need[A];
int color[A];
int cnt[A];
void dfs(int u) {
if (adj[u].size() > 1u) {
cout << "NO\n";
exit(0);
}
color[u] = 1;
for (auto c : adj[u]) {
++cnt[c];
if (color[c] == 1) {
cout << "NO\n";
exit(0)... | 12 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
string newstring = "";
int possarr[123] = {0};
for (int i = 0; i < s.size(); i++) {
if (possarr[s[i]] == 0) {
possarr[s[i]] = 1;
newstring += s[i];
}
}
int len = newstring.size();
if (len % 2 == 0)
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.second.first == b.second.first)
return a.second.second > b.second.second;
return a.second.first < b.second.first;
}
void showvi(vector<int> v) {
for (int i = 0; i < v.size(); i++) cout <<... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 5e2 + 13, mod = 1e9 + 7;
int n, a[maxN], dp[maxN][maxN][2];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int dis = 0; dis < n; dis++) {
for (int r = dis; r < n; r++) {
int l = r - dis;
dp[l][l][0] = 1;
dp[... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int pws[500009], numvals, a[500009], ans = 0;
vector<pair<long long int, int> > lol;
vector<pair<int, int> > edges;
vector<int> temp;
int par[500009], sz[500009], n, tots;
int find(int node) {
if (par[node] != node) {
retur... | 14 |
#include <bits/stdc++.h>
#define ll long long
#define EL "\n"
using namespace std;
int Count[50];
string Solve(string s) {
for (int i = 0; i < 30; i++) Count[i] = 0;
int P = 0, pos = 0;
for (int i = 0; i < s.size(); i++) {
Count[s[i] - 'a']++;
P = max(P, (int) s[i] - 'a');
if (s[i] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long modExpo(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return modExpo((x * x) % 998244353, n / 2);
else
return (x * modExpo((x * x) % 998244353, (n - 1... | 16 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0, 0, 0, 0};
const long long inf = 100000007;
const double eps = 0.000000009;
long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int p = 0;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int t;
int d;
int mn;
double sq;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &d);
mn = d * d - 4 * d;
if (mn < 0) {
puts("N");
continue;
}
sq = sqrt(mn * 1.0);
printf("Y %.12lf %.12lf\n", (d + sq) / 2, (d - sq) / 2);
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x;
int y;
};
bool onSegment(Point p, Point q, Point r) {
if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) && q.y <= max(p.y, r.y) &&
q.y >= min(p.y, r.y))
return true;
return false;
}
int orientation(Point p, Point q, Point r) {
int va... | 8 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long int p = 1000000007;
unsigned long long int power(unsigned long long int x,
unsigned long long int y) {
unsigned long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = ((res % p) * (x % p)) % p;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int M = (1 << 19);
struct node {
long long suma, max_pref, max_suf, max_h;
};
node t[4 * M + 1];
long long d[2 * M], h[2 * M];
node update(node b, node c) {
node a;
a.suma = b.suma + c.suma;
a.max_pref = max(b.max_pref, b.suma + c.max_pref);
a.max_h = max({b... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, a[100][100], f[100];
int main() {
scanf("%d\n", &n);
memset(a, 0, sizeof(a));
memset(f, 0, sizeof(f));
for (int i = 0; i < (n - 1) * n / 2 - 1; i++) {
cin >> x >> y;
x--;
y--;
a[x][y] = 1;
a[y][x] = 1;
f[y]++;
}
for (int i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int v[1002], v1[1002], ad[1002][1002], n;
vector<int> G[1002], RG[1002];
vector<pair<int, int> > edges;
void dfs(int x) {
if (v[x]) return;
v[x] = 1;
int i;
for (i = 0; i < G[x].size(); i++) dfs(G[x][i]);
}
void dfs1(int x) {
if (v1[x]) return;
v1[x] = 1;
int ... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T max2(T x, T y) {
return (x > y) ? x : y;
}
template <typename T>
T min2(T x, T y) {
return (x < y) ? x : y;
}
template <typename T>
T min3(T x, T y, T z) {
return ((x < y)) ? ((x < z) ? x : z) : ((y < z) ? y : z);
}
template <typename T>
T max3... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long mul[1000010], inv[1000010];
long long pw(long long a, long long b) {
long long ret = 1;
while (b > 0) {
if (b & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ret;
}
long long C(int n, int m) {
if (m >... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
if (a[0] ^ a[n / 2])
cout << "Alice" << endl;
else
cout << "Bob" << endl;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
uint64_t rnd_data = 0xDEADBEEFDULL;
inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; }
inline int my_rand() {
rnd_data = rnd_data * 0x5DEECE66DULL + 0xB;
return (rnd_data >> 17) & 0x7FFFFFFF;
}
template <typename T>
void my_random_shuffle(T b... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <class T>
void read(T &val) {
T x = 0;
T bz = 1;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') {
bz = -1;
c = getchar();
}
for (; c >= '0' && c <= '9'; c = getchar(... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, t;
long long numOfCookies[100005];
long long timeForCookie[100005], timeSorted[100005];
map<long long, long long> pos;
vector<pair<long long, long long>> graph[100005];
pair<long long, long long> seg[262200];
void add(long long node, long long num, long long ti... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a, b, c, n, m;
cin >> t;
while (t--) {
cin >> a >> b >> c >> n;
m = max(a, b);
m = max(m, c);
n = n - (m - a) - (m - b) - (m - c);
if (n % 3 == 0 && n >= 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
ans += abs(x);
}
cout << ans << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int a[MAXN], b[MAXN];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
for (int i = n; i > 1; --i) a[i] -= a[i - 1];
for (int i = n; i > 1; --i) b... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100007];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest;
cin >> ntest;
while (ntest--) {
cin >> n;
int le, chan;
le = chan = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline void fre1() {
freopen("C:\\Users\\Administrator\\Desktop\\in.txt", "r", stdin);
freopen("C:\\Users\\Administrator\\Desktop\\out.txt", "w", stdout);
}
inline void fre2() { fclose(stdin); }
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 20, maxm = 1e3 + 20, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k2, k3, k5, k6;
cin >> k2 >> k3 >> k5 >> k6;
int sum = 0;
while (k2 > 0 && k5 > 0 && k6 > 0) {
sum += 256;
k2--, k5--, k6--;
}
while (k2 > 0 && k3 > 0) {
sum += 32;
k2--, k3--;
}
cout << sum;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class num>
inline void rd(num &x) {
char c;
while (isspace(c = getchar()))
;
bool neg = false;
if (!isdigit(c))
neg = (c == '-'), x = 0;
else
x = c - '0';
while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
if (neg) x = -x;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int price[100100];
long long int w[100100];
pair<long long int, long long int> ans[100100];
priority_queue<pair<long long int, long long int>,
vector<pair<long long int, long long int>>,
greater<pair<long long int, long long int>>>
... | 16 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
typedef long int LI;
typedef unsigned long int ULI;
typedef long long int LL;
typedef unsigned long long int ULL;
LL mod = 1e9 + 7;
inline int scanInt() {
int n = 0;
char ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (c... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
string S;
int P[105];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> P[i];
bool ok = 1;
getline(cin, S);
for (int i = 0; i < n; i++) {
S = "";
getline(cin, S);
int j = 0;
string cur = "";
int cnt = 0;
for (int j = 0; j < S... | 4 |
#include <bits/stdc++.h>
int main() {
long long n(0), k(0);
scanf("%lld %lld", &n, &k);
if (n == 1) {
puts("0");
} else if (n <= k) {
puts("1");
} else if (n > k * (k - 1) / 2 + 1) {
puts("-1");
} else {
long long lowerBound(1), upperBound(k - 1), mid(1);
long long subtr = 1 + k * (k - 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a, b;
long long fac[1000010];
long long fast_exp(long long a, long long m) {
if (!m) return 1;
long long k = fast_exp(a, m / 2);
if (m & 1) return (((k * k) % 1000000007) * a) % 1000000007;
return (k * k) % 1000000007;
}
long long bol(long lon... | 16 |
#include <bits/stdc++.h>
using namespace std;
int const MAX = 110000;
struct Node {
int l, r;
int val;
};
Node tree[10 * MAX];
Node a[MAX];
vector<int> ans;
void build(int step, int l, int r) {
tree[step].l = l;
tree[step].r = r;
tree[step].val = 0;
if (l == r) return;
int mid = (l + r) >> 1;
build(step... | 10 |
#include <bits/stdc++.h>
using namespace std;
int abs(int x) {
if (x < 0) return -x;
return x;
}
int dp[50050][10], a[50010][10];
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
for (int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<long long> v(n + 2), a(n + 1), b(n + 2);
for (int i = 1; i <= (n); i++) cin >> v[i];
a[1] = v[1];
b[1] = 0;
bool... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> y;
vector<long long> x;
long long m;
int w = 0;
for (long long i = 0; i < n; i++) {
cin >> m;
if (m == 1) {
w = 8;
}
x.push_back(m);
y.push_back(m);
}
if (w == 0) {
sort(x.... | 0 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
string s[1000];
int vis[1000][1000], ans[1000][1000];
int n, m, t;
void dfs(int i, int j, int c) {
vis[i][j] = c;
if (i > 0 && !vis[i - 1][j] && s[i - 1][j] == s[i][j]) {
dfs(i - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int need[1000];
bool clear[1000];
int gcd(const int &a, const int &b) { return (a % b == 0) ? b : gcd(b, a % b); }
int main() {
int n;
cin >> n;
vector<int> v(n * n);
for (int i = 0; i < v.size(); i++) {
cin >> v[i];
}
if (n == 1) {
cout << v[0] << endl;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 22;
int n, m;
long long cap[N];
int res[N];
int sz[N];
pair<int, int> edge[N];
bool mark[N], eg[N];
vector<int> G[N];
void dfs(int v) {
mark[v] = 1;
for (auto& e : (G[v])) {
int u = edge[e].first + edge[e].second - v;
if (mark[u]) continue;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1024;
const int MAXN = 52;
const int SIGMA = 27;
vector<pair<int, int> > v[SIGMA];
void gao(int n, char s[MAXN], set<int> m[MAXN][SIGMA]) {
for (int k = n - 1; k >= 0; --k) {
queue<pair<int, int> > q;
m[k][s[k] - 'a'].insert(k + 1);
q.push(make... | 15 |
#include <bits/stdc++.h>
using namespace std;
void setIO(string name) {
string is = name + ".in";
string os = name + ".out";
freopen(is.c_str(), "r", stdin);
freopen(os.c_str(), "w", stdout);
}
int s;
int sign(long double a) { return a > 1e-15 ? 1 : a < -1e-15 ? -1 : 0; }
long double calc(long double a, long do... | 10 |
#include <bits/stdc++.h>
long long n, m, p;
long long lmax;
long long Am[50001];
long long fac[50001];
long long l[2000000];
long long f[5010][5010];
long long g[2][5010];
int main() {
scanf("%lld%lld%lld", &n, &m, &p);
fac[0] = Am[0] = f[0][0] = 1;
for (int i = 1; i <= n; i++)
scanf("%lld", &l[i]), lmax = st... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxl = 200005;
int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -w;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + (ch ^ '0');
ch = getchar();
}
return s * w;
}
int... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0;
cin >> t;
while (t--) {
long a, b;
cin >> a >> b;
if (((a + b) % 3) == 0 && 2 * min(a, b) >= max(a, b))
cout << "YES\n";
else
cout << "NO\n";
}
}
| 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 110;
int t, n, m, k, x, y;
bool f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n >> m >> k >> x;
f = 1;
for (int i = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e18;
long long n, a[N], q, seg[4 * N], tp, x, p;
void relax(long long id) {
seg[2 * id] = max(seg[2 * id], seg[id]);
seg[2 * id + 1] = max(seg[2 * id + 1], seg[id]);
seg[id] = 0;
}
void upd(long long id, long long L, long long R, lo... | 8 |
// time-limit: 1000
// problem-url: https://codeforces.com/contest/1529/problem/D
#include<bits/stdc++.h>
using namespace std;
template <int _mod = 998244353>
class Modular {
private:
static constexpr int mod = _mod;
static_assert(_mod > 0, "mod must be positive");
int value;
public:
Modular() : value... | 9 |
#include <bits/stdc++.h>
using namespace std;
int even[100020], odd[100020];
int main() {
int n, k, p, evennum = 0, oddnum = 0;
int dig;
scanf("%d%d%d", &n, &k, &p);
for (int i = 0; i < n; i++) {
scanf("%d", &dig);
if (dig % 2 == 0)
even[evennum++] = dig;
else
odd[oddnum++] = dig;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(
(unsigned int)chrono::steady_clock::now().time_since_epoch().count());
vector<int> gain;
vector<vector<int>> dp;
int n, k;
int solve(int want, int have) {
if (have == 0 || want == 0) return 0;
if (dp[want][have] != -1) {
return dp[want][have];
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, T, ans, big, cas;
double a, b, c, x, y, z, t, t1, t2, t3;
bool allofa, allofb;
bool flag;
int main() {
scanf("%lf%lf%lf", &a, &b, &c);
scanf("%lf%lf%lf", &x, &y, &z);
if (a == 0 && b == 0) {
if (c == 0)
allofa = 1;
else {
printf(... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double TOL = 1e-7;
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N, R, v;
cin >> N >> R >> v;
cout << fixed;
cout << setprecision(12);
for (int n = 0; n < N; ++n) {
int s, f;
cin >> s >> f;
int distance = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n;
string op;
vector<string> ans;
multiset<int> ms;
while (n--) {
cin >> op;
if (op == "insert") {
cin >> x;
ms.insert(x);
ans.emplace_back("insert " + to_strin... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
int n, a[N], b[N], ans, tree_inc[N << 2], tree_dec[N << 2];
void update_dec(int ind, int l, int r, int lw, int rw, int val) {
if (l > rw || r < lw || l > r) return;
if (l >= lw && r <= rw) {
tree_dec[ind] = min(tree_de... | 13 |
#include <bits/stdc++.h>
using namespace std;
int ora[200];
int main() {
int n;
double ans;
while (scanf("%d", &n) == 1) {
ans = 0;
for (int i = (1); i <= (n); ++i) scanf("%d", &ora[i]);
for (int i = (1); i <= (n); ++i) ans += ora[i];
printf("%f\n", ans / n);
}
return 0;
}
| 0 |
//#include <D:\Programming\template\gp1.h>
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vi a(n), b(n), d(n);
vi pos, neg;
int tmp = 0;
for (int i = 0; i < n; i++) cin >> a[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)(1e9 + 7), maxn = (int)(1e4);
const double eps = (1e-7);
int main() {
int n, a[maxn], T, cnt = 1;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> T;
sort(a, a + n);
int uk = 0;
for (int i = 1; i < n; i++) {
int u = i - 1, sz ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 300010;
long long n, x, t, T;
long long a[N];
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
x = x ^ a[i];
}
if (n % 2 == 1) {
puts("YES");
printf("%d\n", n - 1);
for (int i = 1; i < n; i ... | 14 |
#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,... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int sum = 0, p = 1;
char ch = getchar();
while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
if (ch == '-') p = -1, ch = getchar();
while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
return sum * p;
}
const ... | 23 |
#include <bits/stdc++.h>
using namespace std;
void setIO(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
const int MN = 200 * 1e3 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
vector<pair<int, int> > events;
long long factorial[MN * 2];
long long fpow(lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int a = 0; a <= n; a += 1234567) {
for (int b = 0; b <= n - a; b += 123456) {
if ((n - a - b) % 1234 == 0) {
cout << "YES";
return 0;
}
}
}
cout << "NO";
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int n;
cin >> n;
vector<int> r(n);
vector<int> freq(n, 0);
for (int i = 0; i < n; i++) {
cin >> r[i];
r[i]--;
freq[r[i]]++;
}
int best = 0;
int nc = 0;
for (int i = 0; i < n; i+... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
long long n, l, i, x, y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << (n - 1) * 3 + 7 << '\n';
cout << "0 0\n";
cout << "0 1\n";
cout << "1 0\n";
cout << "1 1\n";
x = 2;
y = 2;
for (i = 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
unsigned int n;
cin >> n;
unsigned int cnts[32] = {0};
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, d;
int Orange;
int collect = 0;
int k = 0;
cin >> n >> b >> d;
while (n != 0) {
cin >> Orange;
if (Orange <= b) {
collect += Orange;
if (collect > d) {
collect = 0;
k++;
}
}
n--;
}
cout... | 1 |
#include<bits/stdc++.h>
using namespace std;
long long int x[65];
int main(){
for(int i=1;i<=60;i++){
x[i]=((long long)1<<(i+1))-2;
}
int t;
cin>>t;
long long int k;
for(int c=0;c<t;c++){
cin>>k;
if(k%2){
cout<<-1<<endl;
continue;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long oo = 1e9 + 7;
int n, m;
char g[2008][2008];
bool check(int r, int c) {
if (r + 1 > n) return 0;
if (c + 1 > m) return 0;
return 1;
}
int f(int r, int c) {
int ret = 0;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
if (g[r + i][c + j] ... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void end(string s) {
cout << s;
exit(0);
}
inline void end(long long n) {
cout << n;
exit(0);
}
int mod(int a, int b) { return (((a % b) + b) % b); }
const int N = 105;
int r, c;
int A[N][N], B[N][N], C[N][N];
void erase(char t, int x, int v, int A[N][N]) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, top = 1e9, bot = 0, amx = 0, bmn = 1e9;
string stan, now;
cin >> n;
cout << "0 1\n";
cin >> stan;
for (int i = 1; i < n; ++i) {
cout << (top + bot) / 2 << " 1\n";
cin >> now;
if (now == stan) {
amx = max(amx, (top + bot) / 2... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << "2000\n";
for (int i = 1; i <= 1000; ++i)
cout << i << " 1"
<< " " << i << " 2" << '\n';
for (int i = 1000; i > 0; --i)
cout << i << " 1"
<< " " << i << " 2" << '\n';
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
vector<long long> X;
vector<long long> B;
vector<long long> C;
vector<long long> dp;
long long M;
const long long INF = (long long)1 << 60;
long long rec(long long a) {
if (a == M - 1) return 0;
if (dp[a] == -1) {
{
long long mx = a... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
struct ext {
int kto, len;
};
char typ[] = {'(', ')'};
char str[3000];
ext dp[2005][2005];
int vis[2005][2005];
void care(int &x) {
if (x >= mod) x %= mod;
while (x < 0) x += mod;
}
ext dp_func(int st, int en) {
ext six;
six.len = 0;
s... | 18 |
#include <bits/stdc++.h>
using namespace std;
int mini(int a, int b) {
if (a < b) return a;
return b;
}
char s[110];
int dp[110][60][220][3];
int maxi(int a, int b) {
if (a > b) return a;
return b;
}
int cal(int i, int rem, int x, int dir);
int main() {
int i, j, k, l;
while (scanf("%s", s) == 1) {
scan... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[100000];
string s;
cin >> s;
int n;
n = int(s.length());
int u = 301, u1 = 301;
int max = u1;
int min = u;
int i = 0;
while (i < n) {
if (s[i] == '-') {
++u1;
if (u1 > max) {
max = u1;
}
} else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long OO = 1e7;
const int N = 1e6 + 5;
int par[N];
long long val[N];
long long arr[N];
int n, m, k, T, cnt, SU, idx;
int a, b, c, d;
int l, r, mid;
string s, str;
int one, zero;
struct DSU {
int n;
DSU(int u) {
n = u;
iota(par, par +... | 10 |
#include <bits/stdc++.h>
using namespace std;
int calc() {
int n, k;
cin >> n >> k;
if (n == 0) return 1;
if (n < 3) return 0;
if (k % 3 != 0 || n < k) {
return (n % 3 == 0);
}
n %= (k + 1);
if (n % 3 != 0) return 0;
if (n == k) return 0;
return 1;
}
int main() {
int q;
cin >> q;
while (q)... | 9 |
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> v[], int u, vector<bool>& vis) {
vis[u] = true;
for (auto i : v[u]) {
if (vis[i] == false) dfs(v, i, vis);
}
}
int main() {
int n;
cin >> n;
vector<int> v[n + 26];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (auto... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
long long int m, n, res, k, ans = 0, nbcycle = 0;
string s1 = "", s2 = "zero", ch = "", s;
set<long long int> st;
multiset<long long int> mst;
vector<pair<long long in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100100;
struct Tbuild {
long long b, p;
bool operator<(const Tbuild &a) const { return a.p < p; }
} build[N];
priority_queue<Tbuild> q;
long long a[N], n, m;
bool cmp(Tbuild a, Tbuild b) {
if (a.b == b.b) return a.p < b.p;
return a.b < b.b;
}
voi... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
int flag = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (n == 1) {
cout << "YES\n";
cont... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[100001], tree[4 * 100001], treel[4 * 100001], treer[4 * 100001],
check[4 * 100001];
void build(int l, int r, int node) {
if (l == r) {
tree[node] = a[l];
treel[node] = a[l];
treer[node] = a[l];
check[node] = 1;
return;
}
int mid = (... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void amax(T &x, T y) {
if (x < y) x = y;
}
template <class T>
void amin(T &x, T y) {
if (x > y) x = y;
}
int n;
string s;
long long int L = 0, R = 0;
void solve() {
cin >> n >> s;
for (__typeof(0) i = (0); i < (n - 1); ++i) {
if (s[i] == s[0])... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n, sum, ans;
int road[maxn][maxn];
bool check(int x, int y, int n) {
for (int i = 1; i <= n; i++) {
if (road[i][y] != 0 || road[x][i] != 0) return false;
}
return true;
}
void init() {
memset(road, 0, sizeof(road));
sum = 0;
ans = 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
map<int, int> m;
set<int> s;
queue<int> q;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (s.find(x) == s.end()) {
if (q.size() == k) {
m[q.front()]--;
if (m[q.front()] == 0) s.erase(q.fr... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.