solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long w, a[10], dp[200005];
int main() {
long long sum = 0;
cin >> w;
for (register int i = 1; i <= 8; ++i) scanf("%lld", &a[i]), sum += i * a[i];
if (sum <= w) {
cout << sum << endl;
return 0;
}
long long ans = 0;
long long res = w;
for (registe... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) {
long long n;
cin >> n;
if (n == 1 || n == 2) cout << 1, exit(0);
if (n == 3) cout << 0, exit(0);
if (n % 2 == 1) n -= 3;
int d = n / 2;
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<array<int, 3> > v(n);
for (array<int, 3> &i : v)
for (int &j : i) cin >> j;
vector<array<int, 2> > o(1, {0, 0});
long long ans = 1;
for (array<int, 3> i : v) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
int i = 1;
for (; i * (i + 1) * (2 * i + 4) / 12 <= n; i++)
;
cout << i - 1;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
const long long mod = 1e9 + 7;
const long long INF = 10000000;
void flash() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(9);
}
void solve();
int32_t main() ... | 5 |
#include <bits/stdc++.h>
int main() {
char a[1111];
int n;
scanf("%d", &n);
scanf("%s", a);
for (int i = 0; i < n;) {
if (a[i] == 'o' && a[i + 1] == 'g' && a[i + 2] == 'o') {
i += 3;
while (a[i] == 'g' && a[i + 1] == 'o') {
i += 2;
}
printf("***");
} else {
printf... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
map<int, int> mp;
int main() {
int n, m, y1, y2, rec, temp, maxx;
map<int, int>::iterator it;
scanf("%d %d", &n, &y1);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
scanf("%d %d", &m, &y2);
for (int i = 1; i <= m; i++) ... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long int> v[100002];
vector<unsigned long long int>::iterator it;
set<unsigned long long int> s;
set<unsigned long long int>::iterator iter;
bool check[100005];
int main() {
unsigned long long int n = 0, m = 0, x = 0, y = 0, res = 0, i = 0, j = 0,
... | 4 |
#include <bits/stdc++.h>
const int MAXN = 100000 + 10;
int T, N, cnt[30];
char name[30][100000], phone[30][1000][30];
std::map<std::string, int> mp;
int tot;
bool visited[MAXN];
inline int min(int x, int y) { return x < y ? x : y; }
int main() {
register int i, j, k, l;
std::string S;
int id;
scanf("%d", &T);
... | 6 |
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,x,y) for(int i=x; i<=y; i++)
void task(){
int n,ans=0,sum=0,here;
cin>>n;
int a[n+2];
rep(i,1,n) cin>>a[i];
for(int i=1 ,j=n ;i<=j; i++,j--){
cout<<a[i]<<" ";
if(i!=j) cout<<a[j]<<" ";
}
cout<<" "<<endl;
// end of this
}... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
struct debugger {
static void call(const char* it) {}
template <typename T, typename... valT>
static void call(const char* it, T val, valT... rest) {
string var = "";
for (; *it && *it != ','; it++)
if (*it != ' ') var += *it;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
bool t = false;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = true, ch = getchar();
while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
return t ? -x : x;
}
p... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int N, M, s, cnt[55], DP[55][55][55][55];
vector<array<int, 2>> g[55];
int count(int v, int p) {
int ret = cnt[v];
for (array<int, 2>& e : g[v]) {
if (e[0] == p) continue;
ret += count(e[0], v);
}
return ret;
}
int solve(int u, int v, in... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
if (k % 2 == 0)
k = 2;
else
k = 1;
int a[n + 5], i, j;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (j = 1; j <= k; j++) {
int max ... | 0 |
#include <bits/stdc++.h>
inline void make(char *buf, int *fal) {
static int i, j;
fal[0] = -1;
for (i = 1, j = -1; buf[i]; ++i) {
while (j >= 0 && buf[j + 1] != buf[i]) j = fal[j];
if (buf[j + 1] == buf[i]) ++j;
fal[i] = j;
}
}
inline int match(char *p, char *t, int *fal) {
static int i, j, re;
... | 9 |
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define rep(n) for(int i=0;i<n;i++)
#define repit(x) for(auto it : x)
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vs ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vis, ways;
void solve() {
long long N, X, pos, ans = 1;
cin >> N >> X >> pos;
long long left = 0, right = N, way1 = N - X, way2 = X - 1;
while (left < right) {
long long mid = (left + right) / 2;
vis.push_back(mid);
if (mid <= pos)
... | 7 |
#include <bits/stdc++.h>
int n, m, k, ox[100010], oy[100010];
char map[60][60];
void add(int x, int y) {
ox[k] = x;
oy[k++] = y;
}
void fix_w(int x, int y);
void fix_h(int x, int y) {
if (map[x][y] == 'U') return;
fix_w(x + 1, y);
add(x + 1, y + 1);
map[x][y] = map[x][y + 1] = 'U';
map[x + 1][y] = map[x +... | 19 |
#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
const double PI = acos((double)-1);
int ts, ts2, ts3, ts4;
int n, m, a[105], w, ady[105];
pair<int, int> a1[105];
long long gcd(long long x, long long y) {
long long t;
for (; y != 0;) {
t = x % y;
x = y;
y = t;
}
return x;
}
int... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long n;
cin >> n;
for (long long i = 0; i <= (n / 1234567); i++) {
for (long long j = 0; j <= (n / 123456); j++) {
long long x = (i * 1234567ll) + (j * 123456ll);
long long p = n - x;
if (p >=... | 5 |
#include <bits/stdc++.h>
using namespace std;
int x, y, p, r, n;
struct gripper {
int dis, m, p, r;
long long disori;
bool del = false;
} gp[250020];
int lshcnt, lshm[500050], lshmcnt;
long long lsh[500050];
priority_queue<pair<int, int> > c[500050];
queue<int> availgp;
inline int lowbit(int x) { return x & -x; }... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 0;
cin >> t;
for (int q = 0; q < t; q++) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int cur = n - 1;
while (a[cur] <= a[cur - 1] && cur... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k, x[100007], maxx[100007];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (long long int i = 1; i <= k; ++i) {
long long int t;
cin >> t;
if (!x[t]) x[t] = i;
maxx[t] = i;
}
long long int ans = 0;
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
const double pi = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int limit = 5e5;
int read() {
int s = 0;
char c = getchar(), lc = '+';
while (c < '0' || '9' < c) lc = c, c = getchar();
while ('0' <= c && c... | 11 |
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--){
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;++i)cin>>a[i];
int l=0,r=n-1;
while(l<=r){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int sum[400007];
int A[200007];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i <= n + 5; i++) {
sum[i] = 0;
A[i] = 0;
}
for (int i = 1; i <= n; i++) {
scanf("%d", &A[i]);
sum[A[i]]++;
}
sort(A + 1, A + n + 1);
for (int i = 1; i <= 400... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, flag = 0;
double n, an;
cin >> n >> an;
double p = (180) / n;
long long r = an / p;
if (r == 0) {
cout << "2 1 3\n";
return;
}
if (r >= n - 2) {
cout << "2 1 " << n << endl;
return;
}
if ((an - p * r) <= (p ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2e5 + 2;
long long a[SIZE], prefix[SIZE], suffix[SIZE];
int main() {
int n, k, x;
scanf("%d%d%d", &n, &k, &x);
long long mul = 1;
while (k--) mul *= x;
for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
for (int i = 1; i <= n; i++) prefix[i] = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long inf = pow(10, 18);
long long modulo = pow(10, 9) + 7;
void deal() {
long long n, m, k;
cin >> n >> m >> k;
vector<set<long long> > all(m);
vector<vector<long long> > arr(n, vector<long long>(m));
for (long long i =... | 7 |
#include <bits/stdc++.h>
using namespace std;
multiset<pair<string, int> > mul;
int main() {
string ss;
int k;
cin >> ss >> k;
for (int i = 0; i < ss.size(); i++) {
string temp;
temp += ss[i];
mul.insert({temp, i});
}
long long n = ss.size();
if (2 * k > n * (n + 1)) return !printf("No such li... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 6 * N;
int n, m;
int h[N], e[M], ne[M], w[N], idx;
int top[N], id[N], sz[N], cnt;
int dep[N], son[N], fat[N], mp[N], nw[N];
int fa[N][17];
int dist[N];
struct Edge {
int a, b, w;
} edge[N];
struct Node {
int l, r;
int sum;
} tr[N << 2];
void ... | 13 |
#include <bits/stdc++.h>
long long mod = pow(10, 9) + 7;
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void go() {
long long n, a, x, b, y;
cin >> n >> a >> x >> b >> y;
long long c = n, i = a, j = b;
while (a != x && b != y) {
if (a == b) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
namespace sky_chen {
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;
inline long long read() {
long long ans = 0, f = 1;
char a =
p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
? EOF
: *p1++;
while ... | 17 |
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define float long long double
#define pb push_back
void solve()
{
ll n;
cin>>n;
ll a[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int i=0; i<n-1; i++)
{
if(a[i] ==... | 0 |
#include <bits/stdc++.h>
int main() {
long long A[7];
long long x = 1;
for (int i = 0; i < 6; ++i) {
scanf("%lld", &A[i]);
}
for (int i = 0; i < 3; ++i) {
if (A[i * 2] != 0) {
x *= A[i * 2];
}
}
long long INF = x * 2e9;
long long y = x;
bool inf = false;
for (int i = 0; i < 3; ++i)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a[] = {"ABC", "ACB", "BCA", "BAC", "CAB", "CBA"}, str[3];
;
string str1, str2, str3;
cin >> str[0] >> str[1] >> str[2];
for (int i = 0; i < 6; i++) {
int t[3];
t[a[i][0] - 'A'] = 0;
t[a[i][1] - 'A'] = 1;
t[a[i][2] - 'A'] = 2;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
test = 1;
while (test--) {
int n;
cin >> n;
string a = "abcd";
for (int i = 0; i < n / 4; i++) cout << a;
for (int i = 0; i < n % 4; i++) cout << a[i];
cout << endl;
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
cout << 0 << " " << 0 << " " << n << "\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int mod[] = {1224469897, 1503325967, 1336143462, 937397015};
const int inft = 1000000009;
const int MAXN = 10006;
vector<int> PR;
struct czt {
int t[4];
czt() {
for (int i = 0; i < (4); ++i) t[i] = 1;
}
inline czt &operator*=(const czt B) {
for (int i = 0; i... | 22 |
#include <bits/stdc++.h>
long long num[10], a[10], c[10], ch[10];
long long com(long long x) {
long long to = 0;
for (long long k = 2; k <= sqrt(x); k++) {
if (x % k != 0) continue;
while (x % k == 0) {
x /= k;
to++;
}
}
if (x != 1) to++;
return to;
}
long long max, n;
void tru() {
l... | 14 |
#include <bits/stdc++.h>
using namespace std;
int T, n, cnt, now[100100], ans[100100];
char a[100100];
vector<int> A, B, C;
map<pair<int, int>, bool> mm;
inline void ask() {
int i, j;
if (!A.size()) return;
printf("Q %d ", (int)A.size());
for (i = 0; i < A.size(); i++) printf("%d %d ", A[i], B[i]);
puts("");
... | 22 |
#include <bits/stdc++.h>
struct node {
int link[4], go[4], suff, par, ch, maxlen;
node() {
memset(link, -1, sizeof link);
memset(go, -1, sizeof go);
suff = -1;
maxlen = 0;
}
} tr[320];
int m, dp[320][1310][21], u[120];
void add(int& x, int y) {
long long sum = (x * 1LL + y * 1LL) % 1000000009;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double l, p, q;
cin >> l >> p >> q;
cout << l * p / (q + p);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, k, m, y, i, j;
long long c = 0;
cin >> n >> k >> m;
vector<long long> a(n + 1);
string s[n + 1], str[m + 1];
map<string, long long> mp;
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, p, ans;
int main() {
cin >> n >> p;
for (int i = 1; i <= n; i++) {
long long num = 1;
while (num <= i) {
num *= 10;
}
long long sum1 = (i * num) % p;
long long tmp = i;
long long sum2 = 0;
while (tmp) {
long long s = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, n;
cin >> A >> B >> n;
if (A == 0 && B == 0) {
cout << 0 << endl;
return 0;
}
if (A == 0) {
cout << "No solution" << endl;
return 0;
}
if (B == 0) {
cout << 0 << endl;
return 0;
}
if (B % A != 0) {
cout <<... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
long long x, y;
Point(long long xx = 0, long long yy = 0) { x = xx, y = yy; }
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
long long dot(Point p) { return x * p.x + y * p.y... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long a[n + 1];
for (long long i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
if (n % 2 == 0)
cout << n / 2 - 1 << '\n';
else
cout << n /... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int64_t N = 2e5 + 5e4 + 1e2;
bool mark[N], done;
int64_t n, m, k, d[N], par[N], s;
vector<int64_t> adj[N], leaf;
void path(int64_t v, int64_t u) {
while (v != u) {
cout << v << ' ';
v = par[v];
}
cout << u << '\n';
done = true;
}
void dfs(int64_t v) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int a, b;
} t[5005];
bool cmp(node x, node y) {
if (x.a != y.a) {
return x.a < y.a;
} else {
return x.b < y.b;
}
}
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) {
scanf("%d%d", &t[i].a, &t[i].b);
}... | 6 |
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define IOF \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define M 1000000007
vector<int> primes;
bool vis[31624 + 1];
int fact... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline bool iseq(double x, double y) {
if (fabs(x - y) < 1e-8) return true;
return false;
}
template <typename T>
inline T hpt(T x1, T y1, T x2, T y2) {
return hypot(x1 - x2, y1 - y2);
}
template <typename T>
inline T gcd(T a, T b) {
if (!b)
return a;
else
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, g, a[MAXN], Next[MAXN];
long long ans;
vector<int> s[MAXN];
inline void solve(register int L, register int R) {
for (register int i = L; i <= min(n, R); ++i)
if (Next[i] < R)
ans += 1LL * g * (R - Next[i]), Next[i] = R;
else
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
long long e = -1, s = -1;
for (long long i = 0; i < n; i++) {
cin >> a... | 0 |
#include <bits/stdc++.h>
namespace fmt {
void print(...) {}
} // namespace fmt
using namespace std;
long long start[(50)];
long long succ[(2 * 500)], cap_orig[(2 * 500)], cap[(2 * 500)], to[(2 * 500)];
long long edge_counter = 0;
void _add_edge(long long u, long long v, long long c) {
cap_orig[edge_counter] = c;
c... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100111, inf = 1000111222;
const int max_d = 55;
int n, m, d, comp, used[max_n], eu[max_n], ev[max_n], root[max_n],
dp[max_n][max_d];
char s[max_n][max_d], can[max_n][max_d];
bitset<max_d> b1, b2;
vector<int> g[max_n], rg[max_n], order, order2;
vector<p... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans[n];
for (int i = 0; i < n; i++) {
int a, b, z;
bool k = true;
cin >> a >> b >> z;
ans[i] = 0;
if (a > b) {
k = false;
}
while (a <= z && b <= z) {
if (k) {
a += b;
k = fals... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename X>
void MA(X& a, X b) {
a = max(a, b);
}
template <typename X>
void MI(X& a, X b) {
a = min(a, b);
}
template <typename X>
void clr(X& x, int a) {
memset(x, a, sizeof(a));
};
int cond = 0, multi = 0, gcj = 0;
struct solver_t;
solver_t* solver;
struc... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n == 0) {
cout << 0 << endl;
return 0;
}
if ((n + 1) & 1ll)
cout << (n + 1) << endl;
else
cout << ((n + 1) / 2ll) << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 8;
int n, m = -1, p = -1;
int L[maxn][maxn], H[maxn][maxn], A[maxn][maxn];
int B[maxn][maxn];
void input() {
scanf("%d", &n);
for (int i = 1; i <= n * (n - 1) / 2; i++) {
int u, v;
scanf("%d%d", &u, &v);
scanf("%d%d%d", &L[u][v], &H[u][v], &... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, xi, xa, yi, ya, a0, a1, a2, a3;
while (~scanf("%d", &n)) {
int i, x, y, res = 0;
for (i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
if (!i) {
xi = xa = x;
yi = ya = y;
a0 = a2 = y - x;
a1 = a3 = y + x... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
int pv[MAXN], nx[MAXN];
void del(int x) {
nx[pv[x]] = nx[x];
pv[nx[x]] = pv[x];
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
int left = n;
for (int i = 1; i <= n; i++) {
pv[i] = i - 1;
nx[i] = i + 1;
}
pv[1] = n;
nx[n] = 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long count10 = 0;
long long ans = 1, x = 10;
string s;
int main() {
map<char, bool> letter;
letter['A'] = false, letter['B'] = false, letter['C'] = false;
letter['D'] = false, letter['E'] = false, letter['F'] = false;
letter['H'] = false, letter['I'] = false, l... | 3 |
#include <bits/stdc++.h>
using namespace std;
void si(int &n) { scanf("%d", &n); }
void sii(int &n, int &m) { scanf("%d%d", &n, &m); }
constexpr long long int TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> G[100005], S[100005], T[100005], C[100005];
int nodes;
void recon(int nod, int fat) {
for (int i = 0; i < G[nod].size(); ++i) {
int nnod = G[nod][i];
if (nnod != fat) {
S[nod].push_back(nnod);
recon(nnod, nod);
}
}
}
void baga(... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int SI = 2e5 + 100;
char dp[5005][505];
int pre_x[5005][505], pre_y[5005][505];
bool vis[5005][505];
int mod, s;
struct node {
int sum, m;
};
void bfs() {
queue<node> q;
vis[0][0] = true;
pre_x[0][0] = -1;
pre_y[0][0] = -1;
int news, newm;
node ad, to;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int issq(int n) {
if (n < 0) return false;
int rt = sqrt(n);
return rt * rt == n;
}
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
int ans = -1e9;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (!issq(x)) ans = max(ans, x);
}
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x = 0, t = 1;
register char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = -1, ch = getchar();
while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
return x * t;
}
i... | 23 |
#include <bits/stdc++.h>
using namespace std;
int oo = 0x3f3f3f3f;
double inf = 1.0 / 0.0;
const double pi = 2 * acos(0.0);
const int MOD = 1e9 + 7;
const int MOD1 = 998244353;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> qq;
int xx, rr = 0, rr2 = 0;
for (int i = 1; i <= ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, mod = 1e9 + 7, g, m, ans;
long long a[1001][1001], b[1005], c[1005], xx, yy;
char ch;
string s, st;
vector<int> v[300005], u;
long long f(long long x) { return x * x; }
int main() {
ios::sync_with_stdio(NULL);
cin.tie(0);
c... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T pr(T x) {
return --x;
}
template <class T>
inline T nx(T x) {
return ++x;
}
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline void get(T &n) {
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c... | 13 |
#include <bits/stdc++.h>
using namespace std;
int findX(int A, int B) {
int j = 0, x = 0;
while (A || B) {
if ((A & 1) && (B & 1)) x += (1 << j);
A >>= 1;
B >>= 1;
j += 1;
}
return x;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (... | 0 |
#include <bits/stdc++.h>
using namespace std;
char a[50][50];
char buf[1000000];
int dist[256], have[256];
const int INF = 0x7f7f7f7f;
int main() {
int n, m, limit;
while (scanf("%d%d%d", &n, &m, &limit) != EOF) {
vector<pair<int, int> > ps;
memset(dist, 0x7f, sizeof(dist));
memset(have, 0, sizeof(have)... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long x, long long p) {
for (int i = 2; i * i <= x && i <= p; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
int p, y;
cin >> p >> y;
for (int i = y; i > p; i--) {
if (is_prime(i, p)) {
cout << i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:60777216")
const int max_n = 100050;
int n;
vector<int> neigh[max_n];
int val[max_n];
int c;
int s[max_n], s_ed;
int b[2 * max_n], b_ed;
void run_dfs(int v) {
s[++s_ed] = v;
val[v] = s_ed;
b[++b_ed] = val[v];
for (int j = 0; j < int(n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int M, F, dp[1000 * 1000 + 100];
int main() {
string s;
cin >> s;
int HERE = 0;
for (int i = 0; i < s.size(); i++)
if (s[i] == 'M') {
HERE = i;
break;
}
for (int i = HERE; i < s.size(); i++)
if (s[i] == 'F') {
dp[i] = F;
F++;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string input;
while (cin >> input) {
stack<int> chk;
int single[1000001] = {(0)}, maxi = 0, rept[1000001] = {(0)};
for (int i = 0; i < input.size(); i++) {
if (input[i] == '(') {
chk.push(i);
} else {
if (chk.empt... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1& a, T2 b) {
return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1& a, T2 b) {
return a > b ? a = b, 1 : 0;
}
const int N = 200000, M = 75000;
struct node {
node *l = 0, *r = 0;
long long a = 0,... | 17 |
#include <bits/stdc++.h>
using namespace std;
long int ff(long int n) { return (n * (n + 1)) / 2; }
int main() {
long int n, i = 1, j = 65, sum = 0;
cin >> n;
if (n == 0) {
cout << "a";
return 0;
}
while (n != 0) {
i = 1;
while (ff(i) <= n) {
i++;
}
n -= ff(i - 1);
while (i--... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++) cin >> ar[i];
map<int, int> m;
for (int i = 0; i < n; i++) m[ar[i]]++;
m[0] = 3;
map<int, int>::iterator it = m.begin(), tmp;
int ans = 0;
it++;
while (it != m.end()) {
int p = it... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[1000005], ans = 0, inv[1000005], jc[1000005];
inline void init() {
inv[0] = inv[1] = 1;
for (long long i = 2; i <= n; i++)
inv[i] = ((1000000007LL - 1000000007LL / i) * inv[1000000007LL % i]) %
1000000007LL;
jc[0] = jc[1] = 1;
for (lo... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, a, b, p[maxn], sum[maxn], nex[maxn][21], ans, l;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
using namespace std;
long long spf[301];
long long fac[301];
void sieve() {
spf[1] = 1;
for (long long... | 13 |
#include <bits/stdc++.h>
using namespace std;
int b, ans = 0, n;
int main() {
string a;
cin >> n >> a;
for (int i = 0; i < a.size(); ++i) {
if (a[i] == 'x') {
b++;
} else {
b = 0;
}
if (b > 2) {
ans++;
}
}
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
const int N = 1005, u[4] = {1, 0, -1, 0}, v[4] = {0, 1, 0, -1};
int n, m, h, t, B, W, cnt, f[N * N], g[N * N], c[N], a[5], b[5];
char s[N][N], ch;
int get(int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= m) return -1;
c[s[x][y]]++;
return s[x][y];
}
void check(int i, int j) {
if (ge... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, d, i;
cin >> n >> m;
int a[n], c[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
set<pair<int, int>> s;
for (i = 0; i < n; i++) {
cin >> c[i];
s.insert(make_pair(c[i], i));
}
while (m--) {
long long int cost = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int na, nb;
cin >> na >> nb;
int k, m;
cin >> k >> m;
vector<int> a;
vector<int> b;
int p;
for (int i = 0; i < na; i++) {
cin >> p;
a.push_back(p);
}
for (int i = 0; i < nb; i++) {
cin >> p;
b.push_back(p);
}
if (a[k - 1]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
char s[N], ans[N];
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
scanf("%d", &n);
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
scanf("%s", s);
int cn = 0;
for (int i = 0; i < n; ++i) {
ans[i] = '!';
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while... | 19 |
#include <bits/stdc++.h>
using namespace std;
int xDir[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int yDir[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int EPS = 1e-10;
int dComp(double d1, double d2) {
if (abs(d1 - d2) <= EPS) return 0;
if (d1 > d2)
return 1;
else
return -1;
}
int main() {
ios::sync_with_stdio(0);
cin.t... | 4 |
#include <bits/stdc++.h>
using namespace std;
int k, e1, e2;
void make(int be, int kk, int dir) {
for (int i = be + 1; i <= kk; i++) printf("%d %d\n", be, i);
for (int i = be + 1; i <= kk - 1; i++)
for (int j = i + 1; j <= kk; j++) {
if ((i + dir) % 2 == 0 && j == i + 1) continue;
printf("%d %d\n", ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void func() {
string s, ans;
cin >> s;
long long n = s.length(), cnt = 0, j = -1;
for (long long i = 0; i < n; ++i) {
if (s[i] == '2') {
j = i;
break;
}
}
if (j == -1) {
sort(s.begin(), s.end());
cout << s << "\n";
return;
}
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct state {
int row, col, val;
state(int _r, int _c, int _v) : row(_r), col(_c), val(_v) {}
bool operator<(const state &s) const { return val > s.val; }
};
pair<int, int> p[1005];
int main() {
int n;
scanf("%d", &n);
int xx;
for (int i = 0; i < n; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int dt = 2000010;
inline int read() {
int x = 0, f = 0, c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return f ? -x : x;
}
int tree[16... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 11 * 100100;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
int ncnt = 1;
int nxt[N][4];
vector<vector<long long>> f[64];
long long n;
string s;
int dep;
vector<vector<long long>> get_res(long long init = 0) {
return vector<vector<long long>>(4, vector<long lon... | 22 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
int n = s.size();
ll ans = 0;
for (int l = 0; l < n; l++) {
if (l + 8 < n) ans += n - (l + 8);
bool found = false;
for (int r = l + 1; r < min(n, l + 8); r++) {
for (int k = 1; 2 * k <= r - l... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long C[3010][3010];
int main() {
int n, m, k, a, b;
cin >> n >> m >> k;
for (int i = 0; i < 3010; i++) {
for (int j = i; j < 3010; j++) {
if (i == 0)
C[i][j] = 1;
else
C[i][j] = (C[i - 1][j - 1] + C[i][j - 1]) % 1000000007ll;
}... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int num = 100005;
int cnt[num];
int main() {
int n;
cin >> n;
int x;
int mx = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
cnt[x] = 1;
if (x > 1) cnt[x] += cnt[x - 1];
if (cnt[x] > mx) mx = cnt[x];
}
cout << n - mx << endl;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int v, w, next;
} e[100 * 100 * 5];
int head[100 * 100 + 10];
int ecnt;
char mp[105][105];
int junc[30];
int g[30][30];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
int dir[30][30];
bool in[10005];
const int INF = 200000000;
int n, m, k;
int dist[10... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[(int)(1e+6) * 2], b[10], c[10];
int main() {
int n, i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
b[a[i]]++;
if (b[5] > 0 || b[7] > 0) {
cout << -1;
return 0;
}
}
b[2] -= b[4];
b[1] -= b[4];
if (b[2] < 0 || b[1] < 0) {
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.