solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
set<int> f;
stack<int> s;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
int t;
scanf("%d", &t);
f.insert(t);
}
int idx = 1;
while (m > 0 && m >= idx) {
if (f.find(idx) == f.end() && m - idx >= 0) {
s.push(idx)... | 4 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
char s[10000];
int head = -1;
char buf[256];
gets(buf);
int L = (int)strlen(buf);
for (int i = 0; i < L; i++) {
bool ok = 1;
if (buf[i] == ',' && i != L - 1) {
ok = 0;
if (buf[i + 1] != ' ') {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000], b[100000], h[100000], c = 0, d = 0, e, f, n, m, i, j,
mm = 0;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
h[i] = b[i];
}
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string st, st2 = "WUB";
cin >> st;
vector<char> v;
int l = st.size();
int j = 0;
for (int i = 0; i < l; i++) {
if (st[i] == 'W' && st[i + 1] == 'U' && st[i + 2] == 'B') {
if (i > 0 && j == 0) {
v.push_back('1');
i += 2;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while ((c < '0' || c > '9') && c - '-') c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - 48;
c = getchar();
}
return x * f;
}
cons... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100010];
int nxt[100010][20], status[100010][20], n, root[100010], dep[100010];
bool vis[100010];
void dfs(int u, int d, int rt) {
vis[u] = true;
root[u] = rt;
dep[u] = d;
for (pair<int, int>& e : g[u]) {
nxt[e.first][0] = u;
status... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 3;
int n, m, ans = 1;
bool F, G;
string s[500100];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
G = F = false;
for (int j = 0; j < m; j++) {
if (s[i][j] == '1' || s[i][j] == '2') {... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dp[100005][20], h[100005], sz[100005];
vector<int> vv[100005];
int n;
int DFS(int v, int p) {
dp[v][0] = p;
sz[v] = 1;
for (int i = 0; i < vv[v].size(); i++) {
int to = vv[v][i];
if (to != p) {
h[to] = h[v] + 1;
sz[v] += DFS(to, v);
}
}
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
const long long mod = 1e9 + 7;
int a[maxn][maxn];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j]);
}
}
int flag = 1;
int ans = 0;
for (int i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const size_t MAX = 200000 + 1;
uint64_t gcd(uint64_t a, uint64_t b) { return b ? gcd(b, a % b) : a; }
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
ifstream in("input.txt");
ofstream out("output.txt");
int32_t n, k, a, v = 0;
cin >> n >> k;
... | 5 |
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define en cin.close();return 0;
#define INF ((ll)(4e18))
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
const ll N = 5005;
bool use[N];
... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
const int N = 3e5 + 10;
char ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long binpow(long long a, int n) {
if (n == 0) return 1;
if (n % 2 == 0) {
long long q = binpow(a, n / 2);
return (q * q) % mod;
} else
return (a * binpow(a, n - 1)) % mod;
}
signed main() {
int t;
cin >> t;
while (t--) {... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 1e9;
const long long llf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int n, m;
int a[1010][1010];
vector<int> r[1010], c[1010];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m... | 8 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long base = 131;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
const long double eps = 1e-7;
const int mod = 1e9 + 7;
const int M = 1e5 + 10;
long long int h[M];
int a[1012][1012], d[1012][1012];
int main() {
int n;
scanf("%d", &n);
int... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int INFL = 0x3f3f3f3f3f3f3f3f;
const int N = 1550;
const int M = 0;
const long long int mod = 1e9 + 7;
struct Edge {
int u, v, cap, flow, cost, next;
Edge() {}
Edge(int u, int v, int cap, int flow, int cost, int next)
... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize(2, 3, "Ofast")
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
if (a < b) a = b;
}
int read() {
int x = 0, f = 0;
char ch = getchar();
while (!isdi... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int c = 4e6 + 2, mod = 998244353;
long long n, m, sum = 1, inv[c];
int main() {
cin >> n >> m, inv[1] = 1;
for (int i = 2; i <= n + m; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
if (i <= n) sum += inv[i];
}
cout << (n * inv[m + 1] + 1) % mod... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = INT_MAX;
const long long inff = 5e18;
const long long mod = 1e9 + 7;
long long n, p, q, r;
long long a[maxn];
long long dp[maxn][4];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> p >> q >> r;
for (long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x;
}
const int MAXN = 600;... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long powr(long long x, long long y, long long mod);
long long comb(int n, int c);
long long fn();
long long gn(int x);
int check(int start, int e);
long long fact[100009];
const long long mod = 1000000007;
int n, y = 0;
pair<int, int> arr[100009];
int p[100009];
int ma... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 410;
const long long MOD = 1e9 + 7;
int nowarn;
int n;
int f[MAXN][MAXN] = {0};
int C2(int n) { return int((long long)n * (n - 1) / 2 % MOD); }
void add_mod(int &a, int b) { a = (a + b) % MOD; }
int main() {
nowarn = scanf("%d", &n);
f[1][0] = f[1][1] =... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
const long long inf = 1e18;
vector<int> g[N], st[N];
int dist[N][N], ans[N];
long long d[N], dp[N], dp2[N][N], dp3[N][N][N];
void predfs(int v, int p) {
st[v].push_back(v);
for (int u : g[v]) {
if (u != p) {
predfs(u, v);
for (int x : ... | 19 |
#include <bits/stdc++.h>
const long double eps = 1e-9;
const double pi = acos(-1.0);
const long long inf = 1e18;
using namespace std;
int a[111], n;
int main(int argc, const char* argv[]) {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
int b;
scanf("%d", &b);
if (b != -... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000000 + 10, MOD = 1e9 + 7;
char s[MAXN];
long long dp[MAXN];
int last[26], n, k;
int main() {
scanf("%d%d%s", &n, &k, s + 1);
int m = strlen(s + 1);
dp[0] = 0;
for (int i = 0; i < k; ++i) last[i] = 0;
for (int i = 1; i <= m; ++i) {
int o = s... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long a[N], b[N], dp[N];
struct line {
long long k, b;
double x;
line() {}
line(long long a, long long bb, double c) {
k = a;
b = bb;
x = c;
}
};
line s[N];
int l = 0, r = 0;
void update(long long k, long long b) {
line tm... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
const long long nax = 0;
int t;
void solve() {
int letak;
string ans, a, b;
cin >> a >> b;
ans = a;
for (int i = 0; i < a.size(); ++i) {
int p = i;
string x = a;
for (int j = a.size() - 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
string st;
int main() {
cin >> n >> m;
cin >> st;
ans = n * m - n;
for (int k = 0; k < st.size(); ++k) {
if (k > 0 && st[k] != st[k - 1]) ans += n * m - n;
}
long long c = 1;
for (int k = 1; k < st.size(); ++k) {
if (c == 1) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;
const int inf = 1e9;
int n, m;
char s[N];
int d[N], b[N];
struct cmp {
bool operator()(const int &x, const int &y) const { return d[x] > d[y]; }
};
struct ACtree {
int son[N][26], fail[N], top[N],... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long a[2][300000];
long long ans[300000];
void solve(vector<int> &c) {
if (c.size() == 0 || c.size() == 1) return;
vector<int> d[2];
long long sum[2] = {0, 0}, cnt[2] = {0, 0};
for (int i = 1; i < c.size(); i++) {
if (a[0][c[0]] + a[1][c[i]] < a[1][c[0]] + ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6 + 3;
int main() {
int n;
unsigned long long int ans = 1, INF = 2e1000;
cin >> n;
n--;
for (int i = 0; i < n; i++) {
ans *= 3;
ans %= mod;
}
cout << ans % mod << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debug_out(T t) {
cerr << t;
}
template <typename A, typename B>
void debug_out(pair<A, B> u) {
cerr << "(" << u.first << " " << u.second << ")";
}
template <typename T>
void debug_out(vector<T> t) {
int sz = t.size();
for (int i = 0; i < s... | 23 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[300001];
int l, r, i, j, h, a, b, cnt, x;
string s;
char c;
int main() {
cin >> a >> b;
cin >> s;
for (i = 0; i < a; i++) {
if (s[i] != '.') continue;
if (s[i + 1] == '.') cnt++;
if (i && s[i - 1] == '.')
p[i].first = p[i - 1].first;... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> prms(long long n) {
vector<long long> prms;
if (n % 2 == 0) {
prms.push_back(2);
while (n % 2 == 0) n /= 2;
}
for (long long p = 3; p * p <= n; p += 2) {
if (n % p == 0) {
prms.push_back(p);
while (n % p == 0) n /= p;
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
for (long long i = 0; i < v.size(); ++i) x << v[i] << " ";
return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
for (auto it : v) x << it << " ";
return x;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int pages, speed, maxspeed, accel, reread, days;
int main() {
scanf("%d%d%d%d%d", &pages, &speed, &maxspeed, &accel, &reread);
while (pages > 0) {
if (days > 0) pages += reread;
pages -= speed;
speed = min(maxspeed, speed + accel);
days++;
}
printf("... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int ans = (1LL << 30) - 1LL;
long long int a, b, c;
cin >> a >> b >> c;
long long int all_need = c * a;
for (int k = 29; k >= 0; --k) {
long long int wt = ans ^ (1LL << k);
long long int no_int = 1LL;
long long int dw = (wt * b);... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int place[100005];
int main() {
int n;
cin >> n;
if (n % 4 >= 2)
cout << -1 << endl;
else {
for (int i = 0; i < n / 2; i += 2) {
a[i] = i + 2;
a[i + 1] = n + 2 - a[i];
}
for (int i = n - 1; i > n / 2; i -= 2) {
a[i] =... | 6 |
#include <bits/stdc++.h>
int n, a[2010], b[2010], tot;
struct status {
int c[9], s;
bool operator<(const status& st) const {
for (int i = 0; i < 9; i++)
if (c[i] != st.c[i]) return c[i] < st.c[i];
return 0;
}
} S[720];
int add[720][9], del[720][9];
int trans(status st, int x, int t) {
st.c[x] += t... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<long long> a(n);
for (auto &x : a) {
cin >> x;
}
int ans = 1;
int i = 0, j = 0;
while (i < n) {
j = max(i, j);
while (j < n) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, s, q, ans = 1;
cin >> t >> s >> q;
while (q * s < t) {
ans++;
s = q * s;
}
cout << ans << '\n';
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int tab[18][(1 << 17) + 20];
int main() {
int i, j, k, T, cas = 0, n, m;
scanf("%d%d", &n, &m);
for (i = 0; i < (1 << n); i++) scanf("%d", &tab[n][i]);
bool lst = 1;
for (i = n; i; i--) {
for (j = 0; j < (1 << i); j += 2) {
if (lst)
tab[i - 1][j ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8;
const int MAXR = 1;
const int MAXC = 1;
const int MAXBITS = 64;
const int INF = (int)1e9;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
priority_queue<int, vector<int... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cin.exceptions(cin.failbit);
int T;
cin >> T;
while... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long bit[N] = {};
int idx[N] = {};
int n;
priority_queue<int> A;
priority_queue<int, vector<int>, greater<int>> B;
inline long long __abs(int x) { return (x ^ (x >> 31)) - (x >> 31); }
long long sum(int x) {
int ret = 0;
while (x) {
ret +... | 15 |
#include <bits/stdc++.h>
using namespace std;
int siz;
struct mat {
long long a[130][130];
mat() { memset(a, 0, sizeof(a)); }
mat operator*(const mat b) {
mat c;
for (int i = (0); i <= (siz); i++)
for (int j = (0); j <= (siz); j++)
for (int k = (0); k <= (siz); k++)
(c.a[i][j] += a... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x[3];
} p[200100];
bool cmpforward(int i, int j) {
return p[i].x[0] < p[j].x[0] || p[i].x[0] == p[j].x[0] && i < j;
}
bool cmpbackward(int i, int j) {
return p[i].x[0] > p[j].x[0] || p[i].x[0] == p[j].x[0] && i < j;
}
int ans[200100];
void build1d(v... | 19 |
#include <bits/stdc++.h>
template <typename T>
inline T max(T a, T b) {
return a > b ? a : b;
}
template <typename T>
inline T min(T a, T b) {
return a < b ? a : b;
}
template <typename T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <typename T>
inline bool repr(T &a, T b) {
return a < b ? a = b, 1 : ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int i, j, k, n;
char a[1000];
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
int ans = 1, nds = 0;
if (strlen(a) == 1) {
cout << "Yes"
<< "\n";
} else {
sort(a, a + strlen(a));
for (j = 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
return a ? gcd(b % a, a) : b;
}
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
int sgn(T x) {
return x > 0 ? 1 : (x < 0 ? -1 : 0);
}
const long double p... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
int w[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int r[10][10];
unsigned long long f[200], g[200];
int n, k;
int main() {
for (int i = 0; i <= 9; i++)
for (int k = 0; k <= 9; k++)
for (... | 14 |
#include <bits/stdc++.h>
using namespace std;
std::vector<int> inputs[100005], heavy;
int intersection[340][100005];
bool isHeavy[100005];
long long sum[100005];
long long data[100005];
long long hv[340];
int id[100005];
int main() {
long long n, m, q, i, j, k, x, lim = sqrt(100005);
scanf("%lld", &n), scanf("%lld"... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline void inp(long long int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
n = n * sign;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int Get() {
char c;
while (c = getchar(), c < '0' || c > '9')
;
int X = 0;
while (c >= '0' && c <= '9') {
X = X * 10 + c - 48;
c = getchar();
}
return X;
}
int main() {
int N = Get(), M = Get();
static int Degree[100000];
static vector<int> G[1... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int NN = 111;
const int MOD = 100000007;
const int INF = 11111111;
pair<int, int> dp[NN][NN / 2][3][3];
bool vis[NN][NN / 2][3][3];
int s[NN];
int n;
pair<int, int> rec(int pos, int used, int dir, int v) {
if (used == -1) return make_pair(-INF, INF);
if (pos == n)... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int main() {
long long a, b, x, y;
int n;
cin >> n;
while (n--) {
cin >> x >> y >> a >> b;
if (x > y) swap(x, y);
if (b > 2 * a) {
cout << (x + y) * a << endl;
} else {
cout << (y - x) * a + b * x << endl;
}
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
scanf("%d %d", &n, &a);
int m = n / 2;
if (a % 2)
printf("%d\n", (a + 1) / 2);
else
printf("%d\n", m - (a / 2) + 1);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int N = 100005;
const int M = 1e9 + 7;
vector<int> adj[N];
int tree[N * 2], dep[N], anc[N][23], st[N], ed[N], idx = 0, a[N], b[N], h[N];
long long dp[305];
int low_bit(int x) { return x & -x; }
void update(int x, int y) {
for (; x < N * 2; x ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;
const int N = 4e3 + 6;
const int oo = 1e9;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
long long n, m;
int vis[N];
int v[N][N];
long long degree[N];
int main() {
memset(v, 0, sizeof v);
memset(degree, 0, sizeof degree);
memset(vis, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n;
cin >> n >> k;
int x = 2 * k + 1;
int l = n / x, mod = n % x;
if (mod == 0) {
cout << l << endl;
for (int i = k + 1; i <= n; i += x) cout << i << ' ';
cout << endl;
} else if (mod >= k + 1) {
cout << l + 1 << endl;
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3;
vector<pair<int, int> > v[maxn];
int n, m, k;
pair<int, int> stu[maxn];
int fro[maxn];
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) cin >> stu[i].first;
for (int i = 1; i <= n; ++i) cin >> stu[i].second;
for (int i = 1; i <= n;... | 3 |
#include <bits/stdc++.h>
char c[60][4];
int temp[56][56][56][56], aaa[60];
int tr(char a[4]) {
int sum = 0;
if (a[1] == 'H') sum += 13;
if (a[1] == 'D') sum += 26;
if (a[1] == 'C') sum += 39;
if (a[0] >= '2' && a[0] <= '9') sum += (a[0] - 50);
if (a[0] == 'A') sum += 12;
if (a[0] == 'K') sum += 11;
if (... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
for (T x : a) cout << x << " ";
cout << '\n';
}
vector<long long> xx = {1, 0, -1, 0};
vector<long long> yy = {0, 1, 0, -1};
string dir = "LRUD";
const long long N = 5e5 + 50, oo = 3e18 + 500;
const long long mod = 1e9 +... | 0 |
#include <bits/stdc++.h>
const int INF = 2147483647;
const int MOD = 1000000007;
const long long INF64 = 9223372036854775807;
const long double EPS = 1e-7;
using namespace std;
bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
return (a.first.first == b.first.first ? a.first.second > b.first.secon... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
if (y < x) x = y;
}
int main() {
int n;
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3) {
puts("NO");
ret... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long e = 0, o = 0, t, a[2][2] = {0};
string s;
cin >> s;
for (int i = 0; i < s.length(); i++)
t = s[i] - 'a', a[t][i & 1]++, o += a[t][i & 1], e += a[t][!(i & 1)];
cout << e << " " << o;
}
| 12 |
#include <bits/stdc++.h>
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', 'D', 'U'};
ll add(ll a, ll b) {
a += b;
if (a >= MOD) {
a -= MOD;
}
return a;
}
int sub(int a... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c;
cin >> n >> m;
long long a[n], b[m];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
int i = 0, j = 0;
long long sum = 0, d;
while (j < n && i < m) {
sum += a[j];
while (sum >= b[i]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const double eps = (1e-10);
stringstream out;
int n, m, k, u, v, deg[200005];
bool isGood[200005];
vector<int> ans(200005);
set<pair<int, int> > good;
vector<pair<int, int> > edges(200005);
vector<vector<pair<int, int> > > adj(200005);
int main() ... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
const ll INF = 1e18 + 5;
int a[N], b[N];
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n >> x;
multiset<int> s;
for (int i = 1; i <= n; ++i) {
int val;
cin >... | 11 |
#include <bits/stdc++.h>
using namespace std;
int C[4000000] = {0};
int main() {
int n;
cin >> n;
int even = 0;
int A[4000] = {0};
int B[4000] = {0};
for (int i = 0; i < n; i++) {
int a;
cin >> a;
A[i] = a;
C[a]++;
}
for (int j = 0; j < n; j++) {
int a;
cin >> a;
B[j] = a;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec) is >> v;
return is;
}
template <typena... | 5 |
#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;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), ... | 7 |
#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
for (; a != b; ++a) cerr << *a << ' ';
cerr << endl;
}
const long long int mod = 777777777;
int ok[3][3];
struct segtree {
struct node {
int left, right;
long long int a[3][3];
nod... | 16 |
#include <bits/stdc++.h>
using namespace std;
int A[5][10005], B[5], T[5], V[5], ctos, va = 1, esta = 0, chico, con, trata;
void sig(int suma) {
con = 0;
for (int cual = 1; cual < 4; cual++) {
con += T[cual];
A[cual][V[cual]] = suma + con;
++V[cual];
if (V[cual] > B[cual]) {
V[cual] = 1;
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000002];
map<int, int> mp;
int main() {
long long n, m, i, x, y, z, s = 0;
cin >> n >> m;
for (i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
}
for (i = 1; i <= m; i++) {
scanf("%I64d", &x);
if (x == 3) {
scanf("%I64d", &y);
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void cmin(T &a, T b) {
((a > b) && (a = b));
}
template <class T>
inline void cmax(T &a, T b) {
((a < b) && (a = b));
}
char IO;
template <class T = int>
T rd() {
T s = 0;
int f = 0;
while (!isdigit(IO = getchar())) f |= IO == '-';
do s... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int logn = 17;
const int inf = (int)1e9;
const long long mod = (int)1e9 + 7;
const long long l_inf = (long long)4e12;
const long double pi = acosl(-1.0);
const long double eps = 1e-12;
int n, m, q;
int val[maxn], arr[maxn];
vector<int> g[maxn]... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long fg = 0;
string To_string(long long x) {
string s;
while (x != 0) {
s += (x % 2) + '0';
x /= 2;
}
reverse(s.begin(), s.end());
return s;
}
void Solve(int t) {
long long x, y, i, j;
cin >> x >> y;
string s, s2;
s = To_string(x);
s2 = To_s... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int l, r;
int val;
int d;
Node(int a = 0, int b = 0, int c = 0, int k = 0) : l(a), r(b), val(c), d(k) {}
};
int g_n, g_m, g_cnt;
vector<Node> vn;
vector<vector<int>> vvi_bit;
vector<vector<int>> vvi_edge;
bool input() {
cin >> g_n >> g_m;
if (cin.e... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n;
vector<int> edge[1005];
int deg[1005];
int ask(int u, int v) {
cout << "? " << u << " " << v << endl;
cout.flush();
int ans;
cin >> ans;
return ans;
}
int main() {
cin >> n;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long a, b, c;
cin >> a >> b >> c;
long long res = 0;
if (a >= 3 && b >= 2 && c >= 2) {
long long w = min(a / 3, min(b / 2, c / 2));
res = w * 7;
a -= w * 3;
b -= w * 2;
c -= w * 2;
}
long long remM = 0;
for (long long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int rows, cols;
queue<bool> grid[300][300];
vector<bool> goal[300][300];
int osize[300][300];
struct Move {
int x1, y1, x2, y2;
};
vector<Move> moves;
void makemove(int x1, int y1, int x2, int y2) {
assert(x1 != x2 || y1 != y2);
moves.push_back({x1, y1, x2, y2});
gr... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
puts("YES");
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int a = x1 % 2;
int b = y1 % 2;
if (a < 0) {
a += 2;
}
if (b < 0) {
b += 2;
}
p... | 13 |
#include <bits/stdc++.h>
using namespace std;
FILE *in, *out;
int N, M, K;
int ar[200100];
vector<vector<pair<int, int> > > edges(200100);
int used[200100];
int SUM;
int ANS[200100];
int dfs(int root) {
int i, j, k;
used[root] = 1;
j = ar[root];
for (i = 0; i < (int)(edges[root].size()); i++) {
if (used[edg... | 16 |
#include <bits/stdc++.h>
int matrix[88][88];
int n, k;
int part[88];
int dp[11][88];
int Solve(const std::vector<int>& perm) {
for (int i = 0; i < n; i++) {
int idx = perm[i];
if (i < n / 2) {
part[idx] = 1;
} else {
part[idx] = 2;
}
}
int maxval = 1e9 + 5e8;
for (int i = 0; i <= k; ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (a == b) {
cout << 0 << endl;
} else if (a > b && (a - b) % 2 == 0) {
cout << 1 << endl;
} else if (b > a && (b - a) % 2 != 0) {
cout << 1 << endl;
} else... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b[105] = {0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4}, i, j;
cin >> a;
a -= 10;
if (a < 0) {
cout << 0 << endl;
return 0;
}
cout << b[a] << endl;
}
| 0 |
#include <bits/stdc++.h>
int main() {
int i = 1, k, l, m, p = 0, n, d, count = 0;
scanf("%d\n%d\n%d\n%d\n%d", &k, &l, &m, &n, &d);
while (i <= d) {
if (i % k == 0) {
count++;
} else if (i % l == 0) {
count++;
} else if (i % m == 0) {
count++;
} else if (i % n == 0) {
count+... | 0 |
#include <bits/stdc++.h>
using namespace std;
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
long long fastMin(long long x, long long y) {
return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x;
}
long long fastMax(long lon... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
long long n, a, b, c, d;
int main() {
cin >> n >> a >> b >> c >> d;
long long ans = 0;
for (long long i = 1; i <= n; i++) {
long long x = a + b + i;
long long y = i + c + d;
long long x1 = a + c + i;
long long y1 = b + d... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, K;
int inp[2520][2520];
int p1[10], p2[10];
long long ans;
void solve(int d, int l, int u, int r) {
if (d == u && l == r) {
ans += (inp[u][r] - inp[u][l - 1] - inp[d - 1][r] + inp[d - 1][l - 1]) == K;
return;
}
if (u - d > r - l) {
int mid = (u +... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1e9;
const double eps = (1e-10);
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int dcmp(double x, double y) { return fabs(x - y) <= eps ? 0 : x < y ? -1 ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 4e5 + 10;
struct SAM {
int pa, len;
int trans[26];
} st[maxN + 1];
struct Que {
int l, r, len, id;
Que(int L = 0, int R = 0, int LEN = 0, int ID = 0) {
l = L, r = R, len = LEN, id = ID;
}
};
struct Node {
int x, len;
Node(int X = 0, int LE... | 27 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
if (b < a) a = b;
return a;
}
template <class T>
T &maxx(T &a, T b) {
if (a < b) a = b;
return a;
}
int &madd(int &a, int b) {
a += b;
if (a >= 1000000009) a -... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> arr;
int q;
vector<int> arr1;
for (int i = 0; i < n; i++) {
cin >> q;
arr.push_back(q);
}
sort(arr.begin(), arr.end());
for (int i = 0; i < n; i++) {
if (k % arr[i] == 0) arr1.push_back(k / arr[... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<char, pair<int, int>> mm;
int n, m, ret, peeps, f, ans1;
vector<int> dsu;
vector<vector<int>> dist, in;
vector<vector<bool>> cyc, vis, num;
vector<string> di, bw;
void GiveNumber(int i, int j, int f) {
cyc[i][j] = true;
in[i][j] = f;
dist[i][j] = ret++;
int newi... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
list<int> L;
set<int> s;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
s.insert(k);
}
if (s.size() > k)
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
mt19937 rnd(12332);
const int MAXN = 1e5 + 7;
int ans[MAXN];
pair<int, int> a[MAXN];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, g, past, v, i;
cin >> n;
for (int i = 0; i ... | 21 |
#include <bits/stdc++.h>
using namespace std;
class IO {
static const int bufSize = 1 << 18;
char inBuf[bufSize], outBuf[bufSize];
char *ip1 = inBuf, *ip2 = inBuf;
int goodReadBit = 0, op1 = -1, op2 = bufSize - 1;
template <typename T>
__inline__ __attribute__((always_inline)) void __RI(T& x) {
int ch =... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.