solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int inf = numeric_limits<int>::max();
const long long int linf = numeric_limits<long long int>::max();
const long long int MOD = (long long int)1e9 + 7;
const long long int mod = 998244353;
long long int fast_mod(long long int abcd, int expp) {
long long int res = 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int parent[MAXN], size[MAXN];
int n;
vector<int> erased;
set<int> st;
int Find(int x) {
if (x == parent[x]) return x;
return parent[x] = Find(parent[x]);
}
void Union(int x, int y) {
x = Find(x), y = Find(y);
if (x != y) {
parent[y] = x... | 13 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
vector<long long> x, y;
for (long long i = n - 1; i >= 1; i -= 2) {
x.push_... | 3 |
#include <bits/stdc++.h>
using namespace std;
int cho[100010], t_Alice[100010], t_Bob[100010];
int main() {
int n, res_Alice = 0, res_Bob = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> cho[i];
t_Alice[i] = t_Alice[i - 1] + cho[i];
}
for (int i = n; i > 0; i--) {
t_Bob[i] = t_Bob[i + 1] + cho... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x1 = -1, y1 = -1, x2 = -1, y2 = -1;
string s[120];
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (x1 == y1 && x1 == -1 && s[i][j] == 'B') {
x1 = i, y1... | 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 x, y, z;
x = k * l / nl;
y = c * d;
z = p / np;
if (x <= y && x <= z) {
cout << x / n;
} else if (y <= z)
cout << y / n;
else
cout << z / n;
return ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, ans;
cin >> n >> t;
if (n == 1) {
if (t < 10)
cout << t;
else
cout << -1;
} else {
if (t == 2 || t == 4 || t == 8) {
if (n == 2)
cout << "16";
else {
if (n == 3 && t == 8)
cout << "... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int dat[100003];
vector<int> adj[100003];
int main() {
scanf("%d%d", &n, &m);
long long ans = 0;
for (int i = 0; i < m; i++) {
scanf("%d", &dat[i]);
dat[i]--;
if (i > 0) ans += abs(dat[i] - dat[i - 1]);
}
for (int i = 0; i < m; i++) {
if ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int const N = 200005;
long long int pr[N + 20], sum[N + 20];
vector<long long int> adj[N + 20];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int x, n;
cin >> n;
for (long long int i = 2; i <= n; i++) {
cin >> pr[i];
}
c... | 8 |
#include <bits/stdc++.h>
const int MAX_D = 10;
int t[MAX_D][MAX_D], p[MAX_D * MAX_D];
long double f[MAX_D * MAX_D];
bool v[MAX_D * MAX_D];
void init() {
for (int i = 0, x = 0, y = 0, d = 1; i < MAX_D * MAX_D; ++i) {
t[x][y] = i;
if (y == 9 && d == 1) {
x += 1;
d = -1;
} else if (y == 0 && d ==... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
long long l;
cin >> n >> m >> l;
long hair[n];
bool lc = false;
long cnt = 0;
for (long i = 0; i < n; i++) {
cin >> hair[i];
if (hair[i] > l && !lc) {
cnt += 1;
lc = true;
} else if (hair[i] <= l && lc) {
lc... | 5 |
#include <bits/stdc++.h>
using namespace std;
int x[26], y[26], z[26], q[26];
int p[1 << 20];
int n, m;
char s[26][26];
int g[26][26];
int mi[26];
int a, b, c, d;
int dy[1 << 20];
inline void qmi(int &a, int b) {
if (a > b) a = b;
}
inline void qma(int &a, int b) {
if (a < b) a = b;
}
int main() {
scanf("%d%d", &... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int a, b, c;
node() { a = b = c = 0; }
};
string str;
node st[3000005];
int n, l, r;
node query(int ss, int se, int qs, int qe, int si) {
if (qs <= ss && qe >= se) return st[si];
if (se < qs || ss > qe) {
node y;
y.a = y.b = y.c = 0;
return... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 65;
bitset<500 + 10> f[MAXN][2][500 + 10], las, now;
int n, m;
unsigned long long ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
f[0][z][x][y] = 1;
}
for (int i = 1; i < ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> H[2];
const int maxn = 1e5 + 100;
int T[200], a[maxn], b[maxn];
string str;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> str;
memset(T, 0, sizeof(T));
for (int j = 0; j < str.length(); j++) {
T[str[j]]++;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x;
cin >> x;
cout << x / 2 + 1;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
if (n == 1) {
if (t == 10)
cout << -1;
else
cout << t;
return 0;
}
if (t == 10) {
cout << 1;
for (int i = 0; i < n - 1; i++) {
cout << 0;
}
return 0;
}
for (int i = 0; i < n; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int n, l;
char s[MAXN];
map<long long, long long> mp;
map<long long, long long>::iterator p;
int main() {
while (~scanf("%d", &n)) {
mp.clear();
for (int i = 0; i < n; ++i) {
scanf("%s", s);
l = strlen(s);
long long xx =... | 8 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
void solve() {
long long n, m, k, x, y, z, sx = 0, sy = 0, sz = 0, ct = 0, sum = 0;
cin >> x >> y >> z >> k;
long long t1 = ((((x > z) ? z : x) > k) ? k : ((x > z) ? z : x));
long long t2 = ((x - t1 > y) ? y : x - t1);
cout << 256 * t1 + 32 * ... | 0 |
#include <bits/stdc++.h>
int main() {
int n, i, j;
scanf("%d", &n);
for (i = 0; i < n / 2 + 1; i++) {
for (j = 0; j < n / 2 - i; j++) {
printf("*");
}
for (j = 0; j < (i * 2 + 1); j++) {
printf("D");
}
for (j = 0; j < n / 2 - i; j++) {
printf("*");
}
printf("\n");
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct peoplebus {
int l, r, t, id, type;
bool operator<(const peoplebus &p) const {
return (l < p.l) || (l == p.l && type < p.type);
}
} a[200500], *o;
int b[(200500 * 4)];
int id[(200500 * 4)];
int ans[200500];
int hack;
int n, m, nm;
vector<int> xx;
int get_coo... | 16 |
#include <bits/stdc++.h>
using namespace std;
char a[11], b[11];
int main() {
while (cin >> a >> b) {
int l1 = strlen(a);
int l2 = strlen(b);
int i, j;
if (b[0] != '0' && l2 > l1) {
cout << "WRONG_ANSWER" << endl;
continue;
}
int t = 0;
for (i = 0; b[i] != '0'; i++) t++;
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, g, b;
int max = 0;
int mx = 0;
scanf("%d%d%d", &r, &g, &b);
for (int i = 0; i < 3; i++) {
if (max < r / 3 + g / 3 + b / 3 + mx) max = r / 3 + g / 3 + b / 3 + mx;
if (r > 0 && g > 0 && b > 0) {
r--;
g--;
b--;
mx++... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Maxk = 1005;
string mul(string a, string b) {
int res[Maxk];
memset(res, 0, sizeof(res));
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = 0; i < a.length(); i++) {
for (int j = 0; j < b.length(); j++) {
res[i + j] += (a[i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int MAXH = 20;
typedef struct node {
int mn;
vector<node *> ch;
node() {
ch.resize(2, 0);
mn = inf;
}
} * nodep;
void add(nodep &t, int h, int x) {
if (!t) t = new node();
t->mn = min(t->mn, x);
if (h == -1) return;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> base = {{2, 1, 1, 1, 0, 0}, {1, 2, 1, 1, 0, 0},
{1, 0, 1, 0, 0, 0}, {0, 1, 0, 1, 0, 0},
{1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 1, 1}};
int main() {
static_cast<void>(0);
int n, sx, sy, dx, dy;
long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'
typedef long long ll;
typedef pair<int,int> pii;
typede... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <typename T>
inline bool remin(T& c, const T& n) {
if (n < c) {
c = n;
return 1;
}
return 0;
}
template <typename T>
inline bool remin2(T& c, const T& n) {
if (c < 0 || n < c) {
c = n;
return 1;
}... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 16 |
#include <bits/stdc++.h>
using namespace std;
double mysqrt(double x) { return max(0.0, sqrt(x)); }
int sgn(double x) {
if (fabs(x) < 1e-8) return 0;
if (x < 0)
return -1;
else
return 1;
}
struct point2 {
double x, y;
point2() {}
point2(double _x, double _y) { x = _x, y = _y; }
point2 operator-(co... | 14 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int maxn = 5010;
int nxt[maxn][maxn], dp[maxn][maxn];
char s[maxn];
int main() {
int n;
scanf("%d %s", &n, s);
for (int i = n - 1; i >= 0; --i)
for (int j = n - 1; j >= 0; --j)
nxt[i][j] = s[i] == s[j] ? nxt[i + 1][j + 1] + 1 : 0;
for (int i = n ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXM = 300005;
struct node {
node *l, *r, *p, *m;
int f, v, w, s, id;
node(int v, int w, int id)
: l(), r(), p(), m(this), f(), v(v), w(w), s(w), id(id) {}
};
inline bool is_root(node *n) {
return n->p == NULL || n->p->l != n... | 22 |
#include <bits/stdc++.h>
char ch;
void re(int& x) {
while (ch = getchar(), ch < 33)
;
x = ch - 48;
while (ch = getchar(), ch > 33) x = x * 10 + ch - 48;
}
using namespace std;
const int mod = 1000000007;
int n, ans, a[100001], pre[100001], nxt[100001];
map<int, int> last;
int l[1 << 18], r[1 << 18], tagl[1 <<... | 27 |
#include <bits/stdc++.h>
using namespace std;
int binSearch(int l, int r, bool (*f)(int)) {
int k = l - 1;
int step = 1;
while (step <= r - l) step *= 2;
step /= 2;
while (step > 0) {
if (k + step >= r) {
step /= 2;
continue;
}
if (f(k + step)) k += step;
step /= 2;
}
return k ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long g = 31623;
long long n, sum;
long long cnt[510], poww[32000][2];
long long read() {
long long r = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c <= '9' && c >= '0') r = (r << 1) + ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int fun(int a) {
int sum = 0;
for (int i = 1; i <= 4; i++) {
sum = sum + (a % 10);
a = a / 10;
}
return sum;
}
int main() {
int n, m, p;
cin >> n;
m = n;
for (int i = 1;; i++) {
if (fun(m) % 4 == 0)
break;
else {
m++;
n = m;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100000 + 5;
const long double EPS = 1E-10;
int N, H, K;
pair<pair<int, int>, int> v[NMAX];
int sol[NMAX];
bool solve(long double t) {
int cnt = 0;
for (int i = 1; i <= N && cnt < K; ++i)
if ((cnt + 1.0L) * H <= t * v[i].first.second + EPS)
sol... | 12 |
#include <bits/stdc++.h>
using namespace std;
int mark[1111111];
int dat[1111111];
vector<int> v, q, w;
int main() {
int n;
int f = 0;
scanf("%d", &n);
memset(mark, 0, sizeof(mark));
int i;
for (i = 1; i <= n; i++) {
scanf("%d", &dat[i]);
}
int t;
scanf("%d", &t);
for (i = 0; i < t; i++) {
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
const int MOD = 1e9 + 7;
void FASTIO() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ans;
string a, b;
int main() {
cin >> a >> b;
ans = max(b.length(), a.length());
if (a == b) {
ans = 0;
}
cout << (ans ? ans : -1) << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, maxim = -1, minim = 100000;
cin >> n >> k;
int ar[n];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
int maxpos, minpos;
vector<pair<int, int>> v;
for (int i = 0; i < k; i++) {
maxim = -1, minim = 100000;
for (int j = 0; j <... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int64_t N = 1e5 + 7, M = 2e5 + 7;
int64_t IX = 1e18, IN = -1e18;
int64_t ten[] = {
1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000,
10000000000, 100000000000, 1000000000000... | 5 |
#include <bits/stdc++.h>
int sch[26];
int tch[26];
char s[102];
char t[102];
void worker() {
memset(sch, 0, sizeof(int) * 26);
memset(tch, 0, sizeof(int) * 26);
scanf("%s", s);
scanf("%s", t);
int n = strlen(s);
for (int i = 0; i < n; i++) sch[s[i] - 'a'] = 1;
for (int i = 0; i < n; i++) tch[t[i] - 'a'] =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 20;
map<pair<int, int>, int> M;
int dp[MAXN], n, back[MAXN];
pair<int, pair<pair<int, int>, pair<int, int> > > monkey[MAXN];
bool cmp(pair<int, pair<pair<int, int>, pair<int, int> > > A,
pair<int, pair<pair<int, in... | 16 |
#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
if (fu) v = -v;
}
const int INF = 1e9... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, count = 0;
cin >> k;
vector<int> A(12);
for (int i = 0; i < 12; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
for (int i = 11; i >= 0; i--) {
if (k <= 0) {
break;
}
k -= A[i];
count++;
}
if (k > 0) {
cout... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
int main() {
string s;
int n;
cin >> n;
cin >> s;
string ans;
for (int _n((n)-1), i(0); i <= _n; ++i) {
if (s[i] == '0' || s[i] == '1') continue;
switch (s[i]) {
case '4':
ans += "223";
br... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int n;
long long k;
cin >> n >> k;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (k == 0) break;
if ((i % 2 == 0) && (i + 2) < n &&
(s[i] == '4' && s[i + 1] == '7' && s[i + 2] == '7')) {
k %= 2... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
const int mod = 1e9 + 7;
const int MAXR = 55, MAXSIZ = 7850, MAXP = MAXR * MAXR * 4;
template <typename _T>
void read(_T &x) {
x = 0;
char s = getchar();
int f = 1;
while (s > '9' || s < '0') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' &&... | 23 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool compare(const T &a, const T &b) {
return a.second < b.second;
}
long long ans[1100000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ans[1] = 1, ans[2] = 1;
long long t1 = 1, t2 = 2;
while (1) {
i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 7;
long long dif[MAXN], cnt, zro, sqr, res;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
for (long long i = 0, a; i < n; i++) {
cin >> a;
long long x = sqrt(a);
if (a == 0... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
#pragma GCC optimize("O3")
using namespace std;
const long double eps = 1e-6;
const long double PI = acosl(-1.0);
struct Point {
long double x, y;
Point() : x(0), y(0) {}
Point(long double x, long double y) : x(x), y(y) {}
Point(const Point ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9, I = 1e18;
const int mxn = 1e5;
int t, n;
string s, pr, ans;
bool fl;
void solve() {
fl = 0;
ans = "";
cin >> n;
cin >> pr;
ans = pr;
for (int i = 1; i < n - 2; i++) {
cin >> s;
if (pr[1] != s[0]) {
fl = 1;
ans += s[0]... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else {
if (y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}
long long fast_powe... | 8 |
#include <bits/stdc++.h>
int cnt[5];
int main() {
int n;
int a;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
cnt[a]++;
}
int ans = 0;
if (cnt[1] <= cnt[2]) {
ans += cnt[1];
cnt[3] += cnt[1];
cnt[2] -= cnt[1];
cnt[1] = 0;
ans += cnt[2] * 2 / 3;
cnt[3] += 2... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int ans = 0;
set<char> vowels = {'a', 'e', 'i', 'o', 'u'};
for (char c : s) {
if (isalpha(c) && vowels.count(c)) ++ans;
if (isdigit(c) && (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int list1[111111];
int pos[111111];
int list2[111111];
int n;
multiset<int> st;
int abs(int x) { return x > 0 ? x : -x; }
void find(int x, int &res1, int &res2) {
multiset<int>::iterator i = st.lower_bound(x);
multiset<int>::iterator j;
if (i == st.begin()) {
res1... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -f;
ch = getchar();
}
while (isdigit(ch)) {
res = res * 10 + ch - '0';
ch = getchar();
}
return res * f;
}
namespace qiqi {
const int N = 55;... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int time = 10;
int solvedCount = 0;
int penalty = 0;
for (int i = 0; i < n; i++) {
time = time + a[i];
if (time <= 720) {
solvedCount++;
if (ti... | 10 |
#include <bits/stdc++.h>
using namespace std;
char s[100010];
int fst[2], lst[2];
int main() {
int n, m;
int l0, l1;
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
for (int i = 1; i <= n && (fst[0] == 0 || fst[1] == 0); ++i)
if (fst[s[i] - '0'] == 0) fst[s[i] - '0'] = i;
for (int i = n; i && (lst[0] == 0 ||... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
void cp() {
string s, t;
cin >> s >> t;
int n = ((int)s.length()), m = ((int)t.length());
bool ok = n >= m;
t = t + "#";
int i = 0, j = 0;
map<c... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string a, b, c;
cin >> a >> b >> c;
int n = a.length();
bool p = true;
for (int i = 0; i < n; i++) {
if (a[i] != c[i] && b[i] != c[i]) {
p = false;
break;
}
}
cout << (p ? "YES" : "NO") << endl;
}
int main() {
int t;
cin ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
cin >> n >> k;
if (n / k & 1) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64777216")
const int size = 120;
void Solve() {
int k, n, m, q;
cin >> k >> n >> m >> q;
vector<string> base;
for (int i = 0; i < n; ++i) {
string name;
cin >> name;
base.push_back(name);
}
char st[10000];
gets(st);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
constexpr int seed = 131;
constexpr long long LLMAX = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr double eps = 1e-8;
constexpr int MAXN = 2e3 + 10;
constexpr int hmod1 = 0x48E2DCE7;
constexpr int hmod2 = 0x60000005;
inline long long sqr(long long x) { return x * x; }
inlin... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const long long int MAXN = 1e3 + 5;
const long long int N = 2e5 + 5;
long long int n, m, k;
void solve() {
long long int x, y;
string s;
cin >> s;
n = s.size();
vec... | 6 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
bool vowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
int col_min(vector<vector<int> >& dp, int i) {
int result = inf;
for (int j = 0; j < 4; j++) {
result = min(result, dp[i][j]);
}
return result;
}
int main() ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, arr[110], a[110];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &arr[i]);
a[arr[i]] = i;
}
int q, p, x, y;
scanf("%d", &q);
for (int i = 0; i < q; ++i) {
scanf("%d%d%d", &p, &x, &y);
if (p == 2) {
swap(arr[... | 9 |
#include <bits/stdc++.h>
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;
}
return i;
}
templat... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 9;
int n, a[MX], ans = 100000000;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int j = 1; j <= 100; j++) {
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += (a[i] * abs(i - j) + a[i] * (j - 1));
sum +=... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int n, a[1000010], inv[1000010], s[1000010];
long long int pw(long long int k, long long int x) {
if (x == 0) return 1;
if (x == 1) return k;
if (x % 2) {
long long int tmp = pw(k, x / 2);
return tmp * ((tmp * k) % 1000000007) % 1000000007;
} else ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxk = 10 + 2;
const int maxn = 1e5 + 17;
int N, M, Q;
int in[maxk][maxn];
int msz;
int mp[4 * maxk];
int par[4 * maxk];
inline int find(int x) { return par[x] = x == par[x] ? x : find(par[x]); }
struct Node {
int l, r;
int lv[maxk], rv[maxk];
int size;
No... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long int inf = 0x3f3f3f3f;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int i;
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[51];
int main() {
long long n, m;
cin >> n >> m;
int val = 1, start = 0, end = n - 1;
for (int i = 1; i <= n; i++) {
long long temp = pow(2ll, n - i - 1);
if (temp >= m) {
a[start] = i;
start++;
} else {
a[end] = i;
end--;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> v(n);
map<long long, long long> m;
long long d = -1, mx = 0;
for (long long &first : v) {
cin >> first, m[first]++;
if (mx < m[first... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n, i, j, k = 0, l = 0, m = 0;
cin >> n;
int b[n], c[n], d[n], e[n];
for (i = 0; i < n; i++) {
cin >> b[i];
if (b[i] > n)
e[m++] = i;
else if (a[b[i]] > 0)
c[k++] = i;
a[b[i]]++;
}
for (i = 1; i <= n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int n;
cin >> n;
for (int j = n + 1; j <= 2 * n; j++) {
cout << 2 * j << " ";
}
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int ans = 0, a[1000000], s[1000000], d[1000000], h[1000000];
void l(int e, int e2, int r, int r2, int v) {
if (v == -1) return;
if (d[v] == -1) {
h[ans] = v;
ans++;
return;
}
int c, e1 = e + ((e2 - e) >> 1), r1 = r + ((r2 ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, r;
scanf("%d %d %d", &a, &b, &r);
r *= 2;
int s = (a / r) * (b / r);
if (s == 0) {
printf("Second\n");
} else
printf("First\n");
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
int left, right, cnt;
long long sum[5];
int mid() { return (left + right) >> 1; }
} f[401000];
char op[101000][10];
int num[101000];
int temp[101000];
int cnt;
void build(int left, int right, int k) {
f[k].left = left, f[k].right = right, f[k].c... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.second < b.second);
}
long long gcd(long long a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
... | 10 |
#include <bits/stdc++.h>
const int N = 1e5 + 100;
const int M = 1e5 + 100;
const double EPS = 1e-9;
using namespace std;
int a, b, c, l;
long long ans;
long long calc(long long a1, long long len) {
long long tp = ((a1 + a1 + len - 1ll) * len) / 2ll;
return tp;
}
long long solve(int a1, int b1, int c1, int len) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
const long long int MOD = 998244353;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int fa[MAXN];
int flag[MAXN];
int home[MAXN];
int sum[MAXN];
int find(int x) {
if (x != fa[x]) {
return fa[x] = find(fa[x]);
}
return x;
}
void Union(int fx, int fy) {
fx = find(fx);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long pos[100010];
long long num[100010];
int main() {
long long n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> pos[i];
num[pos[i] - 1] = i;
}
long long ans = 0;
for (int i = 0; i < m; i++) {
long long x;
cin >> x;
long... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 9e18;
const int inf = 2147483647;
long long phi(long long n) {
long long ans = n;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
ans = ans / i * (i - 1);
while (n % i == 0) n /= i;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p, x, y;
int z = 0;
cin >> p >> x >> y;
;
int a[30] = {0};
int s = (x / 50) % 475;
for (int i = 0; i < 25; ++i) {
s = s * 96 + 42;
s %= 475;
a[i] = s + 26;
}
sort(a, a + 25);
if (binary_search(a, a + 25, p) && x >= y) {
c... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int a[N];
int b[N];
int delta[N][N];
int undef;
void fail() {
printf("NO\n");
exit(0);
}
struct Query {
int t, l, r, res;
Query(int t = 0, int l = 0, int r = 0, int res = 0) {
this->t = t;
this->l = l;
this->r = r;
this->res = res... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int c[N];
vector<pair<int, int> > v[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", c + i);
long long res = 0;
while (m--) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
v[a].push_back(pair<... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x1, x2, y1, y2;
x1 = y1 = 1;
x2 = y2 = n;
int high, low, cc;
high = n;
low = 1;
cc = 0;
while (low <= high) {
int mid = (high + low + 1) / 2;
printf("? %d %d %d %d\n", mid, y1, x2, y2);
fflush(stdout);
in... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
cin.ignore(256, '\n');
string n;
getline(cin, n);
int ans = 0;
int vol = 0;
int LOW = 64;
int UP = 91;
for (int i = 0; i < n.size(); i++) {
if (n[i] > LOW && n[i] < UP) {
vol++;
}
if (n[i] == 32 || i == n.s... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct robot {
int l, e;
};
int n, m, q;
long long d[505][505][2], c[505][505], g[505];
basic_string<robot> h[505][505], v[505][505];
bool ok(int x) { return x >= 0 && (x & 3) == 0; }
void mn(long long& x, long long y) { x = min(x, y); }
int main() {
ios_base::sync_with... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, ch;
cin >> s;
ch = s;
reverse(s.begin(), s.end());
string l;
l = ch + s;
cout << l;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<string> arr[2];
for (int i = 0; i < n + m; i++) {
string nam, ip;
cin >> nam >> ip;
arr[0].push_back(nam);
arr[1].push_back(ip);
}
for (int i = n; i < n + m; i++) {
cout << arr[0][i] << " " << arr[... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
if (a < b) a = b;
}
const int maxn = 200 + 10;
const int inf = 1 << 28;
int n, m, k;
int a[maxn];
int d[maxn][maxn];
int pos[7];
int d... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
double d = pow(b, 2.0) - 4.0 * a * c;
if (d < 0 || a == 0 && b == 0 && c != 0) {
cout << 0 << "\n";
return 0;
} else if (a == 0 && b == 0 && c == 0) {
cout << -1 << "\n";
return 0;
} else if (a == ... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool h = true;
vector<int> v;
void add(int x, int y) {
if (h) {
v.push_back(x);
v.push_back(y);
} else {
v.push_back(y);
v.push_back(x);
}
}
int find(int x1, int y1, int x2, int y2) {
if (h) {
printf("? %d %d %d %d\n", x1, y1, x2, y2);
} else {... | 14 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000009] = {0};
int arr1[1000009] = {0};
int t, a = -1, cd = 0, c, d;
bool check(int x, int y) {
if (a >= x) return 0;
c = x - a - 1;
d = cd - c;
if (d >= y || d < 0) return 0;
for (int f = 0; f < t; f++) arr1[f] = arr[f];
for (int f = 0; f < x; f++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
cin >> n;
cin >> a;
if (a % 2 == 0)
cout << (n - a) / 2 + 1;
else
cout << a / 2 + 1;
return 0;
}
| 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.