solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[n + 1];
cin >> a;
int small[26] = {0}, capi[26] = {0}, digit[10] = {0};
for (int i = 0; i < n; i++) {
if (a[i] >= '0' && a[i] <= '9') {
digit[a[i] - '0']++;
} else if (a[i] >= 'a' && a[i] <= 'z') {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
if (b == 0) {
return 1;
}
long long res = binpow(a, b / 2);
res *= res;
if (b % 2) {
return res * a;
}
return res;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)16;
const int MOD = (int)1e9 + 7;
const int infint = (int)1e8 + 3;
const long long inf = (long long)1e18;
long long dp[MAXN][2], L, R, open, close;
int bits[MAXN][4];
int bt(int x, int i) { return (x >> i) & 1; }
string dec(string s) {
int idx = -1;
... | 21 |
#include <bits/stdc++.h>
int main() {
int y, b, r;
scanf("%d %d %d", &y, &b, &r);
while (b < y + 1 || r < y + 2) {
y--;
}
printf("%d\n", 3 * y + 3);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
multiset<int> s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, ch, x, bad = 0, ans = 0, last = 0;
cin >> n >> ch;
ch--;
for (int i = 0; i < n; i++) {
cin >> x;
if (x && i != ch) s.insert(x);
if (i == ch) ans += bool(x);... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6000000;
int cnt, tot;
int head[MAXN], nxt[MAXN], to[MAXN];
int dfn[MAXN], low[MAXN], sta[MAXN], top, vis[MAXN];
inline void ins(int u, int v) {
nxt[++cnt] = head[u];
head[u] = cnt;
to[cnt] = v;
}
int y;
int sum;
void tarjan(int u) {
dfn[u] = low[u]... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long linf = 1000000000000000000LL;
const double eps = 0.000001;
const double pi = 3.14159265358979323846;
template <class T>
T abs(T k) {
return k >= 0 ? k : -k;
}
template <class T>
T sqr(T n) {
return n * n;
}
template <class T>
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 3;
int n;
string a[N], b[N];
string s;
vector<int> adj[4 * N], rev_adj[4 * N];
bool ans[2 * N];
vector<int> order;
bool used[4 * N];
int timer, comp[4 * N];
void create_component(int u) {
used[u] = true;
comp[u] = timer;
for (int to : rev_adj[u]) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int color[1000000];
int f[1000000];
vector<pair<int, int> > go[1000000];
int main() {
int n, m;
cin >> n >> m;
while (m--) {
int x, y, c;
cin >> x >> y >> c;
go[y].push_back({x, c});
}
fill(color, color + n + 1, -1);
fill(f, f + n + 1, 0x7fffffff);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
x *= f;
}
const int M = 510;
const int B = 500;
struct ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, s[20005], a;
int dp[55][105];
int dp1[55][105];
int main() {
scanf("%d%d%d", &n, &k, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
s[i] = (s[i - 1] + a) % m;
}
int sol = INT_MIN;
for (int i = 0; i < 55; ++i)
for (int j = 0; j < 105;... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct sol {
int x, y, z, a, b, t;
};
vector<pair<int, int> > stations;
vector<sol> sols;
int e, s, n, m;
sol driveback(sol car, int si, int fin) {
int dist = stations[si].first - fin;
int i;
i = max(min(car.z, min(s - car.t, dist - car.t)), 0);
car.z -= i;
car.... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t = 0;
long long ans = 0;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
while (1 + (1 << t) <= n) t++;
t--;
for (int i = 0; i < n - 1; i++) {
ans += a[i];
a[i + (1 << t)] += a[i];
a[i] = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char k, w[2][26];
int g, e, m[30], l = 0;
int main() {
string a;
cin >> a;
for (int i = 0; i < a.size(); i++)
if (m[a[i] - 'A'] != 0) {
k = a[i];
e = m[a[i] - 'A'] - 1;
g = i;
} else
m[a[i] - 'A'] = i + 1;
if (g - e == 1) {
cout <... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int R = 1001;
int h[R][R], l[R][R];
int road[100001][2];
int alp[30][2];
string str[R];
int n, m, w;
void Input1() {
memset(alp, 0, sizeof(alp));
memset(h, 0, sizeof(h));
memset(l, 0, sizeof(l));
for (int i = 0; i < n; i++) {
cin >> str[i];
for (int j ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long INF = 1e9;
inline long long pwr(long long base, long long n, long long m) {
long long ans = 1;
while (n > 0) {
if (n & 1) ans = (ans * base) % m;
base = (base * base) % m;
n >>= 1;
}
return ans;
}
int n, x;
ch... | 0 |
#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;
}
long long int fib[200005], fib01[200005], fib10[200005];
long long int fibs[200005], fib01s[200005], fib10s[200005];
int n, m;
int ar[105];... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500 * 1000 + 10;
int n, m, cnt;
set<int> sv;
vector<int> adj[N], ans[N], tmp;
queue<int> q;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >> n >> m;
for (int i = 0, u, v; i < m; i++)
cin >> u >> v, adj[u].push_back(v), ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300, maxc = 1e5;
int n, l[maxn + 5], c[maxn + 5];
map<int, bool> vis;
map<int, long long> f;
priority_queue<pair<long long, int> > q;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int dread() {
int x = 0;
bool f = 0;
char ch = getchar... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, x, y, l, k;
int main() {
cin >> a >> b >> c >> d;
x = (3 * a) / 10;
l = a - a / 250 * c;
y = (3 * b) / 10;
k = b - b / 250 * d;
if (max(x, l) > max(y, k)) {
cout << "Misha";
return 0;
}
if (max(x, l) < max(y, k)) {
cout << "... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int n, m;
vector<pair<int, long long> > G[N];
int u[N], v[N];
long long x[N];
int parent[N], height[N];
long long d[N];
void dfs(int v, int p) {
for (int i = 0; i < G[v].size(); ++i) {
int to = G[v][i].first;
if (to != p) {
d[to] = G[v]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i, mcost = 0;
cin >> n >> k;
vector<long long> v(n), sc(n);
priority_queue<pair<long long, long long>,
vector<pair<long long, long long> >,
less<pair<long long, long long> > >
pq;
for (i = 0; i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int nxt[1000010];
int a[1000010];
long long mod = 1000000007;
long long pow(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1) s = s * a % mod;
a = a * a % mod;
b >>= 1;
}
return s;
}
int main() {
int n, m;
scanf("%d... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b;
cin >> a >> b;
long long x, y;
cin >> x >> y;
cout << max(max(x, a - 1 - x) * b, max(y, b - 1 - y) * a) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
long long t;
cin >> t;
while (t--) solve();
retu... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const double eps = 1e-8;
int n, sqrt3, sqrt2;
pair<long long, int> p[N];
long long v, ans, ansa, ansb, ansc;
void dfsb(int k, int a, long long b) {
if (b > sqrt2) return;
if (k == n + 1) {
long long c = v / a / b, s = 2ll * a * b + 2ll * a * c + 2l... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
vector<pair<long long, long long>> ans;
vector<long long> v;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
ans.push_back(make_pair(x, i));
}
sort(ans.begin(), ans.end());
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int inf = 1000000000;
struct Edge {
int to, next, c, f;
} edge[2000100];
int head[100010], num = -1, e[N][2];
void add_edge(int a, int b, int c, int f) {
edge[++num] = (Edge){b, head[a], c, f}, head[a] = num;
edge[++num] = (Edge){a, head[b], -... | 17 |
#include <bits/stdc++.h>
using namespace std;
int mini(int a, int b, int c, int d, int e) {
return min(a, min(b, min(c, min(d, e))));
}
int maxi(int a, int b, int c, int d, int e) {
return max(a, max(b, max(c, max(d, e))));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, l, r;
cin >> ... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
int fu = 1;
char c = getchar();
while (c > 57 || c < 48) {
if (c == 45) fu = -1;
c = getchar();
}
while (c <= 57 && c >= 48) {
x = (x << 3) + (x << 1) + c - 48;
c = getchar();
}
x *= fu;
}... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool SortGrtScnd(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second > b.second);
}
int gcd(int a, int b) {
if (!b)
return a;
else
return (gcd(b, a % b));
}
unsigned long long powFn(int num, int power) {
unsigned long long serd = 1;
for (i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, s;
int a[N], ans[N];
struct Student {
int b, c, id;
bool operator<(Student b) const { return c > b.c; }
} stu[N];
struct Bug {
int a, id;
bool operator<(Bug b) const { return a < b.a; }
} bug[N];
int cmp(Student a, Student b) { return... | 11 |
#include <bits/stdc++.h>
using namespace std;
class pii {
public:
int first, second;
pii() { first = second = 0; }
pii(int _first, int _second) {
first = _first;
second = _second;
}
bool operator<(const pii &a) const {
if (first != a.first) {
return first < a.first;
}
return second ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1010101010;
int N;
int A[3030];
int B[3030];
int D[3030][3030];
int E[3030][3030];
int nxt[3030][3030];
int main() {
int tc; scanf("%d", &tc);
while(tc--) {
scanf("%d", &N);
for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
for(int i = 1; i <= N; i... | 19 |
#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
int x = 0, y = n, u = 0, v = m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '*') {
if... | 0 |
#include <bits/stdc++.h>
namespace IO {
char ch = '\n';
template <class T>
inline T ReadInt() {
T x(0);
bool f(1);
while (ch < '0' || '9' < ch) {
if (ch == '-') {
f = 0;
}
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
re... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, sum = 0;
cin >> n;
vector<long long int> vec(n);
map<long long int, long long int> cnt;
vector<long long int> dp(100005);
for (long long int i = 0; i < n; i++) {
cin >> vec[i];
cnt[vec[i]]++;
}
dp[1] = cnt[1];
dp[0] = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int pre[4005];
void init() {
for (int i = 1; i <= 4000; i++) pre[i] = i;
}
int find(int x) {
if (pre[x] != x) {
pre[x] = find(pre[x]);
}
return pre[x];
}
void Union(int x, int y) {
int fx = find(x);
int fy = find(y);
pre[fx] = fy;
}
struct event {
int x,... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const long long INF64 = 1e18;
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int fa[maxn], col[maxn][2], dis[maxn];
int find(int x) {
if (x != fa[x]) {
int root = find(fa[x]);
dis[x] ^= dis[fa[x]];
fa[x] = root;
}
return fa[x];
}
int main() {
int t;
cin >> t;
while (t--) {
bool f = false;
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int modu(long long int a, long long int b) {
long long int ans = 1;
while (b > 0) {
if (b & 1) ans = (ans * a) % 1000000007;
b /= 2;
a = (a * a) % 1000000007;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
l... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int n, q, c, l, r, tg, ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
long long a[n], h = 0, m, t;
for (int i = 0; i < n; ++i) {
cin >> c;
h += c;
a[i] = h;
}
t = h;
while (q--) {
cin... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5;
const long long inf = 1e18;
long long n, m, k;
long long A[maxn];
int main() {
long long q, w, e, a, b, f;
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> k;
for (a = 0; a < k; a++) {
set<long long> S;
cin >... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const int MAXN = 120000;
int n;
int a[MAXN];
vector<tuple<int, int, int>> ans;
void out() {
cout << "YES\n";
cout << ans.size() << "\n";
for (auto t : ans) {
int x, y, z;
tie(x, y, z) = t;
cout << x + 1 << " " << y + 1 << " " << ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
cin >> a;
cin >> b;
cin >> c;
cout << (long long int)(ceil(a / c) * ceil(b / c));
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
public:
void build(int node, int l, int r);
int getLeft(int i) { return 2 * i; }
int getRight(int i) { return 2 * i + 1; }
void refresh(int node, int l, int r) {
if (!lazy[node]) return;
lazy[node] = false;
sum[node] = (r - l + 1) - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9 + 1337);
const long long LINF = (long long)(1e18);
const double EPS = 1e-11;
const int MOD = 1000000007;
const int HBASE = 1003;
inline int add(int a, int b) {
a += b;
if (a >= MOD) {
a -= MOD;
}
return a;
}
inline int sub(int a, int b)... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j;
long long curr;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
curr = 2;
for (i = 1; i <= n; i++) {
if (i == 1)
cout << 2 << '\n';
else {
cout << i * (i + 1) * (i + 1) - (i - 1) << '\n';
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)(1e6);
vector<int> graph[MAX_N];
int N, M;
unsigned long long xors[MAX_N];
unsigned long long hs[MAX_N];
void init() {
scanf("%d%d", &N, &M);
for (int i = 0; i < N; i++) {
hs[i] = (unsigned long long)rand() * (unsigned long long)rand() *
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
int a, b, c;
int n;
int x[N];
int main() {
int m = 100000 * 100000;
scanf("%d%d%d", &a, &b, &c);
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", x + i);
sort(x + 1, x + 1 + n);
int ans = lower_bound(x + 1, x + 1 + n, c) - uppe... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int b[105];
int find(int x) {
int i, sma = 1000000, s;
for (i = 1; i < x; i++) {
if (a[i] < sma && b[i] == 0) {
sma = a[i];
s = i;
}
}
b[s] = 1;
return sma;
}
bool fun(int x, int y) {
int i, sum = a[x];
for (i = 1; i < x; i++) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, mx = 0, arr[100009] = {};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
arr[x]++;
mx = max(mx, x);
}
for (int i = mx; i >= 1; i--) {
arr[i] = arr[i] * i + max(arr[i + 2], arr[i + 3]);
}
cout << max(arr[1], arr[2... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, n, m;
long long int a[11] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};
while (cin >> n) {
i = n % 10;
n /= 10;
j = n;
cout << a[i] * a[j] << endl;
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
using pr = pair<int, int>;
int N, M, Q, A[200005], par[200005];
pr E[300005], QS[500005];
bool chk[300005];
set<int> s[200005];
stack<pr> st;
int f(int x) { return par[x] = (par[x] == x ? x : f(par[x])); }
void uni(int x, int y) {
x = f(x), y = f(y);
if (x == y) return;... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int size = 1000000;
string s;
int i, n, a[size];
long long ans, tp;
int main() {
cin >> s;
n = s.size();
for (i = 0; i < n - 1; i++)
if (s[i] - '0' + s[i + 1] - '0' == 9)
a[i] = 1;
else
a[i] = 0;
a[n - 1] = 0;
tp = 0;
ans = 1;
for (i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int id;
long long cost;
node(int x, long long y) {
id = x;
cost = y;
}
};
int main() {
std::ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vector<vector<node> > edges(n + 1);
vector<bool> isSto(n + 1, 0);
vector<int> ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int A[n];
map<int, int> mp;
map<int, int>::iterator itr;
for (int i = 0; i < n; i++) cin >> A[i];
for (int i = 0; i < n; i++) {
int y = 0;
while (A[i] % 2 == 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
bool win(long long s, long long e) {
if (e & 1) return !(s & 1);
if (s * 2 > e) return s & 1;
if (s * 4 > e) return 1;
return win(s, e / 4);
}
bool lose(long long s, long long e) {
if (... | 19 |
#include <bits/stdc++.h>
int a, i, cnt = 0;
int main() {
scanf("%d", &a);
if (a <= 6) {
for (i = 0; i < a; i++) printf("0 %d\n", i);
return 0;
}
printf("0 0\n1 1\n1 -1\n2 2\n2 0\n2 -2\n");
cnt = 6;
for (i = 3; 1; i++) {
printf("%d %d\n", i, i);
cnt++;
if (cnt == a) break;
printf("%d ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
int a[1005];
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int m, l[1005], r[1005];
cin >> m;
for (int i = 0; i < m; i++) cin >> l[i] >> r[i];
for (int i = 0; i < m; i++) {
if (sum >= l[i] && s... | 3 |
#include <bits/stdc++.h>
using namespace std;
int mat[5005][5005];
int desno[5005][5005];
int niz[10000];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cerr.tie(0), cout.tie(0);
cout.precision(0);
cout << fixed;
int n, m;
cin >> n >> m;
string str;
for (int i = 1; i <= n; i++) {
cin >> st... | 8 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using ll = long long;
using namespace std;
const long double PI = acos(-1);
const long long M = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long mo... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long t[100010], cnt;
long long n;
int main() {
cin >> n;
long long nex = sqrt(n);
for (long long i = 1; i <= nex; i++)
if (n % i == 0) {
t[++cnt] = (n + 2 - i) * n / (2 * i);
t[++cnt] = (n + 2 - (n / i)) * n / (2 * (n / i));
}
sort(t + 1, t ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (__typeof((v).begin()) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, i = 2, p;
cin >> n >> m;
p = m;
while (n >= p) {
n++;
p = i * m;
i++;
}
cout << n;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e2 + 4;
const int MAXP = 5e4;
const int MAXV = MAXN + 4;
const int inf = 1e9;
bool isp[MAXP];
int a[MAXN];
int n;
int c[MAXV][MAXV];
int f[MAXV][MAXV];
int d[MAXV];
int q[MAXV];
int ptr[MAXV];
int qh, qt;
const long long flow_inf = 1e18;
struct Dinic {
s... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long xres[200005], a[200005], n;
vector<long long> d[200005];
bool was[2][200005];
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
;
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
if (i - a[i] >= 1) d[i - a[i]].push_... | 11 |
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
struct info {
int cnt = 0;
int id = 0;
};
int go(){
int n;
cin >> n;
map<int, info> mp;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
mp[x].cnt++, mp[x].id = i;
}
for(auto &p : mp){
... | 0 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
std::vector<int> getBorder(const std::string &str) {
int n = str.size();
std::vector<int> border(n, -1);
for (int i = 1, j = -1; i < n; i++) {
while (j >= 0 && str[i] != str[j + 1]) {
j = bo... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
if (n + m < 5)
cout << 0 << endl;
else if (n == 1 || m == 1) {
long long val = n == 1 ? m : n;
long long md = val % 6;
val = 6 * (val / 6);
... | 14 |
#include <bits/stdc++.h>
struct Edge {
Edge(int a, int b) {
to = a;
cap = b;
}
int to, cap;
};
class Dinic {
public:
Dinic(int n) {
edges.resize(n);
this->n = n;
}
int maxFlow(int src, int sink) {
int ans = 0;
while (bfs(src, sink)) {
int flow;
pt.assign(n, 0);
whi... | 16 |
#include <bits/stdc++.h>
using namespace std;
string s;
struct node {
bool winner, loser;
node* ch[26];
void add(int ind) {
if (ind == s.size()) return;
if (ch[s[ind] - 'a'] == NULL) ch[s[ind] - 'a'] = new node;
ch[s[ind] - 'a']->add(ind + 1);
}
void solve() {
bool C = false, N = false;
fo... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class free>
inline void Min(free&, free);
template <class free>
inline void Max(free&, free);
struct inter {
int l, r, id, id1;
inline void operator^=(const inter x) { Max(l, x.l), Min(r, x.r); }
inline inter operator^(const inter x) { return {max(l, x.l), m... | 24 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <typename T>
inline T sq(T a) {
return a * a;
}
template <typename T1, typename T2>
inline pair<T1, T2> mp(T1 a, T2 b) {
return make_pair(a, b);
}
template <typename T1, typename T2>
inline T1 safeMod(T1 a,... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
int a[maxn];
int main() {
int sum = 0, u;
int ans = 0x3f3f3f3f;
cin >> n;
cin >> a[1];
sum = a[1];
for (int i = 2; i <= n; i++) {
cin >> a[i];
sum += a[i];
a[i] += a[i - 1];
}
for (int i = 1; i <= n; i++) {
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "{" << p.first << "," << p.second << "}";
return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
int to[N][26];
vector<int> a[N];
const int ROOT = 0;
int sz = 1;
void add(... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int b, k;
int main() {
scanf("%d%d", &b, &k);
int o = 0;
for (int i_ = 0; i_ < k; i_++) {
scanf("%d", &a[i_]);
if (a[i_] & 1) o++;
}
if (b & 1) {
if (o & 1)
printf("odd\n");
else
printf("even\n");... | 1 |
#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... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(3e4);
int n, x, y;
string second[N];
bool a[33][33], u[33];
char b[33];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> second[i];
}
bool ok;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
int m = min(... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
cout << n + m - 1 - min(n, m) << " " << min(n, m);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 101;
int l, MOD = 1000000007ll;
struct Mat {
long long v[SIZE][SIZE];
Mat() { memset(v, 0, sizeof(v)); }
void init(long long _v) {
for (int i = (0); i <= (SIZE); i++) v[i][i] = _v;
}
};
Mat operator*(Mat a, Mat b) {
Mat c;
for (int i = (0); ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int t[15], x;
char s[15];
int main() {
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] == '4') {
t[i] = 1;
} else {
t[i] = 2;
}
}
for (int i = n - 1; i >= 0; i--) {
x = x + (1 << (n - i - 1)) * t[i];
}
prin... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long l, r, mid, ans;
int n, c, a[220000], b[220000], i;
long long check(long long mid) {
long long res = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] != 0 && mid / b[i] > c / a[i]) return 1e10;
res += mid * a[i] / b[i];
}
return res;
}
int main() {
scan... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
long long int n, a;
char c;
cin >> n >> a;
vector<char> v(n);
for (long long int i = (0); i < (long long int)(n); ++i) {
cin >> v[i];
}
bool changed = false;
for (long long int i = (... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
int main() {
string s;
cin >> s;
int c1, c2, c3;
c1 = c2 = c3 = 0;
n = ((int)(s).size());
for (int i = 0; i < (n); i++) {
if (s[i] == '?') c3... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long ans[100009] = {0};
bool set_col[100009];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, m;
cin >> n >> m;
for (long long i = 0; i < m; i++) {
long long arr[3];
long long setp = -1;
for (long long j = 0; j < 3; j++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int N = 4111;
int eqk[N][N];
int ck[N][N];
int NumContr(int n) {
eqk[1][1] = 1;
for (int i = 2; i <= n; ++i) {
eqk[i][1] = 1;
eqk[i][i] = 1;
for (int k = 2; k < i; ++k) {
eqk[i][k] = (eqk[i - 1][k - 1] + k * (long long)e... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, g[100100][5], d[100100], v[100100];
bool in[100100];
bool dfs(int a, int b, int k = 1) {
v[k - 1] = a, v[k] = b;
if (k < n) {
in[b] = 1;
for (int i = 0; i < 4; ++i) {
int c = g[b][i];
if (in[c]) continue;
if ((g[a][0] == c || g[a][1] == ... | 12 |
#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 = 3.1415926535897932384626433832795;
const string task = "";
template <class T>
T sqr(T x) {
return x * x;
}
const int nmax = 300300;
int n;... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool vis[1000005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int a[n];
long long int i;
for (i = 0; i <= n - 1; i++) {
cin >> a[i];
a[i] -= 1;
}
long long int count1 = 0;
for (i... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
while (*s != ',') cerr << *s++;
cerr << " = " << x << ',';
_DBG(s + 1, a...);
}
int... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops", \
"omit-frame-pointer", "inline")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC option("arch=native", "no-zero-upper")
using namespace std... | 18 |
#include <bits/stdc++.h>
using namespace std;
double start_moment = 0;
double get_runtime() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime() { cout << fixed << setprecision(5) << get_runtime() << '... | 16 |
#include <bits/stdc++.h>
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
inline long long max(long long x, long long y) { return x > y ? x : y; }
inline long long min(long long x, long long y) { return x > y ? y : x; }
const int maxn = 2e5 + 5;
long long seq[maxn];
int main() {
int n;
sca... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace Elaina {
template <class T>
inline T fab(T x) {
return x < 0 ? -x : x;
}
template <class T>
inline void getmin(T& x, const T rhs) {
x = min(x, rhs);
}
template <class T>
inline void getmax(T& x, const T rhs) {
x = max(x, rhs);
}
template <class T>
inline T r... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n, m, k, a, ans, flag;
int f[N], l[N][N], v[N];
inline int Gf(int x) { return f[x] == x ? x : Gf(f[x]); }
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (scanf("%d", &k); k--;) {
scanf("%d", &a);
flag = 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > adj[1005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int a, b;
scanf("%d %d", &a, &b);
int k = a / 1000;
adj[k].push_back(make_pair(b, i));
}
int cnt = 0;
bool cek = true;
for (int i = 0; i <= 100... | 13 |
#include <bits/stdc++.h>
using namespace std;
int mx = 0;
const int maxn = 5100;
int q[maxn][maxn * 2];
int s[maxn * 2];
int f[maxn];
int g[maxn];
int ta[maxn];
int tb[maxn];
int n;
bool cmp(int a[], int b[], int t) {
ta[0] = t;
for (int i = 0; i <= mx; i++) {
if (a[i] == -1 && b[i] != -1) return false;
if ... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define yes cout << "YES\n";
#define no cout << "NO\n";
typedef long long int ll;
#define revfr(i, s, e) for (ll i = s - 1; i >= e; i--)
const ll mod = 1e9 + 7;
typedef vector<ll> vll;
#define all(x) x.begin(), x.end()
#define... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
void solve() {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int g ... | 10 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int N;
int query_count = 0;
map<tuple<int, int, int>, int> memo_c;
map<tuple<int, int, int>, lint> memo_a;
int clockwise(int i, int j, int k) {
if (memo_c.find(tuple<int, int, int>(i, j, k)) != memo_c.end()) {
return memo_c[tuple<int, int, int>... | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.