solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, val[MAXN];
vector<int> adj[MAXN];
bool root[MAXN];
set<int> st;
void dfs(int v, int mx = -1, int mn = 2e9) {
if (mx < val[v] && mn > val[v]) st.insert(val[v]);
if (adj[v][0] >= 0) dfs(adj[v][0], mx, min(mn, val[v]));
if (adj[v][1] >= ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
long long b[n - 1], c[n - 1];
for (int i = 0; i < n - 1; ++i) cin >> b[i];
for (int i = 0; i < n - 1; ++i) {
cin >> c[i];
}
bool flag = true;
for (int i = 0; flag && i < n - ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const int N = 100000 + 7;
const int M = 30;
const int multipleTest = 0;
const double pi = acos(-1);
int n, m;
int light[N];
int k[N];
int cnt[N];
void solve() {
cin >> n >> m;
for (int i = (0), _b = (n); i... | 7 |
#include <bits/stdc++.h>
using namespace std;
void qmax(int &x, int y) {
if (x < y) x = y;
}
void qmin(int &x, int y) {
if (x > y) x = y;
}
inline long long read() {
char s;
long long k = 0, base = 1;
while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
;
if (s == EOF) exit(0);
if (s == '-') ba... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
static void call(string::iterator it, string::iterator ed) {}
template <typename T, typename... aT>
static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
string b;
for (; *it != ','; ++it)
if (*it != ' ') b += *i... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > hints;
int cardToInt(int color, int rank) { return color * 5 + rank % 5; }
bool checkMask(unsigned int mask, vector<int> hand, vector<bool> haveCard) {
bool state[hand.size()][25];
for (int i = 0; i < hand.size(); i++) {
for (int j = 0; j < 25; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int N = 2e5 + 5;
const long long INF = 1e18;
void solve() {
int n;
cin >> n;
vector<int> a(n);
long long sum = 0;
multiset<int, greater<int>> second;
for (int i = (0); i < (n); ++i) {
cin >> a[i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, m;
char a[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
a[0] = 'a', a[n + 1] = 'a';
int cnt = 0, ans = 0;
for (int i = 1; i <= n; i++)... | 8 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.tie(0);
int n;
cin >> n;
cin >> s;
int sum = 0;
int i = 1;
while (1) {
sum += i;
if (sum > s.size()) break;
cout << s[sum - 1];
i++;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300100, M = 500100;
int n, m, ix[M], iy[M], iw[M], sjc, fa[20][N], indfn[N], outdfn[N], tag[M],
dep[N], pre[N];
vector<pair<int, int>> G[N];
void dfs(int x, int las) {
fa[0][x] = las;
indfn[x] = ++sjc;
dep[x] = dep[las] + 1;
for (int i = 1; i < 20;... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int xa, ya, xb, yb, xc, yc;
cin >> xa >> ya >> xb >> yb >> xc >> yc;
int d, m;
d = 0;
if (d < xa) {
d = xa;
m = 0;
}
if (d < ya) {
d = ya;
m = 1;
}
if (d < xb) {
d = xb;
m = 2;
}
if (d < yb) {
d = yb;
m = 3;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double o, k, t, l, p, q;
cin >> l >> p >> q;
if (p > q) {
k = p;
o = q;
t = k / o;
t = t + 1;
cout << l - (l / t);
} else {
k = q;
o = p;
t = k / o;
t = t + 1;
cout << l / t << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c;
cin >> r >> c;
bool ta[r][c];
char a;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> a;
if (a == 'S') {
ta[i][j] = false;
} else {
ta[i][j] = true;
}
}
}
int cn = 0, cm ... | 0 |
#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int calc(int a, int n, int p) {
int nn = (INT)a * n / p;
if (nn == 0) return max(a, p - a * n);
if (p / a * a - a > (INT)a * n % p) nn--;
return calc(a - p % a, nn, a);
}
int solve() {
int a, n, p, h;
scanf("%d %d %d %d", &a, &n, &p, &h);
... | 22 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, k, i;
cin >> n >> k;
vector<long long int> a(n * k);
for (i = 0; i < (n * k); i++) cin >> a[i];
long long int sum = 0, cnt = 0;
for (i = n * k - 1; i >= 0 & k > 0; i--) {
if (cnt == n / 2) {
sum += a[i];
cnt = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k, x, y, s, ct;
cin >> n;
vector<pair<int, int>> a(n);
for (i = 0; i < n; i++) {
cin >> x >> y;
a[i] = {y, x};
}
sort(a.rbegin(), a.rend());
ct = 1;
s = 0;
for (i = 0; (i < n) &... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace debug {
void __(short x) { cout << x; }
void __(unsigned x) { cout << x; }
void __(int x) { cout << x; }
void __(long long x) { cout << x; }
void __(unsigned long long x) { cout << x; }
void __(double x) { cout << x; }
void __(long double x) { cout << x; }
void __... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
cin >> x;
}
template <class H, class... T>
void read(H& h, T&... t) {
read(h);
read(t...);
}
template <class A>
void read(vector<A>& x) {
for (auto& a : x) read(a);
}
template <class H>
void print(vector<H>& x) {
for (auto& a :... | 5 |
#include <bits/stdc++.h>
int main() {
int x, count = 0, j = 1;
scanf("%d", &x);
while (x > 0) {
j = 1;
while (j <= x) j <<= 1;
j >>= 1;
x -= j;
count++;
}
printf("%d", count);
return 0;
}
| 2 |
#include <bits/stdc++.h>
int main() {
int count = 0, i, j, a[2010], t, n;
scanf("%d", &n);
for (i = 0; i < 2 * (n - 1); i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < 2 * (n - 1); i++) {
int flag_2 = 0, flag_1 = 0;
for (j = i + 1; j < 2 * (n - 1); j++) {
if (a[i] == a[j] && a[j] != 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, a[N], d[N], s;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1, m = 0; i <= n; i++) m = min(m + 1, a[i]), d[i] = m;
for (int i = n, m = 0; i; i--) m = min(m + 1, a[i]), d[i] = min(d[i], m);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 1;
const int mod = 1e9 + 7;
ll jc[maxn], ni[maxn];
ll pn[maxn], pm[maxn];
ll qp(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
ret... | 16 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<long long> a;
for (long long i = 0; i < n; ++i) {
long long o;
cin >> o;
a.emplace_back(o);
};
long long m;
cin >> m;
vector<pair<long long, long long>> b;
for (long long i = 0; i < n; ++i) b.emplace... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int M = 300005;
vector<pair<int, int> > Graph[N];
int visited[N];
pair<int, int> edges[M];
int artifact[M];
int isBridge[M];
int isArticulationPoint[N];
int disc[N];
int low[N];
int ti = 0;
void dfs(int u, int p, int pi) {
ti++;
disc[u] = ti;... | 15 |
#include <bits/stdc++.h>
#define endl '\n'
#define lli long long int
#define ld long double
#define forn(i,n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define fastIO(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define SZ(s) int(s.size())
using namespace std;
typedef vector<lli> V... | 14 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
long long res;
string s;
vector<int> sa;
pair<int, int> cmp[100007];
int pos[100007];
int nast[100007];
int lcp[100007];
int size[100007];
int load[2 * (1 << 17)];
void clear() {
memset(lcp, 0, sizeof lcp);
memset(size, 0, sizeof size);
memset(nast, 0, sizeo... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int v[110];
int used[110];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
used[v[i]] = 1;
}
int pair[2] = {0};
int n_zero = 0;
for (int i = 1; i <= n; i++) {
if (!used[i]) {
pair[i % 2]++... | 10 |
#include <bits/stdc++.h>
int main() {
long long r;
while (scanf("%lld", &r) != EOF) {
if (r & 1 && r != 1 && r != 3) {
printf("1 %lld\n", (r - 3) >> 1);
} else {
printf("NO\n");
}
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long V[101][101];
int main() {
long long a, b, c, d, T;
cin >> T;
long long sum = 0;
while (T--) {
cin >> a >> b >> c >> d;
for (int i = a; i <= c; i++) {
for (int j = b; j <= d; j++) {
sum++;
}
}
}
cout << sum;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int D[20][20];
int n, m;
bool rec(long long a00, long long a01, long long a10, long long a11,
long long zeros, long long ones, string& soFar, string& res) {
if (a00 == 0 && a11 == 0 && a10 == 0 && a01 == 0) {
if (zeros > 0)
res = soFar + "0";
else
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
if (n == 1)
cout << 1;
else
cout << (n + 1) / 2;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long c;
int n1, n2, n3;
node(long long c = 0, int n1 = 0, int n2 = 0, int n3 = 0)
: c(c), n1(n1), n2(n2), n3(n3) {}
} dp[300005];
int N, M;
int v[4][300005];
int cnt[4];
void update(node &a, node b) {
if (a.c < b.c) a = b;
}
int main() {
c... | 15 |
#include <bits/stdc++.h>
int N, K, b[10005];
void dfs(int t, int s, int x, int k) {
if (!N) return;
if (t > 3) {
if (t == 4 && (s = std::abs(s - K)) < 1e4 && b[s] != k)
printf("%04d%04d\n", k, s), b[s] = k, N--;
return;
}
dfs(t + 1, x % 10 + s, x / 10, k), dfs(t + 1, x % 10 * s, x / 10, k),
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long MOD = 1e9 + 7;
long long mult(long long x, long long y) {
return ((x % MOD) * (y % MOD)) % MOD;
}
long long sub(long long x, long long y) { return (x - y + MOD) % MOD; }
long long calc(long long x) {
long long a = x;
long long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10, oo = ~0U >> 5;
int n, m;
int ans, resi, resj, resk;
int cnt[maxn];
int main() {
int i, j, k;
scanf("%d %d", &n, &m);
for (i = 1; i <= n; ++i) scanf("%d", &j), cnt[j]++;
ans = oo;
for (i = m / (cnt[3] + cnt[4] + cnt[5]); i >= 0; --i)
for (j... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
template <typename T = int>
inline T nxt() {
char c = nc();
T x = 0;
int f = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long d[1000005];
int main() {
int nn, m;
scanf("%d%d", &nn, &m);
long long n = nn;
while (m--) {
int a, b;
scanf("%d%d", &a, &b);
d[a]++;
d[b]++;
}
long long ans = n * (n - 1) * (n - 2) / 6;
long long tmp = 0;
for (int i = 1; i <= n; i++... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
map<int, int> m;
for (int i = 0; i < n; i++) {
int in;
cin >> in;
m[in]++;
}
map<int, int>::iterator it;
int max = 0;
for (it = m.begin(); it != m.end(); it++) {
if (it->second > max) {
max = it->se... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[5][105];
int i, j, n, m, stu = 1;
inline void print(int x) {
if (x) cout << x << ' ';
}
int main() {
cin >> n >> m;
bool flag = 0;
for (i = 0; i < n; i++) {
if (m == stu) {
a[0][i] = stu;
flag = 1;
break;
}
if (m - stu == 1) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int n, a, b, k;
cin >> n >> a >> b >> k;
long long int* arr = new long long int[n];
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
for (long long int i = 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n;
cin >> n;
vector<pair<int, int> > arr(n);
for (i = 0; i < n; i++) {
cin >> arr[i].first;
arr[i].second = i;
}
sort(arr.begin(), arr.end());
if (n % 2 == 0) {
for (i = 0; i < n; i++) {
if (arr[i].first == 0)
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int m = n / 2 + 1;
printf("%d\n", m);
int i = 1, j = 1;
for (int t = 0; t < n; t++) {
printf("%d %d\n", i, j);
if (i != m)
i++;
else
j++;
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vx, vy;
vx = vy = vector<int>(n);
for (int i = 0; i < n; i++) cin >> vx[i] >> vy[i];
map<int, int> mx, my;
map<pair<int, int>, int> m;
for (int i = 0; i < n; i++) {
mx[vx[i]]++;
my[vy[i]]++;
m[pair<int, i... | 6 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long n, a, t, i, kolvo0, kolvo1, j;
int main() {
cin >> t;
while (t--) {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
if (a == 0) kolvo0++;
if (a == 1) kolvo1++;
}
j = pow(2, kolvo0) * kolvo1;
kolvo0 = 0;
kolvo1 =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, f, k, r, j = 0, count = 0, x1 = 0;
bool flag = true;
scanf("%d %d %d %d", &a, &b, &f, &k);
r = b;
while (j < k) {
if (x1 == 0) {
if (r < f) {
cout << "-1";
return 0;
} else {
x1 = f;
r = r - f;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10, inf = 1e18, M = 15;
long long arr[N], n, k;
void solve() {
long long b[N], t = 1;
;
while (1379 / 6 / 14) {
b[0] = arr[0];
for (long long i = 1; i < n; i++) {
b[i] = b[i - 1] + arr[i];
if (b[i] >= k) {
cout << ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int lim = 1000000;
int mod = 1000000000 + 7;
int inf = 1000000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
string p;
cin >> p;
vector<int> y(m + 2);
y[m + 1] = -1;
for (int i = 1; i <= m; i++... | 11 |
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
#pragma GCC optimize("fast-math")
using namespace std;
const long long mod = 1e9 + 7, mod2 = 998244353;
const long double eps = 1e-6;
const long long inf = 1e18;
const int base = 1e9;
const long double PI = 3.1415926;
vo... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else
return false;
}
template <class T>
bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else
return false;
}
bool g[99][99];
int n, p;
int main() {
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float h, l;
float f;
cin >> h >> l;
f = abs(l * l - h * h) / (2 * h);
printf("%.8f", f);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
;
}
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, cons... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long N = (int)1e5 + 7, inf = 1000000007LL;
int n, m, k, ans[N], vis[N], cnt, a[N], b[N];
int main() {
ios_base ::sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
sort(a + 1, a + ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h;
cin >> n >> h;
int ma = -1051;
vector<int> st, end;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
st.push_back(x);
end.push_back(y);
}
int i = 0, j = 0;
int he = h;
int curr = end[0] - st[0];
while (i < st.... | 9 |
#include <bits/stdc++.h>
using namespace std;
string a, b, c;
string dp[111][111][111];
int f[111];
void check(string &a, string b) {
if (a.size() < b.size()) a = b;
}
int main() {
cin >> a >> b >> c;
int l1 = a.size(), l2 = b.size(), l3 = c.size();
int j = 0, i, k;
for (i = 1; i < l3; i++) {
while (j > 0... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 2;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
srand(time(NULL));
int N;
long long sa = 0, sb = 0;
cin >> N;
vector<int> A(N), B(N), ind(N);
iota(ind.begin(), ind.end(), 0);
for (int i = 0; i < N; ++i) {
cin >> A[i];
... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dp[101][101];
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int m;
cin >> m;
int b[m];
for (int i = 0; i < m; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55, inf = 1e9;
int n, s, m, cnt, head[N], sz[N], f[N][N][N][N], w[N][N], ans, rd[N];
struct edge {
int to, nxt;
} e[N << 1];
void adde(int x, int y) {
e[++cnt].to = y;
e[cnt].nxt = head[x];
head[x] = cnt;
}
void dfs(int u, int par) {
for (int i = hea... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100010;
int n, h[maxN], fw[maxN], bw[maxN], ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
fw[i] = 1;
bw[i] = 1;
}
for (int i = 1; i < n; i++) {
fw[i] = min(fw[i - 1] + 1, h[i]);
}
for (int i = n - 2; i >=... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T pmax(T a, T b) {
return max(a, b);
}
const long long int mod = 1e9 + 7;
const long long int Maa = 3e5;
vector<long long int> edge[Maa];
long long int n, m, l[Maa], r[Maa], q[Maa], A[Maa], p[Maa], c[Maa];
int main() {
cin >> n >> m;
for (int i = 0;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e7 + 10;
bitset<sz> pri;
int ef[sz], prq[sz], pref[sz], mi[sz];
int main() {
int n;
cin >> n;
pref[1] = 0;
for (int a = 2; a <= n; a++) {
ef[a] = 1, pri[a] = 1, mi[a] = -1;
}
for (int a = 2; a <= n; a++) {
if (pri[a]) {
ef[a] = a - ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c, fir, sec = 0, x, y;
cin >> n;
int a[n];
cin >> c >> a[0];
fir = a[0];
x = c;
for (int i = 1; i < n; i++) {
cin >> c;
cin >> a[i];
if (a[i] < fir) fir = a[i];
if (c > x) x = c;
}
cin >> m;
int arr[m];
cin >> arr... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n;
int boy[n], girl[n];
memset(girl, -1, sizeof(girl));
memset(boy, -1, sizeof(boy));
for (int i = 0; i < n; i++) {
cin >> m;
int a[m];
for (int j = 0; j < m; j++... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1073741824;
int main() {
long long k;
string a;
cin >> a >> k;
long long n = a.size();
int j = 0;
while (k > 0 && j < n) {
int idxMax = j;
for (int i = j; i <= min(k + j, n - 1); i++) {
if (a[idxMax] < a[i]) {
idxMax = i;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1LL << 60;
const int maxn = 1 << 23;
bool vis[maxn + 5], have[maxn + 5];
int a[maxn + 5];
int All, n, m;
void Dfs(int x) {
if (vis[x]) return;
vis[x] = true;
int y = x ^ All;
for (int i = 0; i <= n; i++) {
if (x & (... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e5 + 107;
const double pi = acos(-1.0);
const double eps = 0.0000000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
t... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 999999999999999999;
const long long maxn = 1e5 + 7;
const int mod = 1e9 + 7;
void process() {
long long res = 0;
long long n;
cin >> n;
vector<long long> a(n + 1, 0);
map<long long, long long> mp;
for (int i = 1; i <= n; ++i) cin >> a[i];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXH = 31;
const int MOD = 1000000009;
int dp[2][2][MAXH][MAXH][MAXH];
int main() {
int n, h;
scanf("%d%d", &n, &h);
int cur = 0, pre = 1;
dp[cur][1][1][1][1] = 4;
int i, o, a, b, c, aa, bb, cc;
for (i = 2; i <= n; ++i) {
swap(cur, pre);
fill(d... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double population;
cin >> n >> population;
double x, y, r;
pair<double, double> All[n];
for (int i = 0; i < n; i++) {
cin >> x >> y;
All[i].first = sqrt(pow(x, 2) + pow(y, 2));
cin >> All[i].second;
}
sort(All, All + n);
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 1; i < n; i++) {
if (a[i] != a[i - 1]) {
cout << 1 << endl;
return;
}
}
cout << n << endl;
return;
}
int main() {
io... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
long long c[N], t[N], ne[N];
long long d[N], dt[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &c[i]);
d[i] = c[i] - c[i - 1];
}
for (int i = 1; i <=... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const N = 200 * 1000 + 16;
int n, m, k;
int c[N];
int a[3][N];
ll b[3][N];
int cnt[3];
int mark[N];
struct treap {
struct node {
int x;
int s = 1;
ll sum = 0;
node* l = 0;
node* r = 0;
node(int v) {
x = v;
sum ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
inline char gc() {
return getchar();
static const int maxs = 1 << 16;
static char buf[maxs], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, maxs, stdin), p1 == p2)
? EOF
: *p1++;
}
inline lon... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
set<int> a;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.insert(x);
}
int ans1 = *a.rbegin();
if (ans1 % 2 == 0 && ans1 % 3 == 0 && ans1 % 5 == 0)
if (... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, k, N;
int x[100], y[100], sg[100];
int re[77][77];
long long d[77][77], nd[77][77];
char s[10];
bool isOK(int from, int to, int i, int j) {
for (int pos = from; pos <= to; ++pos)
if (re[pos][i] == 0 || re[pos][i] == 1 || re[pos][i] == 3) {
return false;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include <bits/stdc++.h>
using namespace std;
namespace kotespace {
template <class T>
class duplet {
private:
public:
T x, y;
duplet(){};
duplet(T a, T b) : x(a), y(b){};
bool operator<(const duplet P) const {
return (x < P.x || (x == P.x && y < P.y));
}
bool operator>(const duplet P) const {
ret... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int maxn = 2e5 + 5, mod = 998244353;
int n;
vector<int> g[maxn];
int de[maxn];
const int rt = 1;
int vis[maxn], fac[maxn];
int dp[maxn];
int dfs(int cur, int fat = -1) {
if (fat != -1 && g[cur].size() == 1) {
dp[cur] = 1;
return dp[c... | 11 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
int n, k;
std::cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
int lastminus = -1;
std::vector<int> diff;
int minusdays = 0;
for (int i = 0; i < n; i++) {
if (a[i] < 0) {
minusdays++;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0, x; i < n; i++) scanf("%d", &x), a[i] += x, b[i] -= x;
for (int i = 0, x; i < n; i++) scanf("%d", &x), a[i] -= x, b[i] += x;
long long Ans = 0;
for (int i = 0; i < n; i++)
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, r, s = 0, p;
cin >> n >> r;
if (r >= n) {
if (n > 1) {
n--;
s = (n * (n + 1)) / 2;
}
s++;
} else {
s = (r * (r + 1)) / 2;
}
cout << s << endl;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[105];
int main() {
cin >> n;
int tmp;
for (int i = 0; i < n; ++i) {
cin >> tmp;
a[tmp] += 1;
}
int cnt = 0, first = -1, second = -1;
for (int i = 0; i < 105; ++i) {
if (a[i] > 0) {
if (first == -1) {
first = i;
} else... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b;
cin >> a >> b;
long long x = 1;
if (b - a >= 5) {
cout << 0;
} else {
long long iter = 1;
for (long long i = a + 1; i <= b; i++) {
iter = ((i % 10) * iter) % 10;
}
cout << iter;
}
}
int main() {
ios_base... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
int n;
cin >> n;
std::vector<int> v;
std::copy_n(std::istream_iterator<int>(std::cin), n, std::back_inserter(v));
int len = 1;
int max = 1;
for (int i = 1; i < v.size(); i++) {
if (v[i] > v[i - 1]) {
len++;
} el... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int N, M, res;
int ar[MAXN];
int dn[MAXN];
int main() {
scanf(" %d %d", &N, &M);
double a;
for (int i = 1; i <= N; i++) scanf(" %d %lf", ar + i, &a);
for (int i = 1; i <= N; i++) {
dn[i] = 1;
for (int j = 1; j < i; j++)
if (ar[j]... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<double> merge(vector<double> A, vector<double> B) {
int N = A.size();
vector<double> SA(N + 1);
SA[0] = 0;
for (int i = 0; i < N; i++) {
SA[i + 1] = SA[i] + A[i];
}
vector<double> SB(N + 1);
SB[0] = 0;
for (int i = 0; i < N; i++) {
SB[i + 1] =... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a1, a2, k1, k2, c, n;
cin >> a1 >> a2 >> k1 >> k2 >> n;
if (k1 > k2) {
swap(k1, k2);
swap(a1, a2);
}
int cnt = a1 * (k1 - 1) + a2 * (k2 - 1);
if (n - cnt <= 0)
cout << 0 << " ";
else
cout << n - cnt << " ";
if (a1 * k1 >= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int GetMaxDigit(int N) {
int Max = INT_MIN;
while (N) {
Max = max(Max, N % 10);
N /= 10;
}
return Max;
}
int main() {
long long N;
cin >> N;
long long Ans = 0;
while (N) {
int Max = GetMaxDigit(N);
Ans++;
N -= Max;
}
cout << Ans << en... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) {
while (b ^= a ^= b ^= a %= b)
;
return a;
}
int main(void) {
long long n, a, b, p, q;
cin >> n >> a >> b >> p >> q;
long long s = n / a;
long long m = n / b;
long long f = a * b / gcd(a, b);
long long ff = (n / f);
if (p <... | 8 |
#include <bits/stdc++.h>
using namespace std;
int F[605][305][305], a[305][305], n;
int main() {
if (0) freopen("input.txt", "r", stdin);
;
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]);
for (int i = 0; i <= 2 * n; ++i)
for (int j = 0; j <= n; ++j)
... | 12 |
#include <bits/stdc++.h>
int mod(int a) {
if (a >= 0) return a % 256;
return 256 + a % 256;
}
int BitReverse(int a) {
std::string s;
while (a) {
s += char(a % 2 + '0');
a /= 2;
}
int len = s.length(), res = 0;
while (len < 8) {
s += '0';
len++;
}
for (int i = 1; i <= 8; i++)
res +=... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = (1e-10);
bool EQ(double a, double b) { return abs((a) - (b)) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
int n, d;
string senders[10000];
string receivers[10000];
int times[10000];
void solve() {
cin >> n >> d;
for (int i = 0; i... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
out << a.first << " " << a.second;
return out;
}
t... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, f[1001][1001][2];
int main() {
for (long long i = 0; i < 1001; i++)
for (long long j = i; j < 1001; j++)
for (long long k = 0; k < 2; k++) {
if (j == 0) continue;
if (i == 0) {
f[i][j][k] = (j - k + 1) / 2;
contin... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int energy = 0, dolar = 0, n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dolar = h[0];
for (int i = 0; i < n - 1; i++) {
if (h[i] >= h[i + 1]) {
energy += h[i] - h[i + 1];
} else {
if (energy >... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
const int q = 1e9 + 9;
long long a[100009];
int main() {
long long n, m, ans = 0, best = 0;
cin >> n >> m;
for (int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000003;
long double pi = 3.1415926536;
const int mx = 1000003;
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
long long bp(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans = (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 53, INF = 1e18, MOD = 1e9 + 7;
long long dis[N][N][2], way[N][N][2];
long long POW(long long a, long long b) {
if (b == 0) return 1;
long long ans = POW(a, b / 2);
ans *= ans;
ans %= MOD;
if (b % 2) ans *= a;
ans %= MOD;
return ans;
}
long ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
int n;
string s1, s2;
cin >> n >> s1 >> s2;
vector<bool> vis1(n, false), vis2(n, false);
int ans = 0;
for (int i = 0; i < n; i++) {
if (s... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> app[15];
int l[15], r[15];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n;
cin >> n;
for (int i = int(0); i < int(n); i++) {
string cur;
cin >> cur >> l[i] >> r[i];
for (int j = int(0); j < in... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.