solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
int n, m, pos, deg[110], mat[110][110], stack[110] = {-1};
void find() {
int i;
pos = 0;
for (i = 1; i <= n; i++)
if (deg[i] == 1) {
stack[pos++] = i;
}
return;
}
void update() {
int i, j, k;
for (k = 0; k < pos; k++) {
i = stack[k];
deg[i] = 0;
for (j = 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long fi = 13, g;
bool s[1000000];
bool f1(long long n) {
if (n == 2) return 1;
if (n % 2 == 0 || n < 2) return 0;
for (int i = 3; i <= sqrt(n); i += 2) {
if (n % i == 0) {
return 0;
}
}
s[n] = 1;
return 1;
}
long long f2(long long n) {
... | 4 |
#include <cstdio>
#include <vector>
int cs[200005];
int inv[200005];
bool vis[200005];
std::vector<std::pair<int,int> > moves;
void flip(int x,int y){
moves.push_back({x,y});
std::swap(cs[x],cs[y]);
std::swap(inv[cs[x]],inv[cs[y]]);
}
void gobble(int x,int y){
//x and y are in same cycle and have wrong par... | 10 |
#include <bits/stdc++.h>
double pi = 3.1415926535897932384626433832795028841971693993751;
using namespace std;
int a[1000000], b[1000000];
vector<int> s[100005];
int k = 0;
int main() {
long long n;
int k;
scanf("%lld %d", &n, &k);
long long k1 = n;
int c1 = 0, c = 0, c2 = -1, res = -1;
while (k1 != 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Dummyf {
template <typename... Ts>
void operator()(Ts&&...) {}
};
struct Graph {
template <typename Pre = Dummyf, typename Post = Dummyf,
typename PreE = Dummyf, typename PostE = Dummyf,
typename FailE = Dummyf>
void allDFS(Pre pre, Po... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
vector<int> g[MAXN + 1];
bool vis[MAXN + 1];
long long ans;
void fast_io() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool lucky(int n) {
int rem;
while (n) {
rem = (n % 10);
if (rem != 4 and rem != 7) return fals... | 5 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
string s;
const int N = 1e6 + 1, mod = 1e9 + 7;
int pw[N], has[N], x, y, z;
void check(int i1, int i2) {
if (i1 < 1 || i1 >= i2) return;
if (s[1] == '0' && i1 > 1) return;
if (s[i1 + 1] == '... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long x, long long y) {
if (y == 0) return x;
return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return (x * y) / GCD(x, y); }
long long MPOW(long long a, long long b, long long m = LLONG_MAX) {
if (b == 0) return 1;
long long x = MP... | 4 |
#include <bits/stdc++.h>
using namespace std;
string str;
int len;
bool ans;
int main() {
cin >> str;
len = str.length();
ans = false;
for (int i = 1; i < len - 1; i++) {
if (str[i - 1] != '.' && str[i] != '.' && str[i + 1] != '.' &&
str[i - 1] != str[i] && str[i + 1] != str[i] &&
str[i + 1]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
vector<long long> a(n), b(n);
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < n; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline void FAST_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long h, n;
long long count(long long lo, long long hi, bool past_left, long long height) {
if (lo == hi) return 0;
long long mid = (lo + hi) / 2;
long long ret = 0;
if (past_left)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
double ans = 1000.0;
for (int i = 0; i < n; i++) {
double a, b;
cin >> a >> b;
ans = min(ans, a / b);
}
cout << fixed;
cout << setprecision(10) << (double)m * a... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
int n;
long long elm;
int cnt = 1;
cin >> n;
long long sum = 0;
for (int i = 0; i < n; ++i) {
cin >> elm;
v.push_back(elm);
}
sort(v.begin(), v.end());
sum = v[0];
for (int i = 1; i < n; ++i) {
if (v[i] >= su... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b;
cin >> a >> b;
while (a != 0 && b != 0) {
if (a >= 2 * b)
a = a % (2 * b);
else if (b >= 2 * a)
b = b % (2 * a);
else
break;
}
cout << a << " " << b;
}
| 1 |
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
using namespace std;
int cx[4] = {0, 0, 1, -1};
int cy[4] = {-1, 1, 0, 0};
string Yes[2] = {"No\n", "Yes\n"};
string YES[2] = {"NO\n", "YES\n"};
string Possible[2] = {"Impossible\n", "Possible\n"};
string PO... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int s1[n];
int s2[m];
int check = false;
for (int i = 0; i < n; ++i) {
cin >> s1[i];
}
for (int i = 0; i < m; ++i) {
cin >> s2[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (s... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long INF = 1e9;
inline long long bpow(long long t, long long n) {
long long ans = 1;
while (n > 0) {
if (n & 1) ans = (ans * t) % mod;
t = (t * t) % mod, n >>= 1;
}
return ans;
}
int a[MAX... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
template <class T>
inline void sort(T &a) {
sort((a).begin(), (a).end());
}
template <class T>
inline void rsort(T &a) {
sort((a).rbegin(), (a).rend());
}
template <class T>
inline void reverse(T &a) {
reverse((a).begin(),... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
int f, s;
cin >> s >> f;
--f;
--s;
int tot1 = 0;
for (int i = s; i < f; ++i) tot1 += a[i];
int best = tot1;
int bestd = 0;
for (int d... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MOD2 = 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 (... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int INF = 1E9;
const int MAXN = 100500;
const int MOD = (int)1E9 + 7;
void add(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
int n, m;
vector<int> a[MAXN];
vector<int> where[MAXN];
int used[MAXN], useda[M... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &tx) {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
tx = x * f;
}
inline void... | 6 |
#include <bits/stdc++.h>
using namespace std;
int tiendienluckhonglamviec(int start, int end, int t1, int t2, int p1, int p2,
int p3) {
int time = end - start;
int sowat = 0;
if (time > t1) {
sowat = t1 * p1;
} else
return time * p1;
if (time > t1 + t2) {
sowat = t1 * p... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 8;
int spf[MAXN];
void sieve() {
spf[1] = 1;
for (int i = 2; i < MAXN; i++) spf[i] = i;
for (int i = 4; i < MAXN; i += 2) spf[i] = 2;
for (int i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (int j = i * i; j < MAXN; j += i)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long a[30];
cin >> n;
int i;
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
long long added = a[n - 1];
long long net = added;
for (i = n - 2; i >= 0; i--) {
if (a[i] < added) {
net += a[i];
added = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<char> ans;
int len, len1, flag;
string s;
int main() {
cin >> s;
len = s.size();
if (len <= 3) {
cout << s[0] << endl;
exit(0);
}
int i = 0, j = len - 1;
while (j - i >= 3) {
if (s[i] == s[j]) {
ans.push_back(s[i]);
i++;
j--;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
pair<int, int> p[n];
int t = 0;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
sort(p, p + n);
int start = 0, l = 0, r = 0, s = 0;
for (int i = 0; i < 2 * n; i++) {
if (i < n && p[i].first > 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a1;
char s[5];
int f(int x) { return min(abs(x - 2), abs(x - 3)); }
bool xiaodeng(int x, int y) {
printf("%d %d %d\n", 1, x, y);
fflush(stdout);
scanf("%s", s);
return s[0] == 'T';
}
void check(int a2) {
if (a2 < 1 || a2 > n) return;
if (xiaodeng(a2, a... | 7 |
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<bitset>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0... | 12 |
#include <bits/stdc++.h>
using namespace std;
int q, n, x, y, a, b, c, d, minx, miny, maxx, maxy;
bool pom;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> q;
for (int i = 0; i < q; i++) {
cin >> n;
maxx = 1e5;
maxy = 1e5;
minx = -1e5;
miny = -1e5;
pom = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct par {
int x, y;
par(int nx = 0, int ny = 0) {
x = nx;
y = ny;
}
friend bool operator<(par a, par b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
};
char wasteChar;
char getch(char &c = wasteChar) {
do {
scanf("%c", &c);
} ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long h, n, i, s, sb;
cin >> h >> n;
long long a[n];
s = 0, sb = 0;
long long min1 = 1e18;
for (i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
sb = s;
if (s... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e3 + 10;
int n, m, a[N];
long long dp[N][N], x;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
memset(dp, inf, sizeof(dp));
dp[n + 1][0] = 0;
for (int i = n; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int p, i;
cin >> s;
if (s[0] == '-') {
printf("(");
s.erase(0, 1);
s += ")";
}
printf("$");
p = s.find(".");
if (p == -1) {
p = s.size();
if (s[s.size() - 1] == ')') p--;
if (s[s.size() - 1] != ')')
s += "... | 2 |
#include <bits/stdc++.h>
int n, m;
std::map<int, int> mps[10], tmp[10];
int up10[100];
int s[77000];
void marota() {
std::cin >> n;
up10[0] = 1;
for (int i = 1; i <= 9; i++) up10[i] = up10[i - 1] * 10;
for (int k = 1; k <= n; k++) {
std::cin >> s[k];
for (int i = 0; i <= 9; i++) tmp[i].clear();
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long get(long long l, long long r) {
long long ans = 0;
while (l % 2) ans ^= (--l);
while (r % 2 == 0) ans ^= (++r);
ans ^= (r - l + 1) / 2 % 2;
return ans;
}
int main() {
scanf("%d", &n);
long long ans = 0;
while (n--) {
long long x, m;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[310], nxt[310], v[310], cnt, dp[100010];
long long int t;
bool hd[310];
void calc(int idx, int h) {
cnt++;
t -= (a[idx] * h);
if (nxt[idx]) calc(nxt[idx], h + 1);
v[idx] = a[idx] + v[nxt[idx]];
}
int main() {
ios_base::sync_with_stdio(0);
int q, i, j, b... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
if (n == 1) {
cout << "0\n";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100];
int count0 = 0, count1 = 0, i = 0, flag = 0;
cin >> str;
while (str[i] != '\0') {
if (str[i] == '0') {
count0++;
count1 = 0;
if (count0 == 7) {
cout << "YES";
flag = 1;
break;
}
} el... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MAX = 100005;
const long double PI = 3.14159265359;
const long double G = 9.807;
const long long INF = 1e18;
const long double EPS = 1e-6;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
bool isprim... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
int k;
cin >> k;
int n = s.size();
int ans = 0;
for (int i = 0; i < k; i++) {
char a, b;
cin >> a >> b;
int j = 0;
while (j < n) {
int l = 0, r = 0;
while (j < n && (s[j] == a || s[j] == b)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int N, K;
bool special[MAX];
vector<int> adj[MAX];
int sz[MAX];
int calc_size(int source, int father) {
sz[source] = special[source];
for (auto &each : adj[source]) {
if (each != father) {
sz[source] += calc_size(each, source);
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1505;
int BIT[maxn], A[maxn];
int n, m;
void modify(int j, int n) {
for (; j <= n; j += (j & -j)) BIT[j]++;
}
int prefix_sum(int j) {
int sum = 0;
for (; j > 0; j -= (j & -j)) sum += BIT[j];
return sum;
}
int main() {
ios_base::sync_with_stdio(fal... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ts, tf, t, a, ans, wait = 1e12 + 5;
int n;
scanf("%lld %lld %lld", &ts, &tf, &t);
scanf("%d", &n);
while (n--) {
scanf("%lld", &a);
if (a <= tf - t) {
if (ts - a + 1 < wait) {
wait = ts - a + 1;
ans = min(ts, a ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, r, c, i, j, k, w, h;
char grid[101][101];
set<char> st;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) cin >> grid[i];
while (h < n && grid[h][0] == grid[0][0]) h++;
while (w < m && grid[0][w] == grid[0][0]) w++;
if (!((h == n && w * 3 == m) || (h *... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
struct segtree {
vector<T> tree, lazy;
function<T(T, T)> func;
T def;
int n;
segtree(int n, T def, function<T(T, T)> f) : n(n), func(f), def(def) {
tree.resize(4 * n, def);
lazy.resize(4 * n, def);
};
void push(int s, int e, int ind)... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
void add(int64_t& a, int64_t b) { a = (a + b) % MOD; }
void mul(int64_t& a, int64_t b) { a = a * b % MOD; }
int64_t power_mod(int64_t num, int64_t power) {
int64_t prod = 1;
num %= MOD;
while (power > 0) {
if (power & 1) prod = prod * ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
string s, sub, ans;
int l[N + 200], L[N + 200];
int num[11];
string a, b, c;
int main() {
for (int i = 0; i <= 9; i++) l[i] = 1;
for (int i = 10; i < N; i++) l[i] = l[i / 10] + 1;
for (i... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
char ch;
do {
ch = getchar();
if (ch == '-') f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - '0';
ch = getchar();
} while (ch >= '0' && ch <= '9');
return f * x;
}
const int MAXX = 2e5;
const... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 1e6 + 5;
const int M = 1e4 + 5;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const long double pi = acos(-1.0L);
long long read() {
long long x = 0, t = 1;
char ch;
while (!isdigit(ch = getch... | 8 |
#include <bits/stdc++.h>
using namespace std;
int seg[2400005];
int lz[2400005];
void push(int ver) {
lz[2 * ver] = lz[ver];
lz[2 * ver + 1] = lz[ver];
seg[2 * ver] = lz[ver];
seg[2 * ver + 1] = lz[ver];
lz[ver] = 0;
}
void upd(int ver, int tl, int tr, int l, int r, int val) {
if (tl > tr || l > r || tr < l... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 233333;
int par[N][25], dep[N];
int u, v, ans;
int n;
inline int lca(int u, int v) {
if (dep[u] < dep[v]) {
u ^= v;
v ^= u;
u ^= v;
}
for (int i = 0; i < 25; i++)
if (((dep[u] - dep[v]) >> i) & 1) u = par[u][i];
if (u == v) return u;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a[2001];
int n, d;
int main() {
scanf("%d%d", &n, &d);
for (int i = 1; i <= n; i++) scanf("%lld", a + i);
long long ans = 0;
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
ans += (a[i - 1] - a[i]) / d + 1;
a[i] += ((a[i - 1] - a[i]) /... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;
void boost() {
ios_base ::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
string a[33] = {
"111111101010101111100101001111111", "100000100000000001010110001... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[2 * n];
for (int i = 0; i < 2 * n; i++) {
cin >> arr[i];
}
int count = 0;
for (int i = 0; i < 2 * n; i += 2) {
for (int j = 1; j < 2 * n; j += 2) {
if (arr[i] == arr[j] && j - i != 1) {
count++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
deque<int> x, y;
int n;
char whowins() {
if (x.size() == 0) return 'R';
if (y.size() == 0) return 'D';
auto it1 = x.begin(), it2 = y.begin();
if (*it1 < *it2) {
y.pop_front();
x.push_back((*it1) + n);
x.pop_front();
return whowins();
}
x.pop_fron... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
bool is = false;
for (int i = 0; i < s.size() - (!is); i++) {
if (s[i] == '1' || is) {
cout << s[i];
}
if (s[i] == '0') is = true;
}
cout << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int x[100010], y[100010], c, np[100010], ok[100010], ls[100010], t[100010],
p[100010], l[100010];
char s[100010];
vector<int> r[100010];
void ask(int t) {
if (!c) return;
printf("Q %d ", c);
if (!t) {
for (int i = 1; i <= c; i++) printf("%d %d ", x[i], y[i]);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 200;
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct Coor {
double x, y;
} coors[maxn];
double Distan(Coor a, Coor b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double disa[maxn], disb[maxn];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, res;
long long a[1000010];
long long ans[1000010];
bool cmp(long long a, long long b) { return a > b; }
signed main() {
cin >> n;
for (long long i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + 1 + n);
for (long long i = 2; i <= n;... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long n, tmp1, tmp2, ans;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n / 2; i++) tmp1 += a[i];
for (int i = n / 2 + 1; i <= n; i++) tmp2 += a... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int mod = 998244353;
long long mo(long long a, long long b) { return ((a % b) + b) % b; }
long long gcd(long long a, long long b) {
while (b) {
long long t = a % b;
a = b;
b = t;
}
return a;
}
long long lcm(long long a, long lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, xRange[2], yRange[2];
inline void gMax(int &x, int y) { x = x < y ? y : x; }
inline void gMin(int &x, int y) { x = x > y ? y : x; }
int main() {
xRange[0] = yRange[0] = INT_MAX;
xRange[1] = yRange[1] = INT_MIN;
scanf("%d%d%d", &n, &m, &n);
for (int i = 1; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef struct aa {
int x;
int y;
} node;
bool comp(node a, node b) { return a.y < b.y; }
bool comp2(node a, node b) { return a.y > b.y; }
string atob(const int a) {
stringstream os;
string b;
os << a;
os >> b;
return b;
}
int btoa(string b) {
int a;
if (!... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int i = s.length() - 1;
while (s[i] == 'z') i--;
s[i]++;
for (int j = i + 1; j < s.length(); j++) s[j] = 'a';
if (s == t)
cout << "No such string";
else
cout << s;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, sum = 0;
cin >> n >> k;
pair<int, int> p[n];
for (int i = 0; i < n; i++) {
cin >> p[i].first;
p[i].second = i + 1;
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
k -= p[sum].first;
if (k >= 0)
sum++;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265359;
long double eps = 1e-5;
long double getArea(long double x1, long double y1, long double x2,
long double y2, long double x3, long double y3) {
long double ret = 0.0;
ret += x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline void inpint(int &n) {
n = 0;
register int ch = getchar_unlocked();
bool sign = 0;
while (ch < 48 || ch > 57) {
if (ch == '-') sign = 1;
ch = getchar_unlocked();
}
while (ch >= 48 && ch <= 57) {
n = (n << 3) + (n << 1) + ch - 48, ch = getchar_u... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, t, a, b, da, db;
cin >> x >> t >> a >> b >> da >> db;
if (x == 0) {
cout << "YES" << endl;
return 0;
}
if (x == 0 || (x <= a && x > a - da * t && (a - x) % da == 0) ||
(x <= b && x > b - db * t && (b - x) % db == 0)) {
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2 * PI;
int n;
vector<vector<int> > g;
vector<pair<int, int> > e;
map<pair<int, int>, int> idx;
int ans[N];
inline void solve() {
cin >> n;
g.resize(n + 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int m;
string s;
int x[N], y[N], z[N];
int l, r;
bool ans[N];
int X, Y, Z;
int abs(int n) { return n < 0 ? -n : n; }
int main() {
cin >> s >> m;
for (int i = 1; i <= s.length(); ++i) {
x[i] = (s[i - 1] == 'x') + x[i - 1];
y[i] = (s[i - 1]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
struct Node {
int a;
int b;
int c;
};
Node node[N];
int n;
queue<int> Q;
int dfs(int x) {
if (node[x].c == 0) {
return x;
}
return dfs(node[x].c);
}
int main() {
int mark;
int ne;
while (scanf("%d", &n) == 1) {
mark = 1;
whil... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n, x, y, b[N], a[N][N];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
if (a[i][j] == n - 1) {
x = i;
y = j;
}
}
b[x] = n;
for (int j = 1; j <= n; +... | 1 |
#include <bits/stdc++.h>
int main() {
int n, p, q, i, count = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d %d", &p, &q);
if (q - p >= 2) {
count++;
}
}
printf("%d", count);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long arr[100001];
long long arr1[100001];
int main() {
long long n;
cin >> n;
vector<long long> ans;
long long sum = 0;
long long max1 = 0;
for (long long i = 0; i < n; i++) {
long long num;
cin >> num;
arr[i] = num;
}
for (long long i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int a[N];
const long long inf = (long long)1e14;
inline pair<long long, long long> merge(pair<long long, long long> &x,
pair<long long, long long> &y) {
return {min(x.first, y.first),
min(max(x.first,... | 7 |
#include <bits/stdc++.h>
using namespace std;
char arr[3][3][3][3];
int main() {
int cur = -1, cnt = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
for (int l = 0; l < 3; l++) {
char x;
scanf(" %c", &x);
arr[i][k][j][l] = x;
... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937 kk(490571098);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long N;
cin >> N;
long long sx = 0, dx = 1e9 + 1;
long long t = 0;
while (sx < dx - 1) {
t++;
long long m = (sx + dx) / 2;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, K, C, X;
int arr[3005];
int clr[3005];
vector<pair<int, int>> ans;
void dfs(int n) {
while (clr[n] != C) {
clr[n] = C;
n = arr[n];
}
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) {
cin... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, i, k, k1, k2, alic, bob;
int main() {
deque<int> d;
cin >> n;
for (i = 0; i < n; i++) {
cin >> k;
d.push_front(k);
}
if (d.size() == 1) {
cout << "1"
<< " "
<< "0";
return 0;
}
while (true) {
if (d.front() - d.back(... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9;
void solve() {
int n;
cin >> n;
vector<int> vec(n);
int count = 0;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
vec[i] = s[i] - '0';
if (vec[i] == 2) count++;
}
if (count == 1 || count == 2) {
cout << "NO" << endl;
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int dfa[N][26];
void build(string &s) {
dfa[0][s[0] - 'a'] = 1;
for (int i = 1, j = 0; i <= s.size(); i++) {
for (int k = 0; k < 26; k++) dfa[i][k] = dfa[j][k];
if (i < s.size()) {
j = dfa[j][s[i] - 'a'];
dfa[i][s[i] - 'a'] = i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while (T--) {
int n;
string a, b;
cin >> n >> a >> b;
int cnt = 0;
int s = 0, e = n - 1;
vector<int> ans;
for (int i = n - 1; i >= 0; i--) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, Len, Ans;
string str;
cin >> str;
Len = str.size();
Ans = 0;
for (i = 0; i < Len; ++i) {
if (str[i] == '4') {
Ans += 1 << (Len - i - 1);
} else {
Ans += 1 << (Len - i);
}
}
cout << Ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int co[20];
long long a[100100];
vector<long long> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m, i;
cin >> n;
for (i = 0; i < n && cin >> a[i]; i++)
;
long long mx = 0;
for (i = 0; i < n; i++) {
co[a[i]]++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long simulation(long long n, long long k) {
long long sum = 0;
while (n) {
if (n >= k) {
sum += k;
n -= k;
} else {
sum += n;
n = 0;
}
n = n - (n / 10);
}
return sum;
}
int main() {
long long answer = 0, n;
cin >> n;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1<<29);
const int INFF = 0x7fffffff;
const ll LINF = (1ll<<60);
const ll LINFF = 0x7fffffffffffffff;
const long double PI = 3.14159265359;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll a, ll b){return u... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
int n, m;
int p[N], s[N], b[N];
int inc[N], pref[N];
int sz;
struct node {
vector<int> v1, v2;
} seg[(5 * N) << 2];
vector<int> vec;
void compress() {
for (int i = 0; i < n; i++) {
vec.push_back(p[i]);
vec.push_back(s[i]);
vec.push_ba... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<pair<int, int>, int> a;
int cal(int a, int b) {
if (a == 0 || a == n + 1 || b == 0 || b == m + 1) return -100;
return m * (a - 1) + b;
}
bool chk(int x, int y) {
int x_m = a[make_pair(x - 1, y)], y_m = a[make_pair(x, y - 1)];
int tmp = a[make_pair(x, y... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[2000005];
int deg[2000005];
bool u[2000005];
int n, m, cnt;
long long ans;
void dfs(int v) {
u[v] = 1;
if (deg[v] & 1) {
++cnt;
}
for (int to : adj[v]) {
if (u[to]) {
continue;
}
dfs(to);
}
}
void solve() {
scanf("%d %d", &n... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
ll INF = 1e17;
void solve() {
int n;
cin >> n;
string s;
set<string> ans;
cin >> s;
if (s.size() < n) {
string add = "";
for (int i = 0; i < (n - s.size()); i++) {
add += "0";
}
s = add + s;
}
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct rangeincrease {
int l, r;
};
rangeincrease actions[100001];
rangeincrease inprogress[100001];
int actionL = 0;
int nums[100001];
int opened = 0;
int main() {
int n;
int i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> nums[i];
}
for (i = 1; i <= n; i+... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (((n) * (n - 1)) / 2 > k) {
for (int i = 0; i < n; i++) cout << "0 " << i << endl;
} else {
cout << "no solution" << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005, M = 1000005;
int cnt[M], a[N];
int main() {
int n, k, dif = 0, l = 1, ml = 1, mr = 1, len = 1;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) {
if (!cnt[a[i]]) ++dif;
++cnt[a[i]];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z;
cin >> x >> y >> z;
int ans = min(2 * (x + y), x + y + z);
ans = min(ans, 2 * (y + z));
ans = min(ans, 2 * (x + z));
cout << ans;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, w, h, s[102];
bool ok[101][101][4], v[101][101];
void dfs(int x, int y, int c) {
++s[c];
v[x][y] = true;
if ((ok[x][y][0]) && (!v[x - 1][y])) dfs(x - 1, y, c);
if ((ok[x][y][1]) && (!v[x][y - 1])) dfs(x, y - 1, c);
if ((ok[x][y][2]) && (!v[x + 1][y])) dfs(x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int half = n / 2;
vector<int> cheses;
cheses.resize(half);
int resToWhite = 0;
int resToBalck = 0;
int placeOfNextBlack = 1;
int placeOfNextWhite = 2;
for (int i = 0; i < half; ++i) {
cin >> cheses[i];
}
sort(cheses.... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e12;
const int MOD = 1e9 + 7;
const unsigned long long BIT_FLAG_0 = (1 << 0);
const unsigned long long BIT_FLAG_1 = (1 << 1);
const unsigned long long BIT_FLAG_2 = (1 << 2);
const unsigned long long BIT_FLAG_3 = (1 << 3);
co... | 5 |
#include <bits/stdc++.h>
using namespace std;
int f[550000];
int main() {
int n, d, sum = 0;
memset(f, 0, sizeof(f));
scanf("%d%d", &n, &d);
f[0] = 1;
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
sum += a;
for (int j = sum; j >= a; j--)
if (f[j - a] != 0) f[j] = 1;
}
int an... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool win(char x, char y) {
if (x == 'R' && y == 'S') return 1;
if (x == 'S' && y == 'P') return 1;
if (x == 'P' && y == 'R') return 1;
return 0;
}
int n;
int a1, a2;
int i1, i2;
string s1, s2;
int m;
int main() {
cin >> n;
cin >> s1;
cin >> s2;
int l1 = s1.s... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.