solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 7;
const long double pi = 3.14159;
const long long INF = 1e9 + 7;
int n, cnt;
string s;
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
;
srand(time(0));
;
cin >> n;
for (int i = 0; i < 1e5 / 4; i++) {
s += "a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int scnt[256], tcnt[256];
void read(int *cnt) {
string s;
cin >> s;
for (char c : s) {
cnt[c]++;
}
}
int main() {
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
}
ios::sync_with_stdio(false);
read(scnt);
read(tcnt);
int yay = 0,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
t = 1;
while (t--) {
int n;
cin >> n;
map<int, int> mp;
long long int ans = 0;
while (n--) {
string s;
cin >> s;
long long int cur = 0;
... | 8 |
#include <bits/stdc++.h>
const int maxn = 500005;
using namespace std;
int gap, step;
int pap[20][maxn], tmp[maxn], p[maxn], a[maxn], sum[maxn];
int n;
vector<int> ind[2 * maxn];
int all[maxn], one[maxn];
bool saCmp(int x, int y) {
if (pap[step][x] != pap[step][y]) return pap[step][x] < pap[step][y];
x += gap, y +=... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
int T, n, m, k;
int A[maxn], B[maxn];
int check(int x) {
for (int i = 2; i <= n; i++) {
int res = B[i - 1] - x;
if (res + B[i] < A[i]) return -1;
x = A[i] > res ? A[i] - res : 0;
}
return B[n] - x;
}
int main() {
ios::sync_wit... | 16 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
inline void smax(int &x, int y) { x = max(x, y); }
inline void smin(int &x, int y) { x = min(x, y); }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
int main() {
std::ios::sync_with_stdio(false);... | 0 |
#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
ios_base::sync_with_stdio(0);
smain();
return 0;
}
long long n, q, c[100001], v[100001];
void smain() {
for (; cin >> n >> q;) {
for (long long i = 0; i < n; i++) cin >> v[i];
for (long long i = 0; i < n; i++) cin >> c[i], c[i] -= ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int flag = 0, u = 1000000009;
int main() {
long long int n, m, q = 1, a = 1, i;
cin >> n >> m;
q = 1;
for (i = 0; i < m; i++) {
q = (q * 2) % u;
}
for (i = 0; i < n; i++) {
q = (q - 1 + u) % u;
a = (a * q) % u;
}
cout << a;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
struct num {
int a, b;
} arr[300010];
bool ca(struct num a, struct num b) { return (a.a < b.a); }
bool cb(struct num a, struct num b) { return (a.b < b.b); }
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i].a;
arr[i].b = i;
}
sor... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int NSIZ = 1000010;
const int MSIZ = 1000010;
const int inf = 1010580540;
const int mxint = 2147483647;
const long long mxll = 9223372036854775807LL;
const long long prime15 = 1000000000000037LL;
const long long mod = 1000000007LL;
const long long mod9 = 1000000009LL;... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 1E5 + 10;
pair<long long, long long> p[MaxN];
int main() {
long long n, r, avg;
cin >> n >> r >> avg;
long long sum = 0;
for (long long i = 0; i < n; ++i) {
cin >> p[i].second >> p[i].first;
sum += p[i].second;
}
sort(p, p + n);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long int n;
cin >> n;
long int a[n], b[n], suma = 0, sumb = 0;
for (long int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
suma += a[i];
sumb += b[i];
}
vector<pair<long int, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long nb;
vector<long long> tab;
for (int i = 0; i < n; i++) {
cin >> nb;
if (nb % 2 == 0) nb--;
tab.push_back(nb);
}
for (auto i : tab) cout << i << " ";
cout << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
vector<vector<int> > a;
vector<int> f;
int main() {
cin >> n >> m >> q;
a.resize(n + 1);
f.resize(n + 1, 0);
for (int i = 1; i <= n; i++) {
a[i].resize(m + 1);
int s = 0, ans = 0;
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if... | 6 |
#include <bits/stdc++.h>
template <class T1, class T2>
inline bool cmin(T1 &a, const T2 &b) {
return b < a ? (a = b, true) : false;
}
template <class T1, class T2>
inline bool cmax(T1 &a, const T2 &b) {
return a < b ? (a = b, true) : false;
}
template <class Type>
Type read() {
Type a;
bool b;
unsigned char c... | 23 |
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 105;
int n, dp[N][N * N], a[N], b[N];
int main(){
#ifdef FSYo
freopen("1.in", "r", stdin);
#endif
cin >> n;
int S = 0;
memset(dp, -0x3f, sizeof(dp));
dp[0][0] = 0;
for(int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, t;
cin >> n >> s >> t;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
if (s == t) {
cout << 0;
return 0;
}
int st = a[s - 1], ans = 1;
while (st != s) {
if (st == t) {
cout << ans << endl;
return 0;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int w, h, W, H, x1, x2, y1, y2, x = LONG_LONG_MAX,
y = LONG_LONG_MAX;
cin >> W >> H >> x1... | 5 |
#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
sort(s.begin(), s.end());
cout << s;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
int a[101], b[101];
scanf("%d", &n);
scanf("%d", &a[0]);
int max_b = INT_MIN;
int i;
for (i = 1; i < n; i++) {
scanf("%d", &a[i]);
b[i - 1] = a[i] - a[i - 1];
if (b[i - 1] > max_b) {
max_b = b[i - 1];
}
}
int m... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int id[maxn][maxn];
char s[maxn][maxn];
char c[maxn];
int l[maxn], r[maxn], u[maxn], d[maxn];
int n, m, t;
void init() {
int i, j;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
l[id[i][j]] = id[i][j - 1];
r[id[i][j]] = id[i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100111], cnt[11];
vector<int> res[100111];
int main() {
while (scanf("%d", &n) == 1) {
for (int i = (1), _b = (n); i <= _b; i++) res[i].clear();
bool ok = true;
memset(cnt, 0, sizeof cnt);
for (int i = (1), _b = (n); i <= _b; i++) {
scanf("%... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[100001];
int cnt[100001];
long long f(long long val) {
if (val >= 100001) return 0;
if (dp[val] != -1) return dp[val];
return dp[val] = max(f(val + 1), f(val + 2) + val * cnt[val]);
}
int main() {
scanf("%d", &n);
for (int i = 1, x; i <= n; i++... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long countdigit(long long n);
long long power(long long x, long long y);
long long eg(long long a, long long b);
bool isprime(long long n);
vector<long long> aaja(long long n);
vector<long long> soe(long long n);
vector<long long> aaja(long long n) {
long long i, j;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 123;
const int M = 1e5 + 123;
int n, a, mt[M], m, x, y, res, sz;
bool used[M];
vector<int> g[M];
vector<pair<int, int> > f[N];
bool try_kuhn(int v) {
if (used[v]) return 0;
used[v] = 1;
for (int i = 0; i < g[v].size(); i++) {
int x = g[v][i];
if ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
int n, m, q;
vector<int> g[N];
stack<int> s;
int vis[N];
int d[N];
void dfs(int u, int p) {
vis[u] = 1;
s.push(u);
for (auto v : g[u]) {
if (v == p) continue;
i... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string& s, char c) {
vector<string> v;
stringstream ss(s);
string x;
while (getline(ss, x, c)) v.push_back(move(x));
return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<strin... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int K = 13;
int n, k;
struct node {
int mn[K], mx[K], sz;
friend bool operator<(node A, node B) {
for (register int i = (1); i <= (k); ++i)
if (A.mx[i] > B.mn[i]) return 0;
return 1;
}
} t;
set<node> g;
set<node>::iterator it;
void Inc() {
cout <... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long double T;
pair<long double, long double> a[200009];
bool cmp(pair<long double, long double> x, pair<long double, long double> y) {
if (x.second == y.second) {
return x.first < y.first;
} else {
return x.second < y.second;
}
}
long double minm... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 111;
const long long INF = (long long)1e18;
int n, m;
long long d[N], h[N], dist[N];
bool maximize(long long &x, long long y) {
if (x >= y) return false;
x = y;
return true;
}
bool minimize(long long &x, long long y) {
if (x <= y) return fal... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n;
scanf("%d", &n);
multiset<int> s;
long long a = 0;
int x;
while (n--) {
scanf("%d", &x);
s.insert(x);
s.insert(x);
a += x - *s.begin();
s.erase(s.begin());
}
printf("%lld\n", a);
return 0;
}
| 16 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using lld = long double;
using ulli = unsigned long long int;
using pll = pair<lli, lli>;
using ttt = pair<lli, pll>;
using vttt = vector<ttt>;
using vll = vector<pll>;
using vl = vector<lli>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
u... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n;
int c[N], p[N], deg[N], v[N];
int dfs(int x) {
v[x] = 1;
if (v[p[x]])
return c[x];
else
return min(c[x], dfs(p[x]));
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
for (int i = 1; i <= n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int f[10];
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
string a, b;
cin >> a >> b;
for (int i = 0; i < a.size(); i++)
if (a[i] != b[i]) f[a[i] - '0']++;
int x = min(f[4], f[7]), r = 0;
f[4] -= x, f[7] -= x;
r += x;
r += max(f[4], f[7... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
set<int> foo;
int n, q, clk, fst[maxn], out[maxn], pre[maxn], nxt[maxn], cnt_fst[maxn][10],
cnt_out[maxn][10], cnt[10];
char s[maxn];
int main(int argc, char *argv[]) {
scanf("%d%d", &n, &q);
scanf("%s", s + 1);
for (int i = 1; i <= n; +... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
cout << a[i] << ' ';
}
cout << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long num, long long g) {
if (g == 0) return 1;
if (g % 2 == 1)
return (num * power((num * num) % 1000000007, g / 2)) % 1000000007;
return power((num * num) % 1000000007, g / 2);
}
vector<int> vec;
int l;
map<int, int> mp1;
int n;
int a[100005]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int d[100010];
vector<int> v[100010];
void dfs(int cur, int par, int l) {
d[cur] = l;
for (int i = 0; i < v[cur].size(); ++i)
if (v[cur][i] != par) dfs(v[cur][i], cur, l + 1);
}
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n - 1; ++i) {
int x, y... | 14 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const long long ll_inf = 0x3f3f3f3f3f3f3f3f;
using namespace std;
int main() {
std::ios_base::sync_with_stdio(0);
int n, a, b, cnt = 0;
string str;
cin >> n >> a >> b;
cin >> str;
for (int i = 0; i < n; i++) {
if (str[i] == '.') {
if (a > b) {
... | 5 |
#include <bits/stdc++.h>
struct vehicle {
int capacity, index;
};
struct compare {
bool operator()(const vehicle &v1, const vehicle &v2) {
return v1.capacity > v2.capacity;
}
};
std::vector<vehicle> kayak, catamaran, result;
int main() {
int num, volume, type, capacity;
std::cin >> num >> volume;
for (i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i, j, k;
int n, m;
cin >> n >> m;
int a[10000], b[10000], c[10000] = {0};
int q = n / 9, r = n % 9;
int ca = 0, cb = 0;
for (i = 1; i <= q; i++) {
a[ca++] = 9;
b[cb++] = 9;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct event {
int key;
int start, end;
int t;
bool operator<(const event &o) const {
if (end != o.end) {
return end < o.end;
}
return key < o.key;
}
};
bool by_start(event a, event b) {
return make_pair(a.start, -a.key) < make_pair(b.start, -b... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5;
long long a[N];
pair<long long, long long> cnt[N + 2];
long long b[N];
queue<long long> adj[N + 2];
bool cmp(pair<long long, long long> u, pair<long long, long long> v) {
return u.second > v.second;
}
bool cmp1(long long u, long long v) {
if (cn... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int b, g, n;
cin >> b >> g >> n;
int mnb = max(0, n - g), mxb = min(n, b);
cout << abs(mxb - mnb + 1);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
const double Eps = 1e-9;
struct Point {
double x, y;
} st, ed, a[MAXN * 2];
Point operator-(Point &a, Point &b) {
Point res = a;
res.x -= b.x;
res.y -= b.y;
return res;
}
bool operator==(Point &a, Point &b) {
return fabs(a.x - b.x) < Eps &&... | 16 |
#include <bits/stdc++.h>
int n, q;
struct a {
int l, r, x;
} a[10007];
int x[10007];
int qdiff(const void *p, const void *q) {
return ((struct a *)p)->l - ((struct a *)q)->l;
}
void cat() {
int i, j, k, l;
qsort(a, q, sizeof(a[0]), qdiff);
for (i = 0; i <= n; i++) {
x[i] = -1;
}
x[0] = n;
for (i = 0... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16000000")
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 1000010;
char s[maxn];
int corr[maxn] = {};
int go(int fr, int to) {
if (fr == to) {
if (s[fr] == '0')
return 1;
else if (s... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int add(int a, int b) { return ((a += b) >= mod ? a - mod : a); }
int sub(int a, int b) { return ((a -= b) < 0 ? a + mod : a); }
int mul(int a, int b) { return (long long)a * b % mod; }
const int MAXN = 2004;
int c[MAXN][MAXN], p[MAXN], n, f[MAXN];
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mo = 998244353;
const long long g = 3;
const int N = 500000;
int n, ax, bx, rev[N + 10];
long long aa[N + 10], bb[N + 10], c[N + 10], fac[N + 10], inv[N + 10];
long long mul(long long x, long long y) {
long long z = 1;
while (y) {
if (y & 1) z = z * ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
const int inf = 1e9 + 7;
const double eps = 1e-12;
long long n, m, d, x, col[maxn], last;
set<pair<long long, long long> > a;
bool used[maxn];
bool cmp(pair<int, int> a, long long b) { return a.first < b; }
int main() {
ios_base::sync_with_stdi... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long a, b;
} a[100005];
bool operator<(const node &b, const node &c) { return b.b + c.a < b.a + c.b; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].a >> a[i].b;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
long long a, b, c;
for (int i = 0; i < q; i++) {
cin >> a >> b >> c;
long long x = a + b + c;
long long y = (x / 2);
cout << y << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int X = 100010;
vector<int> e[X], s[X];
void make() {
for (int i = 2; i < X; i++)
for (int j = i; j < X; j += i) s[j].push_back(i);
}
int main() {
make();
int n, x, y, i, j, cnt;
scanf("%d", &n);
for (i = 0; i < X; i++) e[i].push_back(0);
for (i = 1; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 510000;
int n, k;
char s1[N], s2[N];
int main() {
scanf("%d%d", &n, &k);
scanf("%s%s", s1 + 1, s2 + 1);
long long ans = 0, now = 0, last = 0;
for (int i = 1; i <= n; i++) {
now = (now << 1) + s2[i] - s1[i];
long long tmp = min((long long)k, now... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
clock_t time_p = clock();
void rtime() {
time_p = clock() - time_p;
cout << "\nTime Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC
<< "s\n";
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
char s[maxn], t[maxn], l[maxn];
vector<int> ans;
int cnt[26];
int n;
void shl(int k) {
for (int i = k, j = n; i; i--, j--) l[j] = s[i];
for (int i = n, j = 1; i > k; i--, j++) l[j] = s[i];
swap(s, l);
}
int main() {
scanf("%d", &n);
sca... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long n, s, t, head[700], nxt[1000000], len[1000000], to[1000000], cnt = -1;
long long cur[1000000];
void add(long long a, long long b, long long l, bool _rev = false) {
nxt[++cnt] = head[a];
to[cnt] = b;
len[cnt] = l;
head[a] = cnt;
if (!_rev) add(b, a, 0, tr... | 21 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
ll ans = 0;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
int l = m + 1, r = n - m;
for (int b = l; b <= r; b++) {
int bb = n + 1 - b;
if (bb < b) continue;
int cur = 0, lim = 3 * b * bb - 1;
int lc = l + bb... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long mem[100100];
long long nn = 100000;
void Set(long long n, long long r) {
for (long long i = 1; i <= r; i++) mem[i]--, mem[n--]++;
return;
}
void Set2(long long n, long long r) {
for (long long i = 1; i <= r; i++) mem[i]++, mem[n--]--;
return;
}
double calc... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
vector<pair<int, int> > v;
int minDiff = 1000000;
for (int i = 0; i < k; i++) {
int max = arr[0], min = arr[0];
int maxI = 0, minI = 0;
for (int j = 0; j <... | 6 |
#include <bits/stdc++.h>
char a[100][2][11];
int main() {
int n, i;
scanf("%d", &n);
int c = 0;
char s1[11], s2[11];
bool has = false;
for (int i = 0; i < n; i++) {
scanf("%s %s", s1, s2);
has = false;
for (int j = 0; j < c; j++) {
if (!strcmp(s1, a[j][0]) && !strcmp(s2, a[j][1])) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int cnt[N];
int main() {
int i = 0, j = 0, cs = 0, in;
int k;
cin >> k;
string s;
cin >> s;
if (k == 0) {
vector<int> sum(s.size());
sum[0] = s[0] - 48;
for (int i = 1; i < s.size(); i++) sum[i] = sum[i - 1] + s[i] - 48;
l... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], m;
char s[1000005];
void work() {
int i, j, x = 0, ans = 0;
m = strlen(s), n = 0;
i = 0;
while (i < m && s[i] == 'F') ++i;
for (; i < m; ++i)
if (s[i] == 'F')
a[n++] = x;
else
++x;
if (n == m || n == 0) {
puts("0");
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int flag[200000 + 2];
int main() {
long long int n, m, w, l;
cin >> n >> m >> w;
l = m;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long int x1 = 1, x2 = 1e16, s = 1, ans = 0;
while (x1 <= x2) {
s = 1;
long long int t = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3], k;
for (int i = (0); i < (int)(3); i++) scanf("%d", a + i);
sort(a, a + 3);
scanf("%d", &k);
k += 3;
long long ans = 0;
do {
for (int u = (1); u <= (int)(k - 2); u++) {
if (u > a[0]) break;
int r = k - u;
int b = mi... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int inf = 1000000000;
int n, k, l, r, mid;
int a[N], f[N], dp[N];
void add(int x, int w) {
for (; x; x -= x & -x) f[x] += w;
}
int query(int x) {
if (x <= 0) return 1;
int s = 0;
for (; x <= n; x += x & -x) s += f[x];
return s;
}
bool c... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char cad[1000005];
int aux, x = 0, y = 0, dif;
gets(cad);
aux = strlen(cad);
for (int i = 0; i < aux; i++) {
if (cad[i] == 'x') {
x++;
} else
y++;
}
dif = abs(x - y);
if (x > y) {
for (int i = 0; i < dif; i++) printf("x")... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> MP;
int ans[100005];
string str[100005];
int cnt[8];
int n;
bool ret(string str, int x) {
str = str.substr(0, str.find(","));
if (MP[str] == x) return 1;
return 0;
}
bool solve() {
for (int i = 1; i <= 6; i++) cin >> cnt[i];
cin >> n;
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
const int INF = 0x3f3f3f3f;
struct node {
int u, v, cap, former_cap, nxt;
} edge[N * 2], e[N * 2];
int head[N], mcnt = 1;
void add_edge(int u, int v, int cap) {
mcnt++;
edge[mcnt].u = u;
edge[mcnt].v = v;
edge[mcnt].former_cap = cap;
ed... | 24 |
#include <bits/stdc++.h>
using namespace std;
template <class IT>
inline void cmax(IT &a, IT b) {
if (a < b) a = b;
}
template <class IT>
inline void cmin(IT &a, IT b) {
if (b < a) a = b;
}
const int N = 2005, M = 4005, inf = -2147483647;
vector<int> DP[M];
struct candidate {
int a, s;
} A[N];
int C[M];
inline vo... | 20 |
#include <bits/stdc++.h>
const long long int maxn = 1e5 + 2;
using namespace std;
bool isPrime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i++) {
if (n % i == 0 || n % (i + 2) == 0) return false;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int l, r;
long long int sum, s0, s1;
void reset(int l = 0, int r = 0, long long int sum = 0, long long int s0 = 0,
long long int s1 = 0) {
this->l = l;
this->r = r;
this->sum = sum;
this->s0 = s0;
this->s1 = s1;
}
};
ve... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005];
char buf[12];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", buf);
if (buf[0] == '?')
a[i] = (1 << 30);
else
a[i] = atoi(buf);
}
for (int i = 0; i < m; i++) {
int prev = -(1 << 30), s =... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200000, maxA = maxN * 10, mod = 1000000007;
int in[maxN], apd[maxA], T[maxA], P[maxA], multipleM[maxA], dcd[maxN];
inline void mult_mod(int& a, int b) { a = 1LL * a * b % mod; }
void updt(int p, int k) {
if (k < T[p]) return;
if (k == T[p]) {
multip... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> s >> n;
stack<char> st;
if (s.size() <= n && s[0] != '0') {
cout << s.size() - 1 << endl;
return 0;
}
if (s[0] == '0') {
cout << 0 << endl;
return 0;
}
int c = 0;
bool x = 0;
for (int i = s.size() - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 220000;
int id[N];
map<int, int> H;
map<int, pair<long long, long long> > ans;
char str[N * 10];
long long t[N], x[N], y[N];
int main() {
ios::sync_with_stdio(0);
int N, L;
cin >> N >> L;
for (int i = 1; i <= N; i++) {
cin >> t[i] >> x[i] >> y[i];
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
const int maxlevel = 600;
vector<double> fi(maxlevel + 1, 0.0), oldfi(maxlevel + 1);
for (int i = 1; i <= n; i++) {
fi.swap(oldfi);
for (int l = 1; l <= maxlevel; l++) {
fi[l] = 0.0;
fi[l] += (k - ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, m, q, a[maxn], b[maxn], total = 1e6;
int st[maxn << 2], lazy[maxn << 2];
void pushDown(int rt) {
if (lazy[rt]) {
st[(rt << 1)] += lazy[rt];
st[(rt << 1 | 1)] += lazy[rt];
lazy[(rt << 1)] += lazy[rt];
lazy[(rt << 1 | 1)] += ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e3 + 10;
vector<int> vp[N];
int belong[N];
int flag[N];
int s[N];
int top;
string str;
string ans1, ans2;
bool dfs(int x) {
if (flag[x ^ 1]) return false;
if (flag[x]) return true;
flag[x] = 1;
s[top++] = x;
for (auto ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MAXN = 2e5 + 100;
const long long MOD = 1000000007;
struct ele {
long long pos, ty;
bool operator<(const ele &a) const { return pos < a.pos; }
} ax[MAXN];
int main(int argc, char const *argv[]) {
long long a[2], b[2], c[2];
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int IT_MAX = 1 << 18;
const long long MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 3234567890123456789ll;
const double PI = acos(-1);
const double EPS = 1e-8;
int n;
long long k;
long long numbers[200007], numbersNext[200007];
struct matr {
long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9;
const long long INFL = (long long)9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const long long MAXLL = ((~0) ^ ((long long)1 << 63));
template <class T>
inline T pow2(T a) {
return a * a;
}
template <class T>
inline bool mineq(T& a, T b) {
retu... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int maxi;
map<pair<long long int, long long int>, long long int> dp;
long long int recur(long long int a, long long int b) {
if (dp.find(make_pair(a, b)) != dp.end()) return dp[make_pair(a, b)];
long long int sum = 1;
for (long long int i = 0; i < ((long lon... | 12 |
#include <bits/stdc++.h>
inline long long read() {
long long x = 0;
char c = getchar(), f = 1;
for (; c < '0' || '9' < c; c = getchar())
if (c == '-') f = -1;
for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * f;
}
inline void write(long long x) {
static char buf[20];
int len... | 11 |
#include <bits/stdc++.h>
using namespace std;
int printbinary(const unsigned int val) {
int a[4], j = 0;
for (int i = 3; i >= 0; i--) {
if (val & (1 << i)) {
a[j] = 1;
j++;
} else {
a[j] = 0;
j++;
}
}
return a[3] * 2 * 2 * 2 + a[2] * 2 * 2 + a[1] * 2 + a[0];
}
int main() {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void add(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
if (x < 0) x += MOD;
}
const int N = 210;
struct AHO {
struct vertex {
int next[20];
int p;
int pch;
int link;
int go[20];
int res;
int lazy;
};
vertex... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, c, v, l, ans;
scanf("%d%d%d", &c, &v, &l);
if (c * l % v == 0)
ans = c * l / v;
else
ans = c * l / v + 1;
printf("%d\n", ans - l);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int linf = (long long)9e18;
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1},
dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};
unordered_map<long long, long long> dp;
long long n, k, a, b;
long long solve(long long n) {
long long ans = 0;
while (n > 1) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<pair<int, pair<int, int> > > p;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
p.push_back(make_pair(a, make_pair(b, i + 1)));
}
sort(p.begin(), p.end());
int final = 0;
for (int i = 0; i < n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005, INF = 1e9;
int n, s[MAXN], c[MAXN];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", s + i);
}
for (int i = 0; i < n; ++i) {
scanf("%d", c + i);
}
int ans = INF;
for (int i = 1; i < n - 1; ++i) {
int mi... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxl = 3e5 + 10;
int n, m, cnt, tot, cas;
long long ans;
long long a, b, c, d;
bool vis[maxl];
char s[maxl];
inline void prework() { scanf("%lld%lld%lld%lld", &a, &b, &c, &d); }
inline long long calc(long long mid) {
long long ret = mid * a, ed = (mid - 1) * d, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-2, -2, 2, 2};
int dy[] = {2, -2, -2, 2};
long long toInt(string s) {
stringstream aa(s);
long long k;
aa >> k;
return k;
}
string toString(long long t) {
stringstream y;
y << t;
return y.str();
}
int gcd(int a, int b) {
if (!b)
return a;
e... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)1e7 + 7;
char c[105][105];
int main() {
int n, m, x, y;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
}
}
int mni, mnj, mxi, mxj, ans = 0;
mni ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long kiran_bhanushali[29][7][20];
void init() {
for (long long i = 0; i < 29; i++) {
kiran_bhanushali[i][0][0] = rand() % 1000;
}
}
long long vis[120], z;
void dfs(long long i, vector<vector<long long>>& g) {
if (vis[i]) return;
z++;
vis[i] = 1;
for (lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int mod = 1000000007;
int main() {
long long int t, n, m, i, j, k = -1, l, x, y, z;
scanf("%lld %lld", &n, &m);
char mat[n][m + 5];
for (i = 0; i < n; ++i) scanf("%s", mat[i]);
for (i = 0; i < n; ++i) {
for (j = 1; j <= m;... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
long long int res = 1, y = a;
while (n > 0) {
if (n & 1) res = (res * y) % temp;
y = (y * y) % temp;
n /= 2;
}
return res % temp;
}
long long int nC2(long long int n) { return (... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimization("O3")
using namespace std;
const long long inf = INT_MAX;
const long long inf2 = 1e18;
const long long minf = -1 * 1e9;
const long long MAX = 1e5 + 5;
const long long MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double EPS = 1e-9;
void init(int precision) {
ios_... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n;
vector<int> g[2];
int d[2][N], deg[2][N];
int dfs(int k, int i, int v) {
int& ret = d[k][i];
if (~ret) return ret;
ret = v;
if (v == 0) {
for (i... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct minion {
int a, b, id;
};
bool sortb(minion x, minion y) { return x.b < y.b; }
int n, k;
minion ar[100];
int dp[100][100];
void calc() {
sort(ar, ar + n, sortb);
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= k; ++j) dp[i][j] = -1e9;
dp[0][0] = ar[0].b... | 17 |
#include <bits/stdc++.h>
using namespace std;
char arr[4][105][105];
int w[2][4];
int p[4];
int ans;
int n;
int calc(int id, int v) {
int ret = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (arr[id][i][j] != v + '0') {
++ret;
}
v ^= 1;
}
}
return ret;
}
void... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.