solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 2E5 + 10, INF = 0x3f3f3f3f;
vector<int> edge[N];
int n, m;
int a[N];
bool vis[N];
int dis[N], cou[N];
void spfa(int root) {
for (int i = 1; i <= (n); ++i) dis[i] = INF;
dis[root] = 0;
queue<int> q;
q.push(root);
vis[root] = 1;
while (!q.empty()) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long k) {
long long ans = 1;
while (k > 0) {
if (k % 2 == 1) ans = ans * a;
a = a * a;
k /= 2;
}
return ans;
}
long long br(long long len) {
long long ans = 1LL;
for (int i = 1; i <= len - 1; i++) {
ans = ans * 4LL... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, flag = 0, r;
cin >> n;
for (i = 1; i <= 100; i++) {
r = (i * (i + 1)) / 2;
if (r == n) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
stack<char> st;
int i = 0, len = s.size();
while (i < len) {
if (st.empty())
st.push(s[i]);
else if (s[i] == ')') {
if (st.top() == '(')
st.pop();
else
st.push(s[i]);
} else
st.pu... | 6 |
#include <bits/stdc++.h>
using namespace std;
char a[100];
int len;
long long res = 0, cur = 0;
int sign = 1;
int main() {
cin >> a;
len = strlen(a);
for (int i = 0; i < len; i++) {
if (a[i] == '-' || a[i] == '+') {
res += sign * cur;
cur = 0;
}
if (a[i] == '-') sign = -1;
if (a[i] == ... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void ckmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void ckmax(T &a, T b) {
if (b > a) a = b;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int n;
cin >> n;
std::vector<int> a(n);
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
static char ibuf[RLEN], *ib, *ob;
(ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
return (ib == ob) ? EOF : *ib++;
}
inline int read() {
char ch = gc();
int res = 0;
bool f = 1;
while (!isdigit(c... | 25 |
#include <bits/stdc++.h>
const int N = 1000007, inf = 0x3f3f3f3f;
using namespace std;
int v[N], last[N], passed[N];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
for (int i = 1; i <= n; ++i) {
last[v[i]] = i;
}
int p, tot = 0;
for (p ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int fr[1001] = {0};
int fc[1001] = {0};
long long int n, m;
cin >> n >> m;
long long int ans = 0;
long long int r, c;
while (m--) {
cin >> r >> c;
fr[r]++;
fc[c]++;
}
for (int i = 2; i < n; i++) {
if (!fr[i]) ans++;
}
for (... | 10 |
#include <bits/stdc++.h>
using namespace std;
string str;
int laz;
int pp;
int arr[100000];
int main() {
while (cin >> str) {
int ans = 0, temp = 0;
bool flag = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] == ')')
temp--;
else if (str[i] == '(')
temp++;
if (temp... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
point(double _x = 0, double _y = 0) {
x = _x;
y = _y;
}
point operator+(point w) { return point(x + w.x, y + w.y); }
point operator-(point w) { return point(x - w.x, y - w.y); }
point operator*(double H) { return point(x * H, ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e4 + 42;
int n, k, inp[nmax];
int dp[nmax], help[nmax];
int MX[nmax];
int pointer = 0;
pair<int, int> lines[nmax];
void init() { pointer = 0; }
pair<int, int> meet(pair<int, int> a, pair<int, int> b) {
pair<int, int> ret = {a.second - b.second, b.first -... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N(1e4 + 200);
int n, a[N], b[N], rpos[N];
struct hh {
int a[N], lb[30], p[30];
vector<pair<int, int> > w;
inline void read() {
for (int i(0); i < n; i++) scanf("%d", a + i);
}
inline void c_lb() {
for (int i(0); i < n; i++)
for (int k(29), ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int NICO = 300000 + 10;
int n;
vector<int> v;
int a[NICO], nxt[NICO], pre[NICO], vis[NICO];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = nxt[i] = i;
}
int pos = 1;
while (pos <= n) {
int t = pos;
while (a[pos] %... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], x[maxn];
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
x[n - 1] = n - 1 - a[n - 1];
for (int i = n - 2; i >= 0; i--) {
x[i] = min(x[i + 1], i - a[i]);
}
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
long n, m, a, b;
vector<long> g[200000];
set<pair<long, long> > done;
vector<pair<long, pair<long, long> > > ans;
long ptr[300000];
long dfs(long v) {
vector<long> dd;
dd.reserve(16);
for (; ptr[v] < g[v].size(); ptr[v]++) {
long q = g[v][ptr[v]];
pair<long, l... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T read() {
T x = 0, w = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') w = -w;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * w;
}
template <class T>
inline T read(T& x) {
return x = read... | 24 |
#include <bits/stdc++.h>
const int N = 1e5 + 10;
using namespace std;
int a[N], m[N][20], len[N], sign[N], s[20];
int het[N];
bool cmp(int x, int y) { return x > y; }
int random(int a, int b) { return rand() % (b - a) + a; }
int main() {
int n, ss = 0, k = 0, p = 0, mine = N * 20, h, q;
scanf("%d", &n);
for (int ... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m;
int d[200000 + 20], inv[200000 + 20];
const int MOD = 998244353;
long long quick(int A, int B) {
if (B == 0) return 1ll;
long long tmp = quick(A, B >> 1);
tmp *= tmp;
tmp %= MOD;
if (B & 1) tmp = tmp * ... | 16 |
#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
s = 0;
register int f = 1;
register char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
s *= f;
return;
}
template <class t, cla... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, MOD = 1e9 + 7;
int n;
vector<int> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
while (n > 0) {
if (n % 4 == 0 && n % 7 != 0) {
v.push_back(4);
n -= 4;
} else {
n -= 7;
v.push_bac... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long k, x;
int q;
int main() {
cin >> q;
while (q--) {
cin >> k >> x;
cout << x + 9 * (k - 1) << "\n";
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 0x7fffffff;
char __INPUT[25];
inline int _I() {
scanf("%s", __INPUT);
return atoi(__INPUT);
}
inline long long int _LLD() {
scanf("%s", __INPUT);
return atoll(__INPUT);
}
template <class T>
inline bool isPrimeNumber(T n) {
if (n <= 1) ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int INF = 1e9 + 7;
const long double EPS = 1e-13;
const long double PI = 3.14159265359;
int toPush[MAXN * 4], mx[MAXN * 4], values[MAXN];
void push(int u) {
if (toPush[u] != 0) {
mx[u * 2 + 1] += toPush[u];
mx[u * 2] += toPush[u];
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 303030;
int n, p, q;
int ma[N], mi[N];
pair<int, int> a[N];
struct Seg {
static const int N = ::N << 2;
int mi[N], cnt[N], la[N];
void build(int l, int r, int rt) {
cnt[rt] = r - l + 1;
mi[rt] = la[rt] = 0;
if (l == r) return;
int mid = l... | 22 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
long long ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
int k = i ^ j;
if (k < i + j && k >= j && k <= n) {
ans++;
}
}
}
std::cout << ans << '\n';
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
int arr[3];
for (int i = 0; i < 3; i++) {
cin >> arr[i];
}
int len = sizeof(arr) / sizeof(arr[0]);
sort(arr, arr + len);
if ((arr[len - 3] + arr[len - 2]) > arr[len - 1])
cout << "0" << endl;
else
cout << (arr[len - 1] -... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
int n, m;
long long a[maxn];
int f[maxn];
int find(int a) { return (a == f[a]) ? a : f[a] = find(f[a]); }
struct edge {
int u, v;
long long w;
edge(int u = 0, int v = 0, long long w = 0) : u(u), v(v), w(w) {}
friend bool operator<(edge a, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
long long int n = s.length();
long long int a[n + 1];
a[n] = n;
long long int ans = 0;
for (long long int i = n - 1; i >= 0; i--) {
a[i] = a[i + 1];
for (long long in... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long dp[1 << 18][100];
int num[10];
int d[19];
int len;
int main() {
cin >> n >> m;
int len = 0;
while (n) {
num[n % 10]++;
d[len++] = n % 10;
n /= 10;
}
long long res = 1;
for (int i = 0; i < 10; i++) {
while (num[i]) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool solve(int x) {
int a[10];
for (int i = 0; i < 10; i++) a[i] = 0;
while (x != 0) {
int j = x % 10;
switch (j) {
case 0:
a[0]++;
break;
case 1:
a[1]++;
break;
case 2:
a[2]++;
break;
cas... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(T& t) {
return (int)t.size();
}
int main() {
int i, j;
vector<string> vs(6);
vector<int> sz(6);
for (i = 0; i < 6; i++) cin >> vs[i];
sort((vs).begin(), (vs).end());
vector<vector<string> > ret;
do {
for (i = 0; i < 6; ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int Du[110930], Cat[110930];
vector<int> f[110930];
int ANS = 0;
void DFS(int x, int y, int z) {
int Z;
if (Cat[x] == 1)
Z = z + 1;
else
Z = 0;
if (Z > m) return;
if (Du[x] == 1 && x != 1) {
ANS++;
return;
}
for (int i = 0; i < Du[x];... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n == 1) {
cout << "Ehab";
return 0;
}
if (n % 2 == 0)
cout << "Mahmoud";
else
cout << "Ehab";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
Point(){};
Point(long long _x, long long _y) {
x = _x;
y = _y;
}
long long x, y;
};
bool colinear(const Point& a, const Point& b, const Point& c) {
long long area = (b.y - a.y) * (c.x - a.x) - (b.x - a.x) * (c.y - a.y);
if (area != 0) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int dat[1111][1111];
int ok;
int n, t;
int maxi = 0;
int pos;
int main() {
cin >> n >> t;
pos = 500;
dat[pos][pos] = n;
ok = 1;
while (ok) {
ok = 0;
for (int i = pos - maxi; i <= pos + maxi; i++) {
for (int j = pos - maxi; j <= pos + maxi; j++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
void fastStream() {
cin.tie(0);
std::ios_base::sync_with_stdio(0);
}
const int mod = 1000000000 + 7;
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} els... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int pw[2] = {(int)1e7 + 19, (int)1e7 + 79};
const int maxn = 1e6 + 88;
const int inf = 2e9 + 88;
const int logn = 22;
const int maxa = 3e6 + 88;
const int block = 1300;
const long long infll = 1e18 + 88;
const char sgl[5] = {'a', 'e', 'i'... | 6 |
#include <bits/stdc++.h>
using namespace std;
string s;
int len[10000], i, j, c, l, k;
bool exist2(string s1) {
for (k = i + 1; k <= s.size() - j; ++k)
if (s1 == s.substr(k, j)) return 1;
return 0;
}
int main() {
cin >> s;
for (i = 0; i < s.size() - 1; ++i)
for (j = 1; j <= s.size() - i; ++j)
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
set<int> G[N], s;
int vis[N];
void bfs(int x) {
queue<int> q;
q.push(x);
s.erase(x);
while (q.size() > 0) {
int y = q.front();
q.pop();
if (vis[y]) continue;
vis[y] = 1;
for (auto it = s.begin(); it != s.end();) {
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
long long mod = (long long)(1e9 + 7)) {
if (!b) return 1;
a %= mod;
return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
const int maxn = 1e3;
int n, m, W, N;
vector<int> adj[maxn];
int vi[maxn],... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 6;
inline int read() {
int x = 0, f = 1;
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 x * f;... | 23 |
#include <bits/stdc++.h>
using namespace std;
int MAX(double a, double b) {
if (a > b) return a;
return b;
}
int main() {
ios_base::sync_with_stdio(false);
long double n, b, k, t, num = 0;
cin >> k >> b >> n >> t;
if (k == 1) {
cout << MAX(ceil((1 + n * b - t) / b), 0);
return 0;
}
num = (log((k... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 105;
int mat[mx][mx];
int main() {
cin.tie(0), ios::sync_with_stdio(false);
int n, a, b;
cin >> n >> a >> b;
if (a * b < n)
cout << "-1" << endl;
else {
int cur = 0;
for (int i = 1; i <= a; i++) {
if (i & 1) {
for (int j = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void da(int *a, int s, int e) {
for (int i = s; i < e; i++) cout << a[i] << " ";
}
void db(string s) { cout << s << '\n'; }
void cp(int *a, int *b, int n) {
for (int i = 0; i < n; i++) b[i] = a[i];
}
const int N = 20, sn = 250, LOG = 19, MOD = 1e9 + 7;
long long n, m, d... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double pii = 3.14159265359;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int q, n, a[N], b[N], t[N];
struct node {
int x, y;
} l[N];
int f[N];
int read() {
int x, f = 1;
char ch;
while ((ch = getchar()) < '0' || ch > '9')
if (ch == '-') f = -1;
x = ch ^ 48;
while ((ch = getchar()) >= '0' && ch <= '9')
x... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int dp[200002];
dp[1] = 1;
dp[2] = 1;
for (long long int i = 3; i <= 200000; i++) {
dp[i] = (dp[i - 1] * i) % 1000000007;
}
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
printf("%lld\n", dp[2 * n]);
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z;
cin >> x >> y >> z;
if (x > y + z)
cout << "+"
<< "\n";
else if (y > x + z)
cout << "-"
<< "\n";
else if (x == y && z == 0)
cout << "0"
<< "\n";
else {
cout << "?"
<< "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool dp[334][201][143] = {};
bool v = 0;
bool solve(int x, int a, int b, int c) {
if (v) return v;
if (x == 0) {
v = 1;
cout << a << " " << b << " " << c << '\n';
return dp[a][b][c] = 1;
}
if (x < 0) return dp[a][b][c] = 0;
bool aa = solve(x - 3, a + 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
namespace Acc {
const int N = 5e3 + 10;
int fa[N], d[N], a[N], n, D, b[N], mx;
void work() {
cin >> n >> D;
if (D > n * (n - 1) / 2) return puts("NO"), void(0);
for (int i = 2; i <= n; i++)
fa[i] = i / 2, d[i] = d[fa[i]] + 1, D -= d[i], b[i] = a[i] = 0;
if (mx =... | 14 |
#include <bits/stdc++.h>
using namespace std;
int c[10000005];
long long prime[664580];
long long factorial(int n) {
if (n == 1)
return 1;
else
return n * factorial(n - 1);
}
int GCD(int a, int b) {
if (b == 0) return a;
return GCD(b, a % b);
}
int main() {
int r1, r2, c1, c2, rook = 0, bishop = 0, ki... | 3 |
#include <bits/stdc++.h>
#define mp std::make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define gc getchar
#define pc putchar
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef long long ll;
typedef long double ld;
typedef unsigned long l... | 25 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int infi = 1147483600;
const long long infl = 1e18 + 5;
const char ENDL = '\n';
const long long MOD = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for (int xx = 0; xx < (int)t; xx++) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, h;
cin >> n >> d >> h;
if ((d + 1) / 2 > h || d == 1 && n != 2)
cout << -1 << endl;
else {
int u = 1, v = 2;
for (int i = 1; i <= h; i++) {
cout << i << " " << v << endl;
v++;
}
for (int i = 1; i <= d - h; i++) ... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct st {
int x;
int ca;
int co;
int f;
};
struct pt {
int x;
int c;
friend int operator<(pt a, pt b) { return a.c > b.c; }
};
st e[(560 * 560 * 2)];
int fr;
vector<vector<int> > v(560);
void adde(int x, int y, int ca, int co) {
e[fr].x = y;
e[fr].ca = c... | 19 |
#include <bits/stdc++.h>
int enlarge(int n) {
int res = 1;
while (res < n) {
res <<= 1;
}
return res;
}
class SegmentTree {
int n;
std::vector<int> mx;
void modify(int u, int l, int r, int x, int v) {
if (l + 1 == r) {
mx[u] = v;
return;
}
int mid = (l + r + 1) >> 1;
if (x ... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int N = 1e5 + 4, in... | 22 |
#include <bits/stdc++.h>
using namespace std;
int a1, a2, ans;
int main() {
cin >> a1 >> a2;
if (a1 == 1 && a2 == 1) {
cout << 0 << endl;
return 0;
}
while (a1 > 0 && a2 > 0) {
ans++;
if (a1 >= a2) {
a1 -= 2;
a2 += 1;
} else {
a2 -= 2;
a1 += 1;
}
}
cout << ans... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int a, b, c;
cin >> a >> b >> c;
long long minn = 3e9 + 10;
int dx[] = {-1, 0, 1};
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++) {
long long x... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool used[1600][1600];
int mark[1600][1600];
int c[1600][1600];
int ans[10000];
int cnt;
int n, m;
int q[2560000][2];
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int size;
bool isray(int x, int y) {
if (x <= 4 || x >= n - 4 || y <= 4 || y >= m - 4) return false;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long numlucky(long long i, long long bound) {
if (i > bound)
return 0;
else
return 1 + numlucky(i * 10 + 4, bound) + numlucky(i * 10 + 7, bound);
}
bool check(long long i) {
if (i <= 0) return false;
while (i > 0) {
int a = i % 10;
if (a != 4 &&... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vi[100005];
int color[100005];
bool visited[100005] = {false};
int main() {
long long q;
cin >> q;
while (q--) {
long long x, y, k;
cin >> x >> y >> k;
if (k < (min(x, y) + abs(x - y))) {
cout << -1 << endl;
continue;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
co... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > G[100010];
int color[100010];
int dfs(int x, int c) {
if (color[x] != -1) return color[x] == c;
color[x] = c;
int nn = G[x].size();
for (int i = 0; i < nn; i++) {
int f = G[x][i].first, s = G[x][i].second;
if (!dfs(f, s ? c ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b;
cin >> n;
vector<pair<long long, long long>> z;
for (int i = 0; i < n; i++) {
cin >> a >> b;
z.push_back({a, b});
}
sort(z.begin(), z.end());
b = 0;
long long m = z[0].second;
for (int i = 1; i < n; i++) {
if (z[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const int INF = 1e9 + 10;
template <typename T>
using MinPQ = priority_queue<T, vector<T>, greater<T>>;
struct ModInt {
static constexpr int MOD = 1e9 + 7;
int v = 0;
ModInt() {}
ModInt(long long x) {
v = x % MOD;
if (v < 0) v += MO... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, *x, id, vis[2001][2001], m;
bool dp[2001][2001];
vector<int> v;
bool solve(int i = 0, int sum = 0) {
if (sum == n) return 1;
if (i == m) return 0;
bool &ret = dp[i][sum];
if (vis[i][sum] == id) return ret;
vis[i][sum] = id;
return ret = solve(i + 1, sum +... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, s = 0, x = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
s = s + 5 * i;
if (s + k <= 240)
x++;
else
break;
}
cout << x;
}
| 0 |
#include <bits/stdc++.h>
typedef struct {
int x, y;
} s_p;
s_p p[200000];
int n;
int compp(const void *A, const void *B) {
s_p *a = (s_p *)A, *b = (s_p *)B;
return (a->x > b->x) - (a->x < b->x);
}
int mmm[2000001], *maks = mmm + 1000000;
int upper() {
int high = 0, i, hl = -10000000, hr = -10000000, a = 0, aty,... | 12 |
#include <bits/stdc++.h>
using namespace std;
int r, c, x, y;
char g[101][101];
bool vis[101][101];
int cost[101][101];
int dr[] = {0, 1, 0, -1};
int dc[] = {1, 0, -1, 0};
string d = "RDLU";
pair<int, int> tar;
int main() {
scanf("%d%d", &r, &c);
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j) {
s... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, x;
int num[N], last[N];
int main() {
last[0] = 1;
num[0] = 1;
scanf("%d", &n);
int ans = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (last[num[x]] == x) {
num[i] = num[x];
} else {
num[i] = ++ans;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9;
int inf = 2 * 1e18;
int n, m;
vector<int> a;
int main(int argc, const char* argv[]) {
int n, t;
cin >> n >> t;
a.resize(n + 1);
string s;
cin >> s;
int point = -1;
int end = s.size() + 1;
int pos = -1;
for (int i = 0; i < s.size(); i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[1000];
int vis[1000];
int a[1000];
int cnt;
vector<int> L;
vector<int> F;
void dfs(int s) {
cnt++;
vis[s] = 1;
L.push_back(s);
F.push_back(a[s]);
for (auto x : v[s]) {
if (vis[x] == 0) dfs(x);
}
}
int main() {
int i, j, k, l, m, n;
cin >> n... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
long long rep(long long x) {
x %= M;
if (x < 0) {
x += M;
}
return x;
}
long long add(long long a, long long b) {
a = rep(a);
b = rep(b);
return rep(a + b);
}
long long mul(long long a, long long b) {
a = rep(a);
b = rep(... | 20 |
#include <bits/stdc++.h>
using namespace std;
char str[100001];
char mul[100001];
char res[100001];
int main() {
int n, len;
int i, j;
scanf("%d %s", &n, str);
len = strlen(str);
strcpy(res, str);
for (i = 1; i < n; i++) {
scanf("%s", str);
for (j = 0; j < len; j++) {
if (mul[j] == 1) continue... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int DEBUT_ABR = 1 << 19;
const int TAILLE_ABR = 1 << 20;
int diff[TAILLE_ABR] = {0};
int mini[TAILLE_ABR] = {0};
void maj(int id) {
if (id == 0) return;
if (id < DEBUT_ABR)
mini[id] = diff[id] + min(mini[2 * id], mini[2 * id + 1]);
else
mini[id] = diff[i... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long N = 100000;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin()) os << ", ";
os << *it;
}
return os << ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
char O[1 << 14], *S = O, *T = O;
inline long long read() {
long long x = 0, f = 1;
char ch =
(S == T && (T = (S = O) + fread(O, 1, 1 << 14, stdin), S == T) ? -1
: *S++);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int t, nx;
} e[200010 << 1];
struct Node {
int x, y, z;
Node(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
} a[200010 << 1];
int Num, h[200010], x, y;
int i, j, k, n, m, p, f[200010], s[200010], S, Rt, l;
int L;
bool b[200010];
inline void Add(i... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int e = 100005;
const long long INF = 1e18 + 5;
template <typename T>
void show2(T &dp) {
for (auto row : dp) {
for (auto col : row) cout << col << " ";
cout << "\n";
}
}
template <typename T>
void show1(T &a) {
for (auto x : a) cout << x << " ";
cout ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int table[3005][27][5][5];
bool trace[3005][27][5][5];
bool vowel[26];
string s;
int solve(int idx, int last, int eq, int block) {
if (idx == s.size()) return 0;
if (table[idx][last][eq][... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, a[400000], i, k, l, o;
cin >> n;
for (long long int i = 0; i <= n - 1; i++) cin >> a[i];
k = 0;
l = 0;
for (long long int i = 0; i <= n - 1; i++) {
o = min(l, a[i]... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, NP = 200010, INF = 10000000;
int prime[NP];
bool is[N];
void create() {
memset(is, 0, sizeof(is));
prime[0] = 0;
for (int i = 2; i < N; ++i) {
if (!is[i]) prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && i * prime[j] < N; ++j) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long ans, sum, cnt, n, m, k, x, y, mn;
int main() {
cin >> n;
while (n--) {
cin >> m;
sum += abs(m);
}
cout << sum;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
k--;
vector<long long> arr(n);
long long li = 0, ri = n - 1;
for (long long i = 1; i <= n; ++i) {
if (i == n) {
arr[li] = n;
break;
}
if (k >= (1LL << (n - i - 1))) {
arr[ri] = i;
ri... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXA = 1000010;
const int MAXN = 110;
int nowarn;
int n, a[MAXN], b[MAXN], m;
bool vis[MAXA];
int main() {
int T;
nowarn = scanf("%d", &T);
while (T--) {
nowarn = scanf("%d", &n);
for (int i = 1; i <= n; ++i) nowarn = scanf("%d", a + i);
memset(v... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[6];
for (int i = 0; i < 6; ++i) {
cin >> a[i];
}
cout << (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -
a[2] * a[2] - a[4] * a[4];
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string list;
cin >> list;
cout << endl;
for (char num : list) cout << num;
for (size_t i{list.size() - 1}; static_cast<int>(i) >= 0; i--)
cout << list.at(i);
cout << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long a, b, c;
} a[111111];
bool cmp(node a, node b) { return a.c > b.c; }
int main() {
long long n, m;
scanf("%I64d%I64d", &n, &m);
long long sum = 0;
for (int i = 0; i < n; i++) {
scanf("%I64d%I64d", &a[i].a, &a[i].b);
a[i].c = a[i].a -... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1500001;
int p, q, f[N], g[N];
bool pal(int n) {
string s = "";
while (n != 0) {
int t = n % 10;
s += (char)(t + '0');
n /= 10;
}
int t = s.length() - 1;
for (int i = 0; i <= t / 2; i++)
if (s[i] != s[t - i]) return false;
return tr... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10000], b[10000], i, j, R = 0, B = 0, n, ans;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
for (i = 0; i < n; i++) {
if (a[i] > b[i]) R++;
if (a[i] < b[i]) B++;
}
if (R == 0)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c;
cin >> a >> c;
b = a;
int h = 1;
for (int i = (signed)b.size() - 1; i >= 0; --i) {
b[i] -= 'a';
b[i] += h;
h = b[i] / 26;
b[i] %= 26;
b[i] += 'a';
}
if (h || !(b > a && b < c))
puts("No such string");
else... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, A, B;
int main() {
scanf("%I64d%I64d%I64d%I64d", &n, &k, &A, &B);
long long ans = 0, x;
x = n;
if (k == 1) {
printf("%I64d", (n - 1) * A);
return 0;
}
while (x != 1) {
if (x < k) {
ans += (x - 1) * A;
x = 1;
continue... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, x[2], y[2];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> x[0] >> y[0] >> x[1] >> y[1];
if (x[0] == n - x[1])
cout << n + min(y[0] + y[1], 2 * n - y[0] - y[1]);
else if (y[0] == n - y[1])
cout << n + min(x[0] + x[1], 2 * n - x[0] - x[1]);
e... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
bool ok(long long t) {
long long res = 0;
for (int i = 1; i <= min(n, m); i++) {
if (t / i <= max(n, m))
res += (t / i);
else
res += max(n, m);
if (!res % i) res--;
if (!t / i) break;
}
return res + 1 <= k;
}
int main(i... | 10 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
long long N = 1 + (n - 1) * 2;
long long cells = ((N / 2) * (2 + (N / 2 - 1) * 2) + N);
cout << cells << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 3;
const long long MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int a[4] = {1, 2, 3, 5};
cout << k * (6 * (n - 1) + 5) << "\n";
for (int i = 0; i < n; i++) {
for (int j =... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int N, M, K, L, P;
long long H;
long long A[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K >> L;
M = N * K;
for (int i = 0; i < M; i++) {
cin >> A[i];
}
sort(A, A + M);
for (int i = 0;... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.