solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct SUFNode {
SUFNode *par, *nxt[4];
int val;
void init(int _val = 0) {
par = NULL;
for (int i = 0; i < 4; i++) nxt[i] = NULL;
val = _val;
}
void copyfrom(SUFNode *from) {
par = from->par;
for (int i = 0; i < 4; i++) nxt[i] = from->nxt[i];
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
long long int a, count = 0;
cin >> n;
while (n--) {
cin >> a;
while (a > 1) {
if (a % 2 == 0) {
a = a / 2;
count++;
} else if (a % 3 == 0) {
a = (2 * a) / 3;
count++;
} else if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int que1[100005], que2[100005];
long long a[100005], b[100005];
int main() {
long long n, k, i;
while (cin >> n >> k) {
long long sum = 0;
if (n == 0) cout << "End of line";
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
sum += ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int c = 14;
int n, dp[1 << c][1 << 7][c], m, k, s, valt[1 << c];
long long ans[1 << c];
bool v[c][c];
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
m = (1 << n), k = (1 << (n / 2)), s = n / 2 + 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j ... | 18 |
#include <bits/stdc++.h>
int main() {
int n, a, c = 0;
std::cin >> n;
int b[n];
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
std::sort(b, b + n);
for (int i = 1; i < n; i++) {
if (b[i] == b[i - 1]) {
b[i]++;
c++;
} else if (b[i] < b[i - 1]) {
a = b[i - 1] - b[i];
b... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, d;
cin >> n >> d;
if (n == 1) {
cout << 1 << '\n';
return 0;
}
d--;
vector<int> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<int> p(n);
for (int i = 0; i < n; i++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 500005;
const int BITS = 20;
const lint INF = 1e18;
int N, K, M;
vector<int> adj[MAXN];
array<int, 3> E[MAXN];
int par[MAXN][BITS];
int depth[MAXN];
int p[MAXN];
int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); }
int GetAn... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[i] = x;
b[i] = y;
}
float min = FLT_MAX;
float c;
for (int i = 0; i < n; i++) {
c = float(a[i] * m) / flo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int cnt[8];
int ccnt[8];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x]++;
ccnt[x]++;
}
int x = 0;
for (int i = 0; i < n / 3; i++) {
int n1 = -1, n2 = -1, n3 = -1;
for (int j = 1; j <= 7; j++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int isprime(long long int n) {
if (n <= 1) return 0;
if (n <= 3) return 1;
if (n % 2 == 0 || n % 3 == 0) return 0;
for (long long int i = 5; i * i <= n; i += 6)
if (n % (i) == 0 || n % (i + 2) == 0) return 0;
return 1;
}
vector<long long int> v;
int ... | 2 |
#include <bits/stdc++.h>
int main() {
int n, x;
int l, r;
int i, j;
int current = 0;
int sum = 0;
scanf("%d %d", &n, &x);
current = 1;
for (i = 0; i < n; i++) {
scanf("%d %d", &l, &r);
r++;
current += (l - current) / x * x;
sum += r - current;
current = r;
}
printf("%d\n", sum);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 0;
const long long MN = 0;
long long mx = MX, mn = MN;
long long x, c, k, n, m, cnt, y, ans;
string s, str;
bool bl;
vector<string> v, vc;
map<char, long long> mp;
set<long long> st;
set<long long>::iterator it;
vector<long long> g[1001];
bool used[1001... | 1 |
#include <bits/stdc++.h>
using namespace std;
int t;
double a, b;
int main() {
scanf("%d", &t);
while (t--) {
cin >> a >> b;
if (b <= 1e-10)
printf("1\n");
else
printf("%.8lf\n", (4 * b - a > 1e-10) ? 0.5 + a / b / 16 : 1 - b / a);
}
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int la, lb;
int a[2000000];
int b[2000000];
int bpos[1000001];
void deb(int* x, int xlow, int xhigh) {
cout << "[";
for (int i = xlow; i < xhigh; i++) {
cout << " " << x[i];
}
cout << " ]";
}
int seen[1000001];
int solve() {
fill(bpos, bpos + 1000001, -1);
f... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long int p[n];
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p, p + n);
if (p[n - 1] < p[n - 2] + p[n - 3]) {
cout << "YES\n";
swap(p[n - 1], p[n - 2]);
for (int i = 0; i < n; i++) cout << p[i] << " ";
} else... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const ll inf = 1e9;
const int N = 2e6 + 66;
int n, a[N], first[N], last[N], x, suffMin[N], prefMax[N], mn[N << 2],
mx[N << 2];
void build(int l = 0, int r = x, int v = 0) {
if (r - l == 1) {
mn[v] = (first[l] ? fir... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 20, M = 998244353, Inv = M / 2 + 1;
long long n, m, cnt[1 << N], g[1 << N];
char s[N][1 << N];
inline void fwt(long long y[], long long m, long long opt) {
for (long long i = 1; i < 1 << m; i <<= 1)
for (long long j = 0, p = i << 1; j < 1 << m; j +... | 18 |
#include <bits/stdc++.h>
using namespace std;
string a, b, st;
int cx, dx, c[500], d[500], maxd, tmp, i;
bool f[1000];
void read_data() {
cin >> st;
for (i = 0; st[i] != ':'; i++) a = a + st[i];
for (i = i + 1; i < st.size(); i++) b = b + st[i];
}
bool can(int i) {
cx = 0;
for (int k = 0; k < a.size(); k++) {... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[5005];
int N, arr[5005], last[5005];
string S;
vector<int> RET;
int solve(int ind) {
int ret = 0;
if (arr[ind] == 5) ret++;
for (int i = ind + 1; i < last[ind]; i++) {
if (arr[i] % 2) {
ret += solve(i);
i = last[i];
}
}
if (arr[ind] == 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, m, l;
scanf("%d%d%d%d", &n, &d, &m, &l);
long long a, b;
for (int i = 1; i <= n; i++) {
a = 1ll * (i - 1) * m + l, b = 1ll * i * m - 1;
if (a / d != b / d) break;
}
printf("%lld\n", a - a % d + d);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int cell[1000][1000] = {0};
cin >> n >> m;
for (register int i = 0; i < n; ++i) {
for (register int j = 0; j < m; ++j) {
cin >> cell[i][j];
}
}
int zeros = 0;
int total_position = 0;
bool there_was_an_actor = false;
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
double v[200010];
double func(double x) {
double mn = 0, mx = 0, a = 0, b = 0;
for (int i = 0; i < n; i++) {
a += v[i] - x;
b += v[i] - x;
mn = min(mn, a);
mx = max(mx, b);
if (a > 0) a = 0;
if (b < 0) b = 0;
}
return max(mx, -mn);
}
i... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solved() {
int n;
cin >> n;
vector<int> ve;
int x;
map<int, int> mp;
for (int i = 1; i <= n; i++) cin >> x, ve.push_back(x), mp[x]++;
sort(ve.begin(), ve.end());
int ans1 = 0, ans2 = 0;
for (int i = 0; i <= 100; i++) {
if (mp[i] < 2) {
ans2 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
string pal;
int a, b, k, div1, mod;
int main() {
scanf("%d%d%d", &k, &a, &b);
cin >> pal;
div1 = pal.size() / k;
mod = pal.size() % k;
if (b * k < pal.size() or a * k > pal.size()) {
printf("No solution");
return 0;
}
for (int i = 0, pos = 0; i < k; i+... | 6 |
#include <bits/stdc++.h>
using namespace std;
double const pi = 3.14159265358979;
int const MAXN = 2000000;
long long const MOD = 1000000007;
long long const INF = 1000000000000000000;
int main() {
string s;
cin >> s;
if (s.length() < 10) {
cout << "NO";
exit(0);
}
for (int i = 0; i < (int)(11); i++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
struct Circle {
double x, y, r;
void read() { scanf("%lf%lf%lf", &x, &y, &r); }
bool operator<(const Circle& t) const { return r < t.r; }
};
int n;
Circle a[maxn];
vector<int> G[maxn];
const double PI = acos(-1.0);
const double eps = 1e-8;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int ans(int w, int h, int k) {
if (k == 0)
return 0;
else {
return (w + h - 2) * 2 + ans(w - 4, h - 4, k - 1);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int w, h, k;
cin >> w >> h >> k;
cout << ans(w, h, k);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long sum4 = count(begin(s), end(s), '4');
long long sum7 = count(begin(s), end(s), '7');
if (sum4 == 0 && sum7 == 0) {
cout << -1 << endl;
exit(0);
}
if (sum4 >= sum7) {
cout << 4 << endl;
} else {
cout <... | 2 |
#include <bits/stdc++.h>
int main() {
long a[100], n, i, d, k, h, min, j, r, tam;
scanf("%ld", &n);
scanf("%ld", &k);
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
d = 0;
h = n - k;
r = n - 1;
min = a[0];
if (n == k) {
for (i = 0; i < n; i++) {
if (a[i] < min) {
min = a[i];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10, mod = 1e9 + 7;
int f[N][N][3], g[N][N][2];
int n, k;
char a[N];
int s[N], t[N];
int main() {
scanf("%d%d", &n, &k);
scanf("%s", a + 1);
for (int i = n; i >= 1; i--) s[i] = a[i] - 'a', t[i] = 'z' - a[i];
f[n + 1][0][1] = 1;
for (int i = n; i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int inf_int = 1e9;
bool debug = 0;
const int MAXN = 5e5 + 5;
vector<int> g[MAXN];
vector<char> g1[MAXN];
vector<int> g2[MAXN];
int siz[MAXN];
int mask[MAXN];
unordered_map<int, int> mp;
int dp[1 << 20];
int h[MAXN];
int st[MAXN], ft[MAXN];
int timer;
int ver[MAXN];
void dfs... | 21 |
#include <bits/stdc++.h>
const int N = 10000000;
int a[10];
int pr[N + 1];
int pal[N + 1];
void gen(int k, int len) {
if (k == (len + 1) / 2) {
int cur = 0;
for (int i = 0; i < len; i++) {
cur = cur * 10 + a[i];
}
pal[cur] = 1;
} else {
for (int i = !k; i <= 9; i++) {
a[k] = a[len - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int tinf = (int)1e9 + 7;
const long long inf = (long long)1e18 + 7;
const int N = 1e5 + 5;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return a.first > b.first;
}
int main() {
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.t... | 8 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
templa... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int n;
int sum = 0;
cin >> t >> n;
while (t--) {
int a;
cin >> a;
sum = sum + a;
}
if (sum < 0) {
sum = -sum;
}
int ans;
if (sum % n == 0) {
ans = sum / n;
} else {
ans = sum / n + 1;
}
cout << ans << end... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
int m, k, n, s, a[maxn], b[maxn], cnt[maxn], vis[maxn], pos, dff, lim, r, del,
rm;
void solve() {
cin >> m >> k >> n >> s;
for (int i = 0; i < m; ++i) {
cin >> a[i];
}
for (int i = 0; i < s; ++i) {
cin >> b[i];
vis[b[i]]++, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long int set_one(long long int a) {
long long int ans = 0;
while (a) {
a = a & (a - 1);
ans++;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
const int Inf = 0x3f3f3f3f;
template <class T>
void Max(T &x, T y) {
x = max(x, y);
}
template <class T>
void Min(T &x, T y) {
x = min(x, y);
}
struct Ed {
int v, n, w;
Ed(int v_ = 0, int n_ = 0, int w_ = 0) : v(v_), n(n_), w(w_){};
};
Ed e[M ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
char c = 'B';
for (int i = 0; i < n; i++) {
string s, ans = "";
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '-')
ans += '-';
else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long m[102][102];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
if (k > n * n) {
cout << "-1\n";
return 0;
}
bool ok = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (k < 0) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<pair<long long, long long> > a;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
long long cur, cur1;
cin >> cur >> cur1;
a.push_back(make_pair(cur, cur1));
}
sort(a.begin(), a.end());
long long cur = a[0].second;
for (int ... | 6 |
#include <bits/stdc++.h>
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
using namespace std;
char a[2001][2001];
vector<pair<long long, long long> > dp[2001];
int x, y, r, c, n, m;
bool visited[2001][2001];
void bfs(int r, int c) {
deque<pair<long long, long long> > q;
q.push_... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4444;
struct hhh {
int a, b, id;
} h[maxn];
int N, tot;
int tmp[maxn];
int dp[maxn], f[maxn], id[maxn][maxn], fa[maxn];
vector<int> vec[maxn], ans[maxn];
void solve(int x) {
int l = h[x].a, r = h[x].b;
dp[l] = 0;
for (int i = l + 1; i <= r; ++i) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int p = 0; p < t; p += 1) {
int n;
cin >> n;
if (n == 1) {
cout << "! " << 1 << " " << 1 << endl;
continue;
}
vector<int> x, y;
for (int i = 1; i < n; i += 2) {
cout << "? " << i << " " << i ... | 10 |
#include<bits/stdc++.h>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define iter(it,v) for(auto it=v.begin();it!=v.end();it++)
#define bloop(i,a,b) for(long long i=a;i>=b;i--)
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsign... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const long long mod = 1000000007;
int n;
long long dp[N], clr[N];
int col[N];
struct Edge {
int v, next;
} es[N * 2];
int head[N], cnt;
long long tot[N];
inline void add_edge(int u, int v) {
es[cnt].v = v;
es[cnt].next = head[u];
head[u] = cnt+... | 12 |
#include <bits/stdc++.h>
using namespace std;
class comp {
public:
bool operator()(int& a, int& b) { return a > b; }
};
bool comp1(pair<int, int> a, pair<int, int> b) { return (a.second < b.second); }
int string_to_int(string s) {
stringstream a(s);
int x;
a >> x;
return x;
}
int gcd(int a, int b) {
if (b ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int dp[5 * 1005][5 * 1005];
vector<int> cols[5 * 1005];
class Solution {
public:
void solve(std::istream& in, std::ostream& out) {
int n, m;
in >> n >> m;
string s;
for (int i = 1; i <= n; i++) {
in >> s;
for (int j = 1; j <= m; j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long comb(long long n, long long m) {
long long r = 1;
for (int i = 1; i <= m; ++i) {
r = r * n-- / i;
}
return r;
}
bool judge(long long n, long long m, long long k) {
long long tot = 0;
for (int i = 0; i <= k; ++i) {
long long c = comb(k, i);
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> b(n, 0);
vector<int> c(n, 0);
int l = a[0], r = a[n - 1];
int l_ind = 0, r_ind = n - 1;
for (int i = 0; i < n; i++) {
if (a[i] <= l + i - l_i... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e6 + 5;
int n, x[N], y[N], seg[4 * N];
void update(int node, int s, int e, int i, int val) {
if (s == e) {
seg[node] = val;
return;
}
int mid = s + e >> 1;
if (i <= mid)
update(node << 1, s, mid, i, val);
else
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void add(int& x, int y) { ((x += y) >= MOD) && (x -= MOD); }
int mul(int x, int y) { return x * 1ll * y % MOD; }
int mpow(int a, int p) {
int res = 1;
for (; p > 0; p >>= 1, a = mul(a, a)) {
if (p & 1) {
res = mul(res, a);
}
}
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
vector<int> arr(n, 0);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
vector<int> marked(n, 0);
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int INF = 1000000005;
int dp[1 << 20];
int d[N];
int W[20][20];
int x[20];
int a[105];
int n, K, L;
inline void checkMin(int &a, const int &b) {
if (b < a) a = b;
}
int main() {
cin >> n >> K >> L;
set<int> M;
M.clear();
for (int i = 0; ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 200000 + 10;
struct node {
node *l, *r;
int value;
};
node *clone(node *u) {
node *ans = new node();
ans->l = u->l, ans->r = u->r, ans->value = u->value;
return ans;
}
node *build(int b, int e) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long N, M, W;
long long h[100010], dis[100010];
bool check(long long H) {
long long cur = 0, dsum = 0;
for (int i = 1; i <= N; i++) {
cur += dis[i];
if (cur < H) {
dsum += H - cur;
dis[i] += H - cur;
if (i + W <= N) dis[i + W] -= H - cur;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, muc[100009][3], v[100009];
void add_vec(int x, int y) { muc[x][++muc[x][0]] = y; }
bool muchie(int x, int y) {
if (x > y) return muchie(y, x);
for (int i = 0; i <= muc[x][0]; i++)
if (muc[x][i] == y) return 1;
return 0;
}
int nr, x[20], y[20], ap[20], fi... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn], t[maxn];
int pre[maxn], suf[maxn];
int len1, len2;
int main() {
scanf("%s%s", s + 1, t + 1);
len1 = strlen(s + 1);
len2 = strlen(t + 1);
int pos = 1;
for (int i = 1; i <= len1; i++) {
if (t[pos] == s[i]) {
pre[pos... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
for (int i = 0; i < 8; i++) {
cin >> s;
char p = s[0];
for (int j = 1; j < 8; j++) {
char c = s[j];
if (p == c) {
cout << "NO" << endl;
return 0;
}
p = c;
}
}
cout << "YES" << endl;
ret... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
ll res = 1;
a = a % MOD;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int a, b, c, m, p, x, y, z;
cin >> a >> b >> c >> m;
x = a;
y = b;
z = c;
p = max({x - y - z, y - x - z, z - x - y});
if (p... | 3 |
#include <bits/stdc++.h>
const int MAX_N = (int)2e5 + 123;
const double eps = 1e-6;
const int mod = (int)1e6 + 3;
using namespace std;
int n;
vector<int> g[MAX_N];
double first[MAX_N];
int sz[MAX_N];
int init(int v) {
sz[v] = 1;
for (auto to : g[v]) sz[v] += init(to);
return sz[v];
}
void dfs(int v, double add = ... | 9 |
#include <bits/stdc++.h>
const int N = 200005;
int key[4 * N][26];
struct P {
int l, r, mid;
} arr[4 * N];
bool u[N];
char s[N], str[105];
void build(int L, int R, int c) {
arr[c].l = L;
arr[c].r = R;
arr[c].mid = (L + R) / 2;
if (L == R) {
key[c][s[L - 1] - 'a'] = 1;
return;
}
build(L, arr[c].mid... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
mt19937 rng(
(unsigned int)chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b) {
long long result = 1;
while (b > 0) {
if (b % 2 == 1) {
result *= a;
}
a *= a;
b /= 2;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[1005];
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int l = 0, r = n - 1;
int suml = 0, sum2 = 0;
int cnt = 0, ansl = 0, ans2 = 0;
while (l <= r) {
if (cnt % 2 ... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("no-stack-protector")
using namespace std;
const long long INF = 1e18;
long long si = 16;
long long dp[1000000], dp2[1000000];
vector<pair<double, long long>> deq;
vector<pair<long long, long long>> vec;
vector<pair<long long, long long>> vec2;
si... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int n, m;
int d[MAXN];
struct Edge {
int to, id;
};
vector<Edge> G[MAXN];
int vis[MAXN] = {0};
vector<int> ans;
void solve(int u) {
vis[u] = true;
vector<Edge> ds;
for (auto v : G[u]) {
if (vis[v.to]) continue;
solve(v.to);
if (d... | 13 |
#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
int n, t;
long long a, b, f[N];
int dp1[110][2], dp2[110][2];
int dfs1(int a, int b, long long c) {
if (a == 1) return c + b == 2;
if (a == 0) return 0;
int &ret = dp1[a][b];
if (ret + 1) return dp1[a][b];
if (b) {... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, k, w;
int LINK[600005], ed[600005], l[300005];
int T[300005], ANS[300005], Q[300005], P[300005], ans[300005], q;
void bd(int x, int y) {
LINK[w] = l[x];
l[x] = w;
ed[w] = y;
w++;
}
void DFS(int x, int y) {
for (int i = l[x]; i != -1; i = LINK[i]... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
int N, K;
vector<int> graph[200011];
vector<int> compress[200011];
int paint[200011], color[200011];
int dp[200011][2];
bool vis[200011];
void floodfill(int node, int c) {
if (vis[node]) return;
vis[node] = true, color[node] = c;
for (int... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, dp[111][8];
char c[111][111];
int type(char ctmp) {
if (isdigit(ctmp)) return 0;
if (isalpha(ctmp)) return 1;
return 2;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%s", c[i]);
for (int i = 0; i <= n; i++)
for (int j = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007ll;
struct data {
long long num, sum;
data() {}
data(long long n, long long s) {
num = n;
sum = s;
}
data operator+(const data& p) const {
return data((num + p.num) % mod, (sum + p.sum) % mod);
}
};
data dp[65][2][2][2... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
int n, m;
int f[maxn];
long long ans[maxn], sz[maxn];
int find(int k) {
if (k == f[k])
return k;
else
return f[k] = find(f[k]);
}
struct ppo {
int u, v, w;
bool operator<(const ppo &r) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100010, mod = 1000000007, OPT = 300;
int f[M];
bitset<(2000000000 / OPT) + 10> g;
vector<int> p;
bool isprime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
return 1;
}
int NN, DD, ANS;
void track(int i, int taken, int sum) {
if ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int32_t answer[50];
int main() {
int32_t n;
int32_t a[50][50];
cin >> n;
for (int32_t index = 0; index < n; index++) {
for (int32_t index2 = 0; index2 < n; index2++) {
cin >> a[index][index2];
}
}
for (int32_t index0 = 1; index0 < n; index0++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool isvowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
string s;
cin >> s;
string ans, str;
str += s[0];
long ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long l, b;
cin >> l >> b;
if (b > l) {
long long temp = l;
l = b;
b = temp;
}
long long x = max(l, 2 * b);
cout << x * x << "\n";
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int x[200005], y[200005];
long long int n;
vector<pair<long long int, pair<long long int, long long int>>> X, Y;
set<long long int> s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i <= n; i++) x[i] = y[i] =... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans0 = 0, a[1000];
cin >> n;
if (n == 1) {
cout << "0";
return 0;
}
a[0] = -1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n - 1; i++) {
if (i == 1 && a[2] == 2) {
ans0++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[400001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int g = 1, s = 1, b = 1;
while (g < n && a[g - 1] == a[g]) g++;
while (g + s < n ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i;
scanf("%i %i", &n, &k);
vector<int> a(n);
int all = 0;
for (i = 0; i < n; i++) scanf("%i", &a[i]), all += a[i];
int ans = 0;
for (i = 0; i < k; i++) {
int sum = all;
for (int j = i; j < n; j += k) sum -= a[j];
ans = max(an... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int T, dd[N], n, x;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(".inp", "r")) freopen(".inp", "r", stdin);
cin >> T;
while (T--) {
memset(dd, 0, sizeof dd);
cin >> n >> x;
for (int i = 1; i <= n; +... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
std::vector<pair<int, int> > el;
bitset<100005> bb, checked;
int c[100005];
bool it = true;
void dfs(int u, int p) {
if (u == p || !it) {
return;
}
for (auto x : g[u]) {
if (x != p) {
if (c[u] != c[x]) {
it = false;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long getzn(long long i, long long j, long long k) {
cout << "2 " << i << " " << j << " " << k << endl;
long long ans;
cin >> ans;
return ans;
}
long long getval(long long i, long long j, long long k) {
cout << "1 " << i << " " << j << " " << k << endl;
long... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
int n, a, b, vl[2222], vis[2222], times, vm[2222], cnt, gp[2222], cs;
int ans_list[2][4444], num_ans, m, pos[2222];
bool go(int left, int right) {
int i, j, s, p, q, lm = inf, rm = -inf, id, ip;
bool mv = true;
while (mv) {
mv = false;
... | 25 |
#include <bits/stdc++.h>
using namespace std;
int dp[2][10005];
char s[10005];
int main() {
cin >> s;
int n = strlen(s);
dp[0][n - 2] = 1;
dp[1][n - 3] = 1;
for (int i = n - 4; i >= 0; i--) {
if (dp[1][i + 2] == 1 ||
(dp[0][i + 2] == 1 && (s[i] != s[i + 2] || s[i + 1] != s[i + 3])))
dp[0][i]... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
int n, m;
int a[Maxn], l[Maxn], r[Maxn];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
r[n - 1] = n - 1;
for (int i = n - 2; i >= 0; i--) r[i] = a[i] <= a[i + 1] ? r[i + 1] : i;
l[0] = 0;
for (int i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int POW = 17;
int p[maxn][POW];
vector<int> edge[maxn], ee[maxn];
int cnt[maxn];
int dep[maxn];
void dfs(int u, int f) {
dep[u] = dep[f] + 1;
for (int i = 0; i < edge[u].size(); i++) {
int v = edge[u][i];
if (v == f) continue;
... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long int MOD = 1000000007;
long long int min(long long int a, long long int b) {
if (b <= a) return b;
retu... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
for (auto v : V) os << v << " ";
return cout << "";
}
template <class T>
ostream& operator<<(ostream& os, set<T> S) {
for (auto s : S) os << s << " ";
return cout << "";
}
template <class L, class R>... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n + 1];
arr[0] = 0;
set<int> second;
vector<int> sol;
for (int i = 1; i < n + 1; i++) {
cin >> arr[i];
second.insert(i);
}
for (int i = 1; i < n + 1; i... | 4 |
#include <bits/stdc++.h>
int main() {
int i, j, n, a[1005][10], b, c, d;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%1d", &a[i][0]);
b = 1;
c = 0;
for (i = 0; i < n; i++) {
if (a[i][0] != b) c++;
b = (b + 1) % 2;
}
b = 0;
d = 0;
for (i = 0; i < n; i++) {
if (a[i][0] != b) d++;
b... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
struct node {
int id;
long long x, y;
} data[maxn];
int ans[maxn];
int main() {
srand(time(NULL));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> data[i].x >> data[i].y;
data[i].id = i;
}
while (true) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int pr[100000 + 10];
vector<unsigned long long> prv;
void sev() {
pr[1] = 1;
for (int i = 2; i <= 100000; ++i) {
if (pr[i]) continue;
prv.push_back(i);
for (int j = i; j <= 100000; j += i) {
pr[j] = i;
}
}
}
int main() {
int n, t;
cin >> t;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long po(long long a, long long b, long long M) {
long long res = 1;
a = a % M;
while (b) {
if (b % 2) res = (res * a) % M;
b /= 2;
a = (a * a) % M;
}
return res;
}
long long pw(long long x, long long y) {
if (y == 0)
return 1;
else if (y %... | 0 |
#include <bits/stdc++.h>
int main(void) {
int n;
scanf("%d", &n);
long long int sum = 0;
for (int i = 0; i < n; i++) {
long long int tmp;
scanf("%I64d", &tmp);
sum += (tmp - 1);
if (sum % 2)
puts("1");
else
puts("2");
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int s[100], dp[101][10001];
int main() {
int n;
scanf("%d", &n);
int ts = 0;
for (int i = 0; i < (int)(n); ++i) scanf("%d", s + i), ts += s[i];
for (int i = 0; i < (int)(n + 1); ++i)
for (int j = 0; j < (int)(10001); ++j) dp[i][j] = -1e9;
dp[0][0] = 0;
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
const long long INF = 1e18;
long long n, k, a, b;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long tmin = INF, tmax = 0;
cin >> n >> k >> a >> b;
for (long long i = 1; i <= n ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300;
int a[maxn];
int dp[maxn];
void dfs(int x, int y) {
if (x == y) {
dp[x]++;
return;
}
dp[y]++;
dfs(a[x], y);
return;
}
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n;
scanf("%d", &n);
memset(dp, 0, sizeof(dp... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.