solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
map<string, int> M;
int main() {
int N;
M["Tetrahedron"] = 4;
M["Cube"] = 6;
M["Octahedron"] = 8;
M["Dodecahedron"] = 12;
M["Icosahedron"] = 20;
while (cin >> N) {
int Sum = 0;
for (int i = 0; i <... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool chk[16];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
int s = 0, x;
for (int j = 0; j < k; j++) {
scanf("%d", &x);
s = s * 2 + x;
}
if (s == 0) return 0 & puts("YES");
chk[s] = true;
}
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long Mod = 1e9 + 7;
long long powmod(long long a, long long b) {
long long res = 1;
a %= Mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % Mod;
a = a * a % Mod;
}
return res;
}
long long gcd(long lo... | 0 |
#include <bits/stdc++.h>
long long pow(long long n, int power) {
long long ans = 1;
for (int i = 0; i < power; i++) {
ans *= n;
}
return ans;
}
int main() {
long long n;
int size = 0;
std::cin >> n;
long long temp = n, sum = 0;
while (temp) {
size++;
temp /= 10;
}
for (int i = 1; i < s... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
void solve() {
cin >> n >> k;
int ans = n;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i <= k) ans = min(n / i, ans);
if (n / i <= k) ans = min(i, ans);
}
}
cout << ans << "\n";
}
int main() {
int t;
cin >> t;
while... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); }
const long long MAX = 1111;
long long C[MAX][MAX];
void pascal_triangle(long long mod) {
for (long long i = 0; i < MAX; ++i) C[i][0] = C[i][i] = 1;
for (long long i = 2; i < MAX; ++i)
for (long long j = 1; j... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long readi() {
long long input = 0;
char c = ' ';
while (c < '-') {
c = getchar();
}
bool negative = false;
if (c == '-') {
negative = true;
c = getchar();
}
while (c >= '0') {
input = 10 * input + (c - '0');
c = getchar();
}
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
int ans = 0;
int c;
map<int, int> m, cnt;
for (int i = 1; i <= n; i++) {
cin >> c;
m[c]++;
if (m[c] == 1) {
cnt[1]++;
} else {
cnt[m[c] - 1]--;
if (cnt[m[c] - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 2;
const int inf = 1e3 + 3;
int n;
int a[N], d[N];
int tmp[N];
pair<int, int> arr[N];
pair<int, int> fff[N];
int solve() {
for (int i = 1; i <= n; ++i) {
fff[i] = make_pair(i - a[i] * inf, i);
}
sort(fff + 1, fff + 1 + n);
for (int i = 1; i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<string> a(n);
unordered_set<string> s;
for (int i = 0; i < n; ++i) {
cin >> a[i];
s.insert(a[i]);
}
long long ans = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
if (i == j) cont... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
const int mod = 1e9 + 7;
const long long llinf = (long long)2e18;
long long dp[N][3];
long long a[N];
long long n;
long long fi, se;
long long ans = llinf;
vector<long long> pr;
inline void get(long long x) {
long long p = 2;
while (p * p <= x) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn], sum[maxn], lazy[maxn];
vector<int> st[maxn], d[maxn];
vector<int> big;
bool Less[maxn];
int cnt[maxn][510];
int main() {
int n, m, q, k;
long long x, ans;
char op[2];
scanf("%d%d%d", &n, &m, &q);
int bsz = sqrt(n);
b... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, count = 0;
cin >> n;
vector<pair<long double, long double>> vct(n);
long long i, j;
for (i = 0; i < n; i++) cin >> vct[i].first >> vct[i].second;
sort(vct.begin(), vct.end());
for (i = 0; i < vct.size() - 1; i++) {
for (j = i + 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_H = 100;
const int MAX_W = 100;
int fs[MAX_H][MAX_W], tps[MAX_H][MAX_W];
int main() {
int h, w;
scanf("%d%d", &h, &w);
memset(fs, -1, sizeof(fs));
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
if (fs[y][x] < 0)
for (int c = ... | 7 |
#include <bits/stdc++.h>
double dp[55][5005];
int f[64], s[64], p[64];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &f[i], &s[i], &p[i]);
}
double l = 0, r = 1000000000;
while (r * 0.9999999999 > l) {
double mid = (l + r) / 2;
for (int i = 0; i <= m... | 8 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int v_, l_, r_;
} tnode_t;
tnode_t lstree[1 << 22];
char s[1000002];
int n, m;
void build(int nidx, int left, int right) {
if (left == right) {
lstree[nidx].v_ = 0;
lstree[nidx].l_ = s[left] == ')' ? 1 : 0;
lstree[nidx].r_ = s[left] == '(' ?... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
int num[N], op[N], n, x;
int main() {
scanf("%d%d", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%d", op + i);
++num[op[i]];
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
int to = x ^ op[i];
to = to == op[i] ? num[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 1;
int n, m, a[maxn], ans[maxn];
const int B = 20;
struct LB {
int vec[B], pos[B];
LB() {
memset(vec, 0, sizeof(vec));
memset(pos, 0, sizeof(pos));
}
inline void push(int value, int pos) {
for (int i = B - 1; i >= 0; --i)
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
namespace mine {
long long qread() {
long long ans = 0, f = 1;
char c = getchar();
while (c < '0' or c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
return ans * f;
}
void write(lon... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct ss {
int v, t;
};
ss s[100006];
int n, a, d;
double tmm[100006];
double t1, t2, t3, s1;
int main() {
scanf("%d%d%d", &n, &a, &d);
for (int i = 0; i < n; i++) {
scanf("%d%d", &s[i].t, &s[i].v);
if (i == 0) {
t1 = (s[i].v * 1.0) / (a * 1.0);
s... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[1005];
vector<int> b[1005];
int n, sz[1005], x, st, ed, id, LL, RR, lo, hi;
int sol(int L, int R, int id) {
lo = -1, hi = b[id].size();
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (b[id][mid] > L)
hi = mid;
else
lo = mid;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500001;
const int oo = 1e9;
const int LOGN = 20;
const int MOD = 1000000007;
const double PI = acos(-1);
int n, a[N];
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int mn = oo, idx = -1;
for (int t = 1; t <= 101; ++t) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 4e5 + 10;
long long mod = 1e9 + 7;
long long sparse[nax][2];
map<int, int> map_l[2];
long long bin_pow(long long a, long long p) {
long long r = 1;
while (p) {
if (p & 1) r = r * a % mod;
a = a * a % mod;
p >>= 1;
}
return r;
}
int main()... | 10 |
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::valu... | 9 |
#include <bits/stdc++.h>
using namespace std;
string A[102], T = "12345RGBYW";
int color[102], num[102], n;
int main() {
cin >> n;
string inp;
for (int i = 0; i < n; i++) cin >> A[i];
int ans = INT_MAX;
vector<string> rem;
for (int mask = 0; mask < (1 << 10); mask++) {
memset(color, 0, sizeof color);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
char s[N];
int main() {
scanf("%d%d%s", &n, &m, s + 1);
char mn = 'z', mx = 'a';
for (int i = 1; i <= n; ++i) mn = min(mn, s[i]), mx = max(mx, s[i]);
if (m > n) {
for (int i = 1; i <= n; ++i) putchar(s[i]);
for (int i = n + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int sc[150];
int p[75][75];
double q[150][75];
int l[150], r[150];
double dp[150][75];
double sum[150];
int main() {
int i, j, k, n, N, pnt;
cin >> N;
n = 1 << N;
for (i = 1; i <= n; i++) {
q[0][i] = 1;
for (j = 1; j <= n; j++) {
scanf("%d", &p[i][j]);... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main(int argc, char const* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
bool comp(pair<int, int>& a, pair<int, int>& b) {
if (a.first < b.first) return true;
if (a.first == b.first) return a.second > b.s... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
char c;
int f = 1;
while (!isdigit(c = getchar()))
if (c == '-') f = -1;
x = (c & 15);
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
x *= f;
}
const int mod = 998244353, inv2 = (mod + 1) / 2;
int n, m, i, j, in... | 13 |
#include <bits/stdc++.h>
const long long INF = 1000000000000000000ll;
void GetDivisors(int a, std::set<int> &divs) {
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
divs.insert(i);
while (a % i == 0) a /= i;
}
}
if (a != 1) divs.insert(a);
}
int Abs(int value) {
if (value < 0) return -v... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int ll[4], rr[4];
long long int ans_x, ans_y, ans_z;
bool check(long long int R) {
for (int i = 0; i < 4; i++)
if (ll[i] - R > rr[i] + R) return false;
for (int i = 0; i < 2; i++) {
long long int l[4], r[4];
for (int j = 0; j < 4; j++) {
l[j]... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010][1010];
int in[1010];
int check() {
for (int t = 1; t < n; ++t) {
for (int i = 0; i < n; ++i) {
int j = (i + t) % n;
if (a[j][i] || a[i][j] || in[i] == m) continue;
a[i][j] = 1;
++in[i];
}
}
for (int i = 0; i < n; +... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int count = 0, a, b, temp = 1;
cin >> a >> b;
while (temp != 0) {
count += a / b;
temp = a % b;
a = b;
b = temp;
}
cout << count;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
string tostore = "[:|:]";
int curr = 0;
unsigned long long toremove = 0;
int i;
for (i = 0; i < n; i++) {
if (s[i] == tostore[curr]) {
if (curr < 2) curr++;
if (curr == 2) break;
} else {... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
long long ans = 1;
x %= p;
while (y > 0) {
if (y & 1) ans = ((ans % p) * (x % p)) % p;
y = y >> 1;
x = (x * x) % p;
}
return ans % p;
}
map<long long, long long> M;
long long n, m;
long long cost... | 3 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long magic = 1e9 + 7;
int main() {
char s[2005];
char s1[2005];
char s2[2005];
scanf("%s", &s);
scanf("%s", &s1);
scanf("%s", &s2);
int sz = strlen(s);
int sz1 = strlen(s1);
int sz2 = strlen(s2);
unsigned long long t1 = 0, t2 = 0;
u... | 6 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long power(long long x, unsigned long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) {
res = res * x;
}
y = y >> 1;
x = x * x;
}
return res;
}
long long powermod(long long x, unsigned long long y, long... | 5 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int combi(unsigned long long int num) {
unsigned long long int ans;
ans = (num * (num - 1)) / 2;
return ans;
}
int main() {
unsigned long long int i, j, rem, ans, a, b, mx, mi, sum, res, div;
cin >> a >> b;
res = a - (b - 1);
mx = (res * (re... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, temp;
cin >> n;
int arr[101];
for (int i = 0; i < 101; i++) arr[i] = 0;
for (int i = 0; i < n; i++) {
cin >> temp;
arr[temp]++;
}
int var = 0;
int c1 = 0, c2 = 0;
int p1, p2;
for (int i = 0; i < 101; i++) {
if (arr[i] != 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int w, h, k, sum = 0;
cin >> w >> h >> k;
for (int i = 0; i < k; i++) {
if ((w - 2) >= 0 && (h - 2) >= 0) {
sum = sum + w * h - ((w - 2) * (h - 2));
w = w - 4;
h = h - 4;
}
}
printf("%d", sum);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int sm[400005];
struct th {
int tp, pl, id;
bool operator<(const th &r) const { return pl < r.pl; }
} p[400005];
const int pls = 200002;
int nr[400005], fr[400005], nx[400005];
int fl[400005];
int ns[400005], res[400005];
int m, n;
int cal(int a, int b) {
if (a > b) s... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
long long diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
long long int r;
cin >> r;
vector<long long int> l(n + 1), t(n + 1);
long long int res = 0;
for (int i = 0; i < n; i++) {
cin >> l[i];
}
for (int i = 0; i < n; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
char x[102400], y[102400];
int XN, YN;
void reduce(char *cp) {
for (cp += 2; *cp; cp++) {
if (cp[0] == '1' && cp[-1] == '1') {
cp[0] = '0';
cp[-1] = '0';
cp[-2] = '1';
cp -= 3;
}
}
}
int main() {
char ans = '=';
gets(x + 1);
gets(y ... | 4 |
#include <bits/stdc++.h>
const int N = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-7;
using namespace std;
int a[N], s[N];
map<int, int> asum, ssum;
map<int, vector<int> > pos;
map<int, int> size;
int main() {
int n, m, k, S;
cin >> m >> k >> n >> S;
for (int i = 1; i <= m;... | 5 |
#include <bits/stdc++.h>
int main() {
int n, ans = 0, a;
int p[10001];
memset(p, 0, sizeof(p));
bool flag = true;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
p[a] = i + 1;
}
for (int j = 10000; j >= 1; j--) {
if (p[j] > 0 && flag) {
printf("%d ", p[j]);
flag =... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long dp[505][505];
long long pw[505][505];
long long c[505][505];
long long fast(long long x, long long y, long long k) {
long long s = 1;
while (y) {
if (y % 2) s = s * x % k;
x = x * x % k;
y = y >> 1;
}
return s;
}
long long inv(long long x) { re... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x... | 8 |
#include <bits/stdc++.h>
const int N = 20, M = 6, K = 5;
int n, a[N];
int f[N][K], g[N][K];
struct Tuple {
int a, b;
Tuple() {}
Tuple(int _a, int _b) : a(_a), b(_b) {}
inline int sum() { return 7 * a + 4 * b; }
};
std::vector<Tuple> tuple;
void init() {
for (int a = 0; a <= M; ++a)
for (int b = 0; a + b <... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
reverse(s1.begin(), s1.end());
cout << (s2 == s1 ? "YES" : "NO");
return 0;
}
| 0 |
#include <bits/stdc++.h>
template <typename A, typename B>
inline void umin(A &x, B y) {
if (x > y) x = y;
}
template <typename A, typename B>
inline void umax(A &x, B y) {
if (x < y) x = y;
}
const int N = 200005;
using namespace std;
int a, b;
long long cnt[N];
long long ans;
int main() {
cin >> a >> b;
for (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)(1e9 + 7);
const int N = 1111;
long long f[N][N][4], result[N], C[N][N];
int n, kk;
inline void add(long long &a, const long long &b) {
a += b;
if (a >= MOD) a -= MOD;
}
int main() {
scanf("%d %d", &n, &kk);
for (int i = 0; i <= n; i++) {
C[... | 9 |
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair<int, int>;
using pLL = pair<ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2>
inline void chadd(T1 &x, T2 y, int Mod = mod) {
x += y;
while (x >= Mod) x -= Mod;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (true) {
if (n == 1) {
cout << "YES";
return 0;
}
if (n % 2 == 1) {
cout << "NO";
return 0;
}
n = n / 2;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 17;
const int inf = 2e8 + 10;
const int mod = 1000000007;
long long n;
int k;
string s, a, b;
int calc(string s, string p, int x = -1) {
string a = p + "#" + s;
if (x != -1) x += p.length() + 1;
int n = a.length();
vector<int> z(n);
int ans =... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point { typedef Point P; T x, y;
explicit Point(T x_=0, T y_=0) : x(x_), y(y_) {}
bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
bool operator==(P p) const { return tie(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, h, d;
cin >> n >> d >> h;
if (d > 2 * h || (d == 1 && n != 2)) {
cout << -1;
return 0;
}
for (int i = 1; i <= h; ++i) cout << i << ' ' << i + 1 << '\n';
int x = 1;
for (int i = 1; i <= d ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char temp[11][36];
string arr[11];
int arrc[11];
int goback(string &str, int cnt, int indx = 0) {
if (cnt < 0 || ((indx == n) && cnt)) return 0;
if (indx == n) {
for (int i = 1; i < m; i++) {
int c = 0;
for (int j = 0; j < n; j++)
if (s... | 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 a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long ans = 0, same = 0;
for (lon... | 1 |
#include <bits/stdc++.h>
void out(int n, int k) {
printf("%d", n);
while (k--) printf("0");
puts("");
}
int a[200];
char s[110000];
int main() {
scanf("%s", s);
int numw = 0, i, j, cnt = 0;
for (i = 0; s[i]; i++) {
if (s[i] == '?')
numw++;
else if (s[i] >= 'A' && s[i] <= 'Z')
a[s[i]]++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
unordered_map<long long, long long> vis;
long long ans = LLONG_MAX;
for (long long i = 0; i < n; i++) ... | 2 |
#include <bits/stdc++.h> //includes maximum header files
using namespace std;
using vi = vector<int>; //works like typedef
using ll = long long;
using vll = vector<long long>;
using vd = vector<double>;
using twodv = vector<vector<ll>>;
#define f(m,n) for(int i = m; i < n; i++)
#define vect(v) v.begin(),v.end()
#defi... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
const int MAXSEG = 1 << 18;
int N, Q;
int A[MAXN];
double seg[MAXSEG];
double mult[MAXSEG];
double add[MAXSEG];
void build_tree(int node, int left, int right) {
if (left == right) {
seg[node] = A[left];
return;
}
int mid = (left + righ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
int num[100005], stp = -1;
vector<pair<int, int> > output;
int ans = 0;
void dfs(int u, int p) {
num[u] = ++stp;
output.push_back({u, stp});
if (stp == ans) {
stp = num[u] - 1 - (int)edges[u].size() + 1;
output.push_back({u, stp});
... | 9 |
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
const int N=55;
int n,k,kb[N];
ll d,lim[N][2],c[N],f[N][N][N][4][4],ans;
bool ck(int i,int l,int r)
{
fo(j,l+1,r-1) if(i+1>=kb[j]) return 0;
return 1;
}
void Mn(ll&x,ll y) {if(x>y)x=y;}
int ma... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool f(int x, int y) { return x > y; }
bool comp(int a, int b) { return (a < b); }
int len(long long num) {
int count = 0;
while (num != 0) {
count++;
num /= 10;
}
return count;
}
long long int fact(long long int a, long long int b) {
long long int j = 1, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
if (b < a) a = b;
return a;
}
template <class T>
T &maxx(T &a, T b) {
if (a < b) a = b;
return a;
}
int &madd(int &a, int b) {
a += b;
if (a >= 1000000007) a -... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long p = 1000003LL;
long long n, c;
long long power(long long x, long long n) {
long long ret = 1LL;
while (n > 0LL) {
if (n & 1LL) ret = ret * x % p;
x = x * x % p;
n >>= 1LL;
}
return ret;
}
long long ans;
int main() {
cin >> n >> c;
ans... | 5 |
#include <bits/stdc++.h>
const int MAXN = 100005;
using namespace std;
void goodbye() {
cout << "NO\n";
exit(EXIT_SUCCESS);
}
void check_occ(const string &s) {
int occ[26] = {0};
for (char c : s) {
occ[c - 'a']++;
if (occ[c - 'a'] > 1) {
goodbye();
}
}
}
string merge(string s1, string s2) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int main() {
int i, n, tots = 0, mx = 0, ans = 0, totone;
gets(s);
n = strlen(s);
for ((i) = 0; (i) < (n); (i)++) {
totone = 0;
tots++;
while (i < n && s[i] == '1') {
i++;
totone++;
}
mx = max(totone, mx);
if (i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
void yes() {
cout << "YES"
<< "\n";
}
void no() {
cout << "NO"
<< "\n";
}
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const long long INF = 8e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7;
void solve() {... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
double large = 1000000000000000000.;
double primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
int n;
double power(double x, int p) {
double ans = 1ll;
for (int i = 0; i < p; ++i) {... | 6 |
#include<bits/stdc++.h>
#define ll long long
#define eb emplace_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
const int M=3e5+9;
int n,m,id=0;
ll ans=0;
int s1[M],s2[M],fat[M],lid[M],dep[M],f[M<<1][29];
vector<int>g[M],d[M];
vector<pii>p[M];
map<int,int>mp[M];
void dfs(int u,int... | 9 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int x[n], y[n], t[n];
double p[n];
for (int i = 0; i < n; ++i) scanf("%d%d%d%lf", x + i, y + i, t + i, p + i);
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (t[j] < t[i])
std::swap(x[i], x[j]), std::swap(y[i], y... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, k, a[300010], q, l, r, x, o;
long long suf[200010];
long long fac[30];
void build() {
for (long long i = n; i >= 1; i--) {
a[i] = i;
suf[i] = suf[i + 1] + a[i];
}
fac[0] = 1;
for (long long i = 1; i <= 15; i++) {
fac[i] = fac[i - 1] * ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long p[n], c[n];
for (long long i = 0; i < n; i++) cin >> p[i] >> c[i];
if (p[0] >= c[0]) {
long long flag = 0;
for (long long i = 1; i < n; i++) {
if... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x[n];
int y[n];
bool r, l, u, d;
r = false;
l = false;
d = false;
u = false;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
int X = x[i];
int Y = y[i];... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long A, long long B) {
return A > B ? gcd(B, A) : A ? gcd(B % A, A) : B;
}
long long lcm(long long A, long long B) { return A / gcd(A, B) * B; }
long long pow(long long A, long long B, long long P) {
if (!B) return 1 % P;
long long h = pow(A, B / 2,... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int p = (n - k);
cout << a[p];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, t, r = 0;
cin >> n >> t;
bool f = true;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (!i) {
r += a;
continue;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using papers = bitset<20000>;
const int N = 200;
int n, m;
papers p[N + 1];
unordered_map<papers, vector<int>> g;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
cin >> n;
m = n * (n - 1) / 2;
if (n == 2) {
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100, mod = 1e9 + 7;
char s[N];
int cnt[200];
int main() {
int n, mx = 0, c = 0;
cin >> n;
scanf("%s", s);
for (int i = 0; s[i]; i++) {
cnt[s[i]]++;
mx = max(mx, cnt[s[i]]);
}
if (cnt['A'] == mx) c++;
if (cnt['G'] == mx) c++;
if (cnt[... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000005], d[1000006];
int main() {
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
memset(d, 0, sizeof(d));
for (int i = 1; i <= n; i++) {
cin >> a[i];
d[a[i]]++;
}
int res = 0, vt = 0;
for (int i = 0; i <= 1e6; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int R, N;
double result;
int main() {
cin >> N >> R;
for (int i = 1; i <= N; ++i) {
result += 2;
if (i - 1 >= 1) result += 2 + sqrt(2);
if (i - 2 >= 1) {
result += 1.0 * (i - 2) * (2 + 2 * sqrt(2));
result += 1.0 * (i - 2) * (i - 3);
}
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Tpoint {
double x, y;
Tpoint() {}
Tpoint(double _x, double _y) {
x = _x;
y = _y;
}
inline void read() { scanf("%lf%lf", &x, &y); }
inline void show() { printf("%lf %lf\n", x, y); }
inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); }... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int allin = 0;
int in = 0;
int folded = 0;
unsigned char c;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c;
if (c == 'A')
allin++;
else if (c == 'F')
folded++;
else
in++;
}
if (allin == 0 && folded ==... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
char s[N];
int main() {
int n;
scanf("%d", &n);
scanf("\n%s", s + 1);
int p = 1, cnt = 0;
if (n & 1) {
printf("%c", s[1]);
p++;
}
while (p <= n) {
cnt++;
if (cnt & 1 && cnt != 1) printf("-");
printf("%c", s[p++]);
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, x;
bitset<512> B[512];
int main() {
for (cin >> n >> k, B[0][0] = 1; cin >> x;)
for (int i = k; i >= x; i--)
if (B[i - x].any()) B[i] = (B[i - x] << x) | B[i] | B[i - x];
cout << B[k].count() << endl;
for (int i = 0; i <= k; i++)
if (B[k][i]) c... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int st, nd, cnt = 0, n, female[5500] = {0}, male[5500] = {0};
char gen;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> gen;
cin >> st >> nd;
for (int j = st; j <= nd; j++) {
if (gen == 'M')
male[j]++;
else
female[... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a = 0;
cin >> n >> m;
while (m >= 2 && n >= 3)
if (n > m + 1) {
n -= 3;
m -= 1;
a += 6;
} else {
n -= 2;
m -= 2;
a += 6;
}
if (n >= 3 || m == 0)
a += 2 * n;
else if (m >= 2 || n <= 1)
a... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll OO = 1e18;
int di[8] = {0, 0, 1, -1, -1, 1, -1, 1};
int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1};
string ys = "YES", no = "NO";
const long double dgr = acos(-1) / 180, dg = 180 / acos(-1);
const int mod = 1e8 + 7, N = 1e7, M... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5111;
const long long base = 10000000;
const int mod = 1000000007;
template <typename T>
T ABS(T n) {
return n > 0 ? n : -n;
}
long long convert(long long x, long long y, long long dx, long long dy) {
return (x << 22) | (y << 2) | (dx << 1) | (dy);
}
se... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
bool sortbysec(const pair<long long, long long>& a,
const pair<long long, long long>& b) {
if (a.sec... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dr4[] = {0, 1, -1, 0};
int dc4[] = {1, 0, 0, -1};
int n, m, h, w;
pair<int, int> p[N];
long long int fact[N];
long long int dp[N];
long long int pw(long long int x, l... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int x, y, a, b;
cin >> x >> y >> a >> b;
if ((y - x) % (a + b) == 0)
cout << (y - x) / (a + b) << endl;
else
cout << "-1" << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[500021], ans[1021][1021];
int main() {
ios::sync_with_stdio(false);
cin >> n;
int pos, x, y;
for (int i = 1; i <= n; i++) {
cin >> pos >> x >> y;
if (pos == 1) {
a[x] += y;
for (int i = 1; i <= 710; i++) ans[i][x % i] += y;
} else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n + 10];
for (int i = 1; i <= n; ++i) cin >> a[i];
long long s, f;
cin >> s >> f;
long long b[n + 10];
for (int i = 1; i <= n + 10; ++i) b[i] = 0;
long long j = 1;
long long z = 0;
for (long long i = 1; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int cmax = 223466;
int p[cmax];
set<int> s;
int n, q;
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int x, int y) {
int xx = find(x);
int yy = find(y);
if (xx == yy) return;
if (rand() % 2) swap(xx, yy);
p[xx] = yy;
}
int main() {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using Pii = pair<int, int>;
constexpr int MAX = 1000100;
using namespace std;
struct SegTree {
i64 sum[MAX];
int M, LIM;
void PushUp(int x) { sum[x] = sum[x << 1] + sum[(x << 1) | 1]; }
void Init(int n, int m) {
for (M = 1; M < n + 2; M <<... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.