solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
bool comp[1001], mark[1001];
char in[1001], out[1001];
int vet[26], primes[1001], pc, len;
void sieve() {
int lim = sqrt(1001) + 1;
for (int i = 2; i <= lim; ++i) {
if (comp[i]) continue;
for (int j = i * i; j < 1001; j += i) comp[j] = true;
}
for (int i = 2; i < 1001; ++i)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int r, c, rS, cS, rE, cE, rez;
char s[1005][1005];
int m[1005][1005], f[1005][1005];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
queue<int> qer, qec;
int main() {
int i, j, rr, cc, nr, nc;
scanf("%d %d\n", &r, &c);
for (i = 0; i < r; ++i) scanf("%s", s[i]);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
const double eps = 1e-9;
string t;
char c[N];
double f[N][2];
inline int read() {
char c = getchar();
int x = 0, f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + c... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, x, c = 0;
char v;
int s[26] = {0};
cin >> n;
if (n > 26) {
cout << "-1" << endl;
return 0;
} else {
for (i = 0; i < n; i++) {
cin >> v;
x = v - 97;
s[x]++;
}
for (j = 0; j < 26; j++) {
if (s[j... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, q;
vector<int> adj[maxn];
int par[maxn][20];
int sum[maxn][20];
vector<int> roots;
bool mark[maxn];
int starttime[maxn], finishtime[maxn], h[maxn];
int timer;
void dfs(int v) {
mark[v] = 1;
starttime[v] = timer++;
for (int i = 1; i < 2... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, a[300000][2], fa[300000], sz[300000], top[300000], d[300000],
prf[300000], f1[300000], q1[300000], q2[300000];
vector<int> g[300000], b[300000];
map<int, map<int, int> > f2[300000];
long long ans;
void dfs1(int u) {
d[u] = d[fa[u]] + 1;
sz[u] = 1;
for... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 14, lg = 18;
int n, l_tbl[lg][maxn * 2], r_tbl[lg][maxn * 2], ans[maxn];
template <class comp>
int query(int *tbl, int l, int r) {
int ans = max(INT_MIN, INT_MAX, comp());
for (l += 2 * n, r += 2 * n; l < r; l >>= 1, r >>= 1) {
if (l % 2) ans ... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x;
int y;
} p[8];
bool cmp(node a, node b) {
if (a.x < b.x) return true;
if (a.x == b.x && a.y < b.y) return true;
return false;
}
int main() {
for (int i = 0; i < 8; i++) scanf("%d%d", &p[i].x, &p[i].y);
sort(p, p + 8, cmp);
if (p[0].x == ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(double &x, double &y) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a = (n - k) / 2;
for (int i = 0; i < n; i++) {
cout << ((i + 1) % (a + 1) == 0);
}
cout << endl;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
bool win[mx], lose[mx];
int trie[mx][26];
int n, k, res = 1;
string s;
void insert() {
int node = 0;
for (auto c : s) {
if (!trie[node][c - 'a']) trie[node][c - 'a'] = res++;
node = trie[node][c - 'a'];
}
}
void search(int val) {
boo... | 5 |
/*jai_ganeshdeva*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push // adds the value to the last of the queue
#define lld long long int
#define ins insert /// used in set to insert the values
#define adv advance /// used to increment the iterator
#define mp make_pair
#define fi f... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
Node() {}
Node(int a, char b) {
to = a;
c = b;
}
int to;
char c;
};
vector<Node> v[100005];
int n, m;
int vis[100005];
vector<int> ans1, ans2;
vector<int> p[3];
bool dfs(int i, int k, char c) {
if (vis[i]) {
return vis[i] == k;
}
vi... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[300009], ans, o[2];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
ans += a[i] / 2;
if (a[i] % 2) {
o[i % 2]++;
}
}
cout << ans + min(o[0], o[1]);
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
if (n < 2 * k + 1) {
cout << "-1";
return 0;
}
long long ans = 0;
cout << n * k << '\n';
for (long long(i) = (0); (i) < (n); ++(i)) {
for (... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define ll int
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pu push
#define db ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int countOnes(int q) {
int count = 0;
while (q != 0) {
q = q & (q - 1);
count++;
}
return count;
}
int main() {
int countOnes(int q);
int n, m, k, sum = 0;
cin >> n >> m >> k;
int arr[m + 1];
for (int x = 0; x < m + 1; x++) {
cin >> arr[x];
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 2) cout << "1\n", exit(0);
if (n == 3) cout << "7\n", exit(0);
if (n == 4) cout << "11\n", exit(0);
cout << (n % 2 != 0 ? "7" + string((n - 3) / 2, '1') : string(n / 2, '1'))
<< endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int pref[n];
pref[0] = 0;
for (int i = 1; i < n; i++) {
pref[i] = a[i] - a[i - 1];
}
int start = 0, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, ans, x, y;
int a[1000000], p[1000000];
vector<int> b;
int main() {
cin >> n >> m;
scanf("%d", &x);
for (i = 0; i < n - 1; i++) {
scanf("%d", &y);
a[i] = y - x;
x = y;
}
scanf("%d", &x);
for (i = 0; i < m - 1; i++) {
scanf("%d",... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1000000007;
const int N = 200000 + 7;
pair<int, int> arr[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;
sort(arr, arr + n);
int f1 =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, v, u;
cin >> n >> v;
long long steps = 0;
for (int i = 1; i < n; i++) {
cin >> u;
if (u < v) steps += v - u;
v = u;
}
cout << steps << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, count, sum = 0, j;
cin >> n >> m;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
count = 0;
for (i = 0; i < n; i++) {
if (a[i] == m) {
count++;
} else {
sum = 0;
j = i;
while (sum <= m && j < n)... | 1 |
#include <bits/stdc++.h>
namespace OI {
template <class T>
T Fabs(T x) {
return x < 0 ? -x : x;
}
template <class T>
void rd(T &x) {
x = 0;
int f = 1;
char c;
while (!isdigit(c = getchar()))
if (c == '-') f = -1;
do {
x = (x << 3) + (x << 1) + (c ^ 48);
} while (isdigit(c = getchar()));
x *= f;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)2e9 + 7;
long long MIN1 = -INF, MIN2 = -INF, MAX1 = INF, MAX2 = INF, n, m, ans = -INF;
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
long long li, ri;
cin >> li >> ri;
MAX1 = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct po {
int to, next, w;
} e[4000005];
int n, m, st, en, a, b, c, d, cnt = 1, cur[4000005], head[4000005],
deep[4000005];
int xb[10005], sr[10005], g, ans = 0;
void add(int x, int y, int z) {
e[++cnt].to = y, e[cnt].w = z, e[cnt].next =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long sum = 0;
long long x = 0;
while (n--) {
long long s;
cin >> s;
sum += s;
x ^= s;
}
cout << 2 << "\n";
cout << x << " " << sum + x... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long int mod = 1e9 + 7;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigne... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
string gen(int x) {
string ret;
while (x--) ret += "1";
return ret;
}
int main() {
cin >> s;
string ans;
int cnt1 = 0;
for (char c : s) {
if (c == '1') {
cnt1++;
continue;
}
ans += c;
}
if (ans.empty()) {
ans = gen(cnt... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
const int lim = 1e6;
bool check(int elem) { return true; }
void bsearch() {
int lo = 0, hi = 1e9, res = -1, mid;
while (lo <= hi) {
mid = lo + (hi - lo) / 2;
if (check(mid)) {
res = mid;
hi = mid - 1;
} else {
lo = mi... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1];
a[1] = 0;
int p;
for (int i = 2; i <= n; ++i) {
cin >> a[i];
}
p = n;
vector<int> ans;
while (p) {
ans.push_back(p);
p = a[p];
}
for (int i = ans.size() - 1; i >= 0; --i) {
cout << ans[i] <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2000;
int t[MAX_N + 1];
int m[MAX_N + 1];
int h[MAX_N + 1];
int eaten[MAX_N + 1];
int main() {
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; ++i) cin >> t[i] >> h[i] >> m[i];
int answer = 0;
int curr_max = 0;
int curr_t = 0;
int ht = x;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
struct Point {
double x, y;
Point(double a = 0, double b = 0) : x(a), y(b) {}
inline void read() { scanf("%lf%lf", &x, &y); }
inline void print() { printf("%.2lf %.2lf\n", x, y); }
inline Point operator+(const Point &b) { return Point(x... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct Order {
int a, b, idx;
};
int n, p, k;
Order orders[100010];
char used[100010];
struct s1cmp {
bool operator()(const int &a, const int &b) {
return orders[a].a == orders[b].a ? orders[a].b < orders[b].b
: orders[a].a < or... | 7 |
#include <bits/stdc++.h>
using namespace std;
string s;
struct gg {
int a, b, c;
} g[120000];
int cmp(gg x, gg y) {
if (x.a != y.a)
return x.a < y.a;
else
return x.b < y.b;
}
int p[120000];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> g[i].a >> g[i].b;
g[i].c = i;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return w == 1 ? x : -x;... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
inline void debug(int x) { fprintf(stderr, "ycx has aked ioi %d times\n", x); }
namespace fastio {
char ... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int mod = (int)1e9 + 7;
const int N = 1e5 + 10;
const long long inf = 1e11;
long long nxt[N][26];
const long long maxm = 250005;
lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &o... | 11 |
#include <bits/stdc++.h>
const int N = 7e5, MASK = 1 << 30;
char s[N];
int kmp[N] = {-1};
std::vector<int> loss[N];
struct bigInt {
const static int base = 10;
std::vector<long long> v;
void reduce() {
for (int i = 0; v[i] >= base; ++i) {
if (i == v.size() - 1) v.push_back(0);
v[i + 1] += v[i] / b... | 12 |
#include <bits/stdc++.h>
using namespace std;
int solve(string &kind, int slide, int hcost, int wcost, int maxt) {
int n = kind.size();
int result = 0;
{
int res = 0, i = 0, takes = 0;
do {
if (i != 0) takes += slide;
takes += kind[i] == 'h' ? hcost : wcost;
++res;
if (takes <= max... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int H = 16;
const int N = 1 << 18;
int p;
int fpow(int x, int y = p - 2) {
if (!y) return 1;
long long z = fpow(x, y >> 1);
z = z * z % p;
if (y & 1) z = z * x % p;
return z;
}
int l[2], a[2][N];
void dfs(int k, int u, int t, int e) {
u = (u + p) % p;
a[... | 9 |
#include <bits/stdc++.h>
using std::map;
using std::pair;
using std::string;
using std::vector;
map<string, vector<pair<bool, bool>>> SampleInput();
map<string, vector<pair<bool, bool>>> ReadInput(
std::istream& in_stream = std::cin);
void WriteAnswer(const vector<bool>& min, const vector<bool>& max,
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
float n;
cin >> n;
long long int flag = 0;
for (float i = 3; i < 1000; i++) {
float x = (i - 2) * (180 / i);
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000007;
long long INFLL = (long long)INF * (long long)INF;
long double EPS = 10e-9;
long double pi = 2 * acos(0.0);
void solve() {
long long n;
cin >> n;
if (n <= 2) {
cout << n << "\n";
return;
}
long long temp = (n) / 2;
if (n % 2 =... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct tr {
int a, b, c, d;
};
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool b[1000][1000];
int spd[11];
int ans[11];
vector<pair<int, int> > st[11];
string s[1000];
int main() {
int n, m, p;
cin >> n >> m >> p;
for (int i = 1; i <= p; i++) cin >> spd[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = (long long)(998244353)) {
return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = (long long)(998244353)) {
return (a % p + b % p) % p;
}
long long neg(long long a, long long p = (lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int id[N][N], n, m, t, mo;
int fa[N * N], rn[N * N], t1;
int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
int ty[N][N];
long long c[N][N], cnt, ans;
int fail;
void merge(int x, int y) {
if (gf(x) == gf(y)) fail = 1;
fa[gf(x)] = gf(y);
}
lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[55 + 5];
int len;
long long t;
int n;
struct Edge {
int x_1, y_1, x_2, y_2;
} edge[305];
int e_len;
Edge make_edge(int x_1, int y_1, int x_2, int y_2) {
static Edge ans;
ans.x_1 = x_1;
ans.x_2 = x_2;
ans.y_1 = y_1;
ans.y_2 = y_2;
return ans;
}
int x;
voi... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int sum, C[4], re[4], A[100050];
void dfs(int z) {
if (!C[z]) return;
A[++n] = z, C[z]--;
if (z == 0)
dfs(1);
else if (z == 1)
dfs(C[0] ? 0 : 2);
else if (z == 2)
dfs(C[3] ? 3 : 1);
else
dfs(2);
}
int main() {
ios::sync_with_stdio(false)... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(b... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int myfind(long long int l, long long int h, long long int x) {
long long int m, ans;
while (l <= h) {
m = ((h - l) >> 1) + l;
if (((m * (m + 1)) >> 1) >= x) {
ans = m;
h = m - 1;
} else
l = m + 1;
}
return ans;
}
int main() {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, m, i, j, a[N];
set<long long> st;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (0)
;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
vector<long long> ans;
for (i =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const int Maxn = 205;
vector<int> edge[Maxn];
pair<int, int> ver[Maxn], cut;
struct Node {
int len, ver;
};
Node dfs(int u, int fa) {
Node res;
res.ver = u, res.len = 0;
for (int i = 0; i < edge[u].size(); i++) {
int v = edge[u][i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
vector<int> ar(n);
for (auto &i : ar) {
cin >> i;
sum += i;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (!((sum - ar[i]) & 1)) {
++ans;
}
}
cout << ans << '\n';
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool div2(T a) {
return !(a & 1);
}
template <class T>
T mod(T a) {
if (a < 0) {
a += 1000000007;
}
return a % 1000000007;
}
template <class T>
T addmod(T a, T b) {
return (mod(a) + mod(b)) % 1000000007;
}
template <class T>
T prodmod(T a, T... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int MAX = 30;
long long x, num;
long long a[40];
bool check(long long x) {
for (int i = 1; i < MAX; ++i) {
if (a[i] == x) return 1;
}
return 0;
}
vector<int> ans;
int main() {
long long x = 1;
for (int i = 1; i < MAX; ++i) {
x... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, par[1000009], val[1000009], rem[1000009];
tuple<string, int, int> x[1000009];
int dfs(int pos) {
if (get<0>(x[pos]) == "IN") {
return val[pos];
}
if (get<0>(x[pos]) == "NOT") {
int v1 = dfs(get<1>(x[pos]));
val[pos] = (1 ^ v1);
}
if (get<0>(x[po... | 6 |
#include<bits/stdc++.h>
using namespace std;
int read(){
int x=0,pos=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return pos?x:-x;
}
const int N = 320005;
int n,m,q;
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int... | 7 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long F[51];
int X[51];
int Y[51];
int k, x, n, m;
char A[2000];
char B[2000];
int main() {
scanf("%d %d %d %d", &k, &x, &n, &m);
for (int a1 = 0; a1 < 3; ++a1) {
for (int an = 0; an < 3; ++an) {
if (n > 1 || a1 == an) {
for (int b1 = 0; b... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
struct Fp {
long long val;
Fp() : val(0) {}
Fp(long long val_) { this->val = mod(val_, MOD); }
Fp operator=(long long val_) {
this->val = mod(val_, MOD);
r... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string get() {
char ch[1000010];
scanf("%s", ch);
return ch;
}
const int MAX_LG = 60;
const long long maxn = 1e6 + 100;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 1;
while (t--) {
int n, m;
cin >> n >> m;
int i;
while (true) {
for (i = 1; i <= n; i++) {
if (m >= i)
m -= i;
else
break;
}
if (i <= n) break;
}
cout << m << endl;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
long long count = 0;
long long n1 = s.length();
long long n2 = t.length();
if (n1 != n2)
cout << "NO"
<< "\n";
else {
for (long long i = 0; i < n1; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 13e5 + 1000, oo = 1e9;
const long long M = 998244353;
long long last;
long long two(long long v) {
long long l = 1, r = v;
while (r - l > 1) {
long long m = (l + r) >> 1;
if (m > (v + m - 1) / m || m * m > v)
r = m;
else
l = m;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
int n;
scanf("%d\n", &n);
char c[5200];
scanf("%s", c);
string s(c);
int pt = 0;
int cnt = 0;
std::vector<int> t;
for (int i = 0; i < n; i++)
if (i == 0 || s[i] != s[i - 1]) {
cnt++;
t.push_bac... | 8 |
#include <bits/stdc++.h>
int main() {
long long n, x, a, b, c, d;
scanf("%lld", &n);
a = (n / 2 + n / 3 + n / 5 + n / 7);
b = (n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35);
c = (n / 30 + n / 42 + n / 70 + n / 105);
d = n / 210;
x = n - a + b - c + d;
printf("%lld", x);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int t;
string n;
const long long P2LIM = (long long)1e18;
int check(string sour, string tar) {
int token = 0;
int ss = 0;
int tt = 0;
while (ss < sour.size() && tt < tar.size()) {
if (sour[ss] == tar[tt]) {
token++;
ss++;
tt++;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, s, p = 1;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x >> y;
s += ((x - p) % m) + (y - x + 1);
p = y + 1;
}
cout << s << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
bool samoglasnik(char ch) {
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}
int main(void) {
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (i + 2 < s.size() && !samoglasnik(s[i]) && !samoglasnik(s[i + 1]) &&
!samoglasn... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int a[N], n;
long long f[N];
long long sub(int l, int r) { return f[r + 1] - f[l]; }
double cc(int l, int x) {
return 1.0 * (sub(l - x, l) + sub(n - x, n - 1) - 1LL * a[l] * (2 * x + 1)) /
(2 * x + 1);
}
pair<double, int> cal(int pos) {
int l... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
i = 1;
cout << n;
while (i <= n - 1) {
cout << " " << i;
i++;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int deg[maxn], xx[maxn];
queue<int> Q;
bool mark[maxn];
vector<pair<int, int> > v;
void add(int fi, int se) { v.push_back(make_pair(fi, se)); }
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long powe(long long x, long long y) {
x = x % mod, y = y % (mod - 1);
long long ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
void f... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long MAXN = 1e6 + 7;
long long n, m, a, b;
vector<long long> fact(MAXN);
vector<long long> rfact(MAXN);
inline long long pw(long long a, long long n);
inline long long sum(long long x, long long y);
inline long long mult(long long x, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 5, maxK = 3e5 + 5, INF = 0x3f3f3f3f;
int n, k, fa[2 * maxN], cnt[2 * maxN];
char str[maxN];
vector<int> light[maxN];
int Get(int now) {
if (fa[now] == now) return now;
return fa[now] = Get(fa[now]);
}
int GetMin(int u) { return min(cnt[Get(u)], cn... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = 0, may = 0, cont = 0;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
i = 1;
while (i <= n) {
if (a[i] > may) may = a[i];
if (i >= may) {
cont++;
i++;
} else
i++;
}
cout << cont << '\n';... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[100];
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % m == 0)
a[i] = (x / m) - 1;
else
a[i] = (x / m);
}
int ans = 0, pos = 0;
for (int i = 0; i < n; i++)
if (a[i] >= ans) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int countCandy[5010][5010];
int minCandy[5010];
int endTime[5010];
int main(void) {
int N, M;
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
int s, e;
scanf("%d %d", &s, &e);
s--;
e--;
countCandy[s][e]++;
}
for (int i = 0; i < N; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<long long> st[30];
long long Ans;
int main() {
string s;
cin >> s;
s = "*" + s;
for (int i = 1; i < s.size(); i++) {
st[s[i] - 'a'].insert(i);
}
long long q;
cin >> q;
while (q--) {
long long t;
scanf("%I64d ", &t);
if (t == 1ll) {
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
using namespace std;
int n, S;
long long mu[3000010], F[3000010], ans = 0;
const long long p = 1e9 + 7;
bool np[3000010];
vector<int> pr;
template <class T>
void read(T &x) {
char ch = x = 0;
b... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first != b.first) {
return a.first < b.first;
} else {
return a.second < b.second;
}
}
bool is_vowel(char c) {
if (c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u')
ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N, A[101010];
template <typename T>
struct segtree {
public:
segtree() : N(0), data(nullptr) {}
segtree(int len) {
for (int i = 0;; ++i) {
if (len <= (1 << i)) {
N = 1 << i;
break;
}
}
data = new T[2 * N];
for (int i = 0;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
long long n, m;
cin >> n >> m;
if (n == 0 and m == 0) {
cout << 0 << " " << 0;
} else if (n == 0 and m != 0) {
cout << "Impossible";
} else {
... | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const ll INF=1e18;
int t,n,dep[N],fa[N];
ll a[N],dp[N],mn[N],mx[N],Min[N],Max[N],levelMin[N],levelMax[N];
vector<int>e[N];
void dfs(int u,int d){
levelMin[d]=min(levelMin[d],a[u]);
levelMax[d]=max(levelMax[d],a[u]);
dep[u]=d;
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 2e5 + 5;
int a[maxn];
int cnt[maxn];
int pre[maxn];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
}
sort(a + 1, a + 1 + n);
pre[0] = 0;
for (int i = 1; i <= 2e5; i++) {
pre[i] = pre[i -... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long dp[300010][41];
int main() {
int N, A[300010];
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", A + i);
}
for (int i = 0; i <= N; i++)
for (int j = 0; j <= 40; j++) dp[i][j] = 2000000000000000000LL;
dp[0][0] = 0;
for (int i = 0; i <... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const double PI = 3.14159;
long long n, m, k, a[N], c, t, ans;
string s, x;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m >> k;
while (k--) {
ans += n * 2;
ans += (m - 2) * 2;
m -= 4;
n -= 4;
}
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[500010];
vector<int> vec[500010];
int p[500010];
vector<int> e[500010];
bool vis[500010];
bool ok[500010];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d %d", &u, &v);
e[u].push_back(v);
e[v].pus... | 4 |
#include <iostream>
using namespace std;
void solve(){
int n, k;
cin >> n >> k;
int x_cord[n], y_cord[n];
for(int i = 0; i < n; i++)
{
cin >> x_cord[i] >> y_cord[i];
}
int ans = -1;
for(int i = 0; i < n; i++)
{
bool flag = true;
for(int j = 0; j < n; j++){
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {
return a.second < b.second;
}
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> a;
vector<int> del;
int x, y;
int i, j, k;
int64_t z, sum;
z = -1e12;
cin >> n;
a.resize(n + 1);
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i < n; i++) {
for (j = n; j > i; j--) {
if (a[i] != a... | 3 |
#include <bits/stdc++.h>
int N, l[300001], r[300001];
long long K;
struct segment {
int l, r, time;
inline bool operator<(const segment &b) const { return l < b.l; }
};
std::set<segment> S;
std::map<int, int> _op[300001];
std::vector<std::pair<int, int> > op[300001];
struct ans_t {
long long count, sum;
inline ... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct ww {
double x, y, z;
inline void read() { scanf("%lf%lf%lf", &x, &y, &z); }
inline void print() { printf("%.12lf %.12lf %.12lf\n", x, y, z); }
inline ww operator-(const ww &A) { return (ww){x - A.x, y - A.y, z - A.z}; }
inline ww operator+(const ww &A) { re... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, x, y, s;
cin >> n;
s = 0;
for (i = 0; i < n; i++) {
scanf("%d %d", &x, &y);
if (s + x <= 500) {
s += x;
printf("A");
} else {
s -= y;
printf("G");
}
}
cout << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<long long> v[2];
long long n;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) {
v[s[i] - 'A'].push_back(i);
}
long long ans = 0;
for (int i = 0; i < v[0].size(); i++) {
if ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long Rnumbs, Lnumbs;
int L[100001], R[100001];
int n;
bool loop() {
Lnumbs = 0;
Rnumbs = 0;
for (int i = 1; i <= n; i++) {
cin >> L[i] >> R[i];
Lnumbs += L[i];
Rnumbs += R[i];
}
int k = 0;
long long maxs = abs(Lnumbs - Rnumbs);
for (int i = 1;... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
char ch = getchar();
long long f = 1, x = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f * x;
}
const long long ma... | 7 |
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
bool adj[18][18];
i64 dp[1 << 18][18];
i64 lenCnt[19][1 << 18];
template <typename T>
void subset_transform(int N, T a[1 << 18]) {
int L = 1 << N;
for (int k = 1; k < L; k *= 2) {
for (int i = 0; i < L; i += 2 * k) {
for (int j = 0; j... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, m, x;
cin >> n >> m >> x;
vector<vector<long long>> g(n, vector<long long>(m));
for (long long i = 0; i < n; i++)
for (long long j = 0; j < m; j++) cin >> g[i][j];
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.