solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[222222];
double f(double x) {
double cur_sum = 0;
double min_sum = 0;
double max_sum = 0;
double ans = 0;
for (int i = 0; i < n; ++i) {
cur_sum += a[i] - x;
ans = max(ans, fabs(cur_sum - min_sum));
ans = max(ans, fabs(cur_sum - max_sum));
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long seg[200000 * 4];
long long lazy[200000 * 4];
int v[200001];
int n, q;
void B(int n, int s, int e) {
if (s == e)
seg[n] = v[s];
else {
int mid = s + e;
mid /= 2;
B(n * 2, s, mid);
B(n * 2 + 1, mid + 1, e);
seg[n] = min(seg[n * 2], seg[n ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100000;
long double fct[MAXM + 5];
void init() {
for (int i = 1; i <= MAXM; i++) fct[i] = fct[i - 1] + log10(i);
}
long double comb(int n, int m) { return fct[n] - fct[m] - fct[n - m]; }
int main() {
init();
int n, m, k;
scanf("%d%d%d", &n, &m, &k);... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx2,avx,fma")
inline long long int poww(long long int a, long long int b) {
long long int r = 1LL;
while (b > 0) {
if (b & 1) r = r * a;
b /= 2;
a = a * a;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
int n;
vector<int> g[MAXN];
int c[MAXN];
void dfs(int u) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (c[v]) continue;
c[v] = 3 - c[u];
dfs(v);
}
}
struct node {
int a, b;
} p[MAXN];
int main() {
scanf("... | 9 |
#include <bits/stdc++.h>
using std::memset;
using std::printf;
using std::scanf;
using llong = long long;
constexpr int maxn = 3000005;
int n;
llong cnt[maxn];
llong ans[maxn];
void used() {
for (int i = 1; i < maxn; ++i) {
if (!cnt[i]) continue;
for (int j = 1; j * i < maxn; ++j) {
if (i == j) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, i;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n, greater<int>());
for (i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << "\n";
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 9e4 + 5;
int cn = 0;
struct node {
int anss;
int l, r;
} nod[maxn];
int main() {
int n, m, a[350], vis[350][2];
scanf("%d%d", &n, &m);
int maxx = -0x3f3f3f3f, minn = 0x3f3f3f3f;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
maxx = m... | 5 |
#include <bits/stdc++.h>
void err() { std::cout << '\n'; }
template <typename T, typename... Args>
void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
void pt() { std::cout << '\n'; }
template <typename T, typename... Args>
void pt(T a, Args... args) {
std::cout << a << ' ';
pt(args...);
}
usin... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
int n, t = 1;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] >= t) t++;
}
cout << t - 1;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool del[300005];
int ans[100005], pos;
int main() {
int t, n, m, u, v;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
memset(del + 1, 0, 3 * n);
pos = 0;
for (int i = 1; i <= m; ++i) {
scanf("%d%d", &u, &v);
if (!del[u] && !del[v] &... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
int n;
cin >> n;
long long ans = 1;
for (int i = 0; i < 3 * n; ++i) {
ans *= 3;
ans %= mod;
}
long long temp = 1;
for (int i = 0; i < n; ++i) {
temp *= 7;
temp %= mod;
}
ans -= temp;
while (ans < 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
if (n & 1) {
for (int i = n - 1; i >= 2; i -= 2) cout << a[i];
for (int i = 1; i <= n; i += 2) cout << a[i];
} else {
for (int i = n - 1; i >= 1; i -= 2) cout << a... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long ans = x;
ans = max(ans, a - (x + 1));
ans = max(y, ans);
ans = max(ans, b - (y... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
template <typename T>
void chmin(T& a, const T& b) {
if (b < a) a = b;
}
int N;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
vector<string> S(N);
for (int i = (0); i < ... | 0 |
#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 == '-'... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;
int main() {
bool m1[3], m2[3];
char c;
for (int i = 0; i < 3; ++i) {
cin >> c;
m1[i] = c == '1';
}
for (int i = 0; i < 3; ++i) {
cin >> c;
m2[i] = c ... | 1 |
#include <bits/stdc++.h>
template <class T>
void rd(T &x) {
x = 0;
T f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
using namespace std;
const int N = 3e5 + 10;
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 4e5 + 10;
char a[100][100];
int dirx[5] = {0, 1, -1, 0, 0};
int diry[5] = {0, 0, 0, 1, -1};
int n;
bool check(int x, int y) {
for (int i = 1; i <= 4; i++) {
int x1 = x + dirx[i], y1 = y + diry[i];
if (x1 < 1 || x1 > n) return false;
if (y1 < 1 ||... | 0 |
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int today = 1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int x, y;
cin >> x >> y;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
if (x * b > a * y) {
x = a;
y... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
for (int i = 0; i < a; i++) {
long long c, d;
cin >> c >> d;
long long arr[c];
for (int i = 0; i < c; i++) {
cin >> arr[i];
}
int mnn = *min_element(arr, arr + c), mxx = *max_element(arr, arr + c);
int t ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const double eps = 1e-7;
int n, l, v1, v2, k;
int main() {
scanf("%d%d%d%d%d", &n, &l, &v1, &v2, &k);
n = (n - 1) / k;
double a = (double)v2 / v1;
double b = (double)(v2 - v1) / (v1 + v2) * 2 * n;
double s = (1 - a) * l / (1 - a - b);
do... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e6 + 5;
const long long inf = 1e18;
long long powermod(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
const int N = 2e5 + 5;
int lc[N], rc[N], a[N], b[N], rt[N], sz[N];
long long pr[N], sum[N];
long long ans = 0;
void upd(int x) {
sz[x] = sz[lc[x]] + sz[rc[x]] + 1;
sum[x] = sum[lc[x]] + sum[rc[x]] + x;
}
int sc(int x, int k) {
if (x == ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
cout << log2(m & -m) + 1;
}
| 2 |
#include <bits/stdc++.h>
int main() {
int k, l, m, n, d, damage = 0;
scanf("%d", &k);
scanf("%d", &l);
scanf("%d", &m);
scanf("%d", &n);
scanf("%d", &d);
for (int i = 1; i <= d; i++) {
if ((i % k) == 0 || (i % l) == 0 || (i % m) == 0 || (i % n) == 0) {
damage = damage + 1;
}
}
printf("%d... | 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:512000000")
template <class T>
T sqr(T a) {
return a * a;
}
int main() {
string s, bad;
int k;
cin >> s >> bad >> k;
int n = s.length();
vector<pair<long long, long long> > v;
long long pr1 = 13, pr2 = 1103;
for (int i = 0; i ... | 5 |
#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int al, b, f;
int n;
typedef struct node {
int l, r;
int car;
int ln, rn;
int clen;
} node;
node tree[800000];
int cmax(int a, int b) { return a > b ? a : b; }
int m(int l, int r) { return (l + r) / 2; }
void build(int root, int l, int r) {
tree[root].l = l;
tre... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& first) {
return first * first;
}
template <class _T>
inline string tostr(const _T& a) {
ostringstream os("");
os << a;
return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const double EPS = 1 - 9;... | 7 |
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
read(x);read(a...);... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 100005;
int arr[2 * SZ];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
if (n % 2 == 0) {
cout << "NO";
} else {
cout << "YES" << '\n';
int p = 1;
int idx = 0;
while (p <= 2 * n) {
arr[idx] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m, p, q;
while (cin >> n) {
for (i = 1; i <= n; i++) {
if (n % i == 0) {
if (i <= (n / i)) {
p = i;
q = n / i;
}
}
}
cout << p << " " << q << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long n, q, u, v, d1, d[100009][20], f[100009][20];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
long i, j;
for (i = 1; i <= n; i++) cin >> d[i][0];
for (j = 1; j <= 18; j++)
for (i = 1; i + (1 << j) - 1 <= n; i++) {
d... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, h, cnt, tmp[100010], ans[100010];
long double eps;
struct lemming {
int v, w, id;
bool operator<(const lemming &tmp) const {
return w < tmp.w || (w == tmp.w && v < tmp.v);
}
} a[100010];
bool check(long double x) {
int now = 1;
memset(tmp, 0, sizeof(... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const long double PI = acos(-1.0);
const long long mod = 1000000007;
const long long INF = 1e9;
const long long LINF = 1e18;
const long long MAXN = 1e5 + 1;
inline long long power(long long x, int y) {
long long res = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, bs = 727, mod = 987654321 - 2;
int zrb(int a, int b) { return (1LL * a * b % mod); }
int jm(int a, int b) {
int tmp = (a + b) % mod;
if (tmp < 0) tmp += mod;
return (tmp);
}
int pw(int a, int b) {
int rt = 1;
for (; b; b >>= 1) {
if (b &... | 11 |
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vii;
typedef pair<ll, ll> pii;
typedef vector< pii > ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], n, k;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1, l = 1, r = n; i <= k; ++i) {
if (i & 1)
a[i] = l, ++l;
else
a[i] = r, --r;
}
for (int i = k + 1; i <= n; ++i) {
if (k & 1)
a[i] = a[i - 1] + 1;
else
a[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long n;
cin >> n;
string s, t;
long long cnt = 0;
cin >> s >> t;
for (int i = 0; i < n / 2; i++) {
if (t[i] == t[n - 1 - i]) {
if (s[i] == s[n - 1 - i]) {
} else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 310, mod = 1e9 + 7, inf = 1e9 + 10;
int a[maxn][maxn];
int g[maxn][maxn][maxn][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie();
int n, m, t;
cin >> n >> m >> t;
int A, B, C;
cin >> A >> B >> C;
for (int i = 0; i < n... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, i, j = 0, even = 0, odd = 0, bit = 0;
cin >> n >> b;
int a[n], c[n];
for (i = 0; i < n; i++) {
cin >> a[i];
if (i > 0 && i % 2 == 0) {
if (even == odd) c[j++] = abs(a[i] - a[i - 1]);
}
if (a[i] % 2)
odd++;
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<unsigned long long int> vec(n);
unordered_set<unsigned long long int> mp;
for (int i = 0; i < n; i++) {
cin >> vec[i];
mp.insert(vec[i]);
}
int root = -1;
for (int i = 0; i < n; i++) {
unsigned long long int p... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, K;
int A[20][110][3];
int main() {
cin >> n >> m >> K;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
for (int j = 0; j < m; j++) {
for (int k = 0; k < 3; k++) cin >> A[i][j][k];
}
}
int res = 0;
for (int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int b[k];
for (int i = 0; i < k; i++) cin >> b[i];
sort(b, b + k);
for (int i = 0; i < n; i++)
if (a[i] == 0) a[i] = b[--k];
bool big = 1;
for (int i = 0; i < n ... | 0 |
#include <bits/stdc++.h>
void sc(int &x) { scanf("%d", &x); }
void sc(int &x, int &y) { scanf("%d%d", &x, &y); }
void sc(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void sc(long long &x) { scanf("%lld", &x); }
void sc(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void sc(long long &x, long lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)4e5 + 10;
const int mod = (int)1e9 + 7;
const int inf = (1 << 30) - 1;
int n, k;
void out(vector<int> a) {
for (int i = 0; i < a.size(); i++) {
if (i) cout << " ";
cout << a[i] + 1;
}
cout << endl;
}
int ask(vector<int> a, vector<int> b) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
const int INF = 1 << 30;
long long a[MAXN];
long long d[MAXN][MAXN], e[MAXN][MAXN];
int main() {
int n;
cin >> n;
int cnt = 0;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
if (x) {
a[cnt] = x;
cnt++;
}
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int dist[3005][3005];
pair<int, int> parent[3005][3005];
bool visited[3005][3005];
vector<int> adj[3005];
long long get_hash(long long i, long long j, long long k) {
return i + 10000 * j + 100000000 * k;
}
unordered_set<long long> s;
int main() {
ios::sync_... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int x = 0, y = 0, n;
n = a.size();
for (int i = 0; i < n; i += 2) {
if (a[i] == b[i]) continue;
if ((a[i] == '[' && b[i] == '8') || (a[i] == '8' && b[i] == '(') ||
(a[i] == '(' && b[i] == '['))
y++;
... | 4 |
#include <bits/stdc++.h>
int main() {
int n, a, b, c, ways = 0;
scanf("%d %d %d %d", &n, &a, &b, &c);
int x = a / 2;
for (int i = c * 2; i >= 0; i -= 2) {
if (i == n) {
ways++;
} else if (i < n) {
for (int j = b; j >= 0; j--) {
if (i + j == n) {
ways++;
} else if (i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, cnt = 0, ar[200];
cin >> n;
if (n == 1) {
cout << "1" << endl << 0 << endl;
return 0;
}
for (i = 2; i * i <= n; i++) {
if (n <= 0) break;
while (n % i == 0) {
ar[cnt] = i;
cnt++;
n /= i;
}
}
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, N;
vector<vector<long long> > g;
vector<long long> w, c;
long long res = 0;
void upd(long long& x, long long y) {
if (x < y) x = y;
}
void add(vector<long long>& dp, int e) {
if (!w[e]) return;
for (int i = k; i >= w[e]; --i) upd(dp[i], dp[i - w[e]] + c[e... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T Mul(T x, T y, T P) {
T F1 = 0;
while (y) {
if (y & 1) {
F1 += x;
if (F1 < 0 || F1 >= P) F1 -= P;
}
x <<= 1;
if (x < 0 || x >= P) x -= P;
y >>= 1;
}
return F1;
}
template <class T>
T Pow(T x, T y, T P) {
T F1 = 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxN = 1000 + 5, mod = 1e9 + 7, inf = 2e18;
long long N, K;
long long per[maxN], fac[maxN];
long long ans[maxN];
long long cmul(long long a, long long b) {
if (a > inf / b) return inf;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() { cout << "INTERCAL"; }
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 30;
long long cnt[M], pref[M], fact[M];
long long solve(int p, int n);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
memset(cnt, 0, sizeof(cnt));
long long k;
cin >> k;
long long p = 2;
whil... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long N = 1e3 + 1;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
int l, r;
int n, m, x, y;
int a[N], b[N], d[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> ... | 1 |
#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
void anton() {
int n;
cin >> n;
int ans = 0;
while (n--) {
string s;
cin >> s;
if (s == "Tetrahedron")
ans += 4;
else if (s == "Cube")
ans += 6;
else if (s == "Octahedron")
ans += 8;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, M;
cin >> n >> M;
vector<char> s(n);
int m = M;
vector<int> p(m), b(n), yes(n, 0), cnt(26, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
cnt[s[i] - 'a']++;
}
for (int i = 0; i < m; i++) {
cin >> p[i];
p[i]--;
}
sort... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, K;
char str[200020];
int a[200020];
bool mark[200020];
struct node {
int c, len;
} res[200020];
node min(node x, node y) { return x.len < y.len ? x : y; }
void Pf(int x) {
if (x)
printf("B");
else
printf("W");
}
int main() {
for (int i = 0; i < 200020... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
long long val;
int pref, suff;
};
int n;
int a[100010];
Node st[400010];
bitset<1010> vis;
map<int, int> mp;
int sz, id;
int pos[1010];
int b[1010];
int nxt[100010];
vector<int> positions[1010];
long long ans = 0;
Node merge(Node a, Node b, int m) {
Node... | 10 |
#include <bits/stdc++.h>
using namespace std;
typedef int type;
const type inf = 1 << 28;
const int MAXN = 2006;
vector<int> V[MAXN];
int n, ujscie, zrodlo;
type M[MAXN][MAXN];
int pocz[MAXN], w[MAXN], Q[MAXN];
type dfs(int u, type ile) {
if (u == ujscie || ile == 0) return ile;
type t, ans = 0;
for (int k = pocz... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct counting_iterator : public iterator<random_access_iterator_tag, bool> {
T value = 0;
counting_iterator(const T &value) : value(value) {}
counting_iterator(const counting_iterator &it) : value(it.value) {}
counting_iterator() {}
typenam... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
using namespace std;
const int N = 110;
int n, s, sum[N];
struct node {
int h, m;
} t[N];
signed main() {
cin >> n >> s;
for (int i = 1; i <= n; i++)
cin >> t[i].h >> t[i].m, sum[i] = t[i].h * 60 + t[i].m;
if (sum[1] > s) return p... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int area(pair<long long int, long long int> p1,
pair<long long int, long long int> p2,
pair<long long int, long long int> p3) {
return p1.first * (p2.second - p3.second) -
p1.second * (p2.first - p3.first) +
... | 9 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline void smax(long long &x, long long y) { x = max(x, y); }
inline void smin(long long &x, long long y) { x = min(x, y); }
bool isSub(long long a, long long b) { return ((a | b) == b); }
bool check(long long x, vector... | 4 |
#include <bits/stdc++.h>
using namespace std;
int k, n;
string s, a;
vector<char> c;
int u[26];
int main() {
cin >> k;
cin >> s;
int n = s.size(), cur = 0;
memset(u, 0, sizeof(u));
for (int i = 0; i < n; i++) {
if (s[i] != '?' && s[n - i - 1] != '?' && s[i] != s[n - i - 1]) {
cout << "IMPOSSIBLE" <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int num;
int id;
};
struct node arr[3 * 100005];
long long cum_arr[3 * 100005];
bool compare(struct node a, struct node b) { return a.num < b.num; }
int main() {
int n, k, left, right, i, upp_bound, low_bound;
long long sum, min_sum;
scanf("%d", &n);... | 6 |
#include <bits/stdc++.h>
const int N = 1e5 + 5;
int n, m, tmp[N];
double A[N];
char IN[300000], *SS = IN, *TT = IN;
struct Queries {
int type, l1, r1, l2, r2;
} q[N];
struct BIT {
int n;
double val[N];
inline void Modify(int p, double v) {
for (; p <= n; p += (p & -p)) val[p] += v;
}
inline double Query... | 7 |
#include <bits/stdc++.h>
using namespace std;
class pa3 {
public:
long long x;
long long y, z;
pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x) return x < p.x;
if (y != p.y) return y < p.y;
return z < p.z;
}
bool ope... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int t;
cin >> t;
vector<string> gu;
for (int g = 0; g < t; g++) {
string x;
cin >> x;
gu.push_back(x);
}
int ans = 6;
for (int g = 0; g < gu.size(); g++) {
for (int y = g + 1; y < gu.size(); y++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
char s[N];
int sum[N << 1], q[N];
int tmp, n, mn, ans, ansl = 1, ansr = 1, t = 0;
void calc(int l, int r) {
int pos = l, cnt = tmp, tot = 1;
for (int i = l + 1; i < r; i++)
if (sum[i] == mn + 1) {
if (ans < cnt) {
ans = cnt;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long s, x;
cin >> s >> x;
vector<int> v;
s -= x;
if (s % 2 == 1 || s < 0) {
cout << 0;
return 0;
}
while (x) {
v.push_back(x % 2);
x /= 2;
}
long long ans = 1;
for (int i = 0; i < v.size(); i++) {
if (v[i]) {
a... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long dp[5011][5011];
int nxt[6000][27];
long long cnt[5011];
long long inv[100000 + 1];
long long kai[100000 + 1];
long long invkai[100000 + 1];
void invinit() {
inv[1] = 1;
for (int i = 2; i <= 100000; i++) {
inv[i] = mod - (mod / i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int p = 998244353;
template <typename T>
inline T read() {
register T sum = 0;
register char cc = getchar();
int sym = 1;
while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
if (cc == '-') sym = -1, cc = getchar();
sum = sum * 10 + cc - '0';
cc =... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = (long long)1e5 + 9;
const long long mod = (long long)1e9 + 7;
int main() {
std::ios::sync_with_stdio(0);
long long i, j, k, t, q, m, l, r, n, v1, v2;
cin >> n >> l >> v1 >> v2 >> k;
long long g = (n / k) + (n % k > 0);
double d, time;
d = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T>
int chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
int chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
return a * a;
}
template... | 9 |
#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
const lli mod = 1e9 + 7;
lli power(lli a, lli b) {
lli ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
vector<lli> mul(const vector<lli>& a, const vector<lli>& b,
const v... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000005;
const double PI = 4 * atan(1);
const long long MAX = 9223372036854775807;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b,... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int a_s[27][100000];
int main() {
int re_i;
int n, i, j, k, min_c, d_c;
int c_i;
int s_num;
int way_num[27];
int d_v[27];
int re[27];
int c_re[27];
int re_min;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (n < 3) {
m... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 5101;
const int inf = 1e9;
int a[M], b[M], c[M];
int sto1[M], sto2[M], sto3[M];
int d[M];
int flag[M];
int f[2][91][91][91];
int calc(int k, int n) {
if (n < 2 * k) return 500;
if (n < 4 * k) return 1000;
if (n < 8 * k) return 1500;
if (n < 16 * k) ret... | 11 |
#include <bits/stdc++.h>
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const int MAXN = 200010;
int n, a[MAXN], b[MAXN], su[MAXN], res;
set<pi> s;
int main () {
ios_base::sync_with_stdio(false);
cin >> ... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
using namespace std;
bool isprime(long long n) {
if (n % 2 == 0) {
return false;
}
for (auto i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
long long digitsum(long long n... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
char c = s[0];
int cnt = 0, ans = 0;
for (int i = 0; i < s.length();) {
int j = i;
while (s[j] == c && cnt < 5 && j < s.length()) {
cnt++;
j++;
}
++ans;
c = s[j];
i = j;
cnt = 0;
}
cout <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
const int INF = 1e9 + 9;
struct elem {
int w, s, c;
int l, r;
elem() {}
} a[N];
int n, second;
int d[N][N], td[N];
vector<int> v[N];
bool operator<(const elem &x, const elem &y) {
return (x.r - x.l != y.r - y.l) ? (x.r - x.l < y.r - y.l) : (x.l <... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int base = 987654323;
const int maxn = 100005;
struct ljb {
int num, dest;
ljb *next;
} * p, *head[maxn], *tail[maxn];
long long bzhash[maxn][18], powc[maxn], hasha[maxn];
int bzfa[maxn][18], dis1[maxn], dis2[maxn], sa[maxn], bak[maxn], f1[maxn],
f2[maxn], fla... | 9 |
#include <bits/stdc++.h>
int GCD(int u, int v) {
while (v != 0) {
int r = u % v;
u = v;
v = r;
}
return u;
}
int main() {
int amtV;
int amtE;
std::vector<std::pair<int, int>> graph;
std::cin >> amtV >> amtE;
int connected = 0;
int remaining = amtE;
if (amtE >= amtV - 1) {
for (int i ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 2102;
int dpf[N][N], dpr[N][N];
int main() {
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
for (int i = n; i >= 1; --i)
for (int j = m; j >= 1; --j)
if (s[i - 1] =... | 6 |
#include <bits/stdc++.h>
using namespace std;
int q;
int fa[400005];
int val[400005];
int a[400005];
int tot = 0;
map<int, int> mp;
inline int find(int x) {
if (fa[x] != x) {
find(fa[x]);
val[x] = val[x] ^ val[fa[x]];
fa[x] = find(fa[x]);
}
return fa[x];
}
inline void uni(int x, int y, int w) {
int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 1000000009;
int rd() {
char c = getchar();
int t = 0, f = 1;
while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar();
while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
return t * f;
}
void wt(int x) {
if (x > 9) wt(x... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
double P[N];
const int IT = 2000000;
int main() {
int n;
scanf("%d", &n);
if (n == 1) {
printf("%.10lf\n", 1.0);
return 0;
}
vector<int> S(n);
for (int i = 0; i < n; i++) {
scanf("%lf", &P[i]);
P[i] /= 100.0;
}
sort(P, P + ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
int n;
double p, c[maxn], k[maxn];
long long tot;
bool check(double w) {
double res = 0;
for (int i = 1; i <= n; i++) {
if (k[i] - w * c[i] > 1e-6) continue;
res += (w * c[i] - k[i]) * 1.0 / p;
}
if (res - w > 1e-6) return 1;
retur... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400200;
int arr[MAXN];
set<int> occs[MAXN];
struct ST {
ST *left, *right;
int L, R;
int minA, deltaA, firstMin, lastMin;
int maxSuffix, maxPrefix, maxTotal;
int sumBet;
ST(int a, int b) {
L = a, R = b;
minA = 0, deltaA = 0, firstMin = L,... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[30][2];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 2; ++j) {
cin >> a[i][j];
}
}
int counter = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i][0] == a[j][1]) counter++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct hh {
int from, to, next;
} qq[20100];
int box[3010];
int n;
int visit[3010];
int vv[3010];
int ans[3010];
int huan[3010];
int fat[3010];
int top;
void add(int from, int to, int kk) {
qq[kk].from = from;
qq[kk].to = to;
qq[kk].next = box[from];
box[from] = k... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
vector<pair<int, char> > gr[N];
vector<int> nivel[N];
pair<int, int> pai[N];
int dist[N];
int solve(vector<int> at, int root) {
if ((int)at.size() <= 1) return root ? (int)at.size() : 0;
int res = 0;
for (char c = 'a'; c <= 'z'; c++) {
vector... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct __io_dev {
__io_dev(const bool& __fastio = false) {
if (__fastio) ios_base::sync_with_stdio(false), cin.tie(nullptr);
srand(time(nullptr));
if (!string("").empty())
freopen(
""
".in",
"r", stdin),
freopen(
... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
inline long FastMax(long x, long y) {
return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
inline long FastMin(long x, long y) {
return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
long IR[] = {0, -1, 0, 1, -1, -1, 1, 1};
long IC[] = {1... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int l;
int r;
} a[200005], b[2000005];
int cmpl(struct node n, struct node m) { return n.l < m.l; }
int cmpr(struct node n, struct node m) { return n.r < m.r; }
int main() {
int n, m;
while (~scanf("%d", &n)) {
int sum = 0;
for (int i = 0; i < ... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.