solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
int p[100000];
int q[100000];
int res[100000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &p[i]);
for (int i = 0; i < n; i++) scanf("%d", &q[i]);
for (int i = 0; i < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = int(2e5);
const long double pi = 3.1415926535897932384626433832795;
int main() {
int n, m;
while (cin >> n >> m) {
if (m < 2 || n < 2 || (m == 2 && n == 2))
cout << n * m << '\n';
else if (min(n, m) == 2 && max(n, m) > 2) {
int ans =... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct cell {
int val, poz;
};
const int NMAX = 105;
int n, k, m, s;
cell a[NMAX];
cell sol[NMAX * 10];
inline bool cmp(const cell A, const cell B) {
if (A.val == B.val) return A.poz < B.poz;
return A.val < B.val;
}
int main() {
int i, j;
cell kk, kkk;
cin.sync_... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, f1 = 0, f2 = 0, f3 = 0, flag = 0;
cin >> n;
long long a[n], b[n];
for (long long i = 0; i < n; i++) cin >> a[i];
for (lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s;
int k, old;
const int maxn = 1000;
int a[maxn];
int main() {
int n, d, u = 0;
cin >> n >> d;
for (int i = 1; i <= d; i++) {
cin >> s;
k = 0;
for (int j = 0; j < s.size(); j++)
if (s[j] == '0') {
k = 1;
break;
}
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, a, b, c, d;
bool f = true;
cin >> n;
for (int i = 0; i < 4; i++) {
cin >> a >> b >> c >> d;
if ((a + c) <= n && f) {
cout << i + 1 << " " << a << " " << (n - a);
f = false;
}
if ((a + d) <= n && f) {
cout << ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 9;
int n, m, cor[MAXN], dist[MAXN][2], ans[MAXN];
bool night_blocks[MAXN];
bool morning_blocks[MAXN];
set<pair<int, int> > black;
set<pair<int, int> > white;
set<pair<int, int> > edges;
vector<int> G[MAXN];
int main() {
ios_base::sync_with_stdio(fal... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
pair<int, int> heroes[N];
int maxKills[N];
int a[N];
bool canKill(int maxM, int countM, int n) {
int l = 0, r = n - 1;
while (l < r) {
int m = (l + r) / 2;
if (heroes[m].first >= maxM) {
r = m;
} else {
l = m + 1;
}
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int dp[5005][5005][2];
map<int, int> mp;
int main() {
int n;
cin >> n;
v.resize(n + 1);
for (int i = 1; i <= n; i++) cin >> v[i];
memset(dp, 0x3f, sizeof(dp));
for (int i = 1; i <= n; i++) dp[i][i][0] = dp[i][i][1] = 0;
for (int i = 1; i <= n; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool DBG = true;
template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const std::pair<T, S>& p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>&... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
using namespace std;
void fastio() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long dp[101][1001], ans1 = 1e9, dp1[1000001];
long long num[10];
long long a[1000000];
bool ch(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int base = 1e9 + 7;
const int N = 2e5 + 2, M = 650;
int r, g;
int d[2][N];
int main() {
cin >> r >> g;
if (r == 0 || g == 0) {
cout << 1;
return 0;
}
d[0][0] = d[0][1] = 1;
int ans = 0, h = 0;
h = 1;
for (int i = 2; i * (i + 1) / 2 <= r + g; ++i)... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, v, a[21], b[21], c[21], k = 100000, m = 0;
cin >> n >> v;
for (int i = 0; i < n; i++) {
cin >> a[i];
m += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
c[i] = b[i] / a[i];
if (c[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
static vector<int> V[MAXN], q[MAXN];
static vector<pair<int, int> > c[MAXN];
static pair<int, int> w[MAXN];
static int n, m, N, a[MAXN], b[MAXN], p[MAXN], Tohka[MAXN], sum[MAXN], id[MAXN];
inline int lowbit(int first) { return first & -first;... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int b, l, k;
int a[100005], s[100005];
int main() {
scanf("%d%d%d", &b, &l, &k);
for (int i = 0; i < b; i++) {
scanf("%d", &a[i]);
if (i) s[i] = a[i] - a[i - 1];
}
if (b == 1)
printf("1");
else {
int ans = a[b - 1] - a[0... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300004;
int a[N], n, m, s1[N], s2[N], c[2];
int main() {
long long t;
c[0] = 1;
scanf("%d", &n);
long long ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%lld", &t);
for (int j = 0; j < 61; j++)
if (t >> j & 1) ++a[i];
s2[i] = s2[i ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, r;
map<char, int> white, black;
int main() {
white['Q'] = 9;
white['R'] = 5;
white['B'] = 3;
white['N'] = 3;
white['P'] = 1;
black['q'] = 9;
black['r'] = 5;
black['b'] = 3;
black['n'] = 3;
black['p'] = 1;
char c;
int w = 0, b = 0;
for (int i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int inf = 1e9 + 9;
const long long int MOD = 1e9 + 696969;
const long long INF = 4LL * 1000000LL * 1000000LL * 1000000LL;
template <class T>
int size(T &&x) {
return int(x.size());
}
template <class A, class B>
ostream &operator<<(ostream ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100100], b[100100], k, v;
pair<int, int> c[100100];
int go(int t) {
int x = 0, y = 0, s1 = 0, s2 = 0;
while (x < a[n] || y < b[n]) {
int *px = lower_bound(a, a + n + 1, x + t),
*py = lower_bound(b, b + n + 1, y + t);
if (px > a + n && py > b + n... | 11 |
#include <bits/stdc++.h>
int main() {
int h, m;
scanf("%d:%d", &h, &m);
double x, y;
if (h == 12 && m == 0)
printf("0 0\n");
else {
x = (30 * (h % 12)) + (m / 2.0);
y = 6 * m;
if (m % 2 == 0)
printf("%.0lf %.0lf\n", x, y);
else
printf("%.1lf %.0lf\n", x, y);
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int next, from, to, w;
} e[1000010];
int hd[300010], etot = 0;
inline void add(int u, int v, int w) {
++etot;
e[etot] = (Edge){hd[u], u, v, w};
hd[u] = etot;
}
stack<int> s;
int dfn[300010], low[300010], cnt = 0;
bool vis[300010];
int clr[300010], ccnt... | 15 |
#include <bits/stdc++.h>
using namespace std;
int h_digit(int a) {
int h = 0, r;
while (a) {
r = a % 10;
if (r > h) h = r;
a /= 10;
}
return h;
}
int bas(int a, int b, int ba) {
int c = 0, coun = 0, r1, r2, s;
while (a || b) {
r1 = a % 10;
r2 = b % 10;
s = r1 + r2 + c;
a /= 10;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
cout << 2 << "\n";
int x = n, y = n - 1;
for (int i = 1; i < n; i++) {
cout << x << " " << y << "\n";
x = (x + y + 1) / 2;
y--;
}
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[800];
int main() {
int n, minval, sum, tot;
cin >> n;
tot = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
tot += a[i];
}
for (int i = 1; i <= n; ++i) {
a[i + n] = a[i];
}
minval = tot;
for (int i = 1; i <= n; ++i) {
sum = 0;
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void coutx(double q, int x) {
cout << fixed << setprecision(x) << q << endl;
return;
}
inline long long ksc(long long x, long long y, long long mod) {
return (x * y - (long long)((long double)x / mod * y) * mod + mod) % mod;
}
long long gcd(long long a, long long b) {... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int power(long long int a, long long int b) {
if (b == 0) return 1;
long long int sr = power(a, b >> 1);
long long int r = sr * sr;
if (b & 1) r = a * r;
return r;
}
long long int sumofdigits(long long int n) {
string s = to_string(... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const int eps = 1e-10;
const int base = 1e9;
int main() {
int n, k, s = 0, i, a;
scanf("%d%d", &n, &k);
for (i = 1; i <= n; i++) {
scanf("%d", &a);
if (a + k <= 5) s++;
}
printf("%d", s / 3);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
namespace SGT {
int addv[800000], minn[800000];
int maxl[800000], maxr[800000], maxn[800000];
int sumv[800000];
inline void pushdown(int o) {
if (addv[o]) {
addv[o * 2] += addv[o];
addv[o * 2 + 1] += addv[o];
minn[o * 2] += addv[o];
minn[o * 2 + 1] += addv... | 24 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, s[1001], sum = 0, a, b, c, d;
int main() {
scanf("%d%d%d", &n, &m, &h);
for (int i = 1; i <= m; i++) {
scanf("%d", s + i);
sum += s[i];
}
double ans = 1;
a = sum - s[h];
b = sum - 1 - (n - 1);
c = sum - 1;
d = a - (n - 1);
if (sum < n)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int c = 0;
long long int calc(long long int a, long long int b) {
long long int r = 0;
for (int i = 0; i < 64 && (1LL << i <= b + 1); i++) r = 1LL << i;
if (r > a) return max(r - 1, 0LL);
return r + calc(a - r, b - r);
}
int main() {
long long int n, l, r;
cin >... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n, k;
cin >> n >> k;
map<long long, long long> m;
long long ar[n];
for (long long int i = 0; i < n; i++) cin >> ar[i];
long long l = 0, r = 0;
long long ans = 0, cnt = 0;
while (l < n... | 11 |
#include <bits/stdc++.h>
int main() {
long long int n, i, k, p, q, mid, x, y;
scanf("%lld%lld", &n, &k);
p = 1;
q = n;
while (p <= q) {
mid = (p + q) / 2;
x = mid;
y = 0;
while (x > 0) {
y = y + (x % 10);
x = x / 10;
}
if ((mid - y) >= k) {
q = mid - 1;
} else {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int t; cin>>t;
while(t--){
string s; cin>>s;
int ans = 0;
for(int i=1; i<s.size();++i){
if(s[i]==s[i-1]||s[i]==s[i-2])
s[i]='Z', ++ans;
}
cout<<ans<<'\n';
}
return 0;
} | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void getar(T a, int n, int m) {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; ++j) {
scanf("%d", &a[i][j]);
}
}
inline void getar(int *a, int n) {
for (int ii = 0; ii < n; ii++) {
scanf("%d", a + ii);
}
}
inline void ge... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100][100], c[100 * 100];
int main() {
int n, m, d, s(0), k(0), z;
scanf("%d %d %d", &n, &m, &d);
bool t(1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
c[k++] = a[i][j];
}
}
sort(c, c + k);
for (... | 6 |
#include <bits/stdc++.h>
const uint64_t MOD = (uint64_t)1e9 + 7;
uint64_t points[300000];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%I64d", points + i);
std::sort(points, points + n);
uint64_t result = 0, last = points[0], power = 2;
for (int i = 1; i < n; ++i) {
result = (... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const double EPS = 10e-9;
const int MAXCOORD = 200;
const int MAXN = 30;
int n, d;
pair<int, int> v[MAXN];
bool res[MAXCOORD * 3][MAXCOORD * 3][2][2];
bool vis[MAXCOORD * 3][MAXCOORD * 3][2][2];
inline bool checkDist(int x, int y) {
x -= MAXCOO... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, r1, r2, r3;
cin >> a >> b >> c;
r1 = sqrt(a * b / c);
r2 = sqrt(b * c / a);
r3 = sqrt(a * c / b);
cout << 4 * (r1 + r2 + r3);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 5000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;
int dp[MAX][MAX][2];
char A[MAX];
void ADD(int& key, int val) {
key += val;
if (key >= M... | 10 |
#include <bits/stdc++.h>
using namespace std;
const string yes = "YES";
const string no = "NO";
signed main() {
long long tt;
cin >> tt;
while (tt--) {
long long n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
long long ans = 0;
for (long long i = 0; i < n; i++) {
if (s1[i] != s2[i]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long N = 300005;
long long powm(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % 998244353;
a = (a * a) % 998244353;
b >>= 1;
}
return res;
}
long long pow(long long a, long lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int x, long long int n,
long long int m = 1000000007) {
long long int res = 1;
while (n > 0) {
if (n & 1) res = (res * x) % 1000000007;
x = (x * x) % 1000000007;
n >>= 1;
}
return res;
}
void solve() {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
char mapp[N][N];
int r, c;
int dx[5] = {0, 1, 0, -1, 0};
int dy[5] = {1, 0, -1, 0, 1};
int f(int a, int b) { return a ? a : b; }
void dfs(int x, int y) {
if (mapp[x][y] != '*') return;
for (int i = 0; i < 4; i++) {
int x1 = x + dx[i];
int y1 ... | 16 |
#include <bits/stdc++.h>
using namespace std;
string inp;
long long dp[2005];
bool yes[2005][2005];
bool ok(int a, int b) {
int c = b;
for (int i = a; i <= b; i++)
if (inp[i] != inp[c--]) return 0;
return 1;
}
int main() {
memset(dp, 0, sizeof dp);
cin >> inp;
int len = inp.size();
for (int i = 0; i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool test(vector<int> x) {
sort((x).begin(), (x).end());
int sum_x = x[0] + x[1] + x[2] + x[3];
return sum_x % 4 == 0 && (x[1] + x[2]) % 2 == 0 &&
sum_x / 4 == (x[1] + x[2]) / 2 && (x[1] + x[2]) / 2 == x[3] - x[0];
}
int main() {
ios_base::sync_with_stdio(f... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, d[1000005], p[1000005], f[1000005], num[1000005], ans;
inline int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3... | 16 |
/**
* author: milos
* created: 11.04.2021 16:53:22
**/
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
assert(m == 1);
return u;
}
template <... | 6 |
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gcd_helper(long long a, long long b) {
if (a % b == 0)
return b;
else
return gcd_helper(b, a % b);
}
long long gcd(long long a, long long b) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<vector<long long> > v(1);
long long n;
cin >> n;
for (long long i = 0; i < n; ++i) {
long long x;
cin >> x;
v[0].push_back(x);
}
long long ans = 0;
long long ind = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int m, s, p;
m = s = p = 0;
vector<pair<char, int>> hai;
for (int i = 0; i < 3; i++) {
cin >> str;
hai.push_back(make_pair(str[1], str[0] - '0'));
if (str[1] == 'm')
m++;
else if (str[1] == 's')
s++;
else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, h;
int a[1005];
int b[1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n >> h;
for (int i = 0; i < n; i++) cin >> a[i];
int ok = 0;
for (int k = 1; k <= n; k++) {
copy(a, a + k, b... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int maxn = 505;
const int maxm = maxn * max... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
vector<long long> a(N);
long long ans[N];
int main() {
long long n, m, k, i, j, ans = 0;
cin >> n >> m >> k;
vector<pair<long long, long long> > v[k + 1];
bool ok = 1;
long long s = 1;
for (i = 1; i <= n; i++) {
if (ok)
for (j = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0;
char ch, t = 0;
while (!isdigit(ch = getchar())) t |= ch == '-';
while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return x = t ? -x : x;
}
inline long long maxll(long long x, long long y) { return x > y ? x : y; }
inline lon... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
inline void add(long long &a, long long b) {
a += b;
a %= mod;
}
inline void sub(long long &a, long long b) { a = (a - b + mod) % mod; }
int main() {... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long gcdll(long long a, long long b) {
if (!b) return a;
return gcdll(b, a % b);
}
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
void seive(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int vis[N], a[N], n, found;
vector<int> g[N], path;
void dfs(int x) {
if (vis[x] || found) return;
path.push_back(x);
vis[x] = 1;
for (int to : g[x]) {
if (vis[to] == 1) {
found = 1;
reverse(path.begin(), path.end());
whi... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 5;
int isnotprime[Max] = {1, 1, 0};
int prime[Max];
int num = 0;
int b[Max] = {0};
int ind = 0;
int ans = 1;
int m1 = Max;
int m2 = 0;
int pow2[63];
void play_prime() {
for (int i = 2; i < Max; i++) {
if (!isnotprime[i]) prime[num++] = i;
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long k = 0;
k = 2 * ((n)*n);
k = k - 2 * n;
k = k + 1;
cout << k;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a, s, d[403], f[403], g, h = -10000000, j, k, l, i, n, m;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> d[i];
d[n + i] = d[i];
}
for (i = 0; i < n; i++) {
for (j = i + 1; j <= n; j++) {
for (a = 0; a < 2 * n; a++) {
f[a] ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i, j, k, x, p, cnt = 0, fl = 0;
cin >> n >> x;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (i = n - 1; i >= 0; i--) {
cnt++;
if (a[i] * cnt >= x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int good[1000006];
int lca[20][1000006], level[1000006];
vector<int> X[1000006];
void dfs(int i, int par, int lvl) {
level[i] = lvl;
lca[0][i] = par;
for (int j = 0; j < X[i].size(); j++)
if (X[i][j] != par) dfs(X[i][j], i, lvl + 1);
}
int countNodes(int i) {
in... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 50 + 5;
const int maxr = 5000 + 5;
long double dp1[maxn][maxr];
long double dp[maxn][maxr];
int n, r;
int s[maxn], f[maxn];
int postsum[maxn];
int top = 0;
long double p[maxn];
const long double eps = 1e-9;
bool check(long double... | 16 |
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
signed main(){
fast;
int t;
cin >> t;
while (t--){
int n, x;
cin >> n >> x;
vector<int> a(n);
for(int i = 0; i < n; i++)
cin >> a[i];
int summ = 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1E6;
const int MAXN = 3000;
int bal[MAXN + 1];
int sz[MAXN + 1];
vector<int> adjList[MAXN + 1];
pair<int, long long> dp[MAXN + 1][MAXN + 1];
void dfs(int v, int p) {
sz[v] = 1;
for (int adj : adjList[v]) {
if (adj == p) continue;
dfs(adj, v);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, x;
cin >> n >> k;
vector<pair<int, int> > v;
int res = 0;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back({x, i});
}
sort(v.rbegin(), v.rend());
for (int i = 0; i < k; i+... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll mod = 1e9 + 7;
string x = "";
void bin(int n) {
if (n > 1)
bin(n >> 1);
x += to_string(n & 1);
}
void solve() {
ll n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return;
}
... | 0 |
#include <bits/stdc++.h>
int main() {
int n, a, b, i;
char s[10000];
scanf("%d", &n);
scanf("%s", s);
a = strlen(s);
for (i = 0; i < a; i++) {
if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) {
i++;
n--;
}
}
printf("%d", n);
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define x1 first
#define y1 second
#define frb(i,a,b) for(int (i)=(a);(i) <= (b); (i)+=(i)&-(i))
#define rfrb(i,a) for(int (i)=(a);(i) > 0;(i)-=(i)&-(i))
#define fr(i,a,b) for(int (i) = (a); (i) <= (b); (i)++)
#define rep(i,c) for(au... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, d;
cin >> a >> b >> c >> d;
double x = (1 - (a / b)) * (1 - (c / d));
x = (a / b) / (1 - x);
cout << x;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int32_t main() {
double s;
double a, b, c;
cin >> s;
cin >> a >> b >> c;
cout << fixed << setprecision(10);
if ((a + b + c) == 0) {
cout << 0 << " " << 0 << " " << 0 << endl;
return 0;
}
cout << (a * s) / (a + b + c) << " " << (b... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
while (a[i] % 2 == 0) a[i] /= 2;
while (a[i] % 3 == 0) a[i] /= 3;
}
bool f = 1;
for (int i = 0; i < n; +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a, b, pa, push_back, max_, i;
scanf("%lld", &n);
scanf("%lld", &m);
scanf("%lld", &pa);
scanf("%lld", &push_back);
max_ = push_back + (pa - 1);
for (i = 0; i < m - 1; i++) {
scanf("%lld", &a);
scanf("%lld", &b);
if (abs... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve(long long n, long long a, long long b, long long x1,
long long flag) {
if (((n % (a + b)) <= a - 1 && (n % (a + b)) >= 1) ||
(b + 1 <= (n % (a + b)) && (n % (a + b)) <= a + b - 1))
cout << "DRAW" << endl;
else {
if (n % (a + b) == 0)
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000006;
int n;
int a[maxn];
vector<int> v;
long long cost(int p) {
long long ret = 0;
for (int i = 0; i < v.size(); i += p) {
int median = v[(i + i + p - 1) / 2];
for (int j = i; j < i + p; ++j) ret += abs(v[j] - median);
}
return ret;
}
in... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int pre[maxn], suf[maxn], a[maxn], now, n, MOD, ans;
set<int> s;
int main() {
scanf("%d%d", &n, &MOD);
for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
for (int i = (1); i <= (n); i++) {
now = (now + a[i]) % MOD;
pre[i] = now;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 8;
void confirm_a_rectangle(long long &x1, long long &y1, long long &x2,
long long &y2) {
long long op, tptr, mid;
mid = x1;
tptr = x2;
if (x1 + 1 < tptr)
cout << "? " << x1 + 1 << " " << y1 + 1 << " " << x2 << " "... | 14 |
#include <bits/stdc++.h>
const int N = 2e5 + 5;
double dp[N];
int t[N];
double sum[3][N];
double getVal(int l, int r) {
return sum[1][r] - sum[1][l - 1] -
sum[0][l - 1] * (sum[2][r] - sum[2][l - 1]);
}
void solve(int l, int r, int pl, int pr) {
if (l > r) return;
int mid = (l + r) >> 1;
double ans = 1e... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n / 2; i++) {
int temp = a[i];
a[i] = a[n - 1 - i];
a[n - 1 - i] = temp;
}
for (int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long dp[4000000];
long long GCD(long long a, long long b) { return a == 0 ? b : GCD(b % a, a); }
long long F(long long from, long long to, long long base, long long k) {
from = from - (to / base) * base;
to = to % base;
for (int i = 0; i < 4000000; i++) dp[i] = b... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long p) {
if (b < 0) return 0;
long long res = 1;
a %= p;
for (; b; b >>= 1) {
if (b & 1) res = res * a % p;
a = a * a % p;
}
return res;
}
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
bit... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m = 1000000007) {
if (b == 0) return 1;
if (b == 1) return a;
long long res = power(a, b / 2, m);
res = (res * res) % m;
if (b & 1) res = (res * a) % m;
return res;
}
long long modinv(long long a, long long m =... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
long long h = 0;
if (s[0] == '-') h = 1;
if (s[0] == '-') s.erase(s.begin());
string b = "128", i = "2147483648", sh = "32768", l = "9223372036854775808";
if (h) {
if ((s... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100000 + 1], sq, st[1000 + 1][1000 + 1], top[1000 + 1], lpr1[1000 + 1],
mx, to[1000 + 1];
long long ans = 0, lpr2[1000 + 1], b[100000 + 1];
int vis[100000 + 1];
template <class T>
void read(T &x) {
char ch;
bool ok;
for (ok = 0, ch = getchar(); !isdigit(c... | 24 |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
using namespace std;
const int N = 153, LG = 31;
struct Matrix {
int n, m;
bitset<N> A[N], B[N];
inline Matrix(int _n = 0, int _m = 0) {
n = _n;
m = _m;
for (int i = 0; i < N; i++) A[i] = B[i] = 0;
}
inline Ma... | 19 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
template <typename T>
inline void write(T x) {
int i = 20;
char buf[... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
int n;
string s[MAX];
vector<int> dp[MAX];
vector<int> ord[MAX];
vector<int> lcp[MAX], lcp_l[MAX], lcp_r[MAX];
vector<int> lcp_self[MAX];
void pre_lcp()... | 20 |
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> tree[100005];
int depth[100005];
int parent[100005][20];
int type[100005][20];
int par[100005];
int comp[100005];
int CC;
void dfs(int cur, int prev) {
comp[cur] = CC;
depth[cur] = depth[prev] + 1;
parent[cur][0] = prev;
for (int i = 0; i < tree[c... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int n, m, s;
long long pos(long long a, long long b) { return (m - a + 1) * (n - b + 1); }
bool check(int a, int b, int c, int d, int x0, int y0) {
if (x0 - a < 1 || x0 + a > m) return false;
if (x0 - c < 1 || x0 + c > m) return false;
if... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5;
std::vector<int> g[N];
int n;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
ll d;
return b == 0 ? (x = 1, y = 0, a)
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int ans[300005];
void dfs(int x, int now) {
ans[now]++;
if (a[x] == now)
return;
else
dfs(a[x], now);
}
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n;
memset(ans, 0, sizeof(ans));
scanf("%d", &n);
for (int i = 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, y1, x2, y2, x, y;
cin >> x1 >> y1 >> x2 >> y2 >> x >> y;
if ((x2 - x1) % x == 0 && (y2 - y1) % y == 0) {
if (abs((x2 - x1) / x) % 2 == abs((y2 - y1) / y) % 2)
cout << "YES";
else
cout << "NO";
} else
cout << "NO";
retur... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int INF = 1e9 + 7;
const double eps = 1e-10;
int N, M, K, T = INF, Cases = 0;
int a[MAXN];
int fodd[5] = {0, 1, 0, 1, 2}, feven[5] = {0, 1, 2, 0, 1};
int ans;
int *p;
int sg(int x) {
if (x < 5)
return p[x];
else if ((K & 1) == 0)
r... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000], sum[100000], ans_l, ans_r, ans, num;
bool cut[100000];
map<long long, int> MAP;
int main() {
long long i, j, k, n;
scanf("%I64d", &n);
memset(cut, 0, sizeof(cut));
memset(sum, 0, sizeof(sum));
for (i = 1; i <= n; i++) {
scanf("%I64d", &a[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
long long f[maxn], a[maxn];
int n;
map<long long, long long> pre, sum;
vector<long long> ans;
void fir() {
int st = 1;
while (st <= n) {
sum.clear();
pre.clear();
stack<long long> s;
int ww = n + 1;
for (int& i = st; i <= n... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
inline int read() {
int sum = 0, p = 1;
char ch = getchar();
while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 312345;
vector<int> v[N];
int read() {
int x;
scanf("%d", &x);
return x;
}
bool used[N];
bool a[N];
void dfs(int x) {
int cnt = 0;
for (int i = 0; i < v[x].size(); i++) {
if (a[x] == a[v[x][i]]) cnt++;
}
if (cnt >= 2)
a[x] = 1 - a[x];
e... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const int MOD = 1e9 + 7;
const int oo = 1e9 + 100;
const long double EPS = 1e-9;
int n;
int a[MAXN], b[MAXN];
int main() {
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; ++i) scanf("%d", a + i);
for (int i = 0; i < n; ++i) scanf(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ea = 0;
int eb = 0;
int aa = 0;
string tmp;
cin >> tmp;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i] == 'a') {
aa++;
ea = max(ea + 1, eb + 1);
}
if (tmp[i] == 'b') {
eb = max(aa + 1, eb + 1);
}
}
cout <... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a((int)1e5 + 5);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
int max_val = 0, sum = 0, cnt = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i], max_val = max(max_val, a[i]);... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.