solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[2005][2005], f[2005][2005], n, m, k, tx, ty;
int myabs(int x) {
if (x < 0)
return -x;
else
return x;
}
bool work(int u, int v, int w) {
int i, j, l, r;
l = u - w;
if (l < 1) l = 1;
r = u + w;
if (r > n) r = n;
for (i = l; i <= r; i++) {
j =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s;
cin >> s1 >> s2 >> s;
map<char, char> m;
for (int i = 0; i < 26; i++) {
m[s1[i]] = s2[i];
}
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i])) {
char t = tolower(s[i]);
s[i] = toupper(m[t]);
} else if... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long N;
int dp[10][10];
int nval[10][10];
int pm[1000010];
long long ndp[10][10];
int nnval[10][10];
int mdig(long long x) {
return ((x == 0) ? 0 : max(x % 10, (long long)mdig(x / 10)));
}
inline int fmdig(long long x) { return max(pm[x / 1000000], pm[x % 1000000]); ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
cin >> n;
for (i = 2; i * i <= n; i++) {
while (n % (i * i) == 0) {
n = n / i;
}
}
cout << n << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class V>
ostream& operator<<(ostream& s, pair<T, V> a) {
s << a.first << ' ' << a.second;
return s;
}
long long int ask(long long int a, long long int b) {
cout << "? " << a << ' ' << b << endl;
long long int x;
cin >> x;
return x;
}
int main(... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1009;
const long long MAXN = 1000005;
const double pi = acos(-1);
long long rev[4 * MAXN];
void fft(complex<double> *a, long long n, long long opt) {
long long bit = 0;
while ((1 << bit) < n) bit++;
for (long long i = 0; i < n; i++) {
rev[i] ... | 18 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
//first second
//memset(dp, -1, sizeof(dp));
//string binary =bitset<8>(n).to_string();
//(mod)->(10*mod+currentmodulo)%m
// bool compare(pos x,pos y)
// {
// return x.a < y.a;
// }
struct keycompare {
bool operator()(c... | 1 |
#include <bits/stdc++.h>
using namespace std;
int T, n, m, memo[105][105], retuser[105];
string name[105], message[105];
bool dp[105][105];
bool isok(char c) {
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z'))
return true;
return false;
}
int cal(int id, int bef) {
if (id >... | 14 |
#include <bits/stdc++.h>
std::mt19937_64 mersenne_twister(
std::chrono::steady_clock::now().time_since_epoch().count());
namespace McDicCP {
int ask(int ai, int bi) {
std::cout << "? " << ai << ' ' << bi << std::endl;
int ret;
std::cin >> ret;
if (ret == -1) exit(0);
return ret;
}
void answer(int undigsh,... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long expo_pow(long long x, long long y) {
if (y == 0) return 1;
y = y % (mod - 1);
x %= mod;
if (y == 0) y = mod - 1;
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
x = (x * x) % mod;
y >>= 1;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int d[5010], mp[5010];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
mp[a]++;
int t = b > a ? b - a : b - a + n;
if (!d[a]) {
d[a] = t;
} else
d[a] = min(d[a], t);
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int N, M;
vector<int> adj[MAXN];
pair<int, int> bt[MAXN][MAXN][2];
queue<tuple<int, int, int> > Q;
deque<pair<int, int> > ans;
void go(int a, int b, int c) {
if (!c) ans.push_back(pair<int, int>(a, b));
pair<int, int>& x = bt[a][b][c];
if (x.firs... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, vx, vy;
long long k, t, p, q, c;
long long gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int abss(int a) { return a < 0 ? -a : a; }
void exgcd(long long &x, long long &y, int a, int b) {
if (b == 0)
x = 1, y = 0;
else {
exgcd(y, x, b, ... | 18 |
#include <bits/stdc++.h>
using namespace std;
struct P {
double first, second;
bool sp;
P(double first, double second, bool sp)
: first(first), second(second), sp(sp) {}
};
int n, m;
int x[4000], y[4000];
int sx, sy, tx, ty;
long long a, b, c;
vector<pair<double, double> > p;
vector<bool> sp;
vector<P> pp;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
int suffix_array_build_rank(int N, const int suffix[], const T equality[],
int new_rank[], int len) {
int cur_rank = 0;
int base = suffix[cur_rank];
new_rank[base] = cur_rank;
for (int i = 1; i < N; ++i) {
int cu... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long inf = 1e18;
long long pow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) {
res = res * a;
}
a = a * a;
b >>= 1;
}
return res;
}
signed main() {
ios_base::sync_with_stdio(f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int A[100000];
int abs(int x) {
if (x < 0) return -1 * x;
return x;
}
int main() {
int n, i, sum1 = 0, sum2 = 0;
cin >> n;
for (i = 0; i < n / 2; i++) {
cin >> A[i];
A[i]--;
}
sort(A, A + n / 2);
int w = n - 1;
int b = n - 2;
for (i = n / 2 - 1; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[2], t[2], aux, sc, tc, v[100];
int ss, tt, k = 0;
void RD() {
while (ss > tt && sc < tc) {
ss--;
sc++;
k++;
strcpy(v + strlen(v), "RD");
}
}
void LD() {
while (ss > tt && sc > tc) {
ss--;
sc--;
k++;
strcpy(v + strlen(v), "LD");
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline void rdl(int &x) {
x = 0;
bool check = false;
register int c;
do {
c = getchar();
if (c == '-') check = true;
} while (c < 48 || c > 57);
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (check) x = -x;
}
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
return os << "(" << p.first << ", " << p.se... | 16 |
#include <bits/stdc++.h>
int main() {
int ind;
long mov;
scanf("%ld", &mov);
scanf("%d", &ind);
mov = mov % 6;
if ((mov == 0 && ind == 1) || (mov == 1 && ind == 0) ||
(mov == 2 && ind == 0) || (mov == 3 && ind == 1) ||
(mov == 4 && ind == 2) || (mov == 5 && ind == 2))
printf("1");
else if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void kehsihba() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
long long n;
cin >> n;
vector<long double> arr(n);
for (long long i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
arr[i] = (atan2(y, x) * 180 / 3.14159265... | 10 |
#include <bits/stdc++.h>
const int kN = 2e5 + 10;
const int kInf = 1e9 + 2077;
int n, m, q, e_num, val[kN], head[kN], v[kN << 1], ne[kN << 1];
int dfnnum, cnt, dfn[kN], low[kN];
int hld_dfnnum, hld_dfn[kN], s[kN];
int fa[kN];
std::vector<int> newv[kN];
std::stack<int> st;
std::multiset<int> minval[kN];
inline int read(... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000007;
int n, m, cnt;
int to[210], nxt[210], head[110], siz[110];
long long f[110][110][110], g[110][110], c[110][110], h[110], bt[110];
void dfs(int x, int fa) {
f[x][1][0] = 1, siz[x] = 1;
for (int i = head[x], j, k, a, b, y; i != -1; i = nxt[... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int t[5];
int a[5];
while (~scanf("%d%d%d%d%d", &t[0], &t[1], &t[2], &t[3], &t[4])) {
sort(t, t + 5);
int ans = 0, ma = 0, mark = 0;
int tim = 1;
int j = 0;
for (int i = 0; i < 4; i++) {
if (t[i] != t[i + 1]) {
a[j++]... | 0 |
#include <bits/stdc++.h>
long long a[200005];
int n, m, k, x;
inline bool check(int mid, int s) {
return (a[s] - (long long)mid * k - 1) / (mid + 1) + 1 <= m;
}
int main() {
long long s = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
scanf("%d%d", &m, &k);
for (int i = 1; i <= n; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
long n, p, temp, ans;
vector<long> vec[100], ovr;
vector<long> av;
long gdeg(long x) {
long r = 0;
while (x) {
r++;
x /= 2;
}
return r - 1;
}
long ar[200000];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >... | 10 |
#include<iostream>
#include<stdio.h>
using namespace std;
#include <set>
#include<vector>
#include<algorithm>
#define ll long long
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include<queue>
#include<map>
#include<stack>
#include<bits/stdc++.h>
const int maxn = 3e5+7... | 11 |
#include <bits/stdc++.h>
using namespace std;
void testcase(int t) { cout << "Case #" << t << ": "; }
void online() {}
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
string a, b;
cin >> a >> b;
for (int i = 0; i < n; i++) {
if (a[i] > b[i]) {
cout << "-1" << endl;
return;
}
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2 * 1e5 + 10;
ll res, mx;
ll a[N], price[N];
std::vector<ll> con[N];
bool vis[N];
ll cal_dis(ll x, ll y, ll nx, ll ny) {
ll k = (nx - x) * (nx - x) + (ny - y) * (ny - y);
return ceil(sqrt(k));
}
void solve() {
ll r, x, y, nx, ny;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
int n;
while (~scanf("%d", &n)) {
int sum1 = 0, sum2 = 0;
int x;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
sum1 += x;
}
for (int i = 0; i < n; i++) {
scanf("%d", &x);
sum2 += x;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, p = 0, i;
vector<int> v;
cin >> n >> m;
if (n > (m + 1)) {
cout << "-1";
} else if (n >= m) {
while (m > 0) {
cout << "01";
m -= 1;
n -= 1;
}
if (n > 0) {
cout << "0";
}
} else {
while (m > n... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<pair<int, int> > v;
pair<int, int> m;
double Min = 10000000, x, y, z;
cin >> x >> y >> n;
for (int i = 1; i <= n; i++) {
int low = 0, high = 100000;
while (high - low > 1) {
int mid = (high + low) / 2;
z = double(mi... | 9 |
#include <bits/stdc++.h>
const int MaxN = 1000 + 5;
bool graph[MaxN][MaxN];
bool poss[MaxN][MaxN];
int main() {
int n, m, x, y;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
graph[i][j] = poss[i][j] = true;
}
while (m--) {
scanf("%d%d", &x, &y);
graph[x -... | 10 |
#include <bits/stdc++.h>
using namespace std;
double binpow(double a, int n) {
double res = 1.;
while (n) {
if (n & 1) res *= a;
a *= a;
n >>= 1;
}
return res;
}
double n, m;
int main() {
cin >> m >> n;
double ans = 0;
for (double i = 1; i <= m; i += 1.)
ans += (1. - binpow((i - 1.) / m, (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int n, a[N], zero, v[N];
void rec(int neg) {
if (v[neg]) {
return;
}
v[neg]++;
for (int i = 0; i <= min(neg, n); i++) {
for (int j = 0; j <= min(zero, neg - i); j++) {
if (n - i - j <= 2 * n - 1 - neg - zero) {
rec(neg - i + ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, q, cnt, p = 1000000007;
vector<int> a[100020];
int f[100020][17];
int dfn[100020];
int low[100020];
int d[100020];
int c[100020];
int r[100020];
int s[100020], ss;
void mk(int x) {
c[x] += c[f[x][0]];
for (__typeof(a[x].begin()) i = a[x].begin(); i !=... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e3 + 10;
char s[maxn];
int main() {
scanf("%s", s);
int len = strlen(s);
int k = 0, t = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '0') {
if (k)
printf("3 1\n");
else
printf("1 1\n");
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> res[200009];
vector<pair<int, int> > path[200009];
int last[200009];
queue<pair<int, int> > Q;
int main() {
cin >> n;
int a, b;
for (int i = 1; i < n; i++) {
scanf("%d%d", &a, &b);
path[a].push_back({b, i});
path[b].push_back({a, i});
... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
vector<string> vs;
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
vs.push_back(s);
}
string first = vs[0];
bool f1 = 1;
long long cnt = 0;
for (long long i = 0; i < m; i++) {
char old =... | 9 |
#include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' &... | 21 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long MM = 998244353, ans;
int SA[200010], invSA[200010];
long long N, K;
string S;
long long f()
{
int i;
long long c = 1;
for (i = 0; i <= N; i++) invSA[SA[i]] = i;
for (i = 2; i <= N; i++)
{
if (invSA[SA[i] + 1] < invSA[SA[i - ... | 16 |
#include <bits/stdc++.h>
using namespace std;
void func() {
int n, k, tot = 0;
cin >> n >> k;
unordered_map<long long, vector<long long>> m;
unordered_map<long long, long long> mc;
long long a[n], ans[n];
fill(ans, ans + n, -1);
m.clear();
mc.clear();
for (int i = 0; i < n; i++) {
cin >> a[i];
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<int> v;
int n, l = 0, i, k, pre;
cin >> n;
for (i = 1; i <= n; i++) v.push_back(i);
f... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long temp;
cin >> temp;
long long inc = temp / 3ll;
long long rem = temp % 3ll;
if (rem == 2) inc++;
long long fit = inc / 12ll;
rem = inc % 12ll;
cout << fit << " " << rem << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int count = 0;
while (n > 0) {
count += n;
n /= 2;
}
cout << count << "\n";
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char op = getchar();
int F = 1;
while (!isdigit(op)) {
if (op == '-') F *= -1;
op = getchar();
}
while (isdigit(op)) {
x = (x << 1) + (x << 3) + op - '0';
op = getchar();
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
long long f[maxn], a[maxn], b[maxn], s[maxn];
struct Linear_basis {
long long p[70];
int cnt, flag;
void init() {
memset(p, 0, sizeof(p));
cnt = 0;
flag = 1;
}
void Insert(long long x) {
for (int i = 63; i >= 0; i--) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double err = 1e-10;
const double PI = 3.141592653589793;
const int N = 1e5 + 5;
void solve() {
int n, k;
cin >> n >> k;
vector<int> Q(n), second(n);
for (int i = 0; i < n; i++) cin >> Q[i];
for (int i = 0; i < n; i++) cin >> se... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[1123456], cnt[1123456], lcm[1123456];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
if (a[i] <= m) cnt[a[i]]++;
}
for (int i = 1; i <= m; ++i) {
for (int j = i; j <= m; j += i) {
lcm[j] += cnt[i];
... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct rnxt {
template <class T>
operator T() {
T t;
cin >> t;
return t;
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int len = rnxt();
vector<int> masks;
for (int m = (1 << 7) - 1; m < (1 << 13); ++m) {
if ... | 20 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
double acc[10000];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < (int)n; ++i) cin >> acc[i];
double l = 0, r = 1000;
while (abs(r - l) > 0.0000001) {
double mid = (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const double eps = 1e-8;
const int inf = 1e9 + 7;
int a, b, c;
int n;
int x[maxn];
int main() {
cin >> a >> b >> c >> n;
int s = 0;
for (int i = 0; i < n; i++) {
cin >> x[i];
if (x[i] > b && x[i] < c) s++;
}
cout << s << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
int arr[1010];
int dp[1010];
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
}
arr[0] = 0;
for (int i = 2; i <= n; ++i) {
arr[i] = min(max(arr[i - 1], arr[i - 2]), arr[i]);
}
cout << arr[n] << endl... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int res = 0;
while (n) {
if (n % 8 == 1) res++;
n /= 8;
}
cout << res << endl;
return 0;
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
T pow_mod(T a, U b, int mod) {
T r = 1;
for (; b > 0; b >>= 1) {
if (b & 1) r = (long long)r * a % mod;
a = (long long)a * a % mod;
}
return r;
}
namespace multihash {
const int D = 2, N = 25;
array<int, D> B[N], iB[N], M, Z... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, D;
cin >> N >> D;
vector<int> V;
for (int i = 0; i < N; i++) {
int X;
cin >> X;
V.push_back(X);
}
sort(V.begin(), V.end());
int Ans = 0;
for (int i = 0; i < N; i++) {
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int DP[1010][4];
int A[] = {
1, 0, 3, 1, 4, 2, 5, 1, 7, 2,
9, 0, 13, 1, 15, 2, 19, 0, 27, 1,
39, 2, 40, 0, 57, 2, 58, 1, 81, 2,
85, 0,... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int L = 100100;
const int LEN = 35;
const int R = 6;
const long long MAXN = 100001000010000ll;
int n, m, p;
int a[L][R], b[L][R];
long long f[2][LEN];
void init(void) {
cin >> n >> m;
int i, j;
for (i = 1; i < m; i++)
for (j = 0; j < n; j++) scanf("%d", &a[i... | 19 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
template <typename Test, template <typename...> class Ref>
struct is_specialization : std::false_type {};
template <template <typename...> class Ref, typename... Args>
struct is_specialization<Ref<Args...>, Ref> : std::true_type {};
void setIn(string s) { fre... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L',... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long N;
map<pair<long long, int>, pair<long long, int> > F;
pair<long long, int> dfs(long long x, int y) {
long long p = 1;
pair<long long, int> a, b, res;
if (!x) return res;
if (x < 10) return make_pair(1, max(y - x, 0ll));
if (F.count(b = make_pair(x, y)))... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c, d;
cin >> a >> b >> c >> d;
int as, bs, cs, ds;
as = a.size() - 2;
bs = b.size() - 2;
cs = c.size() - 2;
ds = d.size() - 2;
int ba, bb, bc, bd;
ba = 0;
bb = 0;
bc = 0;
bd = 0;
if ((as >= bs * 2 && as >= cs * 2 && as >= ... | 5 |
#include <bits/stdc++.h>
const int BUFFER_SIZE = 1 << 25 | 1;
struct InputOutputStream {
char ibuf[BUFFER_SIZE], *s;
InputOutputStream() : s(ibuf) {
ibuf[fread(ibuf, 1, BUFFER_SIZE, stdin)] = '\0';
}
template <typename T>
inline InputOutputStream &operator>>(T &x) {
while (!isdigit(*s)) ++s;
for (... | 17 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long qmul(long long a, long long b, long long m) {
long long res = 0;
while (b) {
if (b & 1) res = (res + a) % m;
a = (a << 1) % m;
b = b >> 1;
}
return res;
}
inline long long qpow(long lo... | 16 |
#include <bits/stdc++.h>
const int MAXN = 55;
const int d[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
int n, m;
char map[MAXN][MAXN];
int last[MAXN][MAXN];
bool vis[MAXN][MAXN];
bool BFS(int x0, int y0) {
static int que[MAXN * MAXN][2];
char color = map[x0][y0];
int x, y;
memset(vis, 0, sizeof(vis));
que[0][0... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ts;
cin >> ts;
while (ts--) {
int n;
cin >> n;
if (n % 4 == 0)
printf("YES\n");
else
printf("NO\n");
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
vector<int> E[MAXN], rev[MAXN];
int n, d[MAXN], sol[MAXN];
void solve() {
for (int i = 0; i < n + 1; ++i) {
d[i] = 0;
E[i].clear();
rev[i].clear();
sol[i] = 0;
}
priority_queue<int> kju;
bool done = false;
cin >> n;
for ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[100005];
vector<int> col[100005];
vector<int> edgeList[100005];
int Qard[100005];
map<int, bool> used;
int BestCol = -1;
int rep = -1;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) scanf("%d", &arr[i]), col[arr[i]].push_back(i);
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 8 |
#include <bits/stdc++.h>
using namespace std;
int P[200050][20], level[200050];
int n, a = 1, b = 2;
vector<int> edge[200050];
void init(int at, int par) {
level[at] = level[par] + 1;
P[at][0] = par;
for (int i = 1; i < 19; i++) {
P[at][i] = P[P[at][i - 1]][i - 1];
}
}
int lca(int x, int y) {
if (level[x]... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
int a, b, l;
inline double sgn(double x) { return fabs(x) < eps ? 0 : x > 0 ? 1 : -1; }
double solve(double x, double w) {
double o, p, q;
if (sgn(x) == 0)
o = 1, p = 0, q = 0;
else if (sgn(x - asin(1)) > 0)
o = 0, p = 1, q = 0;
else... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const double eps = 1e-7;
int n, k;
struct node {
long long a, b, d;
} a[maxn];
bool cmp(node& a, node& b) { return a.d < b.d; }
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].a);
}
for (int i = 0; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
for (long long i = 0; i < a.size(); i++) in >> a[i];
return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
for (long long i = 0; i < a.size(); i++) out << a[i];
ret... | 11 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O0")
#pragma GCC optimize("O1")
long long pw(int a, int b) {
long long ret = 1;
long long mul = a;
while (b > 0) {
if (b & 1) ret *= mul;
mul *= mul;
b /= 2;
}
ret... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, a, b, c, cnt = 0;
cin >> n >> a >> b >> c;
long long ans = n / a;
long long y = n % a;
if (y >= b) ans += ((y - b) / (b - c)) + 1;
if (n >= b) {
cnt += (n - b) / (b - c) + 1;
n = n -... | 9 |
#include <bits/stdc++.h>
using namespace std;
char en = '\n';
void fileIO() {}
const long long N = 1e12;
const long long MOD = 1e9 + 7;
void solve() {
long long n, t;
cin >> n >> t;
string second;
cin >> second;
long long dp[n + 1], i = n - 1, j;
dp[n] = N;
while (second[i] != '.') {
if (second[i] - '... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
getline(cin, a);
for (int i = a.size() - 1; i >= 0; i--) {
if ((a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= 'a' && a[i] <= 'z')) {
if (a[i] == 'A' || a[i] == 'O' || a[i] == 'U' || a[i] == 'Y' ||
a[i] == 'I' || a[i] == 'E' || a[i]... | 0 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
using namespace std;
int a[210000];
long long ans, n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll x[1 << 18];
void safeout(long long sum, long long m) {
using ld = long double;
long long f = sum / m;
long double s = ld(sum % m) / (ld)m;
if (f >= 10) {
s += sum % 10;
cout << f / 10 << (ld)s / (ld)m << endl;... | 17 |
#include <bits/stdc++.h>
using namespace std;
double DP[210][210][2 * 210 + 10];
double P[210];
int Pakage[210];
int main() {
int N, K, L;
scanf("%d %d %d", &N, &L, &K);
for (int i = 1; i <= N; i++) {
scanf("%lf", &P[i]);
P[i] /= 100;
}
for (int i = 1; i <= N; i++) scanf("%d", &Pakage[i]);
DP[0][0][... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10];
int t, n, i;
for (i = 0; i < 10; ++i) {
a[i] = 0;
}
scanf("%d", &n);
getchar();
vector<int> u;
for (i = 0; i < n; ++i) {
t = getchar() - '0';
switch (t) {
case (2):
a[2] += 1;
break;
case (3):
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, D = 100005;
const int oo = 1e9;
int n, k, a[N], b[N];
int dp[N][2 * D];
int f(int i, int val) {
if (i == n) return val == D ? 0 : -oo;
int &ans = dp[i][val];
if (~ans) return ans;
return ans = max(f(i + 1, val), f(i + 1, val + a[i] - b[i]) + a[i])... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int colour[100002];
void dfs(long long int s, vector<long long int> g[], bool vis[],
long long int c) {
vis[s] = true;
colour[s] = c;
for (long long int i = 0; i < g[s].size(); i++) {
if (vis[g[s][i]] == false) {
if (c)
dfs(g[s][i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 16;
int mox[4] = {0, 0, -1, 1};
int moy[4] = {1, -1, 0, 0};
struct point {
int x, y, st, ans;
point() : x(0), y(0), st(0), ans(0) {}
point(int _x, int _y, int _st, int _ans) {
x = _x, y = _y, st = _st, ans = _ans;
}
} o;
queue<point> q;
int len;
ch... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long dp[N];
int main() {
long long n, m, sum, l, r, i, val;
scanf("%lld%lld", &n, &m);
dp[1] = 1;
sum = 1;
for (i = 2; i <= n; ++i) {
dp[i] += sum;
dp[i] = dp[i] % m;
val = i / 2, l = 2, r = i / val;
while (1) {
dp... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[] = {4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292};
int main() {
cin >> n;
if (n <= 11)
cout << a[n - 1];
else
cout << a[10] + 49 * (n - 11);
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int read(int& a) { return scanf("%d", &a); }
int read(long long& a) { return scanf("%lld", &a); }
int read(double& a) { return scanf("%lf", &a); }
static const int MOD = 1000000007;
static const double PI = acos(-1.0);
static const int N = 1 << 20;
int d[16] = {0, 1, 0, 1, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long n, m;
long long damage[200005];
long long prefix[200005];
long long powr(long long r, long long k) {
long long z = 1;
while (k) {
if (k & 1) z = (z * r) % MOD;
r = (r * r) % MOD;
k >>= 1;
}
return z;
}
long long... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, c1 = 0, c2 = 0, x;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x == 5)
c1++;
else
c2++;
}
x = c1 / 9;
x = x * 9;
if (c2 == 0)
cout << -1;
else {
if (x != 0) {
for (i = 1; i <= x; i++) cout <<... | 2 |
#include <bits/stdc++.h>
int a[100005];
int ans[100005];
int b[50005];
int main() {
int n, i, m, x, y, t;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
int j;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) b[j] = 0;
int in, ma;
in = -1;
ma = 0;
for (j = i; j <= n; j++)... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5050;
const int M = 6;
const int H = 90;
int lo[M], hi[M];
int pts[M];
int a[MAX][3];
int cur[MAX];
int cnt[3];
bool can[MAX][3];
int ac[3];
int main(void) {
int n;
scanf("%d", &n);
for (int m = M - 1; m >= 0; --m) {
hi[m] = n >> m;
lo[m] = m +... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int alpha = 26;
unordered_map<int, int> cnt;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long ans = 0;
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
int mask = 0;
for (auto& c : s) mask ^= (1 << (c - 'a'));
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> x;
vector<int> dp;
int main() {
int n;
cin >> n;
x.resize(n);
dp.resize(n);
int sum = 0;
for (int i = 0; i < n; ++i) {
int u;
cin >> u;
sum += u;
x[i] = sum;
}
dp[n - 1] = x[n - 1];
for (int i = n - 2; i >= 0; --i) {
dp[i] =... | 14 |
#include <bits/stdc++.h>
typedef int arr[6][7];
int ans = 10000000, e[8], o[4][600005];
char chr[2] = {'a', 'b'};
arr a = {{1, 1, 0, 0, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 0}, {1, 0, 0, 1, 1, 1, 0},
{0, 1, 1, 0, 1, 1, 0}, {0, 1, 0, 1, 1, 0, 0}, {0, 0, 1, 1, 0, 1, 0}};
int prt[7][4] = {{0, 1, 1, 1}, {1, 0, 1, 1}, {1, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct TT {
int u, v, w, next, ed;
} edge[10001];
int V[10011];
bool ed[10011];
int cntm = 1;
int k;
int MAX1 = -1;
int stt;
int MAX2 = 0;
bool vi[10101];
void adde(int a, int b) {
TT &e = edge[cntm];
e.v = b;
e.u = a;
e.w = 1;
e.ed = 0;
e.next = V[a];
V[a] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ii = long long;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
for (int it = 0; it < q; ++it) {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
v[i]--;
}
vector<int> c... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct Seg {
int sum[4 * 200000 + 5];
bool inv[4 * 200000 + 5];
void down(int l, int r, int idx) {
if (inv[idx]) {
inv[idx] = 0;
int m = (l + r) / 2;
inv[idx << 1] ^= 1;
sum[idx << 1] = m + 1 - l - sum[idx << 1];
inv[idx << 1 | 1] ^= ... | 12 |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.