solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, counter = 0, counter2 = 0, coins = 0;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n == 2) {
cout << 0;
return 0;
}
if (n == 3) {
if (a[0] < a[1] && a[2] > a[1])
cout << 1;
els... | 1 |
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int i = 0, count = 1, prob = 1;
while (i < n - 1) {
if (a[i + 1] <= 2 * a[i]) {
count++;
prob = max(prob, count);
i++;
continue;... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18, n, m, k, p[100100], sum, a[1000100], b[110][110][110],
c[300100], d[100100], f[10], s, x, y, z, mx = -INF, mn = INF, ans,
dlans[110], ind;
bool marked[1010][1010];
double PI = 3.1415926535897932384626433832795;
char ch[1... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
long long int r = (2 * n) % k == 0 ? (2 * n) / k : (2 * n) / k + 1;
long long int g = (5 * n) % k == 0 ? (5 * n) / k : (5 * n) / k + 1;
long long int b = (8 * n) %... | 0 |
#include <bits/stdc++.h>
using namespace std;
stack<int> stk;
queue<int> que;
stack<int> deq;
vector<int> num;
int maxnum;
void solve() {
for (int i = 0; i < num.size(); i++) {
if (num[i] == maxnum) {
que.push(maxnum);
puts("pushQueue");
maxnum = 0;
continue;
}
if (stk.top() > deq.... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e4;
int cnt = 0;
vector<int> v[M];
void dfs(int u, int p = -1) {
if (v[u].size() == 1) cnt++;
for (auto x : v[u]) {
if (x != p) dfs(x, u);
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int isPrime(long long k) {
if (k <= 1) {
return 0;
}
if (k == 2) {
return 1;
}
if (k % 2 == 0) {
return 0;
}
long long i = 3;
while (i * i <= k) {
if (k % i == 0) {
return 0;
}
i += 2;
}
return 1;
}
int main(int argc, const ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct lex_compare {
public:
bool operator()(const pair<long long, long long>& lhs,
const pair<long long, long long>& rhs) const {
if (lhs.second == rhs.second) return lhs.first < rhs.first;
return (lhs.second > rhs.second);
}
};
class trp {
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxN = 1 << 19;
const long long INF = 1000000000000ll;
const long double E = 1e-11;
int T[maxN], lck[maxN];
void solve() {
int n;
scanf("%d", &n);
for (int i = (0); i < (n); i++) scanf("%d", T + i);
for (int i = (0); i < (n); ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long modular_pow(long long base, long long exponent, int modulus) {
long long result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) result = (result * base) % modulus;
exponent = exponent >> 1;
base = (base * base) % modulus;
}
return result;
}
... | 6 |
#include <bits/stdc++.h>
template <class T>
void read(T &x) {
x = 0;
char f = 0, c = getc(stdin);
while (c < '0' || c > '9') f ^= (c == '-'), c = getc(stdin);
while (c >= '0' && c <= '9') x = x * 10 + (c & 15), c = getc(stdin);
f && (x = -x);
}
int Max(int a, int b) { return a > b ? a : b; }
int Min(int a, in... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 0;
cin >> n >> m;
int l[m], r[m], t[m], c[m];
int a[n][m];
memset(a, -1, sizeof(a));
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> t[i] >> c[i];
for (int j = l[i]; j <= r[i]; j++) a[j - 1][i] = t[i];
}
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
;
long long int n, k;
cin >> n >> k;
long long int count = 0;
deque<long long> mess;
int flag = 1;
for (long long int i = 0; i < n; i++) {
long long int m;
cin >> m;
deque<long long>::iterator it;
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long counter[3];
int main() {
int n = 0;
long long s = 0;
cin >> n;
long long a[n];
int x = 0;
cin >> x;
a[0] = x;
s = x;
for (int i = 1; i < n; i++) {
cin >> x;
a[i] = a[i - 1] + x;
s += x;
}
if (s % 3 != 0) {
cout << 0;
retur... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 2019;
const long double pi = acos(-1);
const long long maxn = 300006;
template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
for (auto x : A) out << x << " ";
return out;
}
template <class T>
ostream &operator<<(ostream &out, set<T> &... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 100;
const long long NN = 20 + 10;
const long long inf = 1e15;
long long p[N][NN], h[N], sum[N], ans[N];
pair<long long, long long> dp[N], dp2[N];
vector<pair<long long, long long> > b[N], a[N];
bool pil[N];
void dfs3(long long v, long long p = -1)... | 20 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:300000000")
const long double eps = 1e-20;
const long double pi = acos(-1.0);
const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const long long base = 1000 * 1000 * 1000 + 7;
using namespace std;
map<int, pair<int, int> > m;
int n, q, s, f, t, l, r, ... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n;
int x[1010], y[1010];
vector<int> v;
set<int> s;
void init() {
v.clear();
s.clear();
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= int(n); i++) {
cin >> x[i] >> y[i];
x[i]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int aa, bb, cc, d, dd;
aa = a + b * c;
bb = a * (b + c);
cc = (a + b) * c;
d = (a * b * c);
dd = a + b + c;
int g = max(aa, bb), gg = max(cc, d);
int m = max(g, gg);
cout << max(m, dd);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
char buf[1048576], *p0, *p1;
inline int read() {
int r = 0;
char c =
(p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 1048576, stdin), p0 == p1)
? EOF
: *p0++);
while (c < 48 || c > 57)
c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 104... | 20 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n;
string s;
cin >> n >> s;
long long cnt = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '(') cnt++;
}
for (long long i = 0; i < n; i++) {
if (s[i] == '?') {
if (cnt < n / 2) {
s[i] = '(';
cnt++;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
string str[128];
set<string> st[1024];
int vis[1024];
inline int col(char ch) {
switch (ch) {
case 'R':
return 0;
case 'G':
return 1;
case 'B':
return 2;
case 'Y':
return 3;
case 'W':
return 4;
default:
return -1... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
for (cin >> t; t; --t) {
string s;
cin >> s;
long long n = s.length();
long long negs = 0, pos = 0, sum = n;
for (long long i = 0; i < n; i++) {
if (s[i] == '-') {
negs++;
if (negs > pos) {
su... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long modExpo(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;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr)... | 8 |
#include <bits/stdc++.h>
using namespace std;
namespace fastIO1 {
inline char read() {
static const int IN_LEN = 1000000;
static char buf[IN_LEN], *s, *t;
return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
(s == t ? -1 : *s++) : *s++);
}
template <class T>
inline void read(T &x... | 23 |
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int power(int x, unsigned int y, int p) {
int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
retur... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100];
long long vis[100];
stack<long long> st;
void toposort(long long i) {
vis[i] = 1;
for (auto it : adj[i]) {
if (vis[it] == 0)
toposort(it);
else if (vis[it] == 1) {
cout << "Impossible";
exit(0);
}
}
vis[i] = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
t = 1;
while (t--) {
long long int n;
cin >> n;
string s;
cin >> s;
long long int total = 0;
long long int ans = 0;
int length = 0;
bool check = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1e9, 1e9);
int p[5005], c[5005], u[5005], dx[5005];
void solve(int n, int d) {
int x = 0, y = 0;
for (int i = 1; i <= n; ++i) y += 1 - bool(i & (i - 1)), x += y - 1;
if (!(x <= d && d <= n * (n - 1) / 2)) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int v1, v2, v3, v4, ans;
scanf("%d %d %d %d", &v1, &v2, &v3, &v4);
if (v4 > v3 * 2 || v3 > v4 * 2 || v4 >= v1 || v4 >= v2) {
printf("-1");
return 0;
}
ans = max(v3, v4);
printf("%d %d %d", v1 * 2, v2 * 2, ans);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
struct P {
int from, to, flow, cap;
};
struct Dinic {
vector<P> edge;
vector<int> v[maxn];
int n, st, ed;
void init(int Max) {
n = Max;
for (int i = 0; i <= n; i++) v[i].clear();
edge.clear();
}
void add_edge(int from, int to... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline bool eq(long long a, long long b) { return a == b; }
inline bool lt(long long a, long long b) { return a < b; }
inline bool le(long long a, long long b) { return a <= b; }
inline int sign(long long x) { return eq(x, 0) ? 0 : (x < 0 ? -1 : 1); }
struct point {
long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n = 300100, last, tt, num[300100 << 1], sz[300100];
char str[300100];
struct Node {
long long to[28], cs[4], pa, len, cj;
Node() {
pa = -1;
memset(to, -1, sizeof(to));
}
} node[300100 << 1];
inline void add(int u, int v) {
int np = ++tt, p = last, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int a[103], cnt[500], b[N];
int n, T;
int bit[N];
int mx = 0, SL = 0;
void update(int k, int val) {
for (; k < N; k += k & -k) bit[k] = max(bit[k], val);
}
int query(int k) {
int kq = 0;
for (; k > 0; k -= k & -k) kq = max(kq, bit[k]);
return ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n = 0;
cin >> n;
if (n % 2) {
for (int i = 0; i < n; i++) cout << i << ' ';
cout << endl;
for (int i = 0; i < n; i++) cout << i << ' ';
cout << endl;
for (int i = 0; i < n; i++) cout << 2 * i % n << ' ';
} e... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int _, n, a[maxn], b[maxn];
int t[maxn << 2];
queue<int> q[maxn];
void pushUp(int i) { t[i] = min(t[i << 1], t[i << 1 | 1]); }
void build(int i, int l, int r) {
if (l == r) {
t[i] = a[l];
return;
}
int mid = (l + r) >> 1;
build(i <<... | 16 |
#include <bits/stdc++.h>
const int N = 1010, P = 1e9 + 7;
int f[N][N];
int pwr(int a, int b) {
int r = 1;
for (; b; a = 1ll * a * a % P, b >>= 1) b& 1 ? r = 1ll * r * a % P : 0;
return r;
}
int main() {
int n, m, ans = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= (n); ++i) {
int x;
scanf("%d", &x)... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
bool typy[10000];
pair<int, int> podoba(int a, int b) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k, mas[10005][4], aa, ab[20005], rez[3][400005], r, bb;
int main() {
cin >> n >> m;
j = 0;
while (j < 4) {
i = 0;
while (i < n) {
cin >> mas[i][j];
i++;
}
j++;
}
if (m == 2 * n) {
i = 0;
aa = 0;
while (i < n)... | 13 |
#include <bits/stdc++.h>
using namespace std;
void fff() {
int x, y, z;
cin >> x >> y >> z;
int a, b, c;
a = max(x, y);
b = max(y, z);
c = max(x, z);
if (x != y && y != z && z != x)
cout << "NO";
else if (x == y && y == z)
cout << "YES" << endl << x << " " << y << " " << z << " ";
else if (a =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N], n;
bool st[N];
int solve(int k) {
for (int i = 1; i <= n; ++i) st[a[i]] = 0;
int res = 0;
for (int i = 1; i <= n; ++i) {
int j = i, cur = 0;
while (j <= n) {
if (!st[a[j]]) ++cur;
st[a[j]] = 1;
if (cur > k) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int N = 1000;
const int K = 20;
const int X = 3;
const int P = 1e9 + 7;
int a[N][N];
double x[K][N];
double y[K][N];
double d[K][K];
int p[K];
int ansp[K];
double f[1 << K][K];
int pre[1 << K][K];
int main() {
int N;
scanf("%d", &N);
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
long long power(long long a, long long n) {
long long p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
long long power(long long a, long long n, long long mod) {
long l... | 7 |
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3f;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const int MOD = 1e9 + 7;
template <typename T>
inline void read(T &f) {
f = 0;
T fu = 1;
char c = getchar(... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n, x;
cin >> n >> x;
int A[n];
for (int i = 0; i < n; ++i) {
cin >> A[i];
}
sort(A, A + n);
auto it = lower_bound(A, A + n, x);
int j = 0, ans = 0;
for (int i = 0; i < x; ++i) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 5;
unordered_map<int, int> cp;
int org[N];
int id = 0;
int qs[N], qe[N], qi[N], qa[N];
int n, m;
int arr[N];
int p1, p2;
int freq[N];
set<int> res;
void add(int x) {
if (freq[x] == org[x]) {
res.erase(x);
}
freq[x]++;
if (freq[x] == org[x]) r... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, m, n;
int a[6];
for (i = 0; i < 6; i++) {
cin >> a[i];
}
sort(a, a + 6);
if (a[0] == a[3]) {
if (a[4] == a[5]) {
cout << "Elephant";
return 0;
} else {
cout << "Bear";
return 0;
}
}
if (a[1... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long nxt, to;
} o[1000010];
long long n, k, a[1000010], sta[1000010], top, head[1000010], I, s[1000010],
sz[1000010], t[1000010 << 2], lz[1000010 << 2];
void read(long long& x) {
x = 0;
char s = getchar();
while (s < '0' || s > '9') s = getcha... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l = 0, i = 0, x, k;
map<int, int> a;
std::cin >> n;
for (i = 0; i < n; i++) {
std::cin >> x >> k;
if (a[k] == x) a[k]++;
if (a[k] < x) l = 1;
}
if (l == 0)
std::cout << "YES";
else
std::cout << "NO";
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<long long> is_prime(N + 1, true);
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
return a.second > b.second;
}
bool sort... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int t;
cin >> t;
while (t--) {
double x, y, k;
ll z;
cin >> x >> y >> k;
z = ((k * y + k - 1 + x - 2) / (x - 1)) + k;
cout << z << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
bool sortbySec(const pair<string, int> &a, const pair<string, int> &b) {
return (a.second > b.second);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, n, m, tCase = 0, a, b;
string myName, fName, lName, s;
cin >> myName;
cin >> n;
map<... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000000;
int nv[maxn + 5];
vector<int> mv[maxn + 5];
int n, m, k;
bool check(int x) {
int y = m - x;
long long total = 0;
for (int i = 0; i <= 10000000; i++) {
if (nv[i]) {
total += nv[i];
}
if (!mv[i].empty()) {
if (y == 0) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n;
long long x, s;
vector<long long> ans, v[63];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &x);
v[63 - __builtin_clzll(x)].push_back(x);
}
for (int j = 0; j < 63; j++)
sort(v[j].begin(), v[j].end(... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<long long> dp;
vector<vector<long long> > a, sum;
long long ans;
void update(int l, int r) {
for (int i = l; i <= r; ++i) {
int sz = a[i].size();
for (int j = k; j >= sz; --j) dp[j] = max(dp[j], dp[j - sz] + sum[i][sz]);
}
}
void solve(int l, in... | 20 |
#include <bits/stdc++.h>
using namespace std;
class hito {
public:
int i, t, p;
};
struct order {
bool operator()(const hito& a, const hito& b) { return a.p > b.p; }
};
bool ordera(hito a, hito b) { return a.p < b.p; }
int main() {
int n, m;
cin >> n >> m;
int times[n];
memset(times, 0, sizeof(times));
q... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long lon... | 19 |
#include <bits/stdc++.h>
using namespace std;
bool chana(int a, int b) {
while (a > 0) {
int x = a % 10;
if (x == 7) {
return true;
}
a /= 10;
}
while (b > 0) {
int x = b % 10;
if (x == 7) {
return true;
}
b /= 10;
}
return false;
}
int main() {
int a, b, c;
cin... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2000;
int dp[mxN + 1][mxN + 1], a[mxN + 1];
void solve() {
int n, k;
cin >> n >> k;
for (int i = 1; i < n + 1; i++) cin >> a[i];
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < i + 1; j++) {
dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const int MAXN = 1e6 + 5;
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
void cp() {
long long int a, b, x, y;
long long int max_area = 0;
long... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int sci() {
int a;
scanf("%d", &a);
return a;
}
int main() {
string a, b;
cin >> a >> b;
int diff = 0;
if (a.length() != b.length()) {
cout << "NO";
return 0;
}
int n = a.length();
if (n < 2) {
cout << "NO";
return 0;
}
vector<... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 250111;
int X, Y, P, n, x[maxn], y[maxn], p[maxn], m[maxn], ord[maxn];
long long d[maxn], R, r[maxn];
bool have[maxn];
bool cmp(int x, int y) { return d[x] < d[y]; }
queue<int> q[maxn];
void add(int x) {
for (int i = m[x]; i < maxn; i += i & -i) q[i].push... | 16 |
#include <bits/stdc++.h>
using namespace std;
char state[10000];
int main() {
int x, umur, check;
scanf("%d", &x);
check = 0;
for (int i = 1; i <= x; i++) {
scanf("%s", &state);
if ((int)state[0] < 65) {
if (strlen(state) == 3) {
umur = (((int)state[0] - '0') * 100);
} else if (strle... | 2 |
#include <bits/stdc++.h>
long long hold, a[11111], num;
using namespace std;
bool cmp(string a, string b);
int main() {
cin >> num;
vector<string> dict(num);
for (int i = 0; i < num; i++) {
cin >> dict[i];
}
sort(dict.begin(), dict.end(), cmp);
for (int i = 0; i < num; i++) cout << dict[i];
cout << en... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n % 2 == 1) {
cout << n / 2 + 1 << "\n";
} else {
cout << (n + 2) / 2 << "\n";
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long arr[101];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
long long k;
cin >> n >> k;
vector<long long> vec;
long long sum = 0;
for (int k = 0; k < n; k++) {
cin >> arr[k];
sum += arr[k];
for (int i = 1; i * i <= arr[k... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
point() {}
point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
return a * a;
}
template <class T>
T power(T n, T p) {
T res = 1;
for (int i = 0; i < p; i++) res *= n;
return res;
}
template <class T>
double getdist... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int M4 = 1e4 + 100, M5 = 1e5 + 100, M6 = 1e6 + 100, M7 = 1e7 + 100,
M8 = 1e8 + 100, M9 = 1e9 + 100;
int a[M4], k;
long long sum;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ci... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool is_inc(vector<int> x) {
for (int i = 1; i < x.size(); i++) {
if (x[i] < x[i - 1]) return false;
}
return true;
}
int visited[100000];
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, b, d, e, i, c = 0, wo = 0;
cin >> n;
cin >> b;
cin >> d;
vector<long long int> a(n);
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
e = 0;
if (a[i] <= b) {
c = c + a[i];
e++;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> readList(int n) {
vector<int> a;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
a.push_back(b);
}
return a;
}
long long powmod(long long a, long long b, long long MOD) {
vector<long long> md;
long long s = a;
for (int i = 0; i < 64; i++... | 11 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
cout << "? ";
for (int i = 1; i < 101; i++) cout << 128 * i << " ";
cout << endl;
int ans = 0;
int in1;
cin >> in1;
ans += in1 % 128;
cout << "? ";
for (int i = 0; i < 100; i++) cout << i << " ";
cout << endl;
int in2;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int n, a[N];
int main() {
cin >> n;
a[1] = 1;
for (int i = 1; i < N; i++) {
a[i] = (i * (i + 1)) / 2;
if (i > 1) a[i] += a[i - 1];
if (a[i] > n) {
cout << i - 1;
return 0;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005, maxk = 2005;
int a[maxn], b[maxk];
long long dp[maxn][maxk], lastmin[maxn][maxk];
inline long long ABS(long long x) { return x >= 0 ? x : -x; }
int n, k, p;
int main() {
scanf("%d%d%d", &n, &k, &p);
for (int i = 0; i < n; i++) {
scanf("%d", &a... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
long long t, T;
ios_base::sync_with_stdio(false);
cin >> T;
for (t = (0); t < (T); ++t) {
string S;
cin >> S;
long long m, i, j;
cin >> m;
vector<long long> b(m);
for (i = (0); i < (m); ++i) {
cin >> b... | 10 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
cout << "? 1 2" << endl;
long long x;
cin >> x;
cout << "? 2 3" << endl;
long long y;
cin >> y;
cout << "? 1 3" << endl;
long long z;
cin >> z;
long long a[n];
a[0] = (x + z - y) / 2;
a[1] = (x + y - z) / 2;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long int INF = 1e12;
int n, k;
int memo[101][101][101];
int solve(string &str, int i, int N, int _max) {
_max = max(N, _max);
int &a = memo[i][N][_max];
if (a != -1) return a;
if (i == n) return a = ((_max == k) ? 1 : 0);
if (st... | 12 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
int merge(int a[], int aux[], int l, int mid, int r) {
int i = l, j = mid + 1, k = l;
int cnt = 0;
while(i <= mid && j <= r) {
if (a[i] <= a[j]) {
aux[k++] = a[i++];
} else {
aux[k++] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using vi = vector<int64>;
struct TrieNode {
int nxt[3];
int exist;
vector<int> accept;
TrieNode() : exist(0) { memset(nxt, -1, sizeof(nxt)); }
};
struct Trie {
vector<TrieNode> nodes;
int root;
Trie() : root(0) { nodes.push_back(TrieNo... | 21 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void solve() {
long long n;
cin >> n;
long long st = 1;
while ((st * (st + 1)) / 2 <= n) {
if ((st * (st + 1)) / 2 == n) {
cout << "YES" << endl;
return;
}
++st;
}
cout << "NO" << endl;
}
int main() {
ios_base::s... | 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
int n, x, se = 0, so = 0;
cin >> n;
deque<int> d;
for (int i = 0; i < n; i++) {
cin >> x;
d.push_back(x);
}
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (d.back() > d.front()) {
se += d.back();
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
unordered_map<char, int> m;
char x;
for (int i = 0; i < 16; i++) {
cin >> x;
if (x != '.') {
m[x]++;
}
}
for (auto i = m.begin(); i != m.end(); i++) {
if (i->second > 2 * k) {
cout << "NO";
return... | 1 |
#include <bits/stdc++.h>
using namespace std;
double x[20], v[20], m[20];
vector<pair<double, int> > p;
int main(void) {
int N, i;
double T;
cin >> N >> T;
for ((i) = 0; (i) < (int)(N); (i)++) cin >> x[i] >> v[i] >> m[i];
for ((i) = 0; (i) < (int)(N); (i)++) p.push_back(make_pair(x[i], i));
sort(p.begin(), ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, ans;
int a[105];
int main() {
cin >> t;
while (t--) {
cin >> n;
int maxx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
maxx = max(maxx, a[i]);
}
int temp;
bool flag = true;
for (int i = 1; i <= n; i++) {
temp... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int n_ = 1e5 + 10;
int dp[n_], t[n_];
int n;
int main() {
scanf("%d", &n);
int s90 = 1, s1440 = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &t[i]);
while (t[s90] <= t[i] - 90) s90++;
while (t[s1440] <= t[i] - 1440) s1440++;
dp[i] = min(dp[i - 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int _ = 10010;
long long f[_], ans = ~0ULL >> 2;
int p[_], s[_], n, c;
int main() {
scanf("%d%d", &n, &c);
int i, j;
for (i = 1; i <= n; i++) scanf("%d", p + i);
for (i = 1; i <= n; i++) scanf("%d", s + i);
for (i = 1; i <= n; i++) {
f[i] = f[i - 1] + s[... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 100;
vector<int> G[maxn];
int n;
int sum[maxn];
int res;
void dfs(int u, int fa) {
sum[u] = 0;
for (int i = 0; i < G[u].size(); ++i) {
int v = G[u][i];
if (v != fa) {
dfs(v, u);
sum[u]++;
res += sum[v];
}
}
res +=... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string chess[8];
int white = 0, black = 0;
for (int i = 0; i < 8; i++) {
cin >> chess[i];
for (int v = 0; v < 8; v++) {
if (chess[i][v] == 'Q') {
white += 9;
} else if (chess[i][v] == 'R') {
white += 5;
} else if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long f, T, t0, a[3], t[3], p[3];
void test(long long& best, int NUM1, int NUM2) {
for (long long ii = 0; ((ii - 1) / a[NUM1] - 1) * a[NUM1] < f; ++ii) {
long long i = (ii - 1) / a[NUM1] + 1;
long long bytes_left = f - ii;
long long time_left = T - ii * t[... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
typedef long double ld;
typedef pair<long long, long long> pii;
void solve() {
long long n;
cin >>... | 8 |
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<queue>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;
inline int read(){
int x=0,f=1; char c=getcha... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
int mi[5001], mx[5001];
int a[maxn + 5];
int n, m;
vector<int> tmp;
void solve() {
if (m < mi[n] || m > mx[n]) {
printf("NO\n");
return;
}
printf("YES\n");
int now = n;
for (int i = 0; i <= n; ++i) a[i] = 0;
int d;
for (d = 0; no... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
stack<int> s1;
int p[710];
long long dp[710][710][3][3];
void solve(int l, int r) {
if (l + 1 == r) {
dp[l][r][0][1] = dp[l][r][0][2] = dp[l][r][1][0] = dp[l][r][2][0] = 1;
return;
}
if (p[l] == r) {
solve(l + 1, r - 1);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
ll pwr(ll a, ll b);
const int N = 505;
int dpL[N][N], dp[N][N];
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> dp[i][i];
}
for (int i = 1... | 13 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> Query(int left, int right) {
cout << "? " << left << " " << right << "\n";
cout.flush();
int len = right - left + 1;
int to_read = 1LL * len * (len + 1) / 2;
map<string, int> count;
for (int i = 0; i < to_read; i += 1) {
string str;
getl... | 16 |
#include <bits/stdc++.h>
const int mod = 1000000009;
int n, h, dp[2][32][32][32][32], now, last = 1, ans, a, b, c, d, v;
void upd(int A, int B, int C, int D) {
++A;
++B;
++C;
++D;
if (D > h + 1) D = h + 1;
if (C > h + 1) C = h + 1;
if (B > h + 1) B = h + 1;
if (A > h + 1) A = h + 1;
dp[now][A][B][C][D... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (long long &e : a) cin >> e;
set<pair<long long, long long>> s;
for (long long i = 0; i < n; i++) s.insert({a[i], i});
long long bef = -1;
for (auto it = s.begin(); it != s.end();) {
if (bef == it... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
int main() {
int n, up, x, z, y, count = 0;
cin >> n;
cin >> up;
x = 7 - up;
int temp = n;
while (n--) {
cin >> z >> y;
for (int i = 1; i <= 6; i++) {
if (i == z || i =... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[300003];
vector<pair<int, long long> > q[300003];
long long cnt[300003], res[300003], n;
void dfs(int r, int p, int h, long long sum) {
for (auto u : q[r]) {
sum += u.second;
if (u.first + h + 1 <= n) cnt[u.first + h + 1] += u.second;
}
sum -= cn... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' ||... | 18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.