solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long INF =
(is_same<long long, long long>::value ? 1e18 + 666 : 1e9 + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
if (a > b) {
a = b;
return true;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
vector<LL> p;
const LL inf = 2e18;
int main() {
for (LL i = 2; i <= 1000000; i++) {
LL x = i * i * i;
while (x < inf) {
LL sqrtx = sqrt(x);
while (sqrtx * sqrtx < x) sqrtx++;
if (sqrtx * sqrtx != x) p.emplace_back(x);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
queue<long long int> q;
long long int n, b, t[600000], d[600000], f = 0, p = 0, a[600000], k = 0;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> b;
for (int i = 1; i <= n; i++) {
cin >> t[i] >> d[i];
if (f == 1) {
while (!... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 20;
long long n, d[2 * Maxn][Maxn], tvn[Maxn];
bool par[2 * Maxn][Maxn];
string s, ans;
void pp(int i, int j) {
if (i == 0) return;
if (par[i][j]) {
ans += 'H';
pp(i - 1, j - 1);
} else {
ans += 'M';
pp(i - 1, j);
}
}
int main() {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long sz = 1e5 + 4;
int n, r, g, b;
string s;
int main() {
cin >> n;
cin >> s;
for (int i = 0; i < (int)s.length(); i++) {
if (s[i] == 'R')
r++;
else if (s[i] == 'G')
g++;
else if (s[i] == 'B')
b++... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[100001];
int cnt[3][100001], len, m, l, r;
int main() {
while (scanf("%s", s) == 1) {
len = strlen(s);
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < len; i++) cnt[s[i] - 'x'][i + 1] = 1;
for (int i = 1; i <= len; i++) {
cnt[0][i] += cnt[0][... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long int a, b, m, n, sum = 0, c = 0;
scanf("%lld %lld %lld", &a, &b, &m);
vector<long long int> arr;
if (a == b) {
printf("1 %lld\n", b);
continue;
}
if (a + m >= b) {
pr... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e7 + 5;
long long n, k;
long long a[1000005];
long long cnt[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (long long(i) = (1); (i) <= (n); ++(i)) {
cin >> a[i];
cnt[a[i]]++;
}
long long maxVal = 1e7... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int C = 100001;
vector<vector<int> > tab(C);
vector<vector<long long> > xx(C);
int ij[C], a, b, n, r;
long long f[C], g[C], summ[C];
vector<long long> pom(C);
void Sebasort(vector<long long>& tab, int l, int r) {
if (l > r) return;
int lim = 2, limi = l + 1, limj ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int inf = 2e9;
vector<pair<int, int>> mp[maxn];
int Mx[maxn], My[maxn];
int dx[maxn], dy[maxn];
int dis, mid;
int Nx, Ny;
bool vis[maxn];
bool SearchP() {
queue<int> Q;
dis = inf;
memset(dx, -1, sizeof(dx));
memset(dy, -1, sizeof(dy)... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
vector<vector<long long>> lb(n, vector<long long>(m)),
rb(n, vector<long long>(m)), dp(m, vector<long long>(m));
for (long long i = 0; i < n; ++i) {
long long k;
cin >> k;
while (k--) {
long long ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int cost[200005], n, nrfii[200005], par[200005], snr[200005], impar[200005],
nivel[200005], poz[200005], prfiu[200005], suma[200005];
struct nr {
int val, p;
};
nr aint1[3 * 200005], aint2[3 * 200005];
bool viz[200005];
vector<int> L[200005];
inline void Dfs(int nod, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
set<string> s;
cin >> n >> m;
for (int i = 0; i < n; i++) {
string ss;
cin >> ss;
s.insert(ss);
}
int b = 0;
for (int i = 0; i < m; i++) {
string ss;
cin >> ss;
if (s.count(ss)) b++;
}
if (b & 1) n++;
if (n ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long n, L, a, l, t, lbuf, sum;
int main() {
lbuf = 0;
sum = 0;
cin >> n >> L >> a;
for (long i = 0; i < n; i++) {
cin >> t >> l;
l += t;
sum += (t - lbuf) / a;
lbuf = l;
}
sum += (L - l) / a;
cout << sum;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int t;
string S;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
int c0, c1, ans;
while (t--) {
cin >> S;
c0 = c1 = 0;
for (int i = (0); i < (int(S.size())); ++i) {
if (S[i] == '1')
++c1;
else
++c0;
an... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m = 0, i, j = 0, s = 0, t = 0, a[200001], b[200001];
double aver;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
s = s + a[i];
}
aver = s * 1.0 / n;
for (i = 0; i < n; i++) {
if (a[i] == aver) {
j = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool rd(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9')... | 10 |
#include <bits/stdc++.h>
int main() {
int w, m;
scanf("%d %d", &w, &m);
if (w <= 3) {
printf("YES\n");
} else {
while (m != 0) {
if (m % w != (w - 1) && m % w != 0 && m % w != 1) {
printf("NO\n");
return 0;
}
m = (m + 1) / w;
}
printf("YES\n");
}
return 0;
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1, typename... Tail>
T amin(T& a, T1 b, Tail... c) {
if (b < a) a = b;
if constexpr (sizeof...(c) != 0) {
amin(a, c...);
}
return a;
}
template <typename T, typename T1, typename... Tail>
T amax(T& a, T1 b, Tail... c) {
if (b > ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long a, b, c;
cin >> b >> a;
int k = 0;
c = a + b;
long long d = 0, m;
m = sqrt(c) + 1;
d = b - a;
for (long long i = 2; i <= m; i++) {
if (c % i == 0) {
k = 1;
brea... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 200005;
const double PI = acos(-1);
int i, n, x, y, pref[N];
vector<long long> a, b, c;
inline int getRev(int x, int lg) {
int ans = 0;
for (int i =... | 15 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int k1, k2, n;
cin >> n >> k1 >> k2;
std::vector<int> v1(k1), v2(k2);
for (int i = 0; i < k1; i++) cin >> v1[i];
for (int i = 0; i < k2; i++) cin >> v2[i];
while (!v1.empty() && !v2.empty()) {
sort(begin(v1), end(v1));
sort(begin(v2), end(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, q = 0, w = 0;
string a, b;
char x, y;
cin >> a >> b;
int k = a.length();
if (a == b) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < k; i++) {
if (a[i] == b[i]) continue;
if (a[i] == '4' && b[i] == '7')
q++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<int> st;
int n, x;
bool isPrime[2000010];
int prime[2000010], np;
int main() {
while (scanf("%d%d", &n, &x) != EOF) {
st.clear();
bool flag = false;
for (int i = 0; i < n; i++) {
int val;
scanf("%d", &val);
if (val == 1) flag = true;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2002][2002], u[2002][2002], cnt1, cnt2, cnt;
pair<int, int> Maxx, Maxy, Minx, Miny;
inline void dfs(int i, int j) {
u[i][j] = true;
Minx = min(Minx, make_pair(i, j));
Maxx = max(Maxx, make_pair(i, j));
Miny = min(Miny, make_pair(j, i));
Maxy = max(Maxy, m... | 11 |
#include <bits/stdc++.h>
using namespace std;
string dabiao[] = {
"0\n.\n",
"0\n..\n",
"0\n...\n",
"0\n....\n",
"0\n.....\n",
"0\n......\n",
"0\n.......\n",
"0\n........\n",
"0\n.........\n",
"0\n.\n.\n",
"0\n..\n..\n",
"0\n...\n...\n",
"0\n....\n....\n",
"0\n....... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
char isPrime[1000000];
void init() {
primes.reserve(1000000);
memset(isPrime, -1, sizeof(isPrime));
isPrime[0] = isPrime[1] = 0;
for (int i = 0; i * i < 1000000; i++) {
if (!isPrime[i]) continue;
for (int j = i * i; j < 1000000; j += i) i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[1025][505];
int dizi[505][505] = {0};
int dpf(int cor, int str, vector<int> v) {
int muttin;
if (str == (n - 1)) {
if (cor) {
printf("TAK\n");
for (int i = 0; i < v.size(); i++) {
printf("%d ", v[i] + 1);
}
exit(0);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int T[] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};
int main() {
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
long long int ans = T[k];
for (int i = (1); i <= (n - k); ++i) ans = (ans * (n - k)) % 1000000007;
cout << ans;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
long long pr = -1, sf = n;
long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<string> answer;
void getStrings(string s, long long d) {
if (d == 0)
answer.push_back(s);
else {
getStrings(s + "4", d - 1);
getStrings(s + "7", d - 1);
}
}
int main() {
string s;
cin >> s;
for (long long i = 1; i <= s.size(); i++) getStrings(... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, r;
bool b[1000001];
string s[1000001], v[1000001];
long long N;
bool f(int x) {
int I = 0;
while (s[x][I] == ' ' && s[x].size() > I) I++;
if (I >= s[x].size()) return 0;
if (s[x][I] == '#') return 1;
return 0;
}
string sh(int x) {
string S ... | 9 |
#include <bits/stdc++.h>
int arr[3000000] = {-1};
int main() {
int n, m;
scanf("%d%d", &n, &m);
int k = n + m;
if (n == m) {
for (int i = 0; i < k; i++) {
arr[i] = i % 2;
}
} else if (n > m) {
if (n == m + 1) {
for (int i = 0; i < k; i++) {
arr[i] = i % 2;
}
} else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
long long sub[200005];
long long par[200005];
long long ans;
vector<long long> adj[200005];
long long func(long long node, long long parent) {
dp[node] = sub[node];
for (long long i = 0; i < adj[node].size(); i++) {
if (adj[node][i] != parent) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 2e9;
const long long N = 1e6 + 2;
const long long MAX = 2e5 + 2;
const long double EPS = 1e-8;
long long f(long long x) { return x * (x + 1) / 2; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007, mod2 = 998244353, inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
int a[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
string ans = "";
int l = 1, r = n, las... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 1) {
cout << "1 1\n";
cout << -a[0] << "\n1 1\n0\n1 1\n0\n";
return 0;
}
cout << "1 1\n" << -a[0] << "\n";
cout << "2 " << n << "\n";
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-12;
const int mod = 1e9 + 7;
const int maxn = 300005;
using namespace std;
struct node {
int a, b, id;
} nd[maxn];
bool cmp(node x, node y) { return x.b < y.b; }
set<pair<int, int> > s;
bool use[maxn];
int vis[maxn];
int m... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e6 + 9;
const long long INF = 1e12;
multiset<int> st;
multiset<int>::iterator it_1, it_2;
vector<int> vec[MAX];
int N, K, X, Y, res, hei[MAX], arr[MAX];
void dfs(int node, int par) {
arr[node] = -1;
if (vec[node].size() == 1 and vec[node][0] == pa... | 16 |
#include <bits/stdc++.h>
using namespace std;
char ans[10][1010];
void place(int x1, int y1, int x2, int y2) {
set<char> s;
for (int i(min(x1, x2) - 1); i <= max(x1, x2) + 1; i++)
for (int j(min(y1, y2) - 1); j <= max(y1, y2) + 1; j++) s.insert(ans[i][j]);
for (char i('a');; i++) {
if (s.find(i) == s.end(... | 5 |
#include <bits/stdc++.h>
void solution() {
int t, n;
char c;
std::vector<int> v(262144, 0);
scanf("%d%c", &t, &c);
for (int it = 0; it < t; ++it) {
n = 0;
c = getchar();
switch (c) {
case '+': {
c = getchar();
while ((c = getchar()) != '\n') {
c -= '0';
n ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
const int maxd = 50;
const int inf = 1e9;
char str[maxd + 2];
bool open[maxn][maxd];
vector<int> adj[maxn];
int prv[maxn], low[maxn];
int bel[maxn];
vector<int> s[maxn];
int g[maxn];
bool t[maxn][maxd];
int val[maxn][maxd];
int f[maxn][maxd];
int st... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
long long x = a + b;
if (x >= 1000000007) x -= 1000000007;
if (x < 0) x += 1000000007;
return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline string tostr(const T& x) {
stringstream ss;
ss << x;
return ss.str();
}
const long double EPS = 1e-14;
const int INF = 1000 * 1000 * 1000;
co... | 17 |
#include <bits/stdc++.h>
int n, x[1003], y[1003];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d%d", x + i, y + i);
double l, r;
if (x[1] > x[2])
l = x[2], r = x[1];
else
r = x[2], l = x[1];
for (int i = 3; i < n; ++i) {
double dx = x[i + 1] - x[i];
double dy = y[i + 1]... | 17 |
#include <bits/stdc++.h>
using namespace std;
int ct[10][10];
bool lead[10];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<string> in(n);
for (int i = 0; i < n; i++) {
cin >> in[i];
lead[in[i][0] - 'a'] = true;
reverse(in[i].begin(), in[i].end());
for (int j = 0; ... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
#pragma hdrstop
using namespace std;
inline void sIO() {}
inline void iIO() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
inline void fIO(string fn) {
freopen((fn + ".in").c_str(), "r", stdin);
freopen((fn + ".out").... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int N;
scanf(" %d", &N);
vector<int> L(N), R(N);
set<int> x_posS;
for (int i = 0; i < N; i++) {
scanf(" %d %d", &L[i], &R[i]);
x_posS.insert(L[i]);
x_posS.insert(... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int NM = 2e5 + 10;
int n, m, k;
vector<pair<int, int>> adj[NM];
int zero[NM], dest[NM], last_to_reach[NM];
bool cond[NM];
void bfs() {
vector<int> dist(n + 1, 1e9), used_edge(n + 1, -1);
queue<pair<int, int>> q;
dist[1] = 0;
q.push({1, dist[1]});
while (!q.e... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int n, a[5050], dp[5050][5050];
int calcdown(int l, int r, int val) {
if (l > r) return 0;
int ans = dp[r][val];
if (l) ans -= dp[l - 1][val];
return ans;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void show(T *a, int size) {
int i;
cout << endl << "The array is ";
for (long long i = 0; i < size; ++i) {
cout << a[i] << " ";
}
cout << endl;
}
template <typename T>
void show_vector(vector<T> v) {
cout << endl << "The vector is ";
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005, MOD = 998244353;
const long long inf = 5e18;
int arr[2 * MAX];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
;
int q;
cin >> q;
while (q--) {
long long n, m;
long long a = 0;
cin >> n >> m;
long long d = m % 10;... | 4 |
#include <bits/stdc++.h>
const int N = 1010;
const int MOD = 1000000007;
using namespace std;
int n;
string s;
int dp1[N];
int dp2[N];
int allowed[26];
void solve() {
dp1[0] = 1;
dp2[0] = 1;
bool isPresent[26] = {};
int MAX_LEN = 1;
for (int i = 1; i < n; i++) {
long long res1 = dp1[i - 1];
long long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
typedef struct {
int x, y, t;
double p;
} T;
typedef struct {
double v;
int num;
} Node;
vector<Node> dp;
T targ[maxn];
bool cmp(const T &t1, const T &t2) { return t1.t < t2.t; }
int main() {
int i, j, n;
scanf("%d", &n);
for (i = 1;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int arr[200010];
vector<int> hashArr;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sort(arr, arr + n);
int index = 0, prev = -1, sz = 0;
for (int i = 0; i < n; i++) {
if (arr[i] != prev) {
prev = arr[... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
struct qry {
int l, r, id;
bool operator<(const qry &a) const {
if (r == a.r) return l < a.l;
return r < a.r;
}
};
struct node {
int l, r;
pair<int, int> p;
};
qry ask[maxn];
node tree[maxn << 2];
int a[maxn];
int pos[maxn];
int re... | 16 |
#include <bits/stdc++.h>
long long RemoveZeros(long long a) {
long long Multplier = 0;
long long i = 10;
while (a > 0) {
if (a % 10 != 0) {
Multplier += (a % 10) * i;
i *= 10;
}
a /= 10;
}
return Multplier / 10;
}
using namespace std;
int main() {
long long a, b, c;
cin >> a >> b;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int r[200100];
int l[200100];
int s[200100];
int n, k, a, b, q;
int getsum(int x, int c[]) {
int ret = 0;
while (x) {
ret += c[x];
x -= x & -x;
}
return ret;
}
void update(int x, int c[], int v) {
while (x <= n) {
c[x] += v;
x += x & -x;
}
}
void... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
long long n;
cin >> n;
string s;
cin >> s;
long long l = 0, r = 0, i;
for (i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, max1 = -1, max2 = -1, max, sum = 0, k;
long long n;
cin >> n;
long long a, x[n];
for (int i = 0; i < n; i++) {
cin >> a;
sum += a;
}
for (int i = 0; i < n; i++) {
cin >> x[i];
}
sort(&x[0], &x[0] + n);
max = x[n - 1]... | 1 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int getans(set<int>& S, priority_queue<pii>& gaps) {
if (gaps.empty()) return 0;
return *S.rbegin() - *S.begin() - gaps.top().first;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
set<int> S... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int calch(long long int h, long long int x, long long int y,
long long int t, long long int m) {
for (long long int i = 1; i <= t; i++) {
h = ((h * x) + y) % m;
}
return h;
}
long long int calct(long long int h, long long int x, long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int n, m;
int dir[3] = {2, 3, 5}, ans;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int l, r;
while (~scanf("%d%d", &n, &m)) {
ans = 0;
int flag = 1;
int temp = gcd(n, m);
n /= temp;
... | 5 |
#include <bits/stdc++.h>
const int N = 1e5 + 5, M = 3e5 + 5, P = 998244353;
int n, a[N], mW, f[M], inv[M], s = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += a[i];
inv[1] = 1;
for (int i = 2; i <= s; i++) inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
for (int i = 1; i < ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
long long b[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (long long i = 0; i < n; i++) {
a[i] = (a[i] * (n - i) * (i + 1));
}
sort(a, a + n);
sort(b, b +... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = INT_MAX;
const long long inff = 2e13;
const long long mod = 1e9 + 7;
int t[maxn], h[maxn];
vector<int> G[maxn];
long long dp[maxn][2];
void dfs(int now, int p) {
dp[now][0] = dp[now][1] = inff;
long long sum = 0;
vector<long l... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, h, f[1100][2][31][31][31];
int main(void) {
while (cin >> n >> h) {
memset(f, 0, sizeof f);
f[0][1][0][0][0] = 1;
for (int i = int(0), ni = int(n); i <= ni; i++) {
for (int a = int(0), na = int(h); a <= na; a++)
for (int b = int(0), nb = i... | 15 |
#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > bfs;
vector<int> vec[100003], gt[100003], tipe[100003];
bool visited[100003];
;
int main() {
int n, m, k, s;
scanf("%d %d %d %d", &n, &m, &k, &s);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
tipe[x].push_back(i);
}
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 50;
const int MAXN = 10000 + 99;
int m, n;
bool subset(const uint8_t* A, const uint8_t* B) {
for (int i = 0; i < n; i++) {
if (A[i] < B[i]) return false;
}
return true;
}
uint8_t on_L[MAXM][MAXN];
uint8_t on_R[MAXM][MAXN];
int left(int idx) { retu... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > lr;
int n, p1, p2, p3, t1, t2;
int main() {
cin >> n >> p1 >> p2 >> p3 >> t1 >> t2;
for (int i = 0; i < n; ++i) {
int l, r;
cin >> l >> r;
lr.push_back(make_pair(l, r));
}
int num = 0;
for (int i = 0; i < lr.size(); ++i) {
n... | 1 |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define orz 1000000007
using namespace std;
int T,n,a[2005],b[2005];
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;++i)b[i]=1;
int k=1;
while(1){
++k;
printf("? %d 1\n",k-1);
for(i... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, k, y, x = 0, a;
bool ok = 0;
int main() {
cin >> y >> k >> n;
a = 0;
do {
a++;
x = a * k - y;
if (x > 0 && (x + y) % k == 0 && x + y <= n) {
cout << x << " ";
ok = 1;
}
} while (y + x < n);
if (!ok) cout << "-1" << endl;
return... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
long long fac[N];
int main() {
fac[0] = 1;
for (int i = 1; i < N; i++) {
fac[i] = fac[i - 1] * 4;
}
int t, i, j;
long long n, k;
cin >> t;
while (t--) {
cin >> n >> k;
int f = 1;
long long x = 1;
long long s;
x = fac[... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mmax, s[5005], f[1000005], smax;
bool flag[1000005];
int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int calcans(void) {
int ans, i, j, same;
for (ans = 1;; ans++) {
for (i = ans, same = 0; i <= smax; i += ans) {
same += f[i]... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20) + 5;
bitset<MAXN> used;
vector<pair<int, int>> adj[MAXN];
int a[MAXN];
int n;
vector<int> ans;
void dfs(int x) {
while (!adj[x].empty()) {
if (used[adj[x].back().second / 2]) {
adj[x].pop_back();
continue;
}
auto p = adj[... | 17 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
struct Dinic {
int n, m, h[10005], l[10005], s, t, w[10005];
struct eg {
int v, c, f, x;
} e[(10005 * 4)];
bool bfs() {
static int q[10005];
for (int i(0); i < n; i++) l[i] = -1;... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int m... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void print(int x) {
i... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int size = 11111;
const long long mod = 1e9 + 7;
long long dp[2][size];
long long n, p;
long long a[size], b[size];
int main() {
cin >> n >> p;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < 2; i++)
fo... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int kx[] = {-2, -2, +2, +2, +1, -1, +1, -1};
int ky[] = {+1, -1, +1, -1, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, sol, i, fi, se, th, temp;
priority_queue<long long> Q;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> a >> b;
sol = 0;
for (i = 0; i < 3; i++) {
Q.push(b);
}
while (true) {
fi = Q.top(), Q.pop();
se = Q.top(), Q.pop();... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, l = 0, f = 1, s;
vector<int> a, b, c;
cin >> n >> m;
a.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < 0) l++;
}
if (m < l) {
cout << -1;
return 0;
}
for (int i = 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
int dp[5009][5009][2];
int a[5009];
int n;
int func(int i, int k, bool f) {
if (k < 0) {
return 1000000009;
}
if (k == 0) {
return 0;
}
if (i > n) {
return 1000000009;
}
if (a[i] > a[i - 1]) f = false;
if (~dp[i][k][f]) return dp[i][k][f];
int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, fa[maxn][30], lg[maxn], dep[maxn], vis[maxn], f[maxn];
long long sum, mcost[maxn][30], ans[maxn];
struct node {
int x, y, z, id;
} p[maxn];
struct NODE {
int y, z;
};
vector<NODE> mp[maxn];
bool cmp(node a, node b) { return a.z < b.z;... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int nextint() {
int x;
scanf("%d", &x);
return x;
}
inline long long nextll() {
long long x;
scanf("%lld", &x);
return x;
}
template <typename T>
void scanint(T &x) {
T c = getchar();
while (((c < 48) || (c > 57)) && (c != '-')) c = getchar();
bool ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m, a, b, p[N], u[N], mx, idx, t, c;
bool tkn[N];
void f() {
for (;;) {
mx = -1;
idx = -1;
for (int i = 1; i <= 2 * n; i++) {
if (tkn[i]) continue;
if (u[i] != -1) {
if (p[i] > p[u[i]])
idx = i;
e... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long val[n];
for (long long i = 0; i < n; i++) {
cin >> val[i];
}
for (long long i = 0; i < n; i++) {
for (long long j = n - 1; j > i; j--) {
if (v... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N, x, k, v[100100];
int main() {
for (int i = 0; i <= 100000; ++i) {
v[i] = -1;
}
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> x >> k;
if (x > v[k]) {
if (x == v[k] + 1) {
++v[k];
} else {
cout << "NO";
return 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[100111];
int b[100111];
int c[100111];
int p[100111];
int pp[100111];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
c[a[i]] = i;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
p[i] = c[b[i]];
}
for (int i = 1; i... | 4 |
#include <bits/stdc++.h>
int inp() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
return sum;
}
int size[100010], head[100010], nxt[200010], end[200010], dfn[100010],
dg[100010], fa[100010];
i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 2005;
const long long inf = 1ll << 50;
int mp[10] = {119, 36, 93, 109, 46, 107, 123, 37, 127, 111};
long long disp[maxn], ans[maxn];
long long dp[maxn][maxn];
long long n, k;
bool is_possible(int index, int rem) {
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
char s[311];
void input() { scanf("%s", &s); }
void solve() {
int resp = 0, resm = 0, a = 0;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == '+')
a++;
else
a--;
resp = max(resp, a);
resm = max(resm, -a);
}
cout << resp + resm << endl;
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mass[101];
int n;
int i;
cin >> n;
i = 0;
while (i < n) {
cin >> mass[i];
i = i + 1;
}
std::sort(mass, mass + n);
for (i = 0; i < n; ++i) std::cout << mass[i] << ' ';
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int N = 101;
int n, k;
vector<pair<long long, long long> > v;
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
v.push_back(make_pair(x, i + 1));
}
sort(v.begin(), v.end()... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar(), f = 0;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
}
int n, v[100005... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, p, q;
} save[10000];
struct node1 {
int x, y;
};
int cnt;
int n;
int g[55][55];
int tmp[55];
int mark[66][66];
void bfs() {
node1 que[20000];
int qf, qd;
qf = 1;
qd = 0;
mark[1][1] = 0;
que[0].x = 1;
que[0].y = 1;
while (qf > qd) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
bool tri(int a, int b, int c) { return (a + b > c && b + c > a && c + a > b); }
bool seg(int a, int b, int c) {
return (a + b == c || b + c == a || a + c == b);
}
void solve() {
bool triangle;
bool segment;
int a, b, c, d;
cin >> a >> b... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 18 | 1;
inline char nc() {
static char ibuf[RLEN], *ib, *ob;
(ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
return (ib == ob) ? -1 : *ib++;
}
inline int rd() {
char ch = nc();
int i = 0, f = 1;
while (!isdigit(ch)) {
if... | 26 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int main() {
ios_base::sync_with_stdio(false);
map<char, char> xd;
xd['A'] = 'A';
xd['b'] = 'd';
xd['d'] = 'b';
xd['H'] = 'H';
xd['I'] = 'I';
xd['M'] = 'M';
xd['O'] = 'O';
xd['o'] = 'o';
xd['p'] = 'q';
xd['q'] = 'p';
xd['T']... | 8 |
#include <bits/stdc++.h>
using namespace std;
void dfs(int v, vector<int> &col, vector<int> &ts, vector<vector<int> > &g) {
col[v] = 1;
for (auto u : g[v])
if (col[u] == 0) {
dfs(u, col, ts, g);
}
ts.push_back(v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, t;
cin ... | 26 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.