solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, s1, s2;
vector<int> v(200);
vector<int> rem;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
int y;
for (int j = 0; j < x; j++) {
cin >> y;
if (x % 2 ==... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a, b;
cin >> t;
while (t--) {
cin >> n >> a >> b;
vector<char> v;
for (int i = 0; i < n; i++) {
v.push_back(char(97 + (i % b)));
}
for (int i = 0; i < n; i++) cout << v[i];
cout << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 5];
long long sum = 0;
int mx = -1, smx = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] > mx) {
smx = mx;
mx = a[i];
} else if (a[i] > smx)
smx = a[i];
}
vector<... | 2 |
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 10;
int n, a[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << "? 1 2" << endl;
int x, y, z;
cin >> x;
cout << "? 1 3" << endl;
cin >> y;
cout << "? 2 3" << endl;
cin >> z;
a[0] = ((x + y + z) - z - z... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int main() {
int cases;
cin >> cases;
while (cases--) {
long long n;
cin >> n;
long long x;
cin >> x;
vector<long long> vec;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
vec.push_back(x);
}
l... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct A {
long long m, p;
} a[200005];
int t, n;
multiset<int> st;
int main() {
ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> n;
st.clear();
for (int i = 1; i <= n; i++) cin >> a[i].m >> a[i].p;
sort(a + 1, a + 1 + n,
[](A b, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int t, n, k;
string s;
int dp[N], pref[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> k >> s;
pref[0] = 0;
for (int i = (1); i < (n + 1); i++) {
pref[i] = pref[i - 1] + (s[i - 1]... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int cmp(pair<int, pair<int, int> > x, pair<int, pair<int, int> > y) {
return (x.first) > (y.first);
}
vector<pair<int, pair<int, int> > > vs, vb, fs, fb;
map<int, int> mps, mpb;
int main() {
int n, s;
;
scanf("%d", &n);
scanf("%d", &s... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long a[200005], n, m;
struct ak {
int mx, mn;
};
ak tree[4 * 200005];
void build(long long node, long long st, long long end) {
if (st == end) {
tree[node].mn = st;
tree[node].mx = st;
return;
}
long long mid = (st + end) / ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long INF = LLONG_MAX / 2;
const long long N = 2e5 + 1;
long long power(long long first, long long second, long long p) {
long long ans = 1;
first = first % p;
while (second) {
if (second & 1) ans = (ans * first) % p;
sec... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int a[100010];
bitset<100010> bs;
bool dfs(int idx) {
if (idx >= s.size() || idx < 0) return true;
if (bs[idx] == 1) return false;
bs[idx] = 1;
bool res = false;
if (s[idx] == '<') {
res |= dfs(idx - a[idx]);
} else {
res |= dfs(idx + a[idx]);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m;
vector<int> adj[N];
int vis[N];
int nxt[N];
int ise[N];
bool isEqual(int a, int b) { return a == b; }
bool isLess(int a, int b) {
if (vis[a] == vis[b]) return a < b;
if (vis[a] && !vis[b]) return 1;
return 0;
}
bool in;
bool solve() {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 2000000000;
const long long INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const long long MOD = 1000000007LL;
int main() {
int n;
std::cin >> n;
std::vector<pair<long long, long long>> a(n);
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double PI = 3.1415926535898;
bool debug = 0;
int T, K;
const int MOD = 1e9 + 7;
int ans[MAXN];
void solve() {
int n;
cin >> n;
int n1 = n;
while (n > 0) {
int x = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const long long mod = 998244353;
long long n, n2, fact[MAXN], invfact[MAXN];
long long qpow(long long a, long long k) {
long long ans = 1, tmp = a;
while (k) {
if (k & 1) ans = ans * tmp % mod;
tmp = tmp * tmp % mod;
k >>= 1;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
vector<pair<int, int> > q[500010];
int n, qn, A[500010], pre[500010], lst[500010], Ans[500010];
pair<int, int> T[500010 * 4];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
void fft(vector<complex<double>>& a) {
int n = (int)(a).size(), L = 31 - __builtin_clz(n);
static vector<complex<long double>> R(2, 1);
static vector<complex<double>> rt(2, 1);
for (static int k = 2; k < n; k *= 2) {
R.resize(n);
rt.resize(n);
auto x = p... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool f(int i, int j) { return (i > j); }
int a[2000007];
int main() {
int n, temp;
long long pat = 0;
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n, f);
while (n) {
for (int i = 0; i < n; i++) pat += a[i];
n = n / 4;
}
cout ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
const int N = 2001;
const int INF = 1 << 30;
char field[N][N];
int d[N][N];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
long long int answer = 0;
long long int prev = 0, cur = 0;
for (int i = 0; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e6 + 5;
vector<long long> v1[MAXN];
vector<long long> vsum[MAXN];
long long in[MAXN];
long long getv(long long curr, long long val) {
long long l = 0;
long long r = v1[curr].size() - 1;
long long ans = -1;
while (l <= r) {
long long mid =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, M, T;
map<string, int> mp;
set<string> s;
set<string>::iterator it;
char str[22];
char ss[22][22];
int tb[20][20];
int Mc;
int num[20];
void gen(int idx) {
if (idx == N) {
int i, j, k;
for (i = 1; i <= N; i++)
for (j = i + 1; j <= N; j++)
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int getint() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f * x;
}
const int inf = 12345678;
co... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long nCr(int n, int r) {
if (n - r == 0) return 1;
return nCr(n - 1, r) * (n) / (n - r);
}
int main() {
int n, m, t;
unsigned long long sum = 0;
cin >> n >> m >> t;
for (int i = 4; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i + j == t) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int b, c, x, y;
cin >> b >> c >> x >> y;
x++;
y++;
cout << max((max(c - y, y - 1) * b), (max(b - x, x - 1) * c)) << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1e9, 1e9);
map<long long, long long> mp[40][40];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m, n;
long long k;
cin >> n >> m >> k;
vector<vector<long long>> v(n, vector<lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, tp = 0, ct, ans = 0;
struct data {
int v, id, pop;
} a[100005], b[100005];
bool p1(data a, data b) { return a.v == b.v ? a.id < b.id : a.v > b.v; }
bool p2(data a, data b) { return a.id < b.id; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, str;
int n, i, j, cnt = 0, ans;
cin >> n >> s;
for (i = 0; i < n - 1; i++) {
ans = 0;
for (j = i; j < n - 1; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) ans++;
}
if (ans > cnt) {
cnt = ans;
str.clear();
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
int drink = (int)k * l / nl;
int lime = c * d;
int salt = p / np;
int ans = min(min(drink, lime), salt);
cout << ans / n << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n + 1], car;
for (int i = 0; i < n; i++) {
cin >> car;
arr[car] = i;
}
int cnt = 1, mx = 0;
for (int i = 1; i < n; i++) {
if (arr[i] < arr[i + 1]) {
cnt++;
} else {
mx = max(mx, cnt);
cnt ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline void base() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
bool ok(int a) {
for (int i = 0; i <= 5... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> n >> m;
vector<long long> N(5, 0), M(5, 0);
for (int i = 0; i < n; ++i) ++N[(i + 1) % 5];
for (int i = 0; i < m; ++i) ++M[(i + 1) % 5];
long long ans = N[0] * M[0];
for (int i = 1; i < 5; ++i) ans += N[i] * M[5 - i];
cout << ans... | 1 |
#include <bits/stdc++.h>
int p[65];
int main() {
int n, x, now = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
now = now ^ x;
x = now;
for (int j = 31; j >= 0; j--) {
if (x & (1 << j)) {
if (!p[j]) {
p[j] = x;
break;
} else
x... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int spf[100010];
void seive() {
spf[1] = 1;
for (long long int i = 2; i < 100010; i += 1) {
spf[i] = i;
}
for (long long int i = 2; i < 100010; i += 2) {
spf[i] = 2;
}
for (long long int i = 3; i * i < 100010; i += 1) {
if (spf[i] == i) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double x1, y1, r1, x2, y2, r2, dis, dis2, dis3, dis1;
cin >> x1 >> y1 >> r1;
cin >> x2 >> y2 >> r2;
dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
dis1 = sqrt(dis);
if (dis1 > r1 + r2) {
if (dis1 > r1 + r2) {
dis2 = dis1 - (r1 + r2);... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, s, q, d, l;
int t;
int c = 0;
cin >> t >> s >> q;
d = s;
l = 0;
n = 1;
while (l <= t) {
if (l == t) break;
d += (q - 1);
l += q;
if (l >= d && d < t) {
n++;
l = 0;
}
}
cout << n;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
int len = a.second - a.first + 1;
int len2 = b.second - b.first + 1;
if (len == len2) return a... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long nm = 0, fh = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') fh = -1;
for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * fh;
}
int n, N;
long long L, a[1000020], b[1000020];
inline ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
int n, dfn[MAXN], dfsn, bn, bq;
int beg[MAXN], fin[MAXN];
vector<int> v[MAXN];
struct QUERY {
int type, v, time;
};
vector<QUERY> query[MAXN];
void dfs(int x, int par) {
dfn[x] = beg[x] = fin[x] = ++dfsn;
for (auto &y : v[x]) {
if (y == pa... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int arr[100005], dp[100005];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
queue<int> q;
int d;
int cnt = 0;
std::map<int, int> h1;
for (int i = 0; i < n; ++i) {
cin ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int i_max(int arr[], int n) {
int MAX = arr[0];
int i1 = 0, i2 = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > MAX) {
MAX = arr[i];
i1 = i;
i2 = i;
} else if (arr[i] == MAX) {
i2 = i;
}
}
return max(i1, i2);
}
int i_min(long lon... | 0 |
#include <bits/stdc++.h>
using namespace std;
void read(int &a) {
a = 0;
char c = getchar();
while (c < '0' || c > '9') {
c = getchar();
}
while (c >= '0' && c <= '9') {
a = (a << 1) + (a << 3) + (c ^ 48);
c = getchar();
}
}
const int Maxn = 10000;
const long long Inf = 0x3f3f3f3f3f3f3f3fll;
int... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int h = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (a[i] > a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
... | 0 |
#include<bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << "? " << 1 << " " << n << endl;
cout.flush();
int pos;
cin >> pos;
int pp = 0;
if (pos != 1) {
cout << "? " << 1 << " " << pos << endl;
cout.flush();
cin >> pp;
}
if (pp == pos) {
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[100001];
int n, m;
int ret[100001];
void pre() {
int msort[n][m];
memset(msort, 0, sizeof msort);
for (int j = 0; j < m; ++j) {
msort[n - 1][j] = 1;
for (int i = n - 2; i >= 0; i--) {
if (vec[i][j] > vec[i + 1][j]) {
msort[i][j] =... | 4 |
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long INF = LLONG_MAX;
const long double EPS = 1e-9;
const long double pi = 3.141592653589793238462643383279502884;
long long n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(40);
srand(time... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int fa[N];
vector<int> g[N];
int son[N];
int level[N];
int dfs(int x) {
if (g[x].empty()) {
return 0;
}
son[x] += (int)g[x].size();
for (int i = 0; i < g[x].size(); i++) {
son[x] += dfs(g[x][i]);
}
return son[x];
}
void dfs2(int x... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string tos(T x) {
stringstream ss;
ss << x;
return ss.str();
}
int Ivan = 0;
vector<pair<int, int> > v1, v2;
int i, h, t, r, m, n;
class Substitute {
public:
};
int vis[1000][1000];
void solve() {
queue<pair<pair<int, int>, int> > q;
memset(vis... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool isSafe(int x, int y, int n, int m) {
return x < n && x >= 0 && y < m && y >= 0;
}
int main() {
int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
char ch;
x = 0;
bool fl = false;
while (!isdigit(ch = getchar())) (ch == '-') && (fl = true);
for (x = (ch ^ '0'); isdigit(ch = getchar()); x = x * 10 + (ch ^ '0'))
;
(fl == true) && (x = -x);
}
template <class T>
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
int N;
char S[MAXN];
bool ar[MAXN];
int main() {
cin >> N >> S;
for (int i = 0; i < N; ++i) {
ar[i] = (S[i] == '*');
}
bool good = false;
for (int i = 0; i < N; ++i) {
if (ar[i]) {
for (int len = 1; len < N; ++len) {
boo... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s, t, tmp;
long long k, good[100005], bad[100005];
const long long mod = 1e9 + 7;
int main() {
cin >> s >> t >> k;
long long n = s.size();
long long x = 0, y = 0, f = 0, l = 0;
if (s.size() != t.size()) {
cout << 0;
return 0;
}
for (int i = 1; i <... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
if (b == 0) return 1;
long long res = 1;
while (b) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
b >>= 1;
}
return res;
}
unsigned long long mulmod(unsigned long long a, unsigned long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long k;
pair<long long, long long> _count(long long x) {
pair<long long, long long> res;
res.first = res.second = 0;
for (int i = 1; i <= n; i++) {
res.first += min((long long)m, (x - 1) / (long long)i);
res.second += min((long long)m, x / (long... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, ans;
cin >> n >> m;
cout << max(0ll, n - m * 2) << " ";
ans = 0;
while (ans * (ans - 1) / 2 < m) ans++;
cout << n - ans;
}
| 2 |
#include <bits/stdc++.h>
using std::cerr;
using std::endl;
inline int rd() {
int a = 1, b = 0;
char c = getchar();
while (!isdigit(c)) a = c == '-' ? 0 : 1, c = getchar();
while (isdigit(c)) b = b * 10 + c - '0', c = getchar();
return a ? b : -b;
}
const int N = 6e5 + 233;
int n, m, ban[N], bad;
struct Edge {... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1, M = 998244353;
long long sf[N];
char a[N], b[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
sf[m - 1] = b[0] == '1';
for (int i = m - 2; i >= 0; --i) sf[i] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long K = 11;
const long long MX = 151;
const long long INF = 1e18;
long long sum[MX][K];
long long sumDig(long long n) {
long long ans = 0;
while (n > 0) {
ans += n % 10;
n /= 10;
}
return ans;
}
void solve() {
long long n, k;
cin >> n >> k;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
cin >> n >> k;
long long int i, j;
long long int aa[n + 5];
aa[0] = 0;
for (i = 1; i <= n; i++) {
cin >> aa[i];
aa[i] = aa[i] + aa[i - 1];
}
long ... | 3 |
#include "bits/stdc++.h"
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(x, y) make_pair(x,y)
#define inf INT_MAX
#define infll LLONG_MAX
#define M 1000000007
#define N... | 0 |
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#define int long long
#define fi(i,n) for(int i=0;i<n;i++)
#define f(i, a, b) for(int i=a;i<b;i++)
#define vi vector<int>
#define pb push_back
#define all(x)(x).begin(), (x).end()
#define MOD 1000000007
#define mod 998244353
#define pii pair<int, int>
#de... | 3 |
#include <bits/stdc++.h>
using namespace std;
char Alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string getCol(int Col) {
int tCol = Col;
int vCol = tCol - 1;
string C;
while (tCol != 0) {
C += Alpha[vCol % 26];
tCol = vCol / 26;
vCol = tCol - 1;
}
reverse(C.begin(), C.end());
return C;
}
int main()... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> S;
N = S.size();
int L = 0, R = N - 1;
vector<int> V;
while (L < R) {
while (L < R && S[L] == ')') L++;
while (L < R && S[R] == '(') R--;
if (S[L] == '(' && S[R] == ')') {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100005];
while (cin >> n) {
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
if (a[0] == a[2]) {
long long int x = 3;
for (int i = 3; i < n; i++) {
if (a[i] != a[0]) {
break;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%I64d", &x);
return x;
}
int n;
long long inp[N];
struct Info {
int mx, mx_pos;
int mn, mn_pos;
} t[N * 4];
void Merge(int par, int lft,... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int c = 42, k = 8, c2 = (1 << 20);
int n, m, szint[c];
long long elm[c], po[c], ans[k], akt[k];
bool el[c][c], v[c], pkor;
int maskdb[c2], jodb[c2];
vector<int> sz;
void dfs(int a) {
v[a] = true;
sz.push_back(a);
for (int i = 1; i <= n; i++) {
if (el[a][i] &... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, MAXM = 1e6 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const long long llINF = LLONG_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
const int inv2 = 5e8 + 4;
int n, b, k, x;
struct Matrix {
long long a[105][105];
Matrix operator*(const M... | 6 |
#include <bits/stdc++.h>
using namespace std;
int64_t factorial(int64_t n) {
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int64_t power(int64_t x, int64_t y) {
int64_t res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
int64_t powerMod(int64_t x, i... | 0 |
#include <bits/stdc++.h>
using namespace std;
char str[50010];
int f[3000][3000];
pair<int, int> path[3000][3000];
int c[26], n;
bool mk[3000];
void go(int a, int b) {
if (a == 0 && b == 0) return;
go(path[a][b].first, path[a][b].second);
if (path[a][b].first + 1 == a && path[a][b].second + 1 == b) {
mk[a - 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x;
}
const int N = 600005;
int n, m, r[N];
long long g, mod, w[2][N], W[2][N], X[N], Y[N], a[N], b[N], c[N], da[N], rb... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[2005][2005], visit[2005][2005], cx[2005 * 2005], cy[2005 * 2005],
can[2005 * 2005], c1, n, cnt, cntC, cntS;
double dist[2005 * 2005], Ox, Oy;
void dfs(int x, int y) {
if (visit[x][y]) return;
visit[x][y] = 1;
++cnt;
bool bo = 0;
Ox += x;
Oy += y;
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int casi;
cin >> casi;
while (casi--) {
int n;
cin >> n;
if (n == 1) {
cout << 2 << '\n';
continue;
} else if (n == 2) {
cout << 4 << " " << 6 << '\n';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a == b)
cout << a << endl;
else
cout << 1 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int letternum = 26;
const int maxn = 5005;
bool checked[maxn];
int main() {
string s;
cin >> s;
int n = s.size();
s = s + s;
vector<vector<int> > cnt(letternum);
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a'].push_back(i);
}
int ans = 0;
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline P smin(P &a, Q b) {
if (b < a) a = b;
return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
if (a < b) a = b;
return a;
}
const long long N = 1e5 + 5;
long long read() {
long long x;
cin >> x;
return x;
}
long lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = ~0ull / 4;
const long long maxn = 210000;
bool can[2][30][60][60];
bool ev[30][800];
long long dp[60][60];
vector<string> v[30];
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string s[2];
cin >> s[0] >> s[1];
long long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[405];
vector<int> R[405];
int a[405][405];
int bfs(vector<int> vec[], int n, int src) {
int val;
queue<int> q;
int taken[405] = {0}, distance[405] = {0};
q.push(src);
taken[src] = 1;
distance[src] = 0;
while (!q.empty()) {
int u = q.front();
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long x[2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
x[i % 2] += a / 2;
x[(i + 1) % 2] += (a + 1) / 2;
}
cout << min(x[0], x[1]) << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 9;
int b, g, n;
int main() {
scanf("%d%d%d", &b, &g, &n);
int cou = 0;
for (int i = 0; i <= b; i++) {
if (n - i >= 0 && n - i <= g) {
cou++;
}
}
printf("%d", cou);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
if (n < 2) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; i * i <= n; i = i + 2) {
if (n % i == 0) return false;
}
return true;
}
long long twomutiplierwithminimumdiffrence(long long n) {
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int T;
cin >> T;
while (T--) {
string a;
string b;
cin >> a >> b;
if (a[0] != b[0]) {
cout << "NO\n";
continue;
}
a += '#';
int curr = -1;
int flag = 0;
int c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
double x[3];
cin >> a >> b >> c;
if (a == 0 && b == 0 && c == 0) {
cout << "-1" << endl;
return 0;
}
if (a == 0 && b == 0) {
cout << "0" << endl;
return 0;
}
if (a == 0) {
cout << "1" << endl;
cout << fixe... | 6 |
#include <bits/stdc++.h>
using namespace std;
pair<int, long long> findMaxBlocksAndVolumeHelper(long long volumeLimit,
int currentBlocks,
long long currentVolume) {
if (volumeLimit == 0) return make_pair(currentBlocks,... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, r, i, a[100005], x, m = 1000000000000, mn = 0;
int main() {
cin >> n >> l >> r;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
cin >> x;
a[i] += x;
m = min(m, a[i]);
mn = max(mn, a[i]);
}
if (mn - m > r - l)
co... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300;
char s[N];
int n;
char ss[] = "AGCT";
int cnt[4];
int main() {
scanf("%d", &n);
scanf("%s", s);
if (n % 4) {
puts("===");
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
if (s[i] == ss[j]) cnt[j]++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 401000;
const int BSIZE = 200;
const int NBUCK = 200000 / BSIZE + 20;
int N, Q;
int par[MAXN];
int ssize[MAXN];
int sloc[MAXN];
vector<int> child[MAXN];
int nord;
int ord[MAXN];
long long a[MAXN], b[MAXN];
pair<long long, long long> pp[MAXN];
int M;
long lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int a[16];
long long int dp[1000000];
long long int cost[16][16];
long long int modpow(long long int base, int exp) {
if (exp == 0) return 1;
if (exp == 1) return base;
long long int pv = modpow(base, exp / 2);
pv = (pv * pv) % int(1e9 + 7);
if (exp % 2 ... | 8 |
#include <bits/stdc++.h>
using namespace std;
char a[15], b[15], c[15], d[15];
int main() {
scanf("%s%s", a, b);
printf("%s %s\n", a, b);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s%s", c, d);
if (!strcmp(a, c))
strcpy(a, d);
else
strcpy(b, d);
printf("%s %s\n"... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, m, l, r, c, p, ans;
vector<long long> cnt[1000005], val[1000005];
struct BIT {
long long tree[1000005];
BIT() {
memset(tree, 0, sizeof(tree));
return;
}
inline long long lowbit(long long x) { return x & (-x); }
inline void add(long long pos... | 6 |
#include <bits/stdc++.h>
using namespace std;
int rev(int n) {
int res = 0;
for (int i = 0; i < 8; ++i) res += ((n >> i) & 1) << (8 - i - 1);
return res;
}
int main() {
string s;
while (getline(cin, s)) {
int prev = 0;
for (int i = 0; i < s.length(); ++i) {
int t = (prev - rev(s[i]) + 256) % 256... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[300005] , spare = 0;
int main(){
ll n , q , i , j;
cin >> n >> q;
set < pair < ll , ll > > cur;
for(i = 1;i<=n;i++){
cin >> a[i];
cur.insert( { i , a[i] } );
}
while(q--){
ll x , gone = 0;
cin... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
while (*s != ',') cerr << *s++;
cerr << " = " << x << ',';
_DBG(s + 1, a...);
}
con... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct num {
int num;
int mo;
} a[10];
bool cmp(num a, num b) { return a.mo < b.mo; }
int main() {
for (int i = 1; i <= 3; i++) {
cin >> a[i].num;
a[i].mo = a[i].num % 3;
}
sort(a + 1, a + 4, cmp);
long long ans;
ans = a[1].num / 3 + a[2].num / 3 + a[3... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, kk;
int a[maxn];
double f[2][maxn][maxn];
int Sum(int n) { return n * (n + 1) / 2; }
int main() {
scanf("%d%d", &n, &kk);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
kk = min(kk, 900);
for (int k = 1; k <= kk; k++) {
f... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
;
{
int n, k, q;
cin >> n >> k >> q;
long long t[n + 1];
for (int i = 1; i < n + 1; i++) cin >> t[i];
vector<pai... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long maxn = 1000000;
long long BIT[1000001];
void update(long long pos, long long val) {
for (long long i = pos; i <= maxn; i += i & (-i)) {
BIT[i] += val;
}
}
long long bitse(long long val, long long n) {
long long sum = 0;
long long pos = 0;
long long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int k;
cin >> k;
vector<vector<bool> > vec(1, vector<bool>(1, 1));
while (k--) {
int n = vec.size();
for (int i = 0; i < n; i++) {
vec[i].insert(vec[i].end(), vec[i].begin(), vec[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int const INF = numeric_limits<int>::max();
inline int count_ones(int a) {
int ans = 0;
while (a > 0) {
ans += a & 1;
a >>= 1;
}
return ans;
}
int const MAX = pow(2, 16);
int const N = 1e5 + 5;
int a[N];
long long m[N];
int main() {
ios::sync_with_stdio(fa... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long maxi = LLONG_MIN;
long long mini = LLONG_MAX;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fast();
int x;
cin >> x;
if (x == 1) {
cout << "-1" << '\n';
} else if (x == 2) {
cout << "2"
<< " "
... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.