solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 18 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G;
vector<bool> V;
vector<int> T;
int main() {
int n, m, k1;
scanf("%d %d %d ", &n, &m, &k1);
G.resize(n);
V.resize(n, false);
for (int i = 0; i < k1; i++) {
int x;
scanf("%d ", &x);
V[x - 1] = true;
}
for (int i = 0; i < m; i+... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b, long long m) {
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
long long modInv(long long a, long long m) {
a = a % m;
for (long long x = 1; x < m; x++)
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
int temp = ((n * m) / 2) - k;
if (n % 2) k -= m / 2;
if (m % 2) temp -= n / 2;
if (k >= 0 && t... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int T[4 * maxn];
int a[maxn], b[maxn];
int x[maxn], y[maxn], k[maxn];
void add(int L, int R, int col, int l, int r, int id) {
if (r == R && l == L) {
T[id] = col;
return;
}
int mid = (l + r) / 2;
if (L < mid) add(L, min(mid, R), co... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[200050];
int dp[2][200050];
int _min(int x, int y) {
if (x < y) return x;
return y;
}
int main() {
int t, n, i;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
dp[0][i] = 9999999;
dp[1]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int inf = 1e9;
int n, m, high[N], nxt[N];
int visit[N * 2];
vector<pair<int, int> > E;
vector<int> G[N];
struct Dinic {
int source, sink, n;
struct edge {
int to, c, f;
edge(int to, int c, int f) : to(to), c(c), f(f) {}
};
vector<e... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, dp[26][1000 * 1000 + 10];
string A, B;
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
cin >> a >> b >> A >> B;
long long total = 0, GCD = gcd((long long)A.size(), (long long)B.size());
for (long... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long a[N];
long long t[N];
int main() {
int n;
scanf("%d", &n);
long long ans = 0;
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++) t[i] = max(t[i - 1], a[i] + 1);
for (int i = n; i >= 1; i--) {
t[i... | 9 |
#include <bits/stdc++.h>
int main() {
int i;
char a[200], b[200];
scanf("%s%s", a, b);
for (i = 0; i < strlen(a); i++) {
printf("%d", a[i] ^ b[i]);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int Root = 320;
int n, m, q, p[N], l[N], root, k, used[N], cnt[Root][N], pp[N];
long long sum[Root], add[Root], a[N];
vector<vector<int> > s;
bool cmp(int p, int q) { return l[p] > l[q]; }
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 0... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5);
int n;
int x[N], w[N];
long long a[N], b[N];
int l, r, mid;
int ans, t, d[N], ml[N];
pair<int, int> p[N], q[N];
map<int, int> Mp;
bool cmp(pair<int, int> b, pair<int, int> a) {
return (a.first - a.second > b.first - b.second ||
(a.first -... | 10 |
#include <bits/stdc++.h>
using namespace std;
char layout1[300];
string A, B, S, ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while (cin >> A >> B) {
ans.clear();
for (int i = 0; i < A.length(); i++) {
layout1[A[i] - 'a'] = B[i] - 'a';
}
for (int i = '0'; i <= '9'; i++) layout1[i] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, light[1 << 15], ans = 0, lim, temp;
inline int dfs(int nd) {
int lc = 2 * nd + 1, rc = 2 * nd + 2, ll, rl;
if (lc <= lim) {
ll = dfs(lc);
rl = dfs(rc);
ans += abs(ll - rl);
return light[nd] + max(ll, rl);
} else
return light[nd];
}
int main(... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int MOD = 1e9 + 7;
long long fast_power(long long base, long long power) {
long long result = 1;
while (power > 0) {
if (power % 2 == 1) {
result = (result * base) % MOD;
}
base = (base * base) % MOD;
power = power / 2;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const int maxn = 200000 + 10;
const long long inf = 1LL << 50;
int n;
long long a[maxn];
long long dp[maxn][2];
long long dfs(int x, int dir) {
if (x <= 0 || x > n) return 0;
if (x == 1) return inf;
long long &res = dp[x][dir];
if (res !... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
vector<int> v;
int ans = 0;
for (int i = 0; i < n; i++) {
int f = s.substr(i).find(t[i]);
if (f == string::npos) {
cout << -1;
return 0;
} else {
for (int j = i + f; j >= i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int i, j;
string s;
cin >> s;
vector<int> v;
char c = s[0];
int cc = 1;
for (i = 1; i < s.size(); i++) {
if (c == s[i]) {
cc++;
} else {
if (c == '1') v.push_back(cc);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, n, m, k;
cin >> n >> m >> k;
vector<int> pow(n + 1), sch(n + 1), hi(m + 1, 0);
for (int i = 1; i <= n; i++) cin >> pow[i];
for (int i = 1; i <= n; i++) {
cin >> sch[i];
if (pow[i] > hi[sch[i]]) hi[sch[i]] = pow[i];
}
int cnt = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
string str[maxn];
int id1[maxn], id2[maxn];
int main() {
string S;
while (cin >> S) {
string tmp;
int c = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == ',' || S[i] == ';') {
str[c] = tmp;
c++;
tmp ... | 8 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[30005];
int ans[30005], step[30005], f[30005], l[30005], r[30004], last[30005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + 1 + n);
f[0] = 1;
f[1] = 1;
fo... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, t, n, temp;
cin >> t;
while (t > 0) {
map<int, int> mp;
cin >> n;
int arr[n];
for (i = 0; i < n; i++) {
cin >> temp;
mp[temp]++;
}
int Count = 0;
for (i = 1; i <= n; i++) {
if (mp[i] >= i) Count += (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
cin >> N;
int M = N / 2;
cout << M * (N - M) << endl;
for (int i = 1; i <= M; i++)
for (int j = M + 1; j <= N; j++) cout << i << " " << j << endl;
return 0;
}
| 11 |
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
#define fi first
#define se second
const int N = 2e3 + 5;
const int INF = 2e9;
const lint LINF = 4e18;
const int dr[] = {1, -1, 0, 0};
const int dc[] = {0, 0, 1, -1};
int n, m, t;
int a[N][N];
lint dist_tl[N][N], dist_br[N][N];
int main() {
io... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
long long x, y;
cin >> x >> y;
if (x - y == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int a[100];
vector<int> V;
pair<int, int> S[100];
for (int i = 0; i < n; i++) {
cin >> a[i];
V.push_back((a[i] + 1) / 2);
w -= (a[i] + 1) / 2;
if (w < 0) {
cout << -1;
return 0;
}
S[i] = m... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> v(n);
bool leads[10] = {};
int frequency[10] = {};
bool alloted[10] = {};
for (int i = 0; i < n; i++) {
cin >> v[i];
leads[v[i][0] - 97] = true;
for (int j = v[i].size() - 1; j > -1; j--) {
frequen... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<pair<long long, long long> > ans;
for (long long i = 0; i < (long long)2 * n + 1; ++i) ans.push_back({i, 0});
for (long long i = 1; i < 2 * n + 1; ++ ++i) {
ans.push_back({i, 1});
ans.push_back({i, -1});
}
i... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
using namespace std;
int n, k;
int val[10] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
vector<int> a;
inline int cnt(int mask) {
int ans = 0;
for (int i = 0; i < 8; i++) {
if (mask >> i & ... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int d[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, -1, 1, 1};
int S[1005][1005], T[1005][1005];
int num1[1005], num2[1005];
bool sp;
vector<pair<int, int>> ans;
int ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 95542721;
int seg[maxn * 4][100], lazy[maxn * 4], a[maxn];
void update(int v) {
for (int i = 0; i < 48; i++)
seg[v][i] = (seg[v * 2][i] + seg[v * 2 + 1][i]) % mod;
}
void build(int v, int l, int r, int x, long long val) {
i... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c... | 15 |
#include <bits/stdc++.h>
using namespace std;
char M[3][4];
int main() {
int i, j;
for (i = 0; i < 3; i++) cin >> M[i];
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
if (M[i][j] != M[2 - i][2 - j]) {
cout << "NO\n";
return 0;
}
}
}
cout << "YES\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a[150][150];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> a[i][j];
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
if ((i == j) || (i + j == n + 1) || (i == (n + 1) / 2) |... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool comp(long long a, long long b) { return a > b; }
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
while (b) {
a %= b;
swap(a, b);
}
return a;
}
void sol() {
long long n;
cin >> n;
long long mim = 10000000000000;
vector<long long>... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int num, counter = 0, x, y, z;
cin >> num;
for (int i = 1; i <= num; i++) {
cin >> x;
cout << " ";
cin >> y;
cout << " ";
cin >> z;
cout << "\n";
if (x == 1 && y == 1) {
counter++;
} else if (x == 1 && z == 1) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (auto i = begin(v); i != end(v); i++)
os << *i << (i == end(v) - 1 ? "" : " ");
return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto i = begin(v); i... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > a;
int n, ans[100010];
set<int> visited;
vector<int> final;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int i, flag = 0, x, y, z;
cin >> n;
a.push_back(make_pair(0, make_pair(0, 0)));
for (i = 1; i < 4 * n + 1; ... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, d, a[100069], z[100069], fw[100069], fwp;
priority_queue<pair<long long, long long>> pq;
priority_queue<long long> pq2;
queue<long long> q;
void ud(long long x, long long w) {
for (fwp = x; fwp <= 100000; fwp += fwp & -fwp) {
fw[fwp] += w;
}
}
long long... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long modexp(long long base, long long exp) {
if (exp == 1)
return base;
else if (exp == 0)
return 1;
else {
if (exp % 2 == 0) {
long long base1 = pow(modexp(base, exp / 2), 2);
if (base1 >= 1000000007)
return base1 % 1000000007;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T, class U>
inline T tmin(T a, U b) {
return (a < b) ? a : b;
}
template <class T, class U>
inline T tmax(T a, U b) {
return (a > b) ? a : b;
}
template <class T, class U>
inline void amax(T &a, U b) {
if (b > a) a = b;
}
te... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5;
int n, l[17][17][mxN], r[17][17][mxN];
array<int, 2> qry(int i, int l2, int r2) {
int b = 31 - __builtin_clz(r2 - l2 + 1);
return {max(l[i][b][l2],
l[i][b][(r2 - (1 << b) + 1) % n] - (r2 - (1 << b) + 1 - l2)),
max(r[i][b][(r2... | 21 |
#include <bits/stdc++.h>
using namespace std;
int dx[]{1, -1, 0, 0, 1, 1, -1, -1};
int dy[]{0, 0, 1, -1, 1, -1, 1, -1};
void K_K() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
K_K();
int n;
cin >> n;
vector<int> arr(n);
int sum = 0;
for (auto &it : arr) cin >> it, sum += it;
in... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 2e9;
const int mod = 1e9 + 7;
const long long INF = 2e18;
double a, v, l, d, w, t, t1, second, S1, v1;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> v >> l >> d >> w;
cout.precision(6);
cout << fi... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (1e8);
const long long mod = (1e9 + 7);
int t[(200 + 10)], f[(200 + 10) * 2];
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &t[i]);
}
sort(t + 1, t ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int ap[300005];
int E[300005];
int a[300005];
int big[300005][2];
int n;
vector<int> ord[300005];
vector<int> st;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
a[0] = n + 1;
a[n + 1] = n + 1;
st.push_back(n + 1);
for (int i = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string s) {
string s1 = s;
reverse(s1.begin(), s1.end());
if (s1 == s) return true;
return false;
}
int main() {
string s;
cin >> s;
int n = s.length();
string ans = "";
for (int i = 1; i < (1 << n); i++) {
int num = i;
string s1 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T load() {
T r;
cin >> r;
return r;
}
template <typename T>
vector<T> loadMany(int n) {
vector<T> rs(n);
generate(rs.begin(), rs.end(), &load<T>);
return rs;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto n = load<... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
vector<int> v;
int a[3] = {0};
for (int i = 0; i < n; i++) {
cin >> m;
v.push_back(m);
}
int d = 0;
for (int i = 0; i < n; i++) {
if (v[i] == 25) {
a[0]++;
} else if (v[i] == 50) {
if (a[0] > 0) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> num[1000010];
int main() {
int n, k, l = 0;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
num[i].push_back(l + 1);
num[i].push_back(l + 2);
num[i].push_back(l + 3);
num[i].push_back(l + 5);
l += 6;
}
l -= 1;
printf("%d\n", ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 9;
int n, a, b, k, f;
map<pair<string, string>, int> r_cost;
int main() {
cin >> n >> a >> b >> k >> f;
string prev_fi = "#";
for (int i = 0; i < n; i++) {
string st, fs;
cin >> st >> fs;
if (st == prev_fi) {
r_cost[{min(st, fs... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[1000007], b[1000007];
void mRead() {
cin >> n >> m;
int x;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
}
long long mSolve() {
mRead();
sort(a, a + n);
for (int i = 0; i < m; i++) cout << upper_b... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
priority_queue<long long, vector<long long>, greater<long long> > q;
for (int i = 0; i < n; i++) {
long long tmp;
cin >> tmp;
q.push(tmp);
}
if (q.size() % 2 == 0) q.push(0);
long long answer = 0;
while (q.size() > 1... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p;
vector<pair<double, pair<int, pair<int, int> > > > g, helper;
vector<pair<int, pair<int, int> > > res;
int n, m, k;
int dsu_get(int v) { return (v == p[v]) ? v : (p[v] = dsu_get(p[v])); }
void dsu_unite(int a, int b) {
a = dsu_get(a);
b = dsu_get(b);
if... | 16 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
long long test;
cin >> test;
for (long long ee = 0; ee < test; ++ee) {
long long n;
cin >> n;
long long x = 0, y = 0;
for (long long i = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int a[N], b[N], f[N], p[N];
unordered_multiset<int> st;
basic_string<int> v[N];
int main() {
int n, m, i, j, k, l = 0, t = 0;
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", a + i);
scanf("%d", &m), a[++n] = 2e9;
for (i = 1; i <= m; ++... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long expo(long long x, long long n, long long m) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return expo((x * x) % m, n / 2, m);
else
return (x * expo((x * x) % m, (n - 1) / 2, m)) % m;
}
string DtoB(int j) {
string s = "";
for (int i = 32; i >= ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modular {
public:
using Type = typename decay... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct qin {
int U, D, L, R;
} sum[10005];
int main() {
int n;
cin >> n;
sum[0].U = 0;
sum[0].D = 0;
sum[0].L = 0;
sum[0].R = 0;
char str[205];
for (int i = 1; i <= n; i++) {
cin >> str[i];
if (str[i] == 'D')
sum[i].D = sum[i - 1].D + 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
long long int inp;
cin >> inp;
int sqr = sqrt(inp);
int currd = 1;
bool fin = false;
for (int i = 2; i <= sqr; i++) {
if (inp % i == 0) {
inp /= i;
if (currd != 1) {
fin = true;
if (inp == ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
if (m < n - 1 || m > 2 * n + 2) {
cout << -1 << endl;
return 0;
}
if (m == n - 1) {
cout << 0;
n--;
}
while (m > 0 && n > 0 && m != n) {
if (... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int LOG = 20;
const int N = 1 << LOG;
complex<double> w[N];
complex<double> F[2][N];
int rev[N];
double PI = acos(-1);
int ans[N];
int c[N];
void initFFT() {
for (int i = 0; i < N; i++) {
double angle = 2 * PI * i / N;
w[i] = complex<double>(cos(angle), sin(... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
void solve() {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
map<long long, long long> ff;
map<long long, long long> f;
long long ans = 0;
for (long long i = 0; i < n; i++) {
if (ff... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string ele;
vector<int> ff(9, 0), ss(9, 0);
for (register int i = 0; i < n; i++) {
cin >> ele;
if (ele == "M")
ff[0]++;
else if (ele == "L")
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t-- > 0) {
long long int a, b;
cin >> a >> b;
long long int k = 1, d = -abs(a - b);
while (d < 0) {
d += k;
k++;
}
if (d % 2 == 0) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MaxBasis = 63;
struct LB {
long long base[MaxBasis + 10];
void init() { memset(base, 0, sizeof(base)); }
bool add(long long x) {
for (int i = MaxBasis; i >= 0; i--) {
if (x >> i & 1) {
if (!base[i]) {
base[i] = x;
break;... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 5;
const long long INF = (1ll << 31) - 1;
const double PI = 3.14159265359;
long long n, t, pr[MAXN], a[MAXN];
long long ans;
void calc(int l, int r) {
if (l == r) return;
int mid = (r + l) >> 1;
calc(l, mid);... | 10 |
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;
bool* gens(int n, bool* s) {
if (n <= 1) {
*s = n;
return s + 1;
} else {
return gens(n - 2, gens(n - 1, s));
}
}
struct MP {
const int n;
const bool (&p)[100000];
int (&f)[100001];
int i;
MP(int n0, const bool (&p... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> fragments(n);
unordered_map<int, int> frag(n);
int val = 0;
for (int i = 1; i <= n; i++) {
cin >> val;
frag.emplace(val, i);
}
long long cost = 0;
for (int i = 2; i <= n; i++) {
cost += abs(f... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> cnt;
int a, b, k;
bool check(int l) {
for (int x = a; x <= b - l + 1; x++) {
int tmp = cnt[x + l - 1] - cnt[x - 1];
if (tmp < k) return false;
}
return true;
}
int main() {
cin >> a >> b >> k;
vector<bool> prime(b + 1, true);
prime[0] = prime... | 8 |
#include <bits/stdc++.h>
using namespace std;
char rel[100100], a[2][200];
int N, len[2], x, y, z, tot;
bool bisa[2], oke;
int main() {
scanf("%s", rel);
N = strlen(rel);
scanf("%s", a[0]);
len[0] = strlen(a[0]);
scanf("%s", a[1]);
len[1] = strlen(a[1]);
memset(bisa, false, sizeof(bisa));
for (int i = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.length();
int i, j, cnt = 0;
for (i = 0; i < n; i++)
if (s[i] == '1') break;
for (j = n - 1; j >= 0; j--)
if (s[j] == '1') break;
for (int k = i; k <= j; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long long n, k;
cin >> n >> k;
--k;
long long fib[n];
fib[1] = fib[2] = fib[0] = 1;
for (int i = 3; i < n; ++i) fib[i] = fib[i - 1] + fib[i - 2];
long long sum[n];
sum[0] = 1;
for (int i = 1; i < n; ++i) sum[i] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[200100];
int main() {
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
scanf("%s", s);
char l = '*';
int cont = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '.') {
if (a > b && a > 0 && l != 'a') {
a--, cont++, s[i] = 'a';
} else if (b ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int p[1111];
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int n, x;
cin >> n;
n *= 2;
vector<pair<int, pair<int, int> > > v;
for (int i = 2; i <= n; ++i)
for (int j = 1; j < i; ++j) {
cin >> x;
v.push_back({x, {i, j}});
}
sort(v.b... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long arr[] = {
1, 2, 4, 8, 16, 32,
64, 128, 256, 512, 1024, 2048,
4096, 8092, 16184, 32368, 64736, 129472,
258944, 51... | 11 |
#include <bits/stdc++.h>
using namespace std;
double f, x3, x2, x1;
int n;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> f;
x2 = x2 + ((2 * x1 + 1)) * f;
x1 = (x1 + 1) * f;
}
printf("%.8lf", x2);
}
| 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
priority_queue<int> q;
int val;
while (n--) cin >> val, q.push(val... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
int solve(string& second, int l, int r, char c) {
if (l == r) return second[l] == c ? 0 : 1;
int mid = (l + r) / 2;
int one = solve(second, l, mid, c + 1);
int two = solve(second, mid + 1, r, c... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long dp[70][maxn];
long long a[maxn], f[maxn], f1[maxn];
int cnt;
int sum0[maxn], sum1[maxn], tot0, tot1, n;
void Sort(long long x) {
cnt = 0;
for (int i = 1; i <= n; i++)
if (((a[f[i]] >> x) & 1) == 0) f1[++cnt] = f[i];
for (int i = ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int NR = 2e3 + 10, oo = 2e9;
void pres() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool a[2005][2005], viz[2005];
int n;
void dfs(int nod) { viz[nod] = 1; }
deque<int> dq;
void dfs(int tip, int nod) {
viz[nod] = 1;
dq.push_back(nod);
if (tip ==... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool flag[10000002];
int res[10000002], tempa[100005], tempb[100005], a[100005], b[100005],
aa[10000002], bb[10000002], p1[10000002], p2[10000003];
int count1 = 0, count2 = 0;
void eritosfen() {
int i, j;
flag[1] = true;
flag[2] = true;
aa[2] = 0;
bb[2] = 0;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long maxn = 400400;
long long n, m, k;
vector<long long> X;
map<long long, long long> I;
long long p[maxn], dp[maxn], up[maxn];
long long P[maxn], DP[maxn], UP[maxn];
map<long long, long long> a, b;
long long power(long long x, long l... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T& x) {
return x.size();
}
const int INF_INT = numeric_limits<int>::max();
bool IsPrime(int n) {
if (n <= 1) return false;
if (n == 2) return true;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> primediv;
int fs[200010][4];
map<int, int> cnt;
set<int> st;
long long Pow(int i, int u) {
long long y = 1, x = i;
for (; u; u >>= 1, x *= x)
if (u & 1) y *= x;
return y;
}
void findprimedivisor(int n) {
for (int i = 2; i * i <= n; i++) {
if (n %... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int a, b;
cin >> a >> b;
cout << max(a, b) - 1 << " " << min(a, b) << "\n";
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int d, p;
int num = 5;
int mult(int cell, int c) {
if (c == 0) c = p;
if (c == 1) return cell;
int cell2 = num++;
cout << "+ " << cell << " " << cell << " " << cell2 << endl;
c -= 2;
while (c > 0) {
if (c & 1) cout << "+ " << cell << " " << cell2 << " " << c... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l = 0, d = 0, e = 0, k = 0, n = 0, m = 0, maximum = 0,
minimum = 2147483647, p = 0, q = 0, r = 0, t = 0, end = 0, front = 0,
value = 0, first = 0, second = 0, len = 0, state = 0, size = 0;
int total = 0, temp = 0;
bool check = false;
str... | 0 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[50][55];
vector<int> g[2500], ng[2500];
int par[2500], ra[2500];
int dsuParent(int v) {
if (par[v] == v) return v;
return par[v] = dsuParent(par[v]);
}
void dsuMerge(int u, int v) {
u = dsuParent(u);
v = dsuParent(v);
if (u == v) return;
if (ra[... | 18 |
#include <bits/stdc++.h>
using namespace std;
bool used[1005][1005];
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
if (used[i][j]) continue;
used[i][j] = 1;
int x = i, y = j;
x *= x;
y *= y;
if ((x +... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
long long n, m, i, x, y, z, l, w, p, q, Ans, sum, cnt;
long long a[200010], s[200010], mi[200010], ni[200010];
inline int Abs(int x) { return (x < 0) ? -x : x; }
inline void Swap(int &a, int &b) { a ^= b ^= a ^= b; }
inline int Min(int a, int b) { re... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x, i, d, ans = 0;
char a;
cin >> n >> x;
for (i = 0; i < n; i++) {
cin >> a;
cin >> d;
if (a == '+')
x = x + d;
else if (d > x)
ans++;
else if (d <= x)
x = x - d;
}
cout << x << " " << ans << en... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
int n, m;
bool isgood(int x, int y) {
return (x >= 0) && (y >= 0) && (x <= n) && (y <= m);
}
double dist(const pair<int, int> &a, const pair<int, int> &b) {
return sqrt((a.first - b.first) * (a.first - b.first) +
(a.second - b.seco... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[505];
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
int n, m, i, x, y, c;
double ans = 0;
cin >> n >> m;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 0; i < m; i++) {
cin >> x >> y >> c;
ans = max(ans, 1.0 * (a[x] + a[y]) / c);
}
pr... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int LINF = 1LL * INF * INF;
const int MAXN = 2e5 + 10;
const int MAXM = 5e3 + 10;
priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;
int A[MAXN];
char S[MAXN];
int main() {
int n, m, k, a, b, x, y, q;
int sum = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, j = 0;
bool flag = 0;
cin >> h >> w;
vector<string> A(h);
for (int i = 0; i < h; i++) cin >> A[i];
for (int i = 1; i < h - 1; i++)
for (int u = 1; u < w - 1; u++)
if (A[i][u] == '*' && A[i - 1][u] == '*' && A[i + 1][u] == '*' &&
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
long long pw(long long b, long long p) {
if (!p) return 1;
long long sq = pw(b, p / 2) % 98765431;
sq = (sq * sq) % 98765431;
if (p % 2) sq = (sq * b) % 98765431;
return sq;
}
const int N = 1e5 + 5, M = 2e5 + 5;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long wt[200005], c[200005];
int main() {
int t;
t = 1;
while (t--) {
long long n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> wt[i];
}
long long a;
cin >> a;
for (int i = 0; i < n; i++) {
cin >> c[i];
}
p... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = UINT_MAX;
const double PI = acos(-1.0);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, l;
cin >> n >> l;
vector<long long> c(n);
for (long long &i : c) cin >> i;
for (int i = 0; i + 1 < n; i+... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.