solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 2e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
inline int read_int() {
char c;
int ret = 0, sgn = 1;
do {
c = getchar();
} while ((c < '0' || c > '9') && c... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline void prep() {
cin.tie(0);
cin.sync_with_stdio(0);
};
long long mod = 1e9 + 6;
const int biggg = 1e9 + 1;
const long long bigggest = 1e18;
const double eps = 1e-10;
const double pi = acos(-1.);
long long mymod(long long num) {
if (num < 0) {
if (mod == 1) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int n, a, b;
int t[5005][2];
int dp[5005][2];
vector<pair<int, int> > p;
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a, &b);
p.push_back({a, b});
}
sort(p.begin(), p.end());
for (int i = 0; i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
int max_r;
int b[n];
fill(b, b + n, 0);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
max_r = arr[n - 1];
for (int i = n - 2; i >= 0; i--) {
if (max_r < arr[i]) {
max_r = arr[i];
} else
b... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, big, ans, a[MAXN], b[MAXN];
bool flag;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
do {
flag = false;
big = 0;
int tmp = 0;
for (int i = 0; i <= 30; ++i)
for (int j = 1; j <= n; +... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long sm[55][55][55][55] = {};
long long dp[55][55][55][55] = {};
int32_t main() {
long long n;
cin >> n;
string g[55];
for (long long i = 0; i < n; ++i) cin >> g[i];
for (long long i = n - 1; i >= 0; --i) {
for (long long j = n - 1; j >= 0; --j) {
f... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <c... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long ar[200004], ara[200004];
int main() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> ar[i];
long long cnt = 1;
ara[1] = 1;
long long last = 1;
long long ans = 0;
for (long long i = 2; i <= n + 1; i++) {
if (ar[i] > ar[i - 1])
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100 + 10;
const int INF = 0x7f7f7f7f;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int realcmp(double a, double b) {
return (a > b + eps) ? 1 : ((a + eps < b) ? -1 : 0);
}
vector<int> vt[Maxn];
int main() {
int n, m;
string str;
io... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[1000000];
int main() {
long long int i, j, k, l, n, q, x, f, m, store, sum, p;
sum = 0;
double y;
cin >> n >> m;
long long int a[n + 1];
for (i = 1; i <= n; i++) {
scanf("%I64d%lf", &x, &y);
a[i] = x;
}
for (i = 1; i <= n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, Base = 998244353;
const long long N = 3e5 + 7;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7LL;
const double pie = acos(-1.0);
long long angle, Ang = INF, op, x;
void Take_Min(long long angle, long long x) {
if (ang... | 10 |
#include <bits/stdc++.h>
using namespace std;
void doRoutine() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
srand(322179);
}
const long long INF = 1000000000000000000;
const long long MOD = 998244353;
const int MAXN = 200005;
int n, q;
struct State {
long long val;
long long k, b... | 17 |
#include <bits/stdc++.h>
int main() {
int n, i, j, k, sum = 0, t = 1, count = 0;
scanf("%d", &n);
for (i = 1; i < i + 1; i++) {
for (j = 1; j <= t; j++) {
sum = sum + j;
}
t++;
if (sum > n)
break;
else
count++;
}
printf("%d\n", count);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int v[10001], viz[10001], c[10001], out[10001], b[10001];
multiset<int, greater<double> > s[10001];
int main() {
std::ios::sync_with_stdio(false);
int i, k, n, t, x, y, nr, j;
long long sol;
cin >> n >> t;
for (i = 1; i <= n; i++) {
cin >> x >> y;
if (t >=... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int BASE = 27;
const int N = 200000 + 2;
const int LOGN = 20;
const long long oo = 1e18;
const double EPS = 1e-9;
const int MAXN = 12;
int t, n, m, g[MAXN][2002], mx[MAXN + 1][1 << MAXN], dp[2][1 << MAXN];
struct col {
int mx;
vector<int... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > graf[2 * 100 * 1000 + 5];
pair<int, int> maxi[2 * 100 * 1000 + 5];
int rep[2 * 100 * 1000 + 5], roz[2 * 100 * 1000 + 5];
int grup[100 * 1000 + 5], tab[100 * 1000 + 5];
int szuk(int dom) {
if (dom == rep[dom]) {
return dom;
}
return rep[dom]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x;
cin >> x;
vector<long long int> prime;
long long int n = x;
if (n % 2 == 0) {
prime.push_back(2);
while (n % 2 == 0) n /= 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
if (n % i == 0) {
prime.push_back(i);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool vis[10010];
pair<int, int> P[200];
int main() {
int n;
scanf("%d", &n);
int begin = -1;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &P[i].first, &P[i].second);
if (P[i].first == 0 && begin == -1) begin = i, vis[i] = true;
}
int ka = begin;
int p... | 7 |
#include <bits/stdc++.h>
const int N = 100 + 10, MOD = 1000000007;
int n, m, p;
int mem[2][N][N][N], C[N][N];
int main() {
scanf("%d%d%d", &n, &m, &p);
C[0][0] = 1;
for (int i = 1; i < N; ++i)
for (int j = 0; j <= i; ++j)
C[i][j] = std::min(C[i - 1][j] + (j ? C[i - 1][j - 1] : 0), N) % MOD;
mem[1][1][... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1001;
const long long MOD = 1000000007;
const long long INF = LLONG_MAX;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
vector<string> s;
bool vis[N][N];
bool isvalid(int x, int y) {
return (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> binarysearch(
vector<pair<long long int, long long int>>& arr, long long int low,
long long int high, long long int a) {
if (low > high) {
return make_pair(-1, -1);
}
long long int mid = (low + high) / 2;
if (arr[mid].f... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &res) {
res = 0;
T f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <c... | 25 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MAXN = 2e5 + 5;
int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
while (cin >> str) {
int len = str.size();
int num;
cin >> num;
vector<int> str_pos;
while (num--) {
int pos;
cin >> pos;
str_pos.push_back(pos);
}
sort(str_pos.begin(), str_pos.end());
int sum =... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, a, soma;
cin >> n >> h;
soma = 0;
while (n > 0) {
cin >> a;
if (a <= h) {
soma++;
} else {
soma = soma + 2;
}
n--;
}
cout << soma << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace __detail;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (b >= a)
cout << "Second";
else
cout << "First";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const long long INF = 1e16 + 7;
char ff[5][N];
int cost[5];
long long DP[N][5][1 << 8];
long long fun(int n, int p, int fill) {
if (DP[n][p][fill] != -1) return DP[n][p][fill];
if (n == 0) {
if (fill)
return DP[n][p][fill] = INF;
els... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x = x * f;
}
int T, l, r, d[200020];
int a, b, mid;
signed main() {... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
int a[505][505];
long long meme[2][2][505][505];
long long dp(int x, int y, bool f, bool b) {
if (x > y) return 1;
if (x == y) {
int cnt = 0;
if (f) cnt += a[x - 1][x];
if (b) cnt += a[x][x + 1];
return cnt;
}
if (meme... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-11;
int n, m, w;
vector<pair<int, double> > ans[50];
double c[50];
int occ[50];
int main() {
scanf("%d%d%d", &n, &w, &m);
int nn = n;
double d = n * w;
d /= m;
double dw = d;
d /= w;
int in_d = 0;
int pos = 0;
if (in_d > 0) {
for ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct song {
int l, p;
bool operator<(const song& k) const {
return p * (100 - k.p) * l > k.p * (100 - p) * k.l;
}
};
song s[50005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d %d", &s[i].l, &s[i].p);
sort(s + 1, s + n + 1);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int Min(int a, int b) { return a > b ? b : a; }
static inline int rd() {
unsigned int r = 0;
char c = getchar();
char flag = 0;
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') flag = 1, c = getchar();
for (; c >= '0' && c <= '9'; c =... | 9 |
#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--) {
int n, x;
cin >> n >> x;
if (n <= 2) {
cout << 1 << endl;
} else {
cout << 1 + (n - 2 + x - 1) / x << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, sum = 0, ans = 0;
struct node {
int v, id;
bool operator<(const node &a) const { return v < a.v; }
} A[105];
char str[10005][105];
priority_queue<node> Q;
int main() {
scanf("%d", &n);
int mi = 105;
for (int i = 1; i <= n; i++) {
scanf("%d", &A[i].v), A... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a = 0;
cin >> n;
string s;
cin >> s;
long long m = 2 * n;
vector<long long> p, q;
for (long long i = 0; i < m; i++) {
if (i < n) {
a = s[i] - '0';
p.push_back(a);
} else {
a = s[i] - '0';
q.push_back(a)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
int num[] = {1, 2, 3, 5, 7, 11};
int f(int x) {
for (int i = 0; i < 6; ++i) {
if (x == num[i]) return -1;
}
return x / 4 - x % 2;
}
int main() {
int n;
cin ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, minim = 100000000000, index = 0;
scanf("%I64d", &t);
vector<long long> min_index;
long long arr[200005];
for (int i = 1; i <= t; ++i) {
scanf("%I64d", &arr[i]);
if (arr[i] <= minim) {
minim = arr[i];
}
}
for (int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int fs[100005];
int main() {
queue<int> s1, s2;
int n, p, q;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p;
s1.push(p);
}
for (int i = 0; i < n; i++) {
cin >> q;
s2.push(q);
}
int cnt = 0;
while (!s1.empty()) {
int x = s1.front();
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n, x, c;
int a[1000000];
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
c = 0;
for (int i = 0; i < n; i++) {
if (a[i] != a[i - 1]) c++;
}
cout << c << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
long long int count = 0;
cin >> n;
long int a[n];
for (long int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (long int i = 0; i < n / 2; i++) {
count = count + pow(a[i] + a[n - 1 - i], 2);
}
cout << count;
re... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, l, r;
long long a, b, c, d;
long long s, t;
void ee(long long a, long long b) {
if (b == 0) {
s = 1;
t = 0;
d = a;
return;
}
ee(b, a % b);
long long s1 = t, t1 = s - (a / b) * t;
s = s1, t = t1;
}
int main() {
cin >> a1 ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int fac[1000010], inv[1000010], pre[3][1000010], suf[3][1000010];
char s[1000010];
inline int C(const register int x, const register int y) {
return x >= y && x >= 0 && y >= 0
? 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
long long l, r;
cin >> l >> r;
long long ans = 0;
int x = 0;
while ((r >> x) & 1) {
x++;
if (x == 60) break;
}
int y = 60;
whil... | 9 |
#include <bits/stdc++.h>
int main() {
int alph[26];
int n, i, j, k, add;
long long int length;
scanf("%d", &n);
for (i = 0; i != n; i++) {
scanf("%d", &alph[i]);
}
for (i = 1; i != n; i++) {
k = alph[i];
for (j = i - 1; j >= 0 && alph[j] < k; j--) {
alph[j + 1] = alph[j];
}
alph[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c;
int main() {
cin >> n >> c >> b >> a;
n *= 2;
long long sum = 0;
for (int i = 0; i <= a; i++) {
for (int j = 0; j <= b; j++) {
if ((n - ((i * 4) + (j * 2)) <= c) && (n - ((i * 4) + (j * 2)) >= 0)) {
sum++;
}
}
}
cout <... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool wrap(const string& s, size_t width, size_t k) {
for (size_t init = 0, lines = 1, line_start = 0; init < s.size();) {
auto next = s.find_first_of("- ", init);
if (next > s.size()) next = s.size() - 1;
if (next + 1 - line_start > width) {
lines++;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long int power(long long int a, long long int b) {
long long int res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int arr[258];
int flag[200005];
int main() {
string a, b, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
a = (a + b);
if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
template <class T>
bool domin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool domax(T &a, ... | 14 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e4 + 50;
const int mod = 1e9 + 7;
using namespace std;
int n, k, x, f, r... | 14 |
#include <bits/stdc++.h>
using namespace std;
double power(double x, int n) {
if (n == 0) return 1.0;
if (n == 1) return x;
double t = power(x, n / 2);
t = t * t;
if (n % 2) return t * x;
return t;
}
int main() {
int m, n;
cin >> m >> n;
double ans = 0.0;
for (int i = 1; i <= m; i++) {
ans += i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300011;
const int inf = 1e9;
int n;
set<int> st, pleft, pright;
int main() {
scanf("%d", &n);
st.insert(-inf);
st.insert(inf);
pleft.insert(inf);
pleft.insert(-inf);
pright.insert(inf);
pright.insert(-inf);
int x;
scanf("%d", &x);
st.insert... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
scanf("%d", &N);
int temp = N / 2;
if (N % 2 == 0) {
printf("%d\n", temp);
for (int i = 1; i <= temp; i++) {
printf("2 ");
}
} else {
printf("%d\n", temp);
for (int i = 1; i < temp; i++) {
printf("2 ");
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
while (a[i] % 2 == 0) a[i] /= 2;
while (a[i] % 3 == 0) a[i] /= 3;
}
for (int i = 1; i < n; ++i) {
if (a[i] != a[i - 1]) {
cout << "NO";
return 0;
}... | 5 |
#include <bits/stdc++.h>
long long mpoll(long long a, long long n, long long mod) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % mod;
b = (b * b) % mod;
n >>= 1;
}
return (long long)ret;
}
using namespace std;
using namespace std;
int bit[2 * (int)1e5 + 5];
void upd... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
void solve() {
long long a, b, c, r;
cin >> a >> b >> c >> r;
if (a > b) {
swap(a, b);
}
long long left = c - r;
long long right = c + r;
if (right < a || ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct data {
int idx, val;
};
bool cmp(data d1, data d2) { return d1.val < d2.val; }
int main() {
vector<int> v(26, 0);
string s;
int k;
cin >> s >> k;
int l = s.size();
for (int i = 0; i < l; i++) v[s[i] - 'a']++;
vector<data> w;
for (int i = 0; i < 26; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m;
cin >> n >> m;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
if (x > y) swap(x, y);
a[i] = make_pair(x, y);
}
vector<pair<int, int>> b(m... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
if (a < b) return a;
return b;
}
long long max(long long a, long long b) {
if (a > b) return a;
return b;
}
vector<long long> divisors(long long n) {
vector<long long> d;
int i;
for (i = 1; i * i < n; ++i) {
if (n ... | 8 |
#include <bits/stdc++.h>
const int MAXN = 110;
const int W = 100;
const int P = 998244353;
void exgcd(int a, int b, int& x, int& y) {
if (b == 0)
x = 1, y = 0;
else
exgcd(b, a % b, y, x), y -= a / b * x;
}
inline int inv(int a) {
int x, y;
exgcd(a, P, x, y);
return (x % P + P) % P;
}
int a[MAXN], w[MA... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[2005][2005];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
int ans = 0;
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = 1; j <= m + 1; j++) {
if (s[i][j] == '.')
cnt++... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int x[100009];
int main() {
int n, k, i;
scanf("%d%d", &n, &k);
if (n == 1) {
if (k == 0)
printf("1\n");
else
printf("-1\n");
return 0;
}
if (k < n / 2) {
printf("-1\n");
return 0;
}
for (i = 1; i <= n - (2 + (n & 1));... | 7 |
#include <bits/stdc++.h>
const int N = 100005;
const int M = 200010;
using namespace std;
int n, T;
int fa[N][20], dep[N];
int cnt = 0, dfn[N], las[N];
long long a[N], sum[N], val[N];
int edge[M], lst[N], nxt[M], t = 0;
int lowbit(int x) { return x & (-x); }
void UPD(int x, long long num) {
if (num == 0) return;
fo... | 15 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
using namespace std;
int n, m;
char s[200005];
int mp[3][200005];
struct node {
int ab, aa, bb, ba;
void clear() { ab = aa = bb = ba = inf; }
} tr[200005 * 4];
node pushup(node l, node r) {
node res;
res.aa = min(inf, min(l.aa + r.aa, l.ab + r.ba) + 1);
res... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 200005;
void solve() {
int n, h, m, k;
cin >> n >> h >> m >> k;
vector<int> v;
m /= 2;
map<int, int> mp;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
y++;
v.push_back({y % m});
int yy = v.... | 15 |
#include <bits/stdc++.h>
using namespace std;
int readInt() {
int x;
if (scanf(" %d", &x) != EOF) return x;
return -1;
}
long long int readLint() {
long long int x;
if (cin >> x) return x;
return -1;
}
string readString() {
string s;
if (cin >> s) return s;
return "";
}
struct Operation {
char op;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
char s[5005];
int n;
bool dp[5005][5005];
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
int m = (1 << 31 - __builtin_clz(n)) - 1;
int left = n - m, p;
for (int i = 0; i <= n - left; i++) dp[i][i] = 1;
char ch = 'z' + 1;
for (int i = 1; i <= n; i++)
i... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n, sz[N], par[N];
vector<int> adj[N];
bool mark[N];
void dfs1(int u) {
sz[u] = 1;
for (auto v : adj[u])
if (v ^ par[u]) {
par[v] = u, dfs1(v);
sz[u] += sz[v];
}
}
void dfs2(int u, int x) {
mark[u] |= n - sz[u] - x <= n / ... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667772160")
using namespace std;
struct __isoff {
__isoff() {
if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
srand(time(0));
}
~__isoff() {}
} __osafwf;
const unsigned long long p1 = 31;
const unsigned long long p2 = 29... | 17 |
#include <bits/stdc++.h>
using namespace std;
int r, n, dp[105][5][5];
pair<int, int> f[105];
void load() {
cin >> r >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--, b--;
f[i] = make_pair(a, b);
}
sort(f, f + n);
}
int go(int len, int up, int down) {
if (up == 2 && down == 2) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[3];
char dir[3] = {'P', 'S', 'R'};
int dp[N];
const int INF = 0x3f3f3f3f;
int main() {
int t;
cin >> t;
while (t--) {
string str;
cin >> str;
a[0] = a[1] = a[2] = 0;
string ans = "";
for (int i = 0; i < str.size(); i++... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
long l... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x, a[105], y, z, ft = 0;
cin >> n >> k >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
y += a[i];
if (i < n - k) {
ft += a[i];
}
}
z = ft + (k * x);
if (z < y) {
cout << z;
} else {
cout << y;
}
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
void solve();
void precalc();
int TESTNUM = 0;
int main() {
string s = "";
cin.tie(0);
cout.precision(10);
cout << fixed;
precalc();
int t = 1;
while (t--) {
++TESTNUM;
solve();
}
return 0;
}
template <ty... | 21 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int read() {
int x = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x;
}
bool check(int d, int e, int f) {
if (e > 12 || f > 31) return 0;
int mon[] = {0, 31, 28, 31, 30, 31,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, l;
long long a[300001], ans, s;
long long qpower(long long a, int b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % 998244353;
a = a * a % 998244353;
b >>= 1;
}
return ans;
}
int main() {
scanf("%d", &n);
for (i = 1; i <=... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int maxn = 1e5 + 5;
const int maxm = 1.5e7 + 5;
using namespace std;
struct node {
double x, y;
} p[305];
in... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x[x.length() - 1] == 'o')
cout << "FILIPINO\n";
else if (x[x.length() - 1] == 'u')
cout << "JAPANESE\n";
else
cout << "KOREAN\n";
}
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << endl;
err(... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i, j, res = 100000000000000;
cin >> n >> k;
i = n / 2;
if (i == 0) res = k + 1;
while (i > 0) {
if (n % i == 0) {
j = n / i;
if (res > (i * k + j) && ((i * k + j) % k) * ((i * k + j) / k) == n)
res = i * k + j;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[200005], b[200005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> b[i];
}
int x, y;
for (int i = 1; i < m; i++) {
x = b[i];
y = b[i + 1];
if (x == y) continue;
if (y < x) swap(x, y);
if (x > 1) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, c[100], x, y, sum = 0, s = 0;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> c[i];
s += c[i];
}
cin >> x >> y;
for (int i = 0; i < m; i++) {
sum += c[i];
if ((x <= sum && sum <= y) && (x <= s - sum && s - sum <= y)) {
pr... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX = 1e5 + 5;
const int P = (1 << 6) + 5;
const int MOD = 1e9 + 7;
const int64_t INF = INT_MAX;
const int64_t _INF = I... | 13 |
#include <bits/stdc++.h>
#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)
template <typename T>
void read(T &);
template <typename T>
void write(const T &);
typedef unsigned uint;
typedef long long ll... | 24 |
#include <bits/stdc++.h>
using namespace std;
void readInputData();
void run();
int main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
readInputData();
run();
return 0;
}
int hh;
int mm;
string line;
int str2int(const string& s) {
int n = 0;
for (int i = 0; i < s.size(); ++i)
if (isdigit(s[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b;
cout << (1 << __builtin_popcount(b)) << endl;
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
long long int mod = 1e9 + 7;
long long int INF = 1e18;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, x;
cin >> n >> x;
string s;
cin >> s;
long long int bal[n + 1];
bal[0] = 0;
long lo... | 9 |
#include <bits/stdc++.h>
int main() {
int n, i, j, counter = 0;
double m = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
m = i * i + j * j;
m = sqrt(m);
if (m == (int)m && m <= n) {
counter++;
} else {
continue;
}
}
}
printf("... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long mp[25][25];
long long dp[1 << 20][25];
long long first(long long x) {
for (long long i = 0; i < n; i++) {
if (x & (1 << i)) return i;
}
}
int main() {
while (~scanf("%lld%lld", &n, &m)) {
memset(mp, 0, sizeof(mp));
for (long long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int q, _c;
long long a, b, m, c[105];
int main() {
for (scanf("%d", &q); q; q--) {
_c = 0;
memset(c, 0, sizeof(c));
scanf("%I64d%I64d%I64d", &a, &b, &m);
if (a == b) {
printf("1 %I64d\n", a);
continue;
}
long long l = a + 1, r = a + m;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int len1, len2;
string str1, str2;
vector<vector<long long int>> dp;
void take_input() {
char s1[5100], s2[5100];
scanf("%lld%lld", &len1, &len2);
scanf("%s%s", s1, s2);
string st1(s1), st2(s2);
str1 = st1;
str2 = st2;
dp.resize(len1 + 1, vector<long... | 10 |
#include <bits/stdc++.h>
double k, d, t;
int main() {
scanf("%lf%lf%lf", &k, &d, &t);
double ti = (long long)((k - 1) / d) + 1;
double p = ti * d;
double ans = 0;
double tim = (long long)(2 * t / (p + k));
ans += tim * p;
double rest = 2 * t - (p + k) * tim;
if (rest < 2 * k)
ans += rest / 2;
else... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
bool found = false;
string s, temp = "";
cin >> n >> s;
if (n % 2 == 0) {
for (int(i) = (0); (i) < (n); (i)++) {
temp += s[i];
if (temp.size() == 2) {
cout << temp;
temp = "";
if (i < n - 1) cout << "-";
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long int a, b;
cin >> a >> b;
for (long long int i = 1; i < 100000000000; i++) {
if (i % 2 == 1) {
if (a >= i) {
a -= i;
} else {
cout << "Vladik";
break;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 1205;
int n, m, k, cnt[N], a[N], b[N], num[N][N];
struct ed... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 1e5 + 5;
const int64_t MAXINT = 1e9;
const int64_t MAXLL = 1e18;
int64_t MOD = 1e9 + 7;
struct Matrix {
int64_t n, m;
vector<vector<int64_t> > matrix;
Matrix(int64_t n_, int64_t m_) {
n = n_;
m = m_;
matrix.resize(n);
for (int64_t ... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int a[maxn], b[maxn];
int main() {
int v, n, m, i, flag;
while (scanf("%d%d", &n, &m) != EOF) {
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < m; i++) scanf("%d", &b[i]);
sort(a, a + n);
sort(b, b + m);
flag = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
char s[N], t[N], S[N];
int n, go[N][26], len[N], par[N], top, last;
int New(int L) {
len[++top] = L;
return top;
}
int diff[N], slink[N];
void extend(int n) {
int w = S[n], p = last;
while (S[n - len[p] - 1] != w) p =... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long po(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) {
res = (res * a) % 1000000007;
}
a = (a * a) % 1000000007;
b = b / 2;
}
return res % 1000000007;
}
const int con = 256;
string fun(string s, string s2) {
int ... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.