solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const double EPS = 1e-10;
const double PI = acos(-1);
struct Point {
double x, y;
} a[N], b[N];
inline Point operator+(const Point &a, const Point &b) {
return {a.x + b.x, a.y + b.y};
}
inline Point operator-(const Point &a, const Point &b) {
ret... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[2 * 100000 + 5];
signed long long int freq[3000000 + 5];
signed long long int ans[3000000 + 5];
signed long long int cum[3000000 + 5];
int main() {
int N, M;
cin >> N;
for (int i = (1); i <= (N); ++i) {
int x;
scanf("%d", &x);
freq[x]++;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4 * 1e5 + 1000;
int a[maxn];
map<int, int> m;
int main() {
int n, k;
while (scanf("%d%d", &n, &k) != EOF) {
m.clear();
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int left, right;
left = right = 1;
bool flag = fals... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct wff {
int to, fro, w;
} e[200005 << 1];
struct wf {
int to, nxt, w;
} edge[200005 << 1];
int n, m, ans, w, num, cnt, fa[200005], flag[200005], h[200005], mx[200005][22],
f[200005][22];
int qwq[200005];
int dep[200005];
bool cmp(wff a, wff b) { return a.w < b.... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e3 + 5;
const int inf = 0x3f3f3f3f;
int a, n, m;
int main() {
cin >> a >> n >> m;
vector<bool> rain(a + 1);
vector<int> p(m + 1);
vector<int> umb(a + 1, -1);
vector<vector<int> > d(a + 1, vector<int>(m + 1, inf));
int l, r, x;
for (int i = 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
int data[100000 + 10];
int main() {
int n, cnt;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &data[i]);
}
for (int i = 29; i >= 0; --i) {
int j = (1 << (i + 1)) - 1;
cnt = 0;
for (int k = n; k >= 1; --k) {
if ((1 << i) & data[k... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long dp[1 << 18][18];
int f[18][18];
int a[18];
int bit(int m, int i) { return (m >> i) & 1; }
long long INF = 1LL << 60;
int main() {
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < 18; i++) {
for (int j = 0; j < 18; j++)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bitset<155 * 155> goal, mask, wall, now;
long long n, m, k;
cin >> n >> m >> k;
for (long long i = 0; i < ((long long)n); i++) {
string str;
cin >> str;
for (long long j = 0; j < ((long long)m); j++) {
((str[j] == '#') ? wall : mask).s... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
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();
}
return x * f;
}
int n, k;
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int min_dist[3005][3005];
vector<int> furthest_out[3005];
vector<pair<int, int> > X;
vector<pair<int, int> > furthest_in[3005];
vector<int> E[3005];
int n;
void bfs(int source) {
for (int j = 1; j <= n; j++) min_dist[source][j] = 1 << 30;
min_dist[source][source] = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000005;
const double PI = 4 * atan(1);
const double eps = 1e-7;
const long long oo = 1e18;
long long n;
long long a[N];
vector<long long> v;
std::vector<pair<pair<long long, long long>, long long> > query;
long long m;
long long tr... | 8 |
#include <bits/stdc++.h>
using namespace std;
int k[100 + 10][100 + 10];
int a[100 + 10];
int main() {
int n, z = 0, u = 0, x = 0;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> k[i][j];
if (k[i][j] == -1 || k[i][j] == 2) {
k[i][j] = 0;
}
if (k[i][... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;
struct cmp {
bool operator()(const pair<int, int> &a, const pair<int, int>... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
bool t;
int main() {
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
cout << v[n - 1] << " ";
int x = v[n - 1];
for (int i = n - 1; i > 0; i--) {
if (x % v[i] != 0) {
cout << v[i] << endl;
t... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
cin >> n >> k;
if (n * (n - 1) / 2 <= k) {
cout << "no solution\n";
return 0;
}
for (int i = 1; i <= n; i++) {
cout << 1 << " " << i + i << "\n";
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m;
x = pow(2, n);
cout << m % x;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
pair<int, int> l[MAXN], r[MAXN];
int ll[MAXN], rr[MAXN];
map<int, int> mapl;
map<int, int> mapr;
int main() {
int n;
scanf("%d", &n);
int ansl = 0, ansr = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &ll[i], &rr[i]);
l[i].first ... | 7 |
#include <bits/stdc++.h>
int main() {
int count;
std::string input;
bool yep;
std::cin >> count;
std::string answer[count];
for (int i = 0; i < count; i++) {
yep = false;
std::cin >> input;
if (input.length() % 2 != 0)
yep = false;
else {
for (int j = 0; j < input.length() / 2; j... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int x, y, z;
cin >> x >> y >> z;
if (x == y && x >= z)
cout << "YES\n" << x << " " << z << " " << z << endl;
else if (x == z && x >= y)
cout << "YES\n" << y << " " << x << " " << y << endl;
el... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int rank[n];
for (int i = 0; i < n; i++) cin >> rank[i];
int point[n];
for (int i = 0; i < n; i++) cin >> point[i];
rank[k - 1] = rank[k - 1] + point[0];
int mark = 0;
for (int i = 0; i < k - 1; i++) {
if (rank[i] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const long long int MOD = 1e9 + 7;
template <typename T>
inline voi... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
int pos = n - 1;
for (int i = 1; i < n; ++i) {
if (s[i - 1] > s[i]) {
pos = i - 1;
break;
}
}
for (int i = 0; i < pos; ++i) cout << s[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int r[5005][2], c[5005][2];
int main() {
int n, m, k;
cin >> n >> m >> k;
memset(r, 0, sizeof(r[0][0]) * 2 * 5005);
memset(c, 0, sizeof(c[0][0]) * 2 * 5005);
for (int i = 1; i <= k; i++) {
int a, b;
cin >> a;
if (a == 1) {
cin >> b >> a;
r[... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e2 + 10;
const int maxm = 1e5 + 10;
vector<int> g[maxn];
int x[maxn], y[m... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> a(n);
map<long long, long long> me, p;
me[0] = 1;
p[1] = 0;
long long cont = 1;
for (long long i = 0; i < n; ++i) {
cin >> a[i];
if (p[me[a[i]]] == a[i]) {
p[me[a[i]]] = i + 1;
me[i + ... | 5 |
#include <bits/stdc++.h>
const int N = 1000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
char s[N][N];
int r, c;
int main() {
scanf("%d%d", &r, &c);
for (int i = 0; i < r; ++i) scanf("%s", s[i]);
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
if (s[i][j] == '.') {
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100007];
int avb[100007] = {0};
bool take[100007] = {0};
int main() {
int i, j;
int n, m;
scanf("%d %d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
int c = 0;
for (i = 1; i <= m; i++) {
if (take[a[i]] == 0) {
take[a[i]] = 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (!(n % 2)) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) {
cout << i << " ";
}
cout << endl;
for (int i = 0; i < n; i++) {
cout << i << " ";
}
for (int i = 0; i < n; i++) {
cout << (i * 2) % n ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, x, ans = 0, k = 0;
scanf("%lld %lld", &n, &m);
scanf("%lld", &x);
k = 1;
while ((n - 2 * (k - 1) > 0) && (m - 2 * (k - 1) > 0)) {
if (k == x) {
ans += ((n - 2 * (k - 1)) * (m - 2 * (k - 1)) + 1) / 2LL;
} else if (k > x) {... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
double tick() {
static clock_t oldticks;
clock_t newticks = clock();
double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC;
oldticks = newticks;
return diff;
}
inline int toInt(string s) {
int x = (int)s[0] - 48;
return x;
}
inlin... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct point {
ll x, y;
bool operator<(point b) const {
return make_pair(x, y) > make_pair(b.x, b.y);
}
};
int n;
vector<point> a, p;
ll det(point a, point b, point c) {
return (a.x - b.x) * (b.y - c.y) * c.x * a.y -
(b.x - c.x) * ... | 18 |
#include <bits/stdc++.h>
using namespace std;
void init() {
ios::sync_with_stdio(0);
cin.tie(0);
}
int getRemaining(int a) {
int n = a / 2;
while (a % n != 0) n--;
return n;
}
int main() {
init();
int n;
cin >> n;
int ans = n;
do {
n = getRemaining(n);
ans += n;
} while (n != 1);
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000003;
int n, k, p[N], stk[N], top, head[N], to[N], nxt[N], dfn[N], siz[N], tim;
inline void add(int a, int b) {
static int cnt = 0;
to[++cnt] = b;
nxt[cnt] = head[a];
head[a] = cnt;
}
inline void dfs(int x) {
dfn[x] = ++tim;
siz[x] = 1;
for (r... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int N;
int arr[MAXN];
int sorted[MAXN];
int compare(int A[], int B[]) {
int errors = 0;
for (int i = 0; i < N; ++i)
if (A[i] != B[i]) ++errors;
return errors;
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d"... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 100000;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int ceil(int a, int b) { return (a + b - 1) / b; }
int main(void) {
int n;
cin >> n;
int p[n + 2];
for (int i = 1; i < n + 1; i++) cin >> p[i];... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
const int offset = 1e5 + 1;
vector<int> dp(2 * offset + 5, 0);
int ans = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int Zalgorithm(string s, int word) {
vector<int> Z(s.size());
int sol = 0, max = 0;
int L = 0, R = 0;
for (int i = 0; i < s.size(); i++) {
if (i > R) {
L = R = i;
while (R < s.size() && s[R - L] == s[R]) R++;
Z[i] = R - L;
R--;
} else... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
#pragma GCC diagnostic ignored "-Wsign-compare"
long long k;
long long m = 360360;
long long use = 42424242;
vector<long long> f(400000, 0ll);
long long solve(long long a, long long b) {
for (int i = 0; i < m; i++) f[i] = use;
f[a] = 0;
f... | 12 |
#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0,... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
pair<long long, long long> extgcd(long long a, long long b,
long long *x = new long long(1),
long long *y = new long long(0)) {
if... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = (int)1e5 + 10;
const int BUBEN = 50;
int n, m;
long long t;
int s;
int f[maxN];
int par[maxN];
pair<int, int> now[maxN];
int val_sq[maxN];
int get_par(int i) {
if (i == par[i]) return i;
par[i] = get_par(par[i]);
return par[i];
}
int sub(int a, int b)... | 21 |
#include <bits/stdc++.h>
const int N = 200200;
const long long mod = 998244353;
using namespace std;
int n;
int m;
int q;
int a[N];
int b[N];
int w[N];
int L[N];
int R[N];
long long d1[N];
long long d2[N];
long long t[4 * N];
vector<int> v[N];
void djk(int x, long long d[]) {
for (int i = 1; i <= n; i++) {
d[i] =... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long a[3];
int main() {
for (int i = 0; i < 3; i++) {
scanf("%I64d", a + i);
}
sort(a, a + 3);
if (a[0] == a[1] && a[0] == a[2]) {
puts("0");
return 0;
}
long long ans = a[2] - a[1] - 1 + a[2] - a[0] - 1;
if (a[1] == a[2]) ans++;
cout << ans... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const long long inf = -1e18;
long long n, k, l, r;
int main() {
cin >> n >> k;
cout << (n / 2) / (k + 1) << " " << (n / 2) / (k + 1) * k << " "
<< n - ((n / 2) / (k + 1) + (n... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, k;
long long m;
int c[110][110], g[110], f[110][10011];
int pwd(int a, long long n) {
int ret = 1;
while (n)
if (n & 1LL)
n--, ret = (long long)ret * a % MOD;
else
n >>= 1, a = (long long)a * a % MOD;
return ret;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3030;
const int MOD = 1e9 + 7;
const long long INF = 4e18;
vector<long long> a[N], f[N], now;
int n, k, t[N];
long long sum[N], ans;
vector<long long> dp(vector<long long> &v, int l, int r) {
vector<long long> res = v;
for (int i = l; i <= r; i++) {
fo... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
static inline int Rint() {
struct X {
int dig[256];
X() {
for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
dig['-'] = 1;
}
};
static X fuck;
int s = 1, v = 0, c;
for (; !fuck.dig[c = getchar()];)
;
if (c == '-'... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, T;
int a[110];
bool b[110] = {0};
pair<int, int> p[110];
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
p[i] = make_pair(a[i], i);
}
for (i = 0; i < m; i++) {
int l, r;
scanf("%d %d", &l, &r);
}
sort(... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) { return l + rng() % (r - l + 1); }
const long long N = 1e5 + 5;
const long long mod = 998244353;
long long n, a[N];
long long e[N];
long long add(long long a, long ... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T>& operator--(vector<T>& v) {
for (auto& i : v) --i;
return v;
}
template <typename T>
vector<T>& operator++(vector<T>& v) {
for (auto& i : v) ++i;
return v;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for... | 24 |
#include <bits/stdc++.h>
using namespace std;
int x, l, r, k, u[30], res, t;
string s, a, b;
vector<int> g, e;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> k >> s >> a >> b;
int n = int(s.size());
g.clear();
for (int i = 0; i < k; ++i) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int c = (n + 1) / 3;
cout << int(round(c / 12)) << " " << int(round(c % 12)) << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, r = 0;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
if ((a[j] - a[i]) <= m) r = r + 2;
}
cout << r;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep;
for (const auto &x : v) os << sep << x, sep = ", ";
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
re... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long prime(long long n) {
for (long long i = 2; i * i <= n; ++i)
if (n % i == 0) return 0;
return 1;
}
signed main() {
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
if (prime(n))
cout << 1;
else if (n % 2 == 0)
cout << 2;
else if (pri... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v(3);
bool f0() {
if (v[0] == v[1] && v[0] == v[2]) return true;
if (v[0][1] == v[1][1] && v[0][1] == v[2][1] && v[1][0] == v[0][0] + 1 &&
v[2][0] == v[1][0] + 1)
return true;
return false;
}
bool f1() {
for (int i = 0; i < 3; ++i)
for (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template <class T>
void in(T& x) {
cin >> x;
}
template <class H, class... T>
void in(H& h, T&... t) {
in(h);
in(t...);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long int T = 1;
in(... | 5 |
#include <cassert>
#include <cstdio>
#include <iostream>
using namespace std;
const int _ = 40 + 7;
const int M = 3931649;
const int mod = 1e9 + 7;
bool be;
int n, a[_], num[_], S[_], T[_], idS, idR, sumS, sumT, f[M + 7][_];
bool vis[_];
int fac[_], ifac[_], inv[_], pwfac[_][_], pwinv[_][_], pwpri[_][_];
int pri[_] ... | 25 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int freq[300005];
int main() {
scanf("%d", &n);
v.resize(n);
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
long long int res = 0;
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) res += abs((i + 1) - v[i]);
printf("%lld", res);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, v, u, d, q, to[200005], nxt[200005], p[100005], w[200005];
int anc[100005][35], dep[100005], spe[55], ro[100005][3], cnt, id[100005];
bool chk[100005];
long long dis[100005][35], fl[55][55], ans, diss[100005][55];
void dfs(int x) {
chk[x] = true;
int k = 0;
... | 16 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
ll a[n];
for (int i = 0; i < n; ++i)
{
/* code */
cin>>a[i];
}
ll ans = 0, sum = a[0];
ll start = a[0];
for (int i = 1; i < n; ++i)
{
ll temp = max(0ll,(100... | 5 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
using namespace std;
long long d, k, a, b, t, k_cost_walk, k_cost_drive;
cin >> d >> k >> a >> b >> t;
if (a >= b) {
cout << d * b << "\n";
return 0;
}
k_cost_walk = k * b;
k_cost_drive = k * a + t;
if (k_cost_walk <= k_co... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int ans = 0;
while (true) {
if (n == 1) {
cout << ans << endl;
return;
}
if (n % 6 == 0) {
n /= 6;
} else if (n % 3 == 0) {
n *= 2;
} else {
cout << -1 << endl;
return;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string str;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h1, a1, h2, a2, c;
cin >> h1 >> a1 >> c;
cin >> h2 >> a2;
int k = 0, cnt = 0;
while (h2 > 0) {
if (k & 1) {
h1 -= a2;
} else {
cnt++;
if (h1 <= a2) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string... | 7 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n + 1);
vector<int> b(n + 1);
b[0] = 1;
a[1] = 1;
for (int i = 2; i <= n; ++i) {
vector<int> c = b;
bool good = true... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long k, n, a, b;
cin >> k >> n >> a >> b;
long long c = k - a * n;
if (c > 0) {
cout << n << '\n';
return;
} else {
long long diff = a - b;
c = -c;
long long y = (c + 1LL + diff - 1LL) / diff;
if (y > n) {
cout << ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int tt = 1;
cin >> tt;
while (tt--) {
string s;
cin >> s;
int len = s.size();
int k = 0;
sort(((s).begin()), ((s).end()));
if (s[0] == s[len - 1]) {
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int logN = 17;
const int inf = 1e9;
const int N = 1e6 + 5;
int l[N], n, m, mod, dp[5005][5005], P[N], C[N];
vector<int> all[N];
int f(int l, int k) {
if (!l) return k == 0;
if (!k) return 0;
int &r = dp[l][k];
if (r != -1) retu... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const double eps = 1e-14;
void YES(bool t = 1) {
const string YESNO[2] = {"NO", "YES"};
cout << YESNO[t] << endl;
}
void Yes(bool t = 1) {
const string YesNo[2] = {"No", "Yes"};
cout << YesNo[t] << endl;
}
void yes(bool t = 1) {
const s... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1ll << 60;
const int N = 1010, M = 10001;
long long dp[2][M], c[N], cost[N], B, W, X;
int n, all;
int main() {
scanf("%d %lld %lld %lld", &n, &W, &B, &X);
for (int i = 0; i < n; i++) scanf("%lld", c + i);
for (int i = 0; i < n; i++) scanf("%lld",... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
bool x[6][6];
int a, b;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
x[a][b] = 1;
x[b][a] = 1;
}
for (int i = 1; i <= 3; i++)
for (int j = i + 1; j <= 4; j++)
for (int k = j + 1; k <= 5; k++)
if ((x[i][j] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
string operation(int idx, string a) {
for (int i = 0; i <= idx; i++) {
if (a[i] == '0') {
a[i] = '1';
}
if (a[i] == '1') {
a[i] = '0';
}
}
reverse(a.begin(), a.begin() + idx);
return a;
}
int main() {
int t;
cin >> t;
while (t--) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int f[5];
int m, k, n;
string a, b;
int win(char r1, char r2) {
if (r1 == r2) return 0;
switch (r1) {
case 'R':
return r2 == 'S' ? 2 : 1;
case 'S':
return r2 == 'P' ? 2 : 1;
default:
return r2 == 'R' ? 2 : 1;
}
}
int main() {
cin >> n >... | 5 |
#include <bits/stdc++.h>
using namespace std;
class MaxFlowSolver {
public:
int S, D;
vector<vector<int> > F;
vector<vector<int> > C;
vector<bool> viz;
vector<int> T;
vector<int> Q;
int stq, drq;
vector<vector<int> > G;
MaxFlowSolver(int n) {
n += 3;
S = 0;
D = n - 1;
F.resize(n);
... | 13 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
int A[m];
vector<int> E[n];
for (int i = 0; i < m; i++) {
scanf("%d", A + i);
A[i]--;
if (i != 0) {
if (A[i] != A[i - 1]) {
E[A[i - 1]].push_back(A[i]);
E[A[i]].push_back(A[i - 1]);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 2010;
int v[SZ], ans[SZ];
bitset<SZ> used;
int gcd(int a, int b) {
int t;
while (b) {
t = a;
a = b;
b = t % b;
}
return a;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int q, n, ok, k, i, cnt, l;
cin... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
int chkmin(T &x, const T1 &y) {
return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
int chkmax(T &x, const T1 &y) {
return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
int main() {
ios_base::sync_with_stdio(false);
cin.tie... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
template <typename T>
inline void read(T &x) {
char ch, t = 0;
x = 0;
while (!isdigit(ch = (iS == iT
? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int dominoes;
cin >> dominoes;
int groups = 0;
int prev = 0;
int current = 0;
for (int i = 0; i < dominoes; i++) {
prev = current;
cin >> current;
if (prev != current) {
groups++;
}
}
cout << groups << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> columns;
int column;
for (int i = 0; i < n; i++) {
cin >> column;
columns.push_back(column);
}
sort(columns.begin(), columns.end());
for (int x : columns) {
cout << x << ' ';
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
char mat[110][110];
bool isin(int i, int j) { return i >= 0 && i < 8 && j >= 0 && j < 8; }
bool f[12][10][10];
int main() {
int N, i, M, a, b, j;
int t, x, y, dx, dy;
while (scanf("%s", mat[0]) != EOF) {
for (i = 1; i < 8; i++) scanf("%s", mat[i]);
memset(f, f... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long double eps = 1e-8;
long long read() {
char ch = getchar();
long long x = 0;
int op = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') op = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10];
int piece, len;
int l, r;
for (int i = 1; i <= 6; i++) {
cin >> a[i];
}
piece = 0;
len = a[1];
l = 2, r = 6;
while (l != r) {
if (l == 2 && r == 6) {
len++;
}
if ((l + r) % 2 == 1) {
piece += len * 2;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
template <typename T>
bool chmax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
template <typename A, typename B>
ostream &operator<<(ostream &out, const pair<A, B> &p)... | 22 |
#include <cstdio>
#include <algorithm>
int quick_power(int a,int b,int Mod){
int ans=1;
while(b>0){
if(b&1){
ans=1ll*ans*a%Mod;
}
b>>=1;
a=1ll*a*a%Mod;
}
return ans;
}
const int Mod=998244353;
const int G=3;
const int Maxk=400000;
int find_inv(int x){
return quick_power(x,Mod-2,Mod);
}
int n,k;
namespac... | 25 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const double PI = 3.14159265358979323846264338f;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const long long mod = 1000000007;
const int MAXN = 100005;
inline int read() {
int c = 0, f = 1;
char ch = getchar();
while (ch < '0' ||... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, c, s;
set<pair<int, int> > w, b;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c >> s;
if (c)
b.insert(make_pair(s, i));
else
w.insert(make_pair(s, i));
}
while (b.size() && w.size()) {
pair<int, int> x, y;
x = *... | 13 |
#include <bits/stdc++.h>
using namespace std;
int const mod = 1000000007;
int v[1005];
int main() {
int n, m, a, b;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
v[a] = 1;
v[b] = 1;
}
for (int i = 1; i <= n; i++)
if (!v[i]) a = i;
cout << n - 1 << endl;
for (int i = 1; i <= n... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;
int ans[maxn][maxn];
int main() {
ios::sync_with_stdio(false);
int inti[4][4] = {
{8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};
int n;
cin >> n;
n /= 4;
int mul = 0;
for (int i = 1;... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
cin >> x;
}
template <typename T, typename... Types>
inline void read(T& x, Types&... args) {
cin >> x;
}
const long long N = 100;
long double p[N][N];
long long n;
bool ok[4 * N][N];
long double dp[4 * N][N];
long double d... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5, MOD = 1e9 + 7;
int n, m;
int Arr[MAX_N];
int dp[MAX_N];
int ans[60][60];
int cnt[256];
string s;
int num[256];
int p = 1;
int F[MAX_N];
int Fdiv[MAX_N];
int _sum(int a, int b) {
int c = a + b;
if (MOD <= c) c -= MOD;
return c;
}
int _mul(int... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int read() {
int x = 0;
char ch = getchar();
bool positive = 1;
for ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1100, M = 60;
char a[N], b[N], c[N];
int ne_c[N], ne_b[N], f[N][M][M];
int main() {
scanf("%s%s%s", a + 1, b + 1, c + 1);
int len_a = strlen(a + 1), len_b = strlen(b + 1), len_c = strlen(c + 1);
for (int i = 2, j = 0; i <= len_c; i++) {
while (j && c... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
struct point {
double x, y;
point() {}
point(double x, double y) : x(x), y(y) {}
bool operator==(const point &u) const {
return !(((x - u.x) > 0 ? (x - u.x) : -(x - u.x)) < 1e-9) &&
!(((y - u.y) > ... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using T = pair<ld, ld>;
const ld eps = 1e-6;
inline ld ternary_search(T a1, T a2, T b1, T b2) {
ld l = 0.0, r = 1.0;
T v1 = T(a2.first - a1.first, a2.second - a1.second);
T v2 = T(b2.first - b1.first, b2.second - b1.second);
for (int i = 0; i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN(101);
const int MAXE(5000010);
const int MAXK(100010);
const int MAXC(2);
const int INF((INT_MAX - 1) / 2);
const int BASE(20);
const double LIM(1e50);
const double EPS(1e-5);
const double PER(0.02);
const double MUL(3.5);
int IT;
template <typename T>
inline... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt = -1, temp, qcnt = 0;
int deg[500000], l1[500000], l2[500000];
int fir[500000], to[1000000], nxt[1000000];
int fa[500000], ans[500000], f[500000];
int id[500000], mx[2000000], o[500000];
vector<int> len[500000];
struct query {
int x, val, o;
} qu[1000000];
inli... | 21 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.