solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 9;
const long long int Q1 = 691504013;
const long long int Q2 = 308495997;
const long long int Q3 = 276601605;
long long int power(long long int a, long long int n) {
if (n == 0) return 1ll;
if (n == 1) return a % MOD;
long long int q =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int include(vector<int> &arr, int bits, int A, int B) {
if (B <= A) return 0;
if (bits == 0) return 1;
int mask = 1 << (bits - 1);
int lo = A, hi = B;
int cutoff = B;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if ((arr[mid] & mask) == 0) {
lo = mi... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1), EPS = 1e-9;
const int N = 1e5 + 9;
int main() {
int n, h;
cin >> n >> h;
double s = h / 2. / n;
double b = 0;
for (int i = 1; i < n; i++) {
double... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b;
cin >> a >> b;
if (gcd(a, b) > 1)
printf("Impossible\n");
else {
while (a && b) {
if (a > b) {
printf("%lldA", (a - 1) / b)... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct nd {
long long a, b, ind;
};
bool cmp(nd a, nd b) {
if (a.b < b.b)
return 1;
else if (a.b > b.b)
return 0;
return a.a > b.a;
}
int n, p, k;
vector<nd> vec;
string st;
int main() {
cin >> n >> p >> k;
vec.resize(n);
for (int i = 0; i < n; i++) ci... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3010, M = 4e5 + 5, inf = 1e9 + 7;
char B[1 << 14], *S = B, *T = B;
inline int read() {
int x = 0, f = 1;
char ch =
(S == T && (T = (S = B) + fread(B, 1, 1 << 14, stdin), S == T) ? -1
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x[5010];
long long dp[2][5010], sum[5010];
struct node {
long long p;
int c;
} a[5010];
bool cmp(node a, node b) { return a.p < b.p; }
deque<node> q;
int main() {
scanf("%d%d", &n, &m);
int s = 0;
for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
sort(x... | 18 |
#include <bits/stdc++.h>
namespace fastIO {
template <typename T>
inline T read() {
T f = 1, x = 0;
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;
}
template <typename T>
inline void... | 2 |
#include <bits/stdc++.h>
using namespace std;
int c[101];
long long int mat[101];
void process() {
mat[0] = 0;
for (int i = 1; i < 101; i++) {
for (int j = 1; j < 101; j++) {
if ((i - j) >= 0)
mat[i] = (mat[i] + (c[j] * (1 + mat[i - j]))) % 1000000007LL;
}
}
}
void mulSquareMatrix(long long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long maxn = 5e5 + 10;
int prime[maxn];
bool vis[maxn];
long long phi[maxn];
int miu[maxn];
vector<long long> fac[maxn];
void Euler() {
long long i, j, cnt = 0;
vis[0] = vis[1] = 0;
for (i = 2; i < maxn; i++) {
if (!vis[i]) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.141592653589793238;
const int M = 1e9 + 7;
const int Nmax = 5005;
const int MM = 1e7 + 1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) {
set<string> ss;
string s;
cin >> s;
int day[12] = {... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, maxSize, maxWaste, currentWaste = 0, t = 0, orangeSize;
cin >> n >> maxSize >> maxWaste;
for (int i = 0; i < n; ++i) {
cin >> orangeSize;
if (orangeSize <= maxSize) {
if (currentWaste > maxWaste) {
currentWaste = 0;
t+... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q, i, j, n, p1, pn;
cin >> q;
long long a[201] = {0};
for (i = 0; i < q; i++) {
cin >> n;
for (j = 0; j < n; j++) {
cin >> a[j];
if (a[j] == 1) p1 = j;
if (a[j] == n) pn = j;
}
int flag = 0;
long long c = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
long long odd = 0, even = 0;
cin >> n;
long long no[n];
for (int i = int(0); i < int(n); i++) {
cin >> no[i];
if (no[i] % 2 == 0)
even++;
else
odd++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b, long long m) {
if ((a += b) >= m) a -= m;
return a;
}
long long mult(long long a, long long b, long long m) {
long long res = 0;
while (b) {
if (b & 1) res = add(res, a, m);
a = add(a, a, m);
b >>= 1;
}
return ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10, B = 31, MOD = 1e9 + 9;
long long h[MAXN], t[MAXN];
int n, k, p[MAXN];
string s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> s;
h[0] = s[0] - 'a' + 1;
for (int i = 1; i < n; i++)
h[i] = ((h[i - 1] * B) % MOD... | 14 |
#include <bits/stdc++.h>
using namespace std;
void Print() { cout << endl; }
template <typename T1, typename... T>
void Print(const T1 &t1, const T &...t) {
cout << t1 << " ";
Print(t...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << ", " ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, l1, l2, k, num = 0, q = 0, j;
string s1, s2, s3;
cin >> s1 >> s2;
l1 = (s1).size();
l2 = (s2).size();
i = 0;
while (i < l1 && i < l2 && (s1)[i] == (s2)[i]) i++;
if (i == min(l1, l2)) {
k = i;
if (l1 <= l2) {
for (i = k; i < ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, x, y, c, q;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
c = x * y;
q = floor(pow(c, 1 / 3.0) + 0.5);
if ((q * q * q == x * y) && (x % q == 0) && (y % q == 0)) {
cout <<... | 9 |
#include <bits/stdc++.h>
const int MaxColumnsCount = 10;
const int MaxRowsCount = 10;
const int MaxLevelsCount = 1000;
using namespace std;
int main() {
unsigned int rows_count;
unsigned int columns_count;
unsigned int levels_count;
unsigned int diff_weight;
char levels[MaxLevelsCount][MaxRowsCount][MaxColumn... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
int maxv[210000 << 2], pushdowntag[210000 << 2];
void pushdown(int o) {
maxv[o << 1] = max(maxv[o << 1], pushdowntag[o]);
maxv[o << 1 | 1] = max(maxv[o << 1 | 1], pushdowntag[o]);
pushdowntag[o << 1] = max(pushdowntag[o], pushdowntag[o <... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct bien {
int sl, gt;
};
bien mang[110];
int n;
int x;
int chaym, dp[110];
int kq;
void tinhtong() {
int i;
int tong;
tong = 0;
for (i = 0; i < chaym; i++) {
if (mang[i].gt == 0) {
tong += mang[i].sl;
dp[i] = tong;
}
}
}
void solve() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 110;
int num[Maxn];
int main() {
int n;
int i, j, k;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &num[i]);
int l = 1, r = n, mmin = abs(num[1] - num[n]);
for (i = 1; i < n; i++) {
if (mmin > abs(num[i] - num[i + 1])) {
mmin =... | 0 |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
for(int i=0;i<=4;i++){
string t1=s.substr(0,i);
string t2=s.substr(n-4+i);
string ans=t1+t2;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
vector<pair<int, int>> v(n);
vector<vector<bool>> w(n);
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
}
for (int i = 0; i < n; i++) {
w[i].resize(4);
for (int j = 0; j < n; j++) {
if (v[j... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t;
long long n, m;
long long k;
void read() { cin >> t; }
int main() {
while (~scanf("%lld%lld%lld", &n, &m, &k)) {
if (k == 0)
printf("1 1\n");
else {
if (k < n) {
printf("%lld 1\n", k + 1);
} else if (k < n + m - 1) {
printf... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
const int inf = 1e9;
inline int read() {
register int s = 0;
register bool neg = 0;
register char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-');
for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), c = getchar())
... | 20 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int res = 0;
char c;
while ((c = getchar()) < '0' || c > '9')
;
while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar();
return res;
}
const int N = 4010;
struct st {
long long v, d, p;
} a[N];
int ans[N];
bool out[N];
queue<in... | 10 |
#include <bits/stdc++.h>
using namespace std;
class Fenwick {
public:
Fenwick(int n) {
storage.resize(n + 1);
this->n = n;
for (int i = 1; i <= n; i++) {
insert(1, i);
}
}
int sum(int i) {
int result = 0;
for (; i > 0; i -= i & -i) result += storage[i];
return result;
}
void... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int MOD = 1000000007;
int q, sum;
int p[MAXN];
long long sol;
int pot[MAXN], nck[MAXN][22], dp[MAXN][22];
int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19};
set<int> s;
set<int>::iterator it;
vector<int> g[MAXN];
int add(int a, int b) {
if (a + ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, sum;
cin >> n;
if (n % 2 == 0) {
n = n / 2;
sum = (n * (n + 1)) - n * n;
cout << sum;
} else {
n = (n + 1) / 2;
sum = ((n - 1) * n) - n * n;
cout << sum;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a[10005] = {0}, i, l, r, x, count = 0;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
while (m--) {
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
count = 0;
for (i = l; i <= r; i++) {
if (a[i] < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans;
long long ar[100000];
long long sum[100000];
long long GCD(long long x, long long y) {
if (!y) return x;
return GCD(y, x % y);
}
int main() {
scanf("%I64d", &n);
for (long long i = 0; i < n; i++) scanf("%I64d", &ar[i]);
sort(ar, ar + n);
sum[0]... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long bigMod(long long x, long long y) {
if (y == 1) return x;
long long res = bigMod(x, y / 2LL);
res *= res;
res %= MOD;
if (y % 2) {
res *= x;
res %= MOD;
}
return res;
}
int n, k, x;
long long a[5005];
long long dp[2]... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
bool ispoweroftwo(long long n) { return n & (!(n & (n - 1))); }
long long mod = 1000000007;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, -1, 0, 1};
bool test = 0;
const long long inf = 1e18;
const long... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct Mat {
int n, m;
long long mat[55][55];
Mat() {
memset(mat, 0, sizeof(mat));
n = m = 55;
};
};
Mat operator*(Mat a, Mat b) {
Mat c;
c = Mat();
c.n = a.n, c.m = b.m;
for (int i = 1; i <= a.n; i++) {
for (int j = 1; j <= b.m; j++) {
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int INF = 1e9;
int n;
int a[MAXN];
char str[MAXN];
int solve(int c) {
int mid1, mid2;
int ret = 0;
for (int l = 1, r = n; l <= r; l++, r--) {
while (a[l] == c) l++;
while (a[r] == c) r--;
ret += 2;
mid1 = l, mid2 = r;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 200010;
void sol() {
int n;
cin >> n;
vector<vector<int>> g(n);
vector<int> deg(n, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
while (x--) {
int j;
cin >> j;
--j;
g[j].push_back(i);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long ans = 0;
while (k % 2 == 0) {
k /= 2;
ans++;
}
cout << ans + 1;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, u[N], v[N], m, a[N], b[N], g[N], f[N];
vector<int> adj[N];
int par[N];
void dfs(int x, int p) {
par[x] = p;
for (int y : adj[x]) {
if (par[y] == 0) {
dfs(y, x);
}
}
}
int lca(int x, int y) {
vector<int> vx;
vector<int> vy;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const double eps = 1e-10;
struct P {
double x, y;
P() {}
P(double _x, double _y) {
x = _x;
y = _y;
}
P operator+(const P &a) const { return P(x + a.x, y + a.y); }
P operator-(const P &a) const { return P(x - a.x, y - a.y); }
P ope... | 23 |
#include <bits/stdc++.h>
int main() {
int h, w, H, W;
std::cin >> W >> H >> w >> h;
std::cout << H + H + 2 + W + h + h + w + 2 + W - w;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
void read(vector<T>& a);
template <class T>
void read(T& a) {
cin >> a;
}
template <class A, class... B>
void read(A& a, B&... b) {
read(a);
read(b...);
}
template <class T>
void read(vector<T>& a) {
for (auto& v : a) read(v)... | 9 |
#include <bits/stdc++.h>
using namespace std;
int x[26];
int main() {
string s;
int n, i, k, cnt = 0;
cin >> n >> k;
cin >> s;
if (n == 1) return 0 * printf("1");
char c = s[0];
for (i = 0; i < n; ++i) {
if (c == s[i])
cnt += 1;
else
cnt = 1;
c = s[i];
if (cnt == k) cnt = 0, x[... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int MAXN = 200005;
int n, m, q;
int uf[MAXN];
int find(int x) { return uf[x] = x == uf[x] ? x : find(uf[x]); }
int merge(int x, int y) {
int xr = find(x);
int yr = find(y);
if (xr == y... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int d[maxn];
int n;
int cnt0, cnt1;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i];
if (d[i] == 0) cnt0++;
if (d[i] == 1) cnt1++;
}
for (int i = 1; i <= n; i++) {
if (d[i] == 0)
cnt0--;
else
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 5e8;
const int N = 1010000;
const int P = 1000000007;
const double eps = 1e-7;
template <typename T>
inline void sc(T &x) {
x = 0;
static int p;
p = 1;
static char c;
c = getchar();
while (!isdigit(c)) {
if (c == '-') p = -1;
c = getchar()... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-25, inf = 2e+15;
pair<int, int> v[200010], v1[200010];
map<pair<int, int>, char> sol;
int v2[200010];
int cmp(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first)
return a.second > b.second;
else
return a.first < b.first;
}
in... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void maxi(T &x, T y) {
if (y > x) x = y;
}
template <class T>
inline void mini(T &x, T y) {
if (y < x) x = y;
}
const int N = 1e6 + 5, B = 0x7fffffff;
vector<string> si;
char s[N];
string ss = "";
vector<string> lvl[N];
bool vis[N];
int ma;
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, z;
} ob[100010];
bool cmp(node a, node b) { return a.z < b.z; }
int n, f[100010], size[100010], sum, x[100010];
int find(int x) {
if (f[x] == x) return x;
return f[x] = find(f[x]);
}
void ini() {
scanf("%d", &n);
for (int i = 1; i < n; i++)... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 2 == 0) {
cout << n / 2 << endl;
} else {
cout << -(n + 1) / 2;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
long long n, k;
int main() {
scanf("%lld%lld", &n, &k);
int cnt10 = 0;
int cnt2 = 0;
int cnt5 = 0;
long long m = n;
while (1) {
if (m % 10 == 0) {
cnt10++;
m /= 10;
} else
break;
}
while (1) {
if (m % 5... | 3 |
#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++;
}
inline int read() {
register int x = 0, f = 1;
register char ch = getchar();
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 100 * 200 + 2, maxm = 20, SQ = 1000,
inf = 1000 * 100 * 100 * 100, mod = 1000 * 1000 * 1000 + 7,
base = 255;
vector<string> v;
int main() {
for (int a = 0; a <= 9; a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 1e5 + 10;
bool g[2010][2010];
int ans[2010][2010];
int n, m;
void dfs(int r, int c) {
if (r <= 0 || r > n || c <= 0 || c > m) return;
if (g[r][c]) return;
bool prop = 0;
if (g[r - 1][c] && g[r][c - 1] && g[r + 1][c] && !g[r][c + 1]) {
ans[r][c] = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int MAX = 1e6 + 10;
char S[MAX];
char L[MAX];
char R[MAX];
int main() {
scanf("%s", S);
int n = strlen(S);
int left = 0, right = n - 1;
int t = 0;
while (true) {
if (left + 1 >= right - 1) break;
if (S[le... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 222;
const int INF = 1000000000, mod = 1000000007;
const long long LLINF = 1000000000000000000ll;
double a, d;
int n;
void make_new(double& x, double& y, int go, double di) {
switch (go) {
case 0:
x = di;
y = 0;
break;
case 1:
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int k, aa, bb, v;
int main() {
scanf("%d%d%d%d", &k, &aa, &bb, &v);
for (int a = 0; true; a++) {
int t = min(k - 1, bb);
bb -= t;
aa -= (t + 1) * v;
if (aa <= 0) {
printf("%d\n", a + 1);
return 0;
}
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int n, m, k, q;
vector<int> g[maxn];
int in[maxn], out[maxn];
int vis[maxn];
int dfs_clock;
void dfs(int u) {
in[u] = ++dfs_clock;
for (int i = 0; i < g[u].size(); i++) {
dfs(g[u][i]);
}
out[u] = dfs_clock;
}... | 19 |
#include <bits/stdc++.h>
using namespace std;
int N, i, A[310], B[310], j;
vector<int> SOL;
int main() {
cin >> N;
for (i = 1; i <= N; i++) cin >> A[i];
for (i = 1; i <= N; i++) cin >> B[i];
for (i = 1; i <= N; i++) {
if (A[i] == B[i]) continue;
for (j = i + 1; j <= N; j++)
if (B[j] == A[i]) break... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1234567;
char ch[maxn];
bool used[5];
vector<int> V;
void DYGANDQYM() {
V.clear();
memset(used, 0, sizeof(used));
int sumz = 0;
int len = strlen(ch + 1);
for (int i = 1; i <= len; i++) {
if (ch[i] == '0') {
sumz++;
continue;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
class SA_IS {
vector<int> compress(vector<int>& v) {
set<int> alph(v.begin(), v.end());
vector<int> dic(alph.begin(), alph.end());
vector<int> bucket_size(dic.size(), 0);
for (int i = 0; i < v.size(); i++) {
v[i] = lower_bound(dic.begin(), dic.end(),... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1.0);
const int maxn = 200009;
const int maxm = 1000009;
long long a[maxn], dp[maxn];
int main() {
long long n;
while (cin >> n) {
long long ans = 0;
for (int i = 1; i <= n; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> a;
pair<string, int> get(string s) {
int c1 = 0, c2 = 0;
for (int i = 0; i < (int)(s.length()); i++)
if (s[i] == '&')
c1++;
else if (s[i] == '*')
c2++;
return make_pair(s.substr(c1, s.length() - c1 - c2), c2 - c1);
};
int main() {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string q;
cin >> q;
string Q = q;
double n = q.size();
for (int i = 0; i < n; i++) {
Q[i] = toupper(q[i]);
}
int x = 0;
for (int i = 0; i < n; i++) {
if (q[i] != Q[i]) {
x++;
}
}
if (x < n / 2.0) {
cout << Q;
} else {... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vi;
const int mod = int(1e9) + 7, INF = 0x3fffffff;
const int maxn = 1e5 + 13;
int main(void) {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
int a, b, c, d;
cin >> a >> b >> c >> d;
bool ok = false;
if (n == 4... | 8 |
#include <bits/stdc++.h>
using namespace std;
int static_init = []() {
ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
return 0;
}();
vector<int16_t> a, ans, c;
void Op(int i, int mex) {
--c[a[i]];
++c[mex];
a[i] = mex;
ans.push_back(i + 1);
}
int main() {
int t, n;
cin >> t;
while (--t >... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int c = 0, a, b, j, i;
cin >> a >> b;
int ar[a], sum = 0;
for (i = 0; i < a; i++) {
cin >> ar[i];
sum = sum + ar[i];
}
if (a == b && a != 2) {
cout << 2 * sum << "\n";
for (i =... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(nullptr)
#define INF (1LL<<62)-1
#define F first
#define S second
#define pb push_back
int main()
{
FASTIO;
ll t;
cin>>t;
while(t--)
{
ll a,b,c;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int o, c, h;
scanf("%d %d", &c, &o);
if (o == 1 && c == 0) {
printf("YES");
return 0;
} else if (o > 1) {
h = o - 1;
if (c < h) {
printf("NO");
return 0;
} else {
if ((c - h) % 2 == 0) {
printf("YES");
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const long long inf = (long long)1e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
int n, m, len[N], can[N], used[N];
vector<int>... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, m;
set<int> s;
while (cin >> a >> m) {
s.clear();
while (1) {
if (a == 0) {
cout << "Yes" << endl;
break;
} else if (s.count((a + a) % m)) {
cout << "No" << endl;
break;
} else {
a =... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, k = 0, t;
cin >> t;
while (t--) {
cin >> a >> b;
k = b - a;
if (k == 0) {
cout << "0";
} else if (k > 0) {
if (k % 2)
cout << "1";
else
cout << "2";
} else {
k = -k;
if (k % 2)
... | 0 |
#include <bits/stdc++.h>
#define N 300005
#define K 20
using namespace std;
vector<int> adj[N];
vector<int> paths[N];
int par[N][K];
int dep[N];
map<pair<int,int>,int> mp[N];
map<int,int> mp2[N];
vector<pair<int,int>> lc[N];
vector<pair<int,int>> pa;
int up[N],up2[N];
void dfs(int v,int p){
par[v][0] = p;
dep[v... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 85 - 69;
int a[maxn], b[maxn], c[maxn], ss[maxn], t, k, n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> t >> k;
for (int i = 0; i < t; i++) cin >> a[i];
int sum = 0;
for (int i = t - 2; i >= 0; i--) {
c[i] = m... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, T, f[222][111], g[111][111], a[111], cnt[333];
int main() {
ios::sync_with_stdio(0);
cin >> n >> T;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
int m = min(n, T);
for (int i = 1; i <= m * 2; i++)
for (int j = 1; j <= n; j++) {
... | 11 |
#include <bits/stdc++.h>
int MinD(int n) {
std::vector<int> d(n);
d[0] = 0;
for (int i = 1; i < n; ++i) {
d[i] = d[(i - 1) / 2] + 1;
}
return std::accumulate(d.begin(), d.end(), 0);
}
int MaxD(int n) { return n * (n - 1) / 2; }
const int N = 668;
const int D = 5000;
int min_d[N + 1], max_d[N + 1];
std::pa... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i, n, ans = 0, j;
long double t;
cin >> n >> t;
long double g[n + 1][n + 1];
memset(g, 0, sizeof(g));
g[0][0] = t;
for (i = 0; i < n; i++) {
for (j = 0; j <= i; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 500 + 5, mod = 998244353;
char a[N][N];
long long sum[N][N];
long long f[N];
long long s(long long lx, long long ly, long long rx, long long ry) {
return sum[rx][ry] - sum[lx - 1][ry] - sum[rx][ly - 1] + sum[lx - 1][ly - 1];
}
signed main() {
ios::sy... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dp[200000][3];
const char kavo[] = "RGB";
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
while (q--) {
int n, k;
string s;
cin >> n >> k >> s;
for (int i = 0; i < n; ++i) dp[i][0] = dp[i][1] = dp[i][2] = 0;
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a == b) {
cout << "-1" << endl;
} else
cout << max(a.size(), b.size()) << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int l, r, mx, pre, suf;
};
vector<node> T;
vector<pair<int, int> > ht;
int n, m, a[100055], root[100055], first, second, z;
int init(int l, int r) {
int ind = T.size();
if (l == r) {
T.push_back({-1, -1, 1, 1, 1});
return ind;
}
int mid = (l ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 12;
int a[maxn][maxn], mxcnt[maxn][maxn];
string ans[maxn][maxn];
void dfs(int i, int j, int n, int m, int cnt, int spa) {
if (cnt + spa / 5 - 1 < mxcnt[n][m]) return;
if (i == n) {
if (cnt - 1 < mxcnt[n][m]) return;
mxc... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long t, w, b;
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 / gcd(a, b) * b; }
int check(long long a, long long b, long long c) {
if (log(a * 1.0) + log(b * 1.0) - log(gcd(a, b) * 1.0... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
void read(int &x) {
char ch = getchar();
x = 0;
for (; ch < '0' || ch > '9'; ch = getchar())
;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int ans;
char a[555][555];
int c[555][555], b[555][555];
int main() {
scanf("%d%d",... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 50;
const int inf = 0x3f3f3f3f;
void print(int a) {
int i = 1, ju = 0;
while (i < a) i <<= 1;
while (i) {
if (i & a) {
putchar('1');
ju = 1;
} else if (ju)
putchar('0');
i >>= 1;
}
}
int n, allstate;
long long a[1... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
set<long int> s;
long int n, i;
cin >> n;
long long a[n], b[n], c[n], ans = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
b[i] = s.size();
}
if (n == 1)
cout << "0";
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
string s, str = "";
int n;
int bal = 0, cnt1 = 0, cnt2 = 0;
cin >> n;
cin >> s;
s.push_back('_');
reverse((s).begin(), (s).end());
s.push_back('_');
reverse((s).begin(), (s).e... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long one[5] = {0}, zero[5] = {0};
int main() {
long long n, i, j, k, on, ze, a, s, ans = 0;
cin >> n;
char line[200];
getchar();
for (i = 0; i < 4; i++) {
on = ze = s = 0;
for (j = 0; j < n; j++) {
scanf("%s", line);
for (k = 0; k < n; k++... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int M = 1e6 + 7;
const int lim = 2e6;
const int p = 998244353;
const int inf = 0x3f3f3f3f;
struct Node {
int a, x, y;
} sz[N];
int vis[807], num[807];
bool cmp(Node s, Node t) { return s.a > t.a; }
int main() {
int n, cnt = 0, m;
scanf("%d... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1 = 600;
int x2 = -1;
int y1 = 600;
int y2 = -1;
int x, y;
char P[505][505];
cin >> x >> y;
int br = 0;
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++) {
cin >> P[i][j];
if (P[i][j] == 'X') {
x1 = min(i, x1... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
int main() {
int n, m, k;
cin >> n >> m >> k;
printf("%d\n", m * (m - 1) / 2);
if (k == 0) {
for (int i = 1; i <= m; i++)
for (int j = i + 1; j <= m; j++) printf("%d %d\n", i, j);
} else {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool check(double x1, double y1, double x2, double y2, double x3, double y3) {
double a = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
double b = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
double c = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
double aa = s... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const int maxn = 1e6 + 5;
int n, a[maxn], w[maxn], dp[maxn][2];
vector<int> g[maxn];
long long ans = 0;
long long cur = 0;
void dfs(int at, int p) {
dp[at][w[at]] = 1;
if (w[at] == 1) cur++;
for (... | 13 |
#include <bits/stdc++.h>
#pragma optimise GCC(-O2)
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
long long INF = LLONG_MAX;
const long long M = 1000000007;
long long po... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
#pragma warning(disable : 6031)
#pragma warning(disable : 4244)
#pragma warning(disable : 26451)
#pragma GCC target("sse4.2")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long mod = int(1e9) + 7;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, loc;
long long ans;
string s, p, s1, s2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
bool flag = (s[0] == 'R') && (isdigit(s[1]));
loc = s.find('C');
if (flag && loc > 0) {
s1 = s.substr(1, loc - 1);
s2 = s.... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, t, a, b, c, d, x, y, k;
cin >> t;
for (i = 0; i < t; i++) {
cin >> a >> b >> c >> d >> k;
if (a % c == 0) {
x = (a / c);
} else {
x = (a / c) + 1;
}
if (b % d == 0) {
y = (b / d);
} else {
y = (b / d)... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sz(a) ((a).size())
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define mem(a,val) memset(a,val,s... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
int ans1[200010], ans2[200010], sz[200010];
vector<int> son[200010];
void rec1(int i, bool small) {
if (son[i].size() == 0) {
ans1[i] = 1;
sz[i] = 1;
} else {
for (auto x : son[i]) {
rec1(x, !small);
sz[i] += sz[x];
... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.