solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int times = 1;
int T, S, q;
int now = 0;
int clk = 0;
cin >> T >> S >> q;
while (S < T) {
clk++;
clk %= q;
if (clk != 0) {
S++;
}
now++;
if (now >= S && S != T) {
now = 0;
times++;
}
}
cout << times ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
vector<int> from[N], to[N], ans;
set<pair<int, int> > st;
int ar[N];
int n;
bool used[N];
int getzero() {
for (int i = 0; i < n; ++i) {
if (!ar[i]) return i;
}
return -1;
}
bool dfs(int ind) {
for (auto &x : to[ind]) {
if (used[x]) continu... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long P = 1e9 + 7;
const int N = 1005;
const int INF = 1e9;
const double pi = acos(-1);
mt19937 rng(time(0));
long long n, x[N], y[N];
vector<int> g[N];
int group[N];
unordered_map<int, vector<int>> hlines, vlines;
unordered_map<int, unordered_map<int, int>> ids;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int num;
int ans1, ans2, n;
int fk[100005];
struct SuffixArray {
char s[100005];
int sa[100005];
int rank[100005];
int height[100005];
int t[100005], t2[100005], c[100005];
int n;
void clear() {
n = 0;
memset(sa, 0, sizeof(sa));
}
void build_sa(int... | 13 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
map<pair<int, int>, int> cnt;
vector<int> V[200010];
long long total;
int parent[200010];
bool visit[200010];
void dfs(int curr) {
total++;
visit[curr] = true;
for (int i = 0; i < V[curr].size(); i++) {
dfs(V[curr][i]);
}
}
int main() {
ios_base::syn... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
const ll ub = 1e10;
map<ll, string> pw_, pw[11];
for (ll i = 2; i * i <= ub; ++i) {
ll p = i;
for (int j = 2; j < 200; ++j) {
if (p > ub / i) break;
p *= i;
if (p > ub) break;
string s = to_string(i) +... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long invmask(long long x) {
long long m = 0;
long long d = 0;
while (x > 0) {
d = x % 10;
if (d == 4 || d == 7) {
m *= 10;
m += d;
}
x /= 10;
}
return m;
}
int main() {
long long a, b, c;
cin >> a >> b;
c = a + 1;
int invb ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6e4 + 1000;
int n;
int x[N], v[N];
double l[N], r[N];
bool check(double m) {
for (int i = 1; i <= n; ++i) {
l[i] = (double)x[i] - m * (double)v[i];
r[i] = (double)x[i] + m * (double)v[i];
}
double L = l[1], R = r[1];
for (int i = 2; i <= n; ++i... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline void qread(int &x) {
x = 0;
int sign = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') sign = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
x = x * sign;
}
inline void qpri... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, i, j;
vector<pair<int, int> > v;
string s;
cin >> a >> s;
int x = 0, y = 0;
for (i = 0; i < s.size(); i++) {
if (s[i] == 'R')
x++;
else if (s[i] == 'L')
x--;
else if (s[i] == 'U')
y++;
else if (s[i] == 'D')
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long MAX = -1000000000000000000;
const long long MIN = 1000000000000000000;
const long long inf = 1000000000;
const long long KOK = 100000;
const long long LOG = 30;
const long long li = 500005;
const long lon... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph;
int n;
int main() {
long long int n, temp;
long long int sum, minodd = 1000000009;
sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
sum += temp;
if (temp % 2 != 0) minodd = min(minodd, temp);
}
if (sum % 2 =... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
using Weight = pair<long long int, int>;
struct Edge {
int src, dst;
long long int weight;
long long int c;
int id;
Edge(int src_, int dst_, long long int weight_, const int id_)
: ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, c[2];
signed main() {
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> x;
c[0] += x / 2;
c[1] += x / 2;
if (x % 2) c[i % 2] += 1;
}
printf("%lld", min(c[0], c[1]));
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int a, tot, n, ans;
int main() {
cin >> n;
while (n--) {
cin >> a;
if (a & 1) {
tot++;
if (tot & 1)
ans = ceil(a / 2.0);
else
ans = floor(a / 2.0);
if (ans == -0) ans = 0;
cout << ans << endl;
} else {
cout... | 2 |
#include <bits/stdc++.h>
using namespace std;
int many;
int at[200010];
int hd[200010];
int cd[200010];
int give = 0;
int main() {
cin >> many;
for (int i = 1; i <= many; i++) {
scanf("%d", &hd[i]);
at[hd[i]] = 0;
}
for (int i = 1; i <= many; i++) {
scanf("%d", &cd[i]);
at[cd[i]] = i;
}
if (... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int inf = 1e9;
int dp[2][maxn][60][60];
int n, p, k;
int A[maxn];
int B[maxn];
void init() {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < maxn; j++) {
for (int a = 0; a < 55; a++) {
for (int b = 0; b < 55; b++) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
constexpr static int mod = 1e5;
void mul(long long &a, long long b) { a = ((a % mod) * (b % mod)) % mod; }
int main() {
string s;
cin >> s;
for (auto &it : s) it -= '0';
vector<int> p = {s[0], s[2], s[4], s[3], s[1]};
long long num = 0;
for (auto it : p) num = 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a;
vector<vector<int>> g;
bool visited[1005], done;
int ans[1005];
void dfs(int s, int idx) {
if (done) return;
visited[s] = true;
for (int i = 0; i < g[s].size(); ++i) {
if (!visited[g[s][i]]) {
dfs(g[s][i], idx);
} else {
ans[idx] = g[s][i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
;
cin.tie(NULL);
int zz = 1;
cin >> zz;
for (int zzz = 1; zzz <= zz; zzz++) {
int n;
cin >> n;
int l = 0, r = 0;
string s;
cin >> s;
vector<int> a(n, 0);
for (int i = 0; i < n; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, n, c = 0;
cin >> n >> s;
for (i = 1; i <= n; i++) {
string ss;
cin >> ss;
if (s[0] == ss[0] && s[1] == ss[1] && s[2] == ss[2]) c++;
}
if (c == n - c)
printf("home\n");
else
printf("contest\n");
return 0;
}
| 1 |
#include <bits/stdc++.h>
const int Max = 50006;
const int Inf = 2e9;
const long long MOD = 1e9 + 7;
using namespace std;
void solve() {
int n;
cin >> n;
map<int, int> h;
int year, cnt = 1;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
h[x]++;
h[y]--;
if (i == 1) year = x;
}
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, t, l;
void read_solve() {
cin >> n >> k >> m >> t;
int q, i;
l = n;
while (t--) {
cin >> q >> i;
if (q) {
if (i <= k) k++;
l++;
} else {
if (i < k) {
k -= i;
l -= i;
} else
l = i;
}
cou... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int g[N][N];
int n;
int ans = 1e9;
int cur = 0;
void dfs(int x, int sum, int fa) {
if (x == 1) {
cur++;
if (cur > 1) {
ans = min(ans, sum);
return;
}
}
for (int i = 1; i <= n; i++) {
if (i == fa) continue;
if (g[x][i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
const int MAX_M = 10;
int N, M;
int A[MAX_M][MAX_N];
vector<pair<int, int> > al[MAX_N];
long long solve() {
if (M == 0) return N * (N + 1LL) / 2;
for (int i = 0; i < M; i++) {
for (int j = 0; j < N;) {
int k = j + 1;
while (k <... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50;
int n, P, S;
int tab[MAXN + 3];
long double D[MAXN + 3][MAXN + 3][2 * MAXN + 3];
long double silnia[MAXN + 3], wyn;
void wczytaj() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &tab[i]), S += tab[i];
scanf("%d", &P);
silnia[0] = 1.... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
vector<vector<int> > g;
vector<bool> used;
int t;
vector<int> in, fup, br;
vector<pair... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
int n, m, k;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
scanf("%d%d%d", &n, &m, &k);
int n1 = n, m1 = m;
int d = gcd(n, k);
k /= d;
n1 /= d;
d = gcd(m, k);
k /= d;
m1 /= d;
if (k > 2)
puts("NO");
... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool isprime[1000006], vis[100005];
vector<pair<int, int> > v[100005];
void print(int x) {
if (!vis[x]) {
vis[x] = true;
int sz = v[x].size();
for (int i = 0; i < sz; i++) {
printf("%d %d %d\n", x, v[x][i].first, v[x][i].second);
print(v[x][i].firs... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int a[100005], b[100005];
int aa[100005], bb[100005];
int main() {
int n, s;
cin >> n >> s;
char ch;
int q, p;
vector<int> v, vv;
for (int i = 0; i < n; i++) {
cin >> ch >> p >> ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
if (n == 1) {
cout << "NO" << endl;
continue;
}
if (n == 2) {
int num1 = s[0] - '0';
int num2 = s[1] - '0';
if (num2 > num1) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
bool vis[maxn];
queue<int> q;
vector<int> v;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vis[a[i]] = true;
if (!a[i]) v.push_back(i);
}
for (int i = 1; i <= n; i++)
if (!vis[i]) q... | 7 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
using namespace std;
long long fastpow(long long base, long long pow) {
if (!base) return 0;
if (!pow) return 1;
if (pow == 1) return base;
long long x = fastpow(base, pow / 2) % mod;
x *= x;
x %= mod;
if... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int DX[] = {0, +1, 0, -1, 0};
const int DY[] = {0, 0, +1, 0, -1};
char s[105];
int main() {
gets(s);
int x = 0, y = 0;
set<pair<int, int> > was;
was.insert(make_pair(x, y));
for (int i = 0; s[i]; i++) {
int px = x;
int py = y;
switch (s[i]) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2000], m;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (a[i] > a[j]) ans ^= 1;
cin >> m;
while (m--) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<string> arr;
int n, m, k, cnt;
void dfs(int a, int b, char c) {
arr[a][b] = c;
cnt++;
if (a != n - 1 && arr[a + 1][b] == '.') {
dfs(a + 1, b, c);
}
if (a != 0 && arr[a - 1][b] == '.') {
dfs(a - 1, b, c);
}
if (b != m - 1 && arr[a][b + 1] == '.')... | 8 |
#include <bits/stdc++.h>
char s[500005];
int f[500005];
int main() {
int n, cur = 0;
long long ans = 0, sum = 0;
scanf("%d%s", &n, s + 1);
for (register int i = 1; i <= n; ++i) f[i] = n + 1;
for (register int i = n; i; --i) {
if (s[i] == '1') {
++cur;
sum += f[cur] - i;
} else {
whil... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const int N = 2e3 + 1;
void solve() {
bitset<N> E[N];
int n, m, c[N];
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= n; ++j) E[i][j] = 0;
c[i] = -1;
}
while (m--) {
int x, y;
cin >> x >> y;
--x;
... | 18 |
#include <bits/stdc++.h>
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
std::mt19937 rnd(time(NULL));
template <class T>
void cxk(T& a, T b) {
a = a > b ? a : b... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
vector<long long> adj[N], col(N, 0);
void dfs(long long x, long long p, long long c) {
col[x] = c;
long long cnt = 1;
for (auto i : adj[x]) {
if (i == p) continue;
while (cnt == col[x] || cnt == col[p]) ++cnt;
dfs(i, x, cnt++);... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
vector<long long> a;
long long i, j, k, ii;
for (i = 1; (i * i) <= n; i++) {
if (n % i == 0) {
j = (n / i) + 1;
j--;
k = (j) * (2 + ((j - 1) * i));
k = k / 2;
a.push_back(k);
if (... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int INF = 1 << 30;
int n, m;
int p[MAXN + 10], a[MAXN + 10], pos[MAXN + 10], after[MAXN + 10],
before[MAXN + 10];
set<pair<int, int> > S;
int read(void) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d%d", &p[i], &a[i]);... | 20 |
#include <bits/stdc++.h>
using namespace std;
void fre() {
freopen("c://test//input.in", "r", stdin);
freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
if (b < a) a = b;
... | 12 |
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#defi... | 9 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll mod = 998244353;
ll n, m;
ll fact[21];
ll inv[21];
ll solve(vector<ll>& nums)
{
ll sz = nums.size();
ll ret = 1;
for(ll i = 0; i < sz; i++)
{
ret = (ret * (nums[i] - i - 1)) % mod;
}
ret = ret * fact[n - sz] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
double x, y, p, q;
cin >> x >> y >> p >> q;
std::cout << std::fixed;
if (x * q == y * p) {
cout << 0 << endl;
} else if (p == q || p == 0) {
cout << -1 << endl;
} else {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> a[3];
int n[3];
ll sq(ll x) { return x * x; }
ll calc(ll x, ll y, ll z) {
ll ret = sq((x - y)) + sq((y - z)) + sq((z - x));
return ret;
}
void solve() {
for (int i =... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
long long r = 0, c = 0;
if (r1 == r2) r++;
if (c1 == c2) c++;
cout << 2 - r - c << " ";
long long k = 0, l = 0, m = 0, n = 0;
if ((r1 + c1) % 2 == (r2 + c2) % 2) k++;
if ((r1 + c1) == (r2 ... | 3 |
#include <bits/stdc++.h>
char *fs, *ft, buf[1 << 20];
inline int read() {
int x = 0, f = 1;
char ch =
(fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))
? 0
: *fs++;
;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = (fs == ft &&
(ft =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, i, j, k, l, r;
cin >> n;
vector<int> a(n);
for (int i = (0); i < n; ++i) cin >> a[i];
string s;
cin >> s;
for (i = 0; i < s.length();) {
j = i;
while (j < s.length(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
double n, t;
cin >> n >> t;
cout << fixed << setprecision(6) << pow(1.000000011, t) * n << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
int main() {
int n, a[1001];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] % 2 == 0) a[i]--;
printf("%d ", a[i]);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int sum[100005], s[100005];
char A[100005], B[100005], C[100005];
int main() {
int m, t = 0;
scanf("%d", &m);
scanf("%s", A + 1);
int n = strlen(A + 1);
for (int x = 0; x < 26; x++) {
char c = x + 'a';
bool f = 1;
sum[0] = 0;
for (int i = 1; i <= n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int T, n, m, x, y, z, sum = 10;
int len[10][10], vis[10][10][10];
void wonden(int aa, int bb, int use) {
if (vis[aa][bb][use] || use > 6) return;
vis[aa][bb][use] = 1;
if (aa + bb == 0) {
sum = min(sum, use);
return;
}
for (int i = 0; i <= aa; i++) {
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p, par, vec;
vector<vector<int>> ind, val;
int root(int x) {
if (par[x] < 0) return x;
return par[x] = root(par[x]);
}
void merge(int v, int u) {
v = root(v);
u = root(u);
if (v == u) return;
if (v > u) swap(v, u);
par[v] += par[u];
par[u] = v;
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
long long int a[N + 5];
struct node {
int a, b;
long long int x;
node(int aa = 0, int bb = 0, long long int c = 0) { a = aa, b = bb, x = c; }
} b[N + 5];
int main() {
int n, m, x, y, len = 0;
long long int d;
scanf("%d%d", &n, &m);
for (int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1E5 + 10;
int num[MAXN];
int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
int n;
int big = 0, group = 0;
memset(num, 0, sizeof(num));
scanf("%d", &n);
for (int a, i = 1; i <= n; ++i) {
scanf("%d", &a);
++num[a];... | 9 |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
long long LG = 18;
vector<vector<long long>> mx;
long long GL[300000];
long long gmx(long long l, lon... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = ~(((long long)0x1) << 63) / 2;
const int INF = 0X3F3F3F3F;
const double eps = 1e-7;
const long long MOD = 1000000007;
long long dp[2][11111];
long long c[110][110];
long long t[2][11111];
long long solve(long long a, long long p) {
long long ans = 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
void file() {}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
const int N = 510 + 20;
int main() {
file();
fast();
long long x, d;
cin >> x >> d;
vector<long long> ans;
long long cur = 1;
int idx = 0;
while (x > 0) {
if (x % 2 == 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a[] = {1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
40... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int a[N];
vector<int> ans;
void query(int p) {
int cur = a[p] ^ a[p + 1] ^ a[p + 2];
a[p] = a[p + 1] = a[p + 2] = cur;
ans.push_back(p);
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int xor_sum = 0;
for (in... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int t, n, k, ans = 0, v[3][maxn];
char s[3][maxn];
struct node {
int x, y;
} a[3 * maxn];
bool judge(char x) {
if (isalpha(x)) return false;
return true;
}
int bfs(node tmp) {
queue<node> q;
q.push(tmp);
while (!q.empty()) {
node nod = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long long a, b, c;
cin >> t;
while (t--) {
cin >> a >> b;
c = abs(a - b);
if (c % 5 == 0) {
cout << c / 5 << endl;
} else if (c % 5 == 1 || c % 5 == 2) {
cout << c / 5 + 1 << endl;
} else {
cout << c / 5 + 2 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long P = 1000 * 1000 + 3, Q = 1000 * 1000 * 1000 + 9, K = 315;
struct forest {
vector<vector<int> > tree;
vector<bool> used;
vector<int> parent;
int badVerticle;
int n;
void addEdge(int u, int v) {
tree[u].push_back(v);
tree[v].push_back(u);
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<pair<int, char>>> v;
short dp[105][105][2][27];
bool solve(int node1, int node2, bool player, int last) {
if (dp[node1][node2][player][last] != -1)
return dp[node1][node2][player][last];
bool win = 0;
if (player == 0) {
for (int i = 0; i <... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
string s;
cin >> s;
map<string, char> mp;
mp["."] = '0';
mp["-."] = '1';
mp["--"] = '2';
string ss = "";
string ans = "";
for (int i = 0; i < s.size(); i++) {
ss.push_b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, j, k, x, y = 0;
cin >> n >> m;
map<long, long> c;
for (i = 1; i <= m; i++) {
if (i % 5 == 0)
c[5]++;
else if (i % 5 == 1)
c[1]++;
else if (i % 5 == 2)
c[2]++;
else if (i % 5 == 3)
c[3]++;
el... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1005], cnt;
pair<int, int> pos[1005], ans[1000000];
int main() {
cin >> n;
for (int i = (1), _ = (n); i <= _; i++)
cin >> a[i], pos[i] = pair<int, int>(a[i], i);
sort(pos + 1, pos + n + 1);
for (int i = (1), _ = (n); i <= _; i++) {
int ps = pos[i].s... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ans;
cin >> n;
ans = (3 * n) / 2;
ans += n % 2;
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long alice = arr[0];
long bob = 0;
int i = 1, j = n;
while (i < j) {
if (alice <= bob) {
alice += arr[i];
i++;
} else if (bob < alice) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n1, n2, k, m;
cin >> n1 >> n2 >> k >> m;
long long int a[n1 + 5], b[n2 + 5];
for (int i = 0; i < n1; i++) {
cin >> a[i];
}
for (int i = 0; i < n2; i++) {
cin >> b[i];
}
if (a[k - 1] < b[n2 - m])
cout << "YES" << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 5;
int a[MAXN], sum[MAXN];
int n;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (sum... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(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 mod = 1e9 + 7, N = 1e5 + 10;
int ... | 22 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tostr(const T& t) {
ostringstream os;
os << t;
return os.str();
}
bool sieve[2000000 + 1];
int DP[2000002];
void sieve_erastothenes() {
register unsigned int p;
sieve[0] = sieve[1] = true;
for (p = 2;; ++p) {
unsigned long long p... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int flag = 0;
int vis[100005];
vector<pair<int, int> > orient;
int timer = 0;
int in[100005], low[100005];
void dfs(int node, int par) {
timer++;
in[node] = low[node] = timer;
for (auto i : v[node]) {
if (i ^ par) {
if (vis[i] == 1) co... | 12 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 200200;
const int me = 33;
int c = 1;
int trie[ms * me][2];
int has[ms * me];
int addTrie(unsigned int num, int x) {
int st = 0;
for (int i = 31; x > 0; i--, x--) {
unsigned int bit =... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
long long a[N];
long long n, q;
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%lld%lld", &n, &q);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
a[0] = a[n + 1] = 0;
long long res = 0;
for (int i = 1; i <= n... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 505, M = 998244353;
int n, m;
int c[maxn];
void madd(int& a, int b) {
a += b;
if (a > M) a -= M;
}
int mult(int a, int b) { return (1LL * a * b) % M; }
int dp[maxn][maxn];
int f(int l, int r) {
if (l >= r) return 1;
if (dp[l][r... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
vector<char> stack;
for (int i = 0; i < ((int)(s).size()); i++) {
while (((int)(stack).size()) && s[i] > stack.back()) s... | 3 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
using namespace std;
using namespace std;
using namespace std;
using namespace std;
using namespace std;
using namespace std;
using namespace std;
int a[505];
int main() {
int m, n, i, j, k;
double ans = 0;
cin >> m >> n;
for (i = 1; i <= m; i++... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
long long ir1, ir2, ir3, id;
__int128 sml = 0, smr = 0;
cin >> n >> ir1 >> ir2 >> ir3 >> id;
__int128 r1 = ir1, r2 = ir2, r3 = ir3, d = id;
vector<__int128> a(n);
vector<__int128> v1(n... | 15 |
#include <bits/stdc++.h>
using namespace std;
int M = 10010;
class Solution {
public:
Solution(vector<pair<int, int>>& pos)
: points(pos),
pb(pos.size(), vector<double>(pos.size(), 0.0)),
point2lines(pos.size()),
move1(pos.size()) {
build();
}
vector<double> query(vector<pair<in... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, m1, m2;
char c[0];
cin >> h1 >> c[0] >> m1;
cin >> h2 >> c[0] >> m2;
int hp = h1 - h2;
int mp = m1 - m2;
if (mp < 0) {
mp += 60;
hp -= 1;
}
if (hp < 0) hp += 24;
printf("%02d:%02d", hp, mp);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double ans;
int in;
};
bool com(struct node x, struct node y) {
if (x.ans == y.ans)
return x.in < y.in;
else
return x.ans > y.ans;
}
struct node ar[2000];
int main() {
int t3 = 1, i, n;
double t1, t2, k, a, b;
while (t3--) {
cin >> n ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, p, q;
double a[100001], b[100001];
double f(double x) {
double y = 1.0;
for (int i = 0; i < n; i++)
if (y > (1.0 - a[i] * x) / b[i]) y = (1.0 - a[i] * x) / b[i];
return x * p + y * q;
}
int main() {
cin >> n >> p >> q;
double l = 0, r = 10000001;
for ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int l = 0;
int r;
int ans = INT_MAX;
void solve(int t) {
int last_ast = -1;
int right_P = -1;
for (int i = 0; i < n; i++) {
if (s[i] == '*') {
if (right_P >= i) {
last_ast = -1;
} else if (last_ast == -1) {
last_ast = i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, q, p, x;
long long a[N], sum[N], maxn[N << 2], add[N << 2];
void build(long long k, long long l, long long r) {
if (l == r) {
maxn[k] = sum[l];
return;
}
long long mid = l + r >> 1;
build(k << 1, l, mid);
build(k <... | 17 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3", "unroll-loops")
long long mod = 1e9 + 7;
void solve();
void tests() {
long long test;
cin >> test;
while (test--) {
solve();
}
}
void io_files() {}
int32_t main() {
;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NU... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long inf = 2147383647;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
struct debugger {
template <typename T>
debugger &operator,(const T &v) {
cerr << v << " ";
return *this;
}
} dbg;
inline long long gcd(long ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
vector<std::vector<long long> > ans;
long long sq(long long x) { return x * x; }
long long gcd(long long a, long long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 100 * 100;
int mn[4 * MAXN + 10];
int marked[4 * MAXN + 10];
void update(int node, int b, int e, int p, int q, int val) {
if (marked[node] != 0) {
marked[2 * node] += marked[node];
marked[2 * node + 1] += marked[node];
mn[2 * node] += ma... | 18 |
#include <bits/stdc++.h>
using namespace std;
int parent[1000], n;
struct edge {
int a, b, first, second;
};
bool sortl(const edge& l, const edge& r) {
return l.first == r.first ? l.second < r.second : l.first < r.first;
}
bool sortr(const edge& l, const edge& r) {
return l.second == r.second ? l.first < r.first ... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class C>
inline bool in_(const typename C::key_type& k, const C& A) {
return A.find(k) != A.end();
}
inline bool in_(const string& s, const string& S) {
return S.find(s) != string::npos;
}
const int maxb = 24;
int dp[1 << maxb];
int main() {
ios::sync_with_s... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int N = 1010;
int n, m, k, a[N][N], px, py;
long long ps... | 17 |
#include <bits/stdc++.h>
const int W = 30, N = 200005;
int n, a[N], b[N], Q, opt, l, r, x, t2[N * 4], tag;
struct line {
int a[31], siz;
void clear() {
memset(a, 0, sizeof(a));
siz = 0;
}
void insert(int x) {
for (int i = W; i >= 0; i--)
if (x & (1 << i)) {
if (!a[i]) {
a[i] ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int dp[n][2];
int i, j;
for (i = 0; i < n; i++) {
cin >> dp[i][0];
cin >> dp[i][1];
}
int count = 0;
for (i = 0; i < n; i++) count = count + dp[i][1] - dp[i][0] + 1;
if (count % k == 0)
cout << 0;
else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
char s[1011111];
int pig[1011111], npig;
int food[1011111], nfood;
int cnt[1011111];
int dp[1011111];
void upd(int &a, int b) { a = max(a, b); }
bool chk(int d) {
dp[0] = dp[1] = dp[2] = 0;
for (int i = 0; i < npig; i++) {
dp[i + 3] = 0;
int it = dp[i];
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 3e5 + 5;
const int mx = 1.5e7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long pwr(long long x, long long y);
bool isprime(long long x);
int factor[mx], numdiv[mx], a[N];
void s() {
for (long... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
if (k >= n - 1) {
cout << n - 1 << endl;
} else {
cout << k + (2 + n - k) * (n - 1 - k) / 2 << endl;
}
return 0;
}
| 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.