solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long x, y, z, a[125][10], c[10];
long long rec(long long s, long long ss, long long n) {
long long indx = 0;
if (s * 2 > ss) {
indx = 1;
} else if (s * 4 > ss) {
indx = 2;
} else if (s * 8 > ss) {
indx = 3;
} else if (s * 16 > ss) {
indx = 4;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
if (a > b) {
return a;
} else {
return b;
}
}
long long min(long long a, long long b) {
if (a < b) {
return a;
} else {
return b;
}
}
int q;
int a[602][602];
int r, c;
void solve(int id) {
scanf("%d%d",... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
long long p[100000];
int main() {
long long n, a, b;
cin >> n >> a >> b;
set<int> rem;
for (int i = 0; i < n; i++) {
cin >> p[i];
rem.insert(p[i]);
}
set<int> s0;
bool yes = true;
for (int i = 0; i < n; ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
char a[N], r[N];
int n, nr, c[N], p[N];
long long rez;
set<pair<int, int> > h;
bool ver(int poz, int &nr) {
if (nr < 0) {
if (h.empty()) return 0;
int add = h.begin()->first, po = h.begin()->second;
h.erase(h.begin());
rez += add;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, m, max = -1, fristRow = -1, FristCoulmn = 0, lastRow = 0,
lastColumn = 0;
cin >> x >> m;
char arr[1000][1000];
for (int i = 0; i < x; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
if (arr[i][j] == '*') {
... | 0 |
#include <bits/stdc++.h>
const int MAXN = 5 * 1e5 + 1;
const int MOD = 1000003;
int n, m;
char *g[MAXN];
bool H[MAXN][5];
bool V[MAXN][5];
long long memof[MAXN][5];
long long memoh[MAXN][5];
long long f(int i, int prev) {
if (i == m) return 1;
long long &res = memof[i][prev];
if (res != -1) return res;
res = 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
void Start() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
bool endline = false;
bool endlineA = false;
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
for (auto& i : v) {
in >> i;
}
return in;
}
template <class T>
ostream& ope... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, d, p1, p2;
cin >> a >> b >> c >> d;
p1 = max(3 * a / 10, (a - (a * c) / 250));
p2 = max(3 * b / 10, (b - (b * d) / 250));
if (p1 > p2)
puts("Misha");
else if (p1 < p2)
puts("Vasya");
else
puts("Tie");
}
| 1 |
#include <bits/stdc++.h>
int main() {
int i, n;
double max, temp_max, a, b, j;
scanf("%d", &n);
for (i = 0; i < (n); i++) {
scanf("%lf%lf", &a, &b);
if (a >= b) {
printf("YES \n");
continue;
}
max = b;
for (j = 1; j <= a; j++) {
temp_max = j + ceil(b / (j + 1));
if (t... | 3 |
#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int INF = 0x7FFFFFFF;
using namespace std;
const int maxn = 10010;
int p[maxn];
bool sorting(int l, int r, int index) {
int low = 0;
for (int i = l - 1; i < r; i++)
if (p[i] < p[index - 1]) low++;
if (l + low == index) return 1;
return 0;
}
int ma... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, a[1001], u;
scanf("%d", &N);
for (int i = N; i >= 2; i--) {
printf("? %d %d\n", 1, i);
fflush(stdout);
scanf("%d", &a[i]);
}
printf("? 2 3\n");
fflush(stdout);
scanf("%d", &u);
printf("!");
printf(" %d %d", a[3] - u, a[2] + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void smin(T &a, T b) {
a = a < b ? a : b;
}
template <typename T>
inline void smax(T &a, T b) {
a = a > b ? a : b;
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<st... | 10 |
#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int m, d;
string a, b;
vector<int> A, B;
int n = 2000;
int memo[1][1][2][2];
int mem[2000][2000][2][2][2][2];
int rec(int i, int r, bool ea, bool eb, bool beg, bool par) {
if (i == n) return r == 0;
int &ret = mem[i][r][ea][eb][b... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 9;
const int P = 1000000000 + 7;
const int inv2 = (P + 1) / 2;
inline int add(int a, int b) { return a + b < P ? a + b : a + b - P; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + P : a - b; }
inline int mul(int a, int b) { return (long lo... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n, i;
cin >> n;
vector<int> a(n);
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int count = 0;
i = 0;
while (n) {
i = 0;
for (int j... | 6 |
#include <bits/stdc++.h>
using namespace std;
void main0();
int main() {
clock_t start, end;
ios::sync_with_stdio(false);
cin.tie(0);
main0();
return 0;
}
const int dx[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int dy[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int N = 1e6 + 5;
const int M = 1e5;
const int INF = 0x3... | 15 |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long on... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int maxn = 2e5 + 10;
vector<int> ans;
int main() {
int n, k;
cin >> n >> k;
int l = 1, r = 1e9;
while (l <= r) {
int mid = (l + r) >> 1;
long long res = 1LL * (mid + mid + k - 1) * k / 2;
if (res <= n)
l = mid... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<unsigned long long> L, S, D, G, T, C;
vector<unsigned long long> P10, P2;
char dig[6];
const int maxn = 1e6;
const int M = (1 << 6);
const unsigned long long MOD = 1e9 + 7;
inline void digits(int x) {
for (int i = 0; i < 6; ++i) {
dig[i] = x % 10;
x ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n;
string second;
void solve() {
int count = 0, ans = 0;
for (int i = 1; i < n; i++) {
if (second[i] == second[i - 1]) {
count++;
if (i != n - 1 && second[i + 1] == 'R') {
if (second[i] == 'R' || second[i] == 'G') {
second[i] = 'B';... | 6 |
#include <bits/stdc++.h>
using namespace std;
static const int maxn = 3000 + 5;
static const int maxm = 6000 + 5;
static int n, c;
static int suf[maxn], pre[maxm], tar[maxm], e;
static int vis[maxn], dep[maxn], dis[maxn];
static int deg[maxn], que[maxn], head, tail;
static double ans;
inline int read() {
int k = 0, f... | 22 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, k;
const int maxN = 3 * (int)1e5 + 100;
int par[maxN];
vector<int> g[maxN];
int a[maxN];
void dfs(int v, int p) {
for (int to : g[v]) {
if (to == p) continue;
par[to] = v;
dfs(to, v);
}
}
int b[maxN];
int dp[maxN];
bool is_g... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, p, m;
cin >> n;
int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
b[i] = 1;
}
m = 0;
for (i = 0; i < n; i++) {
if (b[i]) {
p = 1;
for (j = i; a[j] > 0; j = a[j] - 1) {
b[j] = 0;
p++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2007;
const int MX = 1e9 + 7;
const long long int INF = 1e18 + 9LL;
int n, m;
char s[N];
int cnt[N];
int res;
int x[N], y[N];
bool used[N];
queue<int> Q;
bitset<N> B[N];
void add(int u, int v) {
x[++res] = u;
y[res] = v;
}
int get(int u) {
for (int i = 1... | 25 |
#include <bits/stdc++.h>
using namespace std;
int n, t, a, m, cou, l, r;
char c[1001][1001];
int main() {
cin >> t;
while (t--) {
cin >> n >> m;
cou = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> c[i][j];
for (int i = 1; i <= n; ++i)
if (c[i][m] == 'R') ++cou;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s[1000005];
int vis[3000000];
int n, m;
int dfs(int x, int y) {
if (vis[x * m + y] || x >= n || y >= m || s[x][y] == '#') {
return 0;
}
if (x == n - 1 && y == m - 1) {
return 1;
}
if (x || y) {
vis[x * m + y] = 1;
}
return dfs(x + 1, y) || d... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[200000 + 5];
int n, k, rem, rk;
long long sum;
int main() {
scanf("%d%d", &n, &k);
rem = n;
rk = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
long long d = 1ll * sum - 1ll * (rk - 1) * (rem - rk) * a[i];
if (d < (long long)k)
rem--, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 12, mod = int(1e9) + 7;
int t, n, a[N];
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
if (n == 1) {
printf("0 0 0\n");
return;
}
int last = 0;
for (int i = 1; i < n; i++) {
if (2 * i > n) br... | 7 |
#include <bits/stdc++.h>
int read() {
register int x = 0;
register char f = 1, ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f ^= 1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
return f ? x : -x;
}
int n, m, q1, q2, l[1600005], r[1600005], ansf;
int edge... | 19 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
}
void online_judge() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
const int flag_max = 0x3f3f3f3f;
const long long OO = 1e9;
const double EPS = (1e-7);
int dcmp(d... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct Trie {
int dat;
Trie *to[26];
Trie() {
dat = -1;
for (int i = 0; i < 26; i++) to[i] = nullptr;
}
Trie(Trie *old) {
dat = old->dat;
for (int i = 0; i < 26; i++) to[i] = old->to[i];
}
Trie *set(string &s, int val, int pos = 0) {
Trie *... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5002, NP = 1000000000;
int Add[MAXN], MyResult[MAXN], MyCheck[MAXN];
bool check(int n, vector<pair<int, pair<int, pair<int, int> > > > A) {
for (int i = 0; i < n; i++)
if (MyCheck[i] > NP || MyCheck[i] < -NP) return 0;
for (int i = 0; i < A.size(); ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ma, mb, target_x;
vector<int> ca[100001];
vector<int> cb[100001];
int rev(int x) {
int res = 0;
while (x) {
res = res * 10 + x % 10;
x /= 10;
}
return res;
}
bool is_palin(int x) { return (x == rev(x)); }
int gcd(int a, int b) { return (b == 0) ? a : gcd... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<int> a(n);
long long sum = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
}
if (sum % 3 != 0) {
cout << 0;
return 0;
}
long long part = sum / 3;
long long count = 0;
long long nowsu... | 4 |
#include <bits/stdc++.h>
int main() {
long long int n;
scanf("%lld", &n);
n++;
if (n == 1)
printf("0");
else if (n & 1)
printf("%lld", n);
else
printf("%lld", n / 2);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
static int sc_ret = 0;
struct pt_nl {};
struct sc {
sc& operator>>(char& v) {
v = sc_ret = getchar();
return *this;
}
sc& operator>>(int& v) {
sc_ret = scanf("%d", &v);
return *this;
}
sc& operator>>(unsigned& v) {
sc_ret = scanf("%u", &v);
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a[10000], c[10000], b[6000][6000];
int main() {
int n, m, ans;
while (scanf("%d%d", &n, &m) != EOF) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
c[i] = 0;
for (int j = i; j <= n; j+... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 20;
const double PI = M_PI;
const double EPS = 1e-15;
const int MaxH = 200005;
int H, M, N;
int row[MaxH];
int col[MaxH];
int size[MaxH];
vector<set<int> > second;
map<int, pair<int, int> > pos;
int main() {
scanf("%d%d%d", &H, &M, &N);
for (int i = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, r1, r2;
const int N = 1e5 + 5;
int ans[N];
vector<vector<int>> v(N);
int vis[N];
void solve(int node = r2) {
if (vis[node]) return;
vis[node] = 1;
for (int i = 0; i < v[node].size(); i++) {
if (!vis[v[node][i]]) ans[v[node][i]] = node;
}
for (int i = 0;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
a[i] = (t > 0) ? t : -t;
}
long long ans = 0;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
ans += upper_bound(a + ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> f(26, 0);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
long double x;
cin >> n >> m >> x;
char grid[n + 1][m + 1];
bool shift = 0;
vector<pair<long double, long double> > shiftPos;
set<char> letters;
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, n, b, total;
cin >> n >> b;
total = n;
while (n >= b) {
total += n / b;
r = n % b;
n = n / b + r;
}
cout << total;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(0.0);
struct node {
int a, b, c, d, e;
} dis[1009];
int cun[1009];
int n;
bool pan(int k) {
int flag = 1;
for (int i = 1; i <= n; i++) {
if (i != k)
for (int j = 1; j <= n; j++) {
if ((j != i) && (j != k)) {
node q, w... | 9 |
#include <bits/stdc++.h>
using namespace std;
void PLAY() {
cout << fixed << setprecision(10);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool isprime1(long long n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
bool vis... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, c, i;
cin >> n >> c;
long long int a[n - 1];
long long int b[n - 1];
long long int bsum[n];
bsum[0] = 0;
for (i = 0; i < n - 1; i++) {
cin >> a[i];
}
for (i = 0; i < n - 1; i++) {
cin >> b[i];
bsum[i + 1] = bsum[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
char str1[100], str2[100];
scanf("%s%s", str1, str2);
int l = strlen(str1);
int a = 0, b = 0;
for (int i = 0; i < l; i = i + 2) {
if (str1[i] == '(') {
if (str2[i] == '[')
b++;
else if (str2[i] == '8')
a++;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
string n;
cin >> n;
for (long long int i = 1; i <= 5; i++) {
long long int c = (n.size() + i - 1) / i;
if (c <= 20) {
cout << i << " " << c << "\n";
long long int as = i * c - n.siz... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long arr[100000], arr2[100000];
double mon = 1000.00;
long long getmul(long long x, long long y, long long p) {
long long low, high;
if (x % p == 0)
low = x / p;
else
low = (x / p) + 1;
high = y / p;
if (high < low) return 0;
return high - low + 1;
... | 9 |
#include <bits/stdc++.h>
int main() {
long I, K, L, M, N, S, E, Data[10000];
while (scanf("%ld", &N) == 1) {
I = 0;
K = 0;
for (I = 1; I <= N; I++) scanf("%ld", &Data[I]);
L = 0;
S = 1;
E = N;
for (I = 1; I <= N; I++) {
if (Data[S] > Data[E]) {
if (I % 2 == 1)
L +... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, m;
int C[MAXN];
long long V[MAXN];
long long S[MAXN];
long long dn[MAXN];
const long long inf = 1e15;
void maxc(pair<long long, long long> a, pair<long long, long long> &mx1,
pair<long long, long long> &mx2) {
if (a.first > mx1.... | 12 |
#include <bits/stdc++.h>
const int N = 100005, K = 205, P = 1000000007;
template <typename T>
void rd(T& x) {
int fl = 0, ch;
while (ch = getchar(), ch < 48 || 57 < ch) fl ^= !(ch ^ 45);
x = (ch & 15);
while (ch = getchar(), 47 < ch && ch < 58)
x = (x + (x << 2) << 1) + (ch & 15);
if (fl) x = -x;
}
templa... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = (1ll << 30);
const int MX = 209;
long long dp[2][MX][MX * 30], n, k, x, f[MX], t[MX];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
scanf("%lld", &x);
while (x % 2 == 0) {
x /= 2;
t[i]+... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
double x1, ans, p;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%lf", &p);
ans += (2 * x1 + 1) * p;
x1 = (x1 + 1) * p;
}
printf("%.7f", ans);
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long bigmod(long long b, long long p, long long m) {
if (p == 0) return 1;
if (p % 2 == 0) {
long long temp = bigmod(b, p / 2, m);
return (temp * temp) % m;
}
return (bigmod(b, p - 1, m) * (b % m)) % m;
}
int main() {
int cnt = 0;
int n... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int inf = 1e9 + 7;
vector<int> a(maxn);
int sum[maxn];
int sum1[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<pair<pair<int, int>, int>> b(m);
for (int i = 0; i < m; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, m, x, y, a, b;
cin >> n >> m >> x >> y >> a >> b;
int d = gcd(a, b);
a /= d;
b /= d;
int l = 1, r = (int)1e9 + 10;
while (l < r) {
int mid = l + r >> 1;
long long w = 1LL * mid... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a = 0, b = 0;
string s;
for (int i = 0; i < n; ++i) {
cin >> s >> s;
if (s == "soft")
a++;
else
b++;
}
if (a < b) {
int c = a;
a = b;
b = c;
}
for (int i = 0; i < 1000; ++i) {
int x ... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long d, k, a, b, t;
long long cal(long long p) { return p * k * a + (p - 1) * t + (d - p * k) * b; }
int main() {
scanf("%I64d%I64d%I64d%I64d%I64d", &d, &k, &a, &b, &t);
{
long long ans;
if (d % k == 0)
ans = (d / k - 1) * t + d * a;
else
an... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int cnt = 0;
int n;
scanf("%d", &n);
int num[150005] = {0};
for (int i = 0; i < n; i++) scanf("%d", &num[i]);
int MAXN = num[n - 1];
for (int i = n - 1; i >= 0; i--) {
if (num[i] <= M... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int power1(long long int a, long long int b) {
long long int result = 1;
while (b) {
if (b % 2) result = (result * a) % 1000000007;
a = (a * a) % 1000000007;
b = b / 2;
}
return result;
}
long long int MOD_ADD(long long int k) {
if (k >= 1000... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 1e5 + 7;
struct edge {
int to, nxt;
long long w;
edge() {}
edge(int _to, int _nxt, long long _w) : to(_to), nxt(_nxt), w(_w) {}
} E[N * 68];
int head[N << 2], tot;
long long d[N << 2];
bitset<N << 2> vis;
int id[2][N << 2]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string ans[] = {"home", "contest"};
scanf("%d", &n);
cout << ans[n % 2] << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char pos[60];
char inst[60];
cin >> pos >> inst;
int i = 0;
int j = 0;
while (j < strlen(inst)) {
if (inst[j] == pos[i]) i++;
j++;
}
if (i > strlen(pos)) i = strlen(pos) - 1;
cout << i + 1;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
unordered_map<char, int> m;
m['Q'] = 9;
m['R'] = 5;
m['P'] = 1;
m['B'] = 3;
m['N'] = 3;
m['q'] = 9;
m['r'] = 5;
m['p'] = 1;
m['b'] = 3;
m['n'] = 3;
int b = 0, w = 0;
... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long mod = 1e9 + 7;
long long GCD(long long x, long long y) {
if (!y) return x;
return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return (x * y) / GCD(x, y); }
void solve() {
long long n, m = 0, k = 0, i = 1, j, p, f, x, y, z... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[100], p, q;
int i, j, k, m, n, x, y, z;
int main() {
scanf("%I64d%I64d", &p, &q);
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
int flag = 1;
for (i = 1; i <= n; i++) {
if (a[i] > 1 << 31 - 1 && q > 1 << 31 - 1) {
flag = 0;... | 9 |
#include <bits/stdc++.h>
const int MAXN = 1000 + 5;
const long long INF = 4e18;
int n, m;
long long k;
char str[MAXN];
int lcp[MAXN][MAXN];
std::vector<std::pair<int, int> > S;
inline bool cmp(std::pair<int, int> a, std::pair<int, int> b) {
int lcp = ::lcp[a.first][b.first];
if (a.first + lcp > a.second || b.first ... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, l, t, q, x, y, z, a[100005];
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> x >> y >> z;
long long ans = x / z + y / z;
long long ans2 = 0;
if ((x % z + y % z) >= z) {
if (x % z > y % z) {
ans2 = z - x % z;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
struct point {
int x, y, z;
point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a[502][502];
int b[502][502], c[502][502];
string s;
int n;
int f(int i, int j) {
if (a[i][j] == 0) {
if (i == j || i > j)
a[i][j] = 1;
else {
a[i][j] = f(i + 1, j - 1);
if (s[i] != s[j]) a[i][j]++;
}
}
return a[i][j];
}
string fs(str... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long dp[100001];
long long s1(long long n) {
if (n < 0) return 0;
if (n == 0) return 1;
if (n == 1) return 1;
if (dp[n] != -1) return dp[n];
dp[n] = (s1(n - 1) + s1(n - 2)) % mod;
return dp[n];
}
long long modex(long long a, long lo... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
template <class T>
T gcd(T a, T b) {
return a ? gcd(b % a, a) : b;
}
template <class T>
T lcm(T... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 1e5;
int datos[MAXN + 2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> datos[i];
sort(datos, datos + n);
int sig = n / 2;
int resp = n;
for (int i = 0; i < n / 2; ++i) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
scanf("%d", &n);
long long sum = n + (n - 1);
n -= 2;
for (int i = 2; n >= 1; i++) {
sum += (n * i);
n--;
}
printf("%I64d\n", sum);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int NN = 1000000 + 10;
bool is_p[NN];
vector<int> pp;
void make() {
for (int i = 2; i < NN; i++) is_p[i] = 1;
is_p[1] = 1;
for (int i = 2; i < NN; i++) {
if (is_p[i]) {
for (long long j = (long long)(i)*i; j < NN; j += i) is_p[j] = 0;
}
}
for (... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m, t[maxn], idx[maxn];
long long sum[maxn], a[maxn], cnt[2][maxn], ans[maxn], need[2][maxn], k,
cur = 0;
long long b[maxn];
struct Query {
int l, r, b, idx;
bool operator<(const Query& rhs) const {
return b == rhs.b ? r < rhs.r ... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct Node {
int a, f;
map<int, Node *> ch;
Node(int _a, int _f = 0) : a(_a), f(_f), ch() {}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
stack<Node *> s;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int grundy(int x) {
if (x == 0) return 0;
if (x == 1) return 1;
if (k & 1) {
if (x == 2) return 0;
if (x == 3) return 1;
if (x == 4) return 2;
if (x & 1) return 0;
if (grundy(x / 2) == 1) return 2;
return 1;
} else {
if (x == 2)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long x, y, n;
cin >> x >> y >> n;
long long maxx = (n / x) * x;
if (maxx + y <= n) {
cout << maxx + y;
} else
cout <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
int a[n];
set<int> rooms;
rooms.insert(0);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (rooms.count(a[i])) rooms.erase(a... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int ans = 0, sum = 0, mx = 0, x;
char st[500005];
vector<long long int> v;
int main() {
int i, j, k, a, b, n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lld", &x);
v.push_back(x);
}
scanf("%s", st);
for (i = 0; st[i]; i++) {
if (st[... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
if (!n1) return n2;
if (!n2) return n1;
if (n1 % n2 == 0) return n2;
return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
long long ans = 1;
while (exponent) {
if (exponent & 1) ans = (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
struct line {
int leftmn, leftmx, rightmn, rightmx, ind;
};
bool cmp1(line a, line b) { return a.leftmx < b.leftmx; }
line l[500002];
int suf1[500002], pref[500002], suf2[500002];
char ch[500002];
void solve() {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
void Rd(int &x) {
static char c;
x = 0;
while ((c = getchar()) < 48)
;
do x = (x << 3) + (x << 1) + (c ^ 48);
while ((c = getchar()) > 47);
}
int n, m;
int Next[100004 << 1], V[100004 << 1], Head[100004], tot;
void Add_Edge(int u, int v) { Next[++tot] = Head[u... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int m = n;
n *= 4;
for (int i = n - 2, s = 0; s < m; i -= 2) cout << i << " ", s++;
printf("\n");
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int x1, y1, z1, x2, y2, z2;
cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
if (x1 == x2 || y1 == y2 || z1 == z2)
cout << "YES";
else
cout << "NO";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) solve()... | 3 |
#include <bits/stdc++.h>
using namespace std;
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, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 3 |
#include <bits/stdc++.h>
int main() {
int a1 = 0, a2 = 0, a3 = 0, b1 = 0, b2 = 0, b3 = 0;
int max(int a, int b);
scanf("%d%d", &a1, &b1);
scanf("%d%d", &a2, &b2);
scanf("%d%d", &a3, &b3);
int temp = 0, sum[5] = {0}, longl[5] = {0};
sum[1] = a2 + a3;
sum[2] = a2 + b3;
sum[3] = a3 + b2;
sum[4] = b3 + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
double inff = 1.0 / 0.0;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long int x, y, n, i, z, j, k, w, u, q, t, c, p, m;
vector<long long int> v;
long long int div1(long long int x, long long int y) {
if (x ... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct pkt {
int x, y;
};
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> p(n);
for (int i = 0; i < n; ++i) cin >> p[i];
vector<vector<int> > a(n, vector<int>(m, -1));
for (int k = 0; k < n; ++k) {
for (int l = 1; l < m... | 15 |
#include <bits/stdc++.h>
using namespace std;
int func(long long int n) {
long long int i = 1, sum = 0, ans = 0;
while (sum < n) {
sum = sum + i;
i++;
ans++;
}
long long int diff = sum - n;
if (n == 0) ans = 0;
if (diff % 2 != 0) {
if ((diff + i) % 2 == 0)
ans = ans + 1;
else
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
int main() {
string s;
int n;
cin >> n;
int l = 1, r = n;
int ans = 0;
int pos = 1;
int t = 1;
while (l <= r + 1) {
++t;
if (t % 2 == 0) {
ans += (pos + r) % (n + 1);
r--;
pos = r + 1;
} e... | 2 |
#include <bits/stdc++.h>
using ll = long long;
ll MOD = 1e9 + 7;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
int n;
cin >> n;
int a[n];
int b[n];
for (int i = 1; i <= n; i++) {
int a_, b_;
cin >> a_ >> b_;
a[i] = a_;
b[i] = b_;
}
int open = 0;
for (... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 202;
bool g[N * 2][N * 2], type[1 << 7];
char s[N], bigger[1 << 7][2];
int l, n, m;
void init() {
char t[30];
scanf("%s", t);
type['V'] = 0, type['C'] = 1;
for (l = 0; t[l]; ++l) type[l + 'a'] = type[t[l]];
scanf("%d %d", &n, &m);
while (m--) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, t;
int x, y;
scanf("%d", &x);
scanf("%d", &y);
if (x <= 1 && x >= 0 && y == 0) {
printf("%d\n", 0);
return 0;
}
if (x >= 1) {
if (y > -x + 1 && y <= x) {
printf("%d\n", 1 + (x - 1) * 4);
return 0;
}
}
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, x;
cin >> n;
vector<long long int> vc;
for (i = 0; i < n; i++) {
cin >> x;
vc.push_back(abs(x));
}
sort(vc.begin(), vc.end());
long long int l, h, m, res = 0;
for (i = 0; i < n - 1; i++) {
l = i;
h = n - 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long m, n, c[1010][1010], f[1010], b[1010], x, ans = 1;
map<long long, long long> mp;
int main() {
for (cin >> m >> n; n--;)
for (int i = 0; i < m; ++i) scanf("%1lld", &x), b[i] |= x << n;
for (int i = 0; i < m; ++i) ++mp[b[i]];
for (int i = 0; i <= m; ++i)
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const bool print = false;
const int MAXN = 200111;
int univ[MAXN];
vector<int> kraw[MAXN];
int ojc[MAXN];
long long wyn = 0;
int kk;
void dfs(int v) {
for (auto b : kraw[v]) {
if (b == ojc[v]) continue;
ojc[b] = v;
dfs(b);
univ[v] += univ[b];
}
wyn += ... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.