solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long md = 998244353;
struct modular_num {
long long d;
modular_num(long long x = 0) { d = normal(x); }
long long normal(long long x) {
x %= md;
while (x < 0) x += md;
return x;
}
modular_num inverse(modular_num t) { return t ^ (md - 2); }
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long ans = 0;
for (int i = 1; i < n; i++) {
if (a[i - 1] == 1) {
if (a[i] == 3)
ans += 4;
else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<string, set<string>> p;
map<set<string>, set<string>> q;
void solve() {
int n;
cin >> n;
for (__typeof(n) i = 0; i != n; i += 1) {
string s;
cin >> s;
int k = -1;
for (__typeof((int)s.size()) j = 7; j != (int)s.size(); j += 1) {
if (s[j] == '... | 13 |
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool cmp(long long a, long long b) { return (a > b); }
int main() {
c_p_c();
cout << fixed << setprecision(10);
long long t;
cin >> t;
while (t--) {
long long n;
int s = 0;
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
in >> p.first >> p.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
out << p.first << " " << p.second;
return out;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[5];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
if (n == 1) return cout << -1, 0;
if (n == 2) {
if (p[0].first == p[1].first || p[0].second == p[1].second)
return cout << -1, 0;
cout <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long MOD = 1000000007;
const int MAXN = 22;
struct matrix {
int n, m;
unsigned long long arr[MAXN][MAXN];
matrix() {}
matrix(int x, int y, int V = 0) {
n = x;
m = y;
for (int j = 0; j < n; j++)
for (int i = 0; i < m; i++) arr[j][i] = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int sum = 0;
for (int i = 1; i < n; i++) {
sum += (n - i) * i;
}
sum += n;
cout << sum << "\n";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3;
const long long INF = 1e18;
struct Dinic {
struct edge {
int from, to;
long long cap, flow;
};
vector<edge> es;
vector<int> G[N];
bool vis[N];
int dist[N], iter[N];
void init(int n) {
for (int i = 0; i <= n + 10; i++) G[i].clear(... | 16 |
#include <bits/stdc++.h>
using namespace std;
void add_ele(pair<int, int> p1, pair<int, int> p2, pair<int, int> p3,
vector<vector<int> > &ans) {
vector<int> temp = {p1.first, p1.second, p2.first,
p2.second, p3.first, p3.second};
ans.push_back(temp);
}
int main() {
int t;
cin... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<int>> grid(1001, vector<int>(1001));
vector<ll> fact(2001), invfact(2001);
ll MOD = 1e9 + 7;
ll inv(ll b, ll p = MOD - 2) {
if (p == 0) return 1LL;
ll x = inv(b, p / 2);
x = x * x % MOD;
if (p % 2) x = x * b % MOD;
return x;
}
l... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w;
scanf("%d%d", &h, &w);
pair<int, int> s = make_pair(h, w), e = make_pair(0, 0), p;
char g[h + 3][w + 3];
for (int i = 0; i < h; i++) scanf("%s", g[i]);
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
if (g[i][j] == '*') {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, k = 0;
cin >> n >> k;
set<int> s;
deque<int> d;
for (int i = 0; i < n; i++) {
int x = 0;
cin >> x;
if (s.count(x) == 0) {
if (d.size() == k) {
int y = d.back();
d.pop_back();
s.insert(x);
d.... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
int x, y, z, ind;
pt() : x(0), y(0), z(0), ind(0){};
pt(int a, int b, int c, int d) : x(a), y(b), z(c), ind(d){};
};
bool compare(const pt &a, const pt &b) {
if (a.x != b.x) return a.x < b.x;
if (a.y != b.y) return a.y < b.y;
if (a.z != b.z) return a... | 9 |
#include <bits/stdc++.h>
int mod = 1000000007;
using namespace std;
bool isp(long long x) {
for (long long i = 2; i * i <= x; ++i)
if (x % i == 0) return false;
return true;
}
void pog() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
}
bool sortinrev(const pair<long long, long long> &a,
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y, ans;
int a[8][8];
int main() {
while (scanf("%d%d", &n, &m) != EOF) {
ans = 1000;
memset(a, 0, sizeof a);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
a[x][y] = a[y][x] = 1;
}
if (n <= 6)
printf("%d\n", m)... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int a[MAXN], crime[MAXN], ncrime[MAXN], no;
bool mark[MAXN];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] > 0)
crime[a[i]]++;
else {
ncrime[-a[i]]++;
no++;
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long a[200000];
long long n, k, l;
long long mins[200000];
long long cnt[200000];
stack<long long> fuck;
stack<long long> suck;
int main() {
memset(mins, 31, sizeof(mins));
cin >> n >> k >> l;
for (long long i = 0; i < n * k; i++) {
cin >> a[i];
}
sort(a,... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[10005] = {0};
int main() {
int n;
cin >> n;
int pre = 0, Max = -1, Maxpos = 0;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
if (i == 0) {
pre = num;
continue;
}
a[i] = num - pre;
if (Max < a[i]) {
Max = max(Max, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, k;
cin >> n >> k;
if (k < n + 1 || n == 4) {
cout << -1 << endl;
return 0;
}
int a, b, c, d;
cin >> a >> b >> c >> d;
vector<int> p;
for (int i = 1; i <= n; i++) {
if (i == a || i == b || i == c || i == d) continue;
p.... | 8 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
inline long long pwr(long long base, long long n) {
long long ans = 1;
while (n > 0) {
if (n % 2 == 1) ans = ans * base;
base = base * base;
n /= 2;
}
return ans;
}
struct range {
int l, h;
};
using namespace std;
int main() {
ios_base::sync_with... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const double pi = acos(-1.0), eps = 1e-6;
double dist(int x, int y) { return sqrt((long long)x * x + (long long)y * y); }
struct Range {
double l, r;
bool operator<(const Range &b) const {
return fabs(l - b.l) < eps ? r > b.r : l < b.l;
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int today;
int temp;
cin >> today;
cin >> temp;
for (int i = 1; i < n; i++) {
today++;
int nwdocfrday;
int nwdoceach;
cin >> nwdocfrday;
cin >> nwdoceach;
int dayfornewdoc = nwdocfrday;
while (today > d... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const double eps = 1e-9;
int n;
struct cmp {
bool operator()(int const& lhs, int const& rhs) const { return lhs > rhs; }
};
void solveAA() {
int t;
cin >> t;
for (int z = 0; z < t; z++) {
cin >> n;
set<int, cmp> p;
map<int, int> mp;... | 2 |
#include <bits/stdc++.h>
using namespace std;
string d_ver[7][3] = {{"...", "...", "..."}, {"...", ".O.", "..."},
{"..O", "...", "O.."}, {"..O", ".O.", "O.."},
{"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"},
{"O.O", "O.O", "O.O"}};
string d_hor[7][3] = {{"... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool dfs(int i, int j, vector<vector<int>>& a, int& sum, int n, int m) {
if (i + 1 < n && a[i + 1][j] == 0) dfs(i + 1, j, a, sum, n, m);
if (j + 1 < m && a[i][j + 1] == 0) dfs(i, j + 1, a, sum, n, m);
a[i][j] = min(a[i + 1][j], a[i][j + 1]) - 1;
if (a[i][j] <= a[i -... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> NameSet;
int NameSetLen, A[1010], B[1010], n, m, K;
struct Block {
vector<int> Peo, Key, Room;
void Check() {
sort(Peo.begin(), Peo.end());
sort(Key.begin(), Key.end());
sort(Room.begin(), Room.end());
}
};
bool operator==(Block A, Block B... | 15 |
#include <bits/stdc++.h>
using namespace std;
using VI = vector<long long>;
using VLL = vector<long long>;
using PII = pair<long long, long long>;
using PLL = pair<long long, long long>;
using VPII = vector<PII>;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
template <typename T>
T abs(T a) {
return a < 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
struct Diameter {
int from, to, d;
};
P farthest(int u, int p, vector<vector<int>> &g) {
P r(0, u);
for (auto e : g[u]) {
if (e == p) continue;
P c = farthest(e, u, g);
c.first++;
r = max(r, c);
}
return r;
}
Diameter tree... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, u, v;
vector<int> g[N], g2[N];
int vis[N], vis2[N];
string ans;
void DFS(int node) {
if (vis[node] == 2) return;
vis[node] = 1;
for (int i = 0; i < (int)g[node].size(); i++) {
if (vis[g[node][i]] == 1) {
puts("-1");
exit... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e18;
long long r, n;
long long t[100005], x[100005], y[100005];
long long ans[100005];
long long tt[1000005];
long long mx[1000005];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> r >> ... | 12 |
#include <bits/stdc++.h>
using namespace std;
void no() {
cout << "NO\n";
exit(0);
}
void yes() { cout << "YES\n"; }
int nxt() {
int x;
cin >> x;
return x;
}
void query(vector<int> &a, vector<int> &res) {
int n = ((long long)a.size());
cout << "? ";
for (int i = (int)0; i < (int)n; i++) cout << char(a[i... | 14 |
#include <bits/stdc++.h>
const int N = 100010;
using namespace std;
int n;
long long x[N], c, d[N], b[N];
bitset<N> a[71];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%I64d", x + i);
for (int i = 0; i < n; i++) {
c ^= x[i];
for (int j = 0; j < 63; j++) a[62 - j][i] = ((x[i] & (1ll << ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r, R;
cin >> n >> R >> r;
if (n == 1) {
if (R < r)
cout << "NO" << endl;
else
cout << "YES" << endl;
} else if (R < 2 * r)
cout << "NO" << endl;
else {
double a = asin((double)r / (double)(R - r));
double m = aco... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] += k;
}
for (int i = 0; i < n; i++) {
if (a[i] <= 5) {
v.push_back(a[i]);
}
}
int s = v.size();
cout << s / 3 << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long n, ans1, ans2, ans3;
int main() {
cin >> n;
ans1 = 1;
ans2 = 1;
ans3 = n - 2;
if (ans3 % 3 == 0) {
ans3--;
ans1++;
}
cout << ans1 << " " << ans2 << " " << ans3 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s, ss;
cin >> s >> ss;
long long int one_first = 0, one_second = 0;
for (auto it : s)
if (it == '1') one_first++;
for (auto it : ss)
if (it == '1') one_second++;
one_first += (one_first % 2);
if (one_first >= one_second)
cout ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e18;
const unsigned long long N = 2e5 + 5;
unsigned long long power(unsigned long long a, unsigned long long b) {
unsigned long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
multiset<long long> s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
long long x, y;
for (int(i) = 0; (i) < (n); i++) {
cin >> x >> y;
if (s.size() < k) {
s.insert(x + y);
cout << x + y << '\n';
} else {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int aa;
int count = 1;
int dd = 0;
cin >> aa;
if (aa < 0) aa = -aa;
while (dd < aa) {
dd += count;
count++;
}
count--;
if (dd == aa)
cout << count << endl;
else {
int vv = dd - aa;
if (vv % 2 == 0)
cout << count << ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int vis[1005][1005], sp[1005], cnt[1005];
char s[1005][1005];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
struct node {
int x, y, steps;
};
int main() {
int n, m, p;
cin >> n >> m >> p;
for (int i = 1; i <= p; i++) scanf("%d", &sp[i]);
queue<node> q[10];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 5;
const long long nax = 101010;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
string C;
string A;
cin >> n >> C ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int p[100100];
int main() {
int n, i;
scanf("%d", &n);
if (n % 4 != 0 && n % 4 != 1) {
printf("-1\n");
return 0;
}
for (i = 1; i <= n / 2; i += 2) {
p[i] = i + 1;
p[i + 1] = n + 1 - i;
p[n - i + 1] = n - i;
p[n - i] = i;
}
if (n % 4 == ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6 + 5, mn = 100;
int testCase = 1, cas = 0;
int main() {
ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
while (testCase--) {
long long n, l;
cin >> n >> l;
vector<long long> vec(n);
lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> res;
int getsum(int a) {
int r = a;
while (a) {
r += a % 10;
a /= 10;
}
return r;
}
int main(void) {
int n;
cin >> n;
res.clear();
int min = n > 90 ? n - 90 : 0;
for (int i = min; i != n; i++) {
if (getsum(i) == n) res.push_back(i);... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int mod = 1000000007;
inline void inc(int &x, int y) { (x += y) >= mod && (x -= mod); }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / mod * mod; }
int n, k, m, ans;
struct matrix {
int mat[225][225];
void clear() {... | 22 |
#include <bits/stdc++.h>
using namespace std;
long a[100500], b[100500];
long P = 1000;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long n, t, r, last = 0;
cin >> n >> t >> r;
for (int i = 0; i < n; i++) {
long x;
cin >> x;
a[P + x] = 1;
last = max(last, P + x);
}
long need = t,... | 8 |
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
void calc(int u,vector<int> &vis, const vector<vector<int>> &adj,const vector<int> &dist, vector<int> &dp){
vis[u] = 1;
dp[u] = dist[u];
for(auto v : adj[u]){
if(!vis[v] && dist[u] < di... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
int f[110000], a[110000];
long long s[110000];
struct sb {
int x, y, z;
};
sb b[110000];
int n, m;
long long ans;
bool cmp(sb a, sb b) { return a.z > b.z; }
int find(int x) {
if (f[x] == x) return x;
f[x] = find(f[x]);... | 11 |
#include <bits/stdc++.h>
using namespace std;
int dp[4][102][10002];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
vector<int> a(n+1), b(n+1);
vector<double> sol(n+1, 0);
int sumc=0, suml=0;;
for(int i=1;i<=n;++i){
cin>>a[i]>>b[i];
sumc+=a[i];
suml+=b[i];
}
for(int k=0;k<=n+1;+... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int BASE = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct SegmentTree {
int st[6 * maxn], lp[6 * maxn];
int L[6 * maxn], R[6 * maxn];
void Build(int k, int x, int y) {
L[k] = x;
R[k] = y;
st[k] = 0;
lp[k] = -1;
if (L[k... | 23 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
using namespace std;
int a[N], b[N];
int main() {
ios::sync_with_stdio(false);
int n, m, p;
cin >> n >> m >> p;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const long long N = 2 * (long long)1e5 + 10;
long long n, a, b, last;
bool zm[N];
pair<long long, long long> x[N], po[N];
vector<pair<long long, long long> > v;
signed main() {
init_ios();
cin >> n >> a >... | 13 |
// after seeing discussions nice DP 10/10
/* dont stick to an approach */
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#inclu... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[100009], b[100009], ans[100009], n, m, mod;
int main() {
cin >> n >> m >> mod;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
for (int i = 1; i <= m; i++) ans[i] += b[i], ans[n - m + 1 + i] -= b[i];
for (int i = 1; i <= n... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const long long INF = 1e18;
long long power(long long x, long long y) {
long long t = 1;
while (y > 0) {
if (y % 2)
y -= 1, t = t * x % mod;
else
y /= 2, x = x * x % mod;
}
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long k[200005], d[200005], a[200005];
bool dbrs[200005];
int main(void) {
long long n, m;
cin >> n >> m;
for (long long i = 1; i <= n; ++i) cin >> a[i];
long long p = 0;
for (long long i = 1; i <= m; ++i) cin >> k[i], p += (k[i] > 0);
long long s = 0;
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a;
for (int i = 0, v; i < n; i++) {
cin >> v;
if (v != -1) {
a.push_back(v);
} else {
for (auto &x : a) {
x = 0;
}
}
}
long l... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
int n;
struct Btree {
long long num, tag;
int cmx, cmi;
long long mi;
int left, right;
} tree[MAXN * 4];
void _clean(int x) {
if (tree[x].left == tree[x].right) return;
if (tree[x].tag == 0) return;
long long tag = tree[x].tag;
tre... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, i;
cin >> n >> a >> b;
long long h[n];
for (i = 0; i < n; i++) cin >> h[i];
sort(h, h + n);
cout << h[b] - h[b - 1] << endl;
}
| 0 |
#include <bits/stdc++.h>
void answer(int x, int y) { std::cout << x << ' ' << y << '\n'; }
void solve(unsigned l, unsigned r) {
const unsigned y = 2 * l;
if (y > r)
answer(-1, -1);
else
answer(l, y);
}
void test_case() {
unsigned l, r;
std::cin >> l >> r;
solve(l, r);
}
int main() {
size_t t;
st... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
int main() {
long long n;
cin >> n;
long long m = 2 * n;
long long a[m];
long long t = 0, ans = 0;
for (int i = 0; i < m; i++) {
cin >> a[i];
mp[a[i]]++;
if (mp[a[i]] == 1) {
t++;
} else {
t--;
}
ans = ... | 0 |
#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, flag = 0;
cin >> n;
long long m[n], a[n], i;
for (int i = 1; i <= n; i++) cin >> m[i];
if (m[1] + m[2] <= m[n])
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, sum;
long long a[110], k;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
sum = 2;
for (int i = 1; i < n; i++) {
if (a[i] - a[i - 1] > 2 * k)
sum += 2;
else if (a[i] - a[i - 1] == 2 * k)
sum++;
}
cout << sum << end... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
map<int, int> m;
int n, x;
int main() {
int i, j, k;
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> x;
m[x]++;
}
int t = 0, last;
for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
int x = it->first;
if (m[x] > ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 301;
const int MOD = 1e9 + 7;
int n, k, have[MAXN];
multiset<int> arr;
long long dp[MAXN][MAXN], com[2 * MAXN][2 * MAXN], fac[MAXN];
void inp() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
arr.insert(x);
}
return;
}
bool ch... | 17 |
#include <bits/stdc++.h>
using namespace std;
string G[2];
int dp[200008][20][2][2], n;
void init() {
for (int i = 0; i < 19; i++) {
for (int j = 0; j < 200008; j++) {
for (int a = 0; a < 2; a++)
for (int b = 0; b < 2; b++) dp[j][i][a][b] = 1e9;
}
}
for (int i = 0; i < n - 1; i++) {
for ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 5;
const int base = 303;
const int mod = 1e9 + 9;
string s;
int n, res, f[N];
long long hash_fw[N], hash_bw[N], pw[N];
long long gethash_fw(int x, int y) {
return ((hash_fw[y] - hash_fw[x - 1] * pw[y + 1 - x]) % mod + mod) % mod;
}
long long gethash_bw... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int ti = 0; ti < t; ti++) {
int n;
cin >> n;
vector<long long> a(n);
vector<long long> b;
b.reserve(n * 2);
b.push_back(0);
long long mel = 0, indm = -1;
for (int i = 0; i < n; i++) {
cin >> a[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long g() {
char c;
while (!isdigit(c = getchar()))
;
long long x = c - '0';
while (isdigit(c = getchar())) x = x * 10 + c - '0';
return x;
}
int s[100005];
int main() {
int n = g(), a = g(), b = g();
long long sum = 0;
for (int i = 0; i <= n ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, q, m, bm, l, r;
bool x[19][200005];
char y[19][200005][2][32];
int ta;
long long tb;
void cal(int a, int b) {
if (((1 << (a - 1)) * (b * 2 + 1)) < n) {
bool xa = x[a - 1][b * 2];
bool xb = x[a - 1][b * 2 + 1];
for (int i = 0; i <= bm; i++) {
y[a][... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int z[maxn], a[maxn], b[maxn];
int main() {
int n, su = 0;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", z + i);
if (z[i] == 2) ++su;
}
for (int i = 1; i <= n; ++i) {
if (z[i] == 1)
a[i] = a[i - 1] + 1;
el... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long st[4005][4005], f[4005];
int C[4005][4005];
void Stirling() {
for (int i = 0; i < 4005; i++) st[i][0] = st[i][1] = 1;
for (int i = 2; i < 4005; i++)
for (int j = 2; j <= i; j++)
st[i][j] = (st[i - 1][j - 1] + j * st[i - 1][j]) % 1000000007;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 20) + 5;
long long a[maxn], b[maxn], mod;
int d[maxn];
long long mul_mod(long long a, long long b) {
return (a * b - (long long)(a / (long double)mod * b + 1e-3) * mod + mod) %
mod;
}
long long pow_mod(long long a, long long n) {
long lon... | 22 |
#include <bits/stdc++.h>
using namespace std;
char getc() {
char c = getchar();
while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
c = getchar();
return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
int x = 0, f = 1;
char c = getchar();
while (c... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
long long N, M, K, P;
long long a[1010][1010];
priority_queue<long long> q1, q2;
long long cnt1[MAXN + 1], cnt2[MAXN + 1];
void solve() {
cin >> N >> M >> K >> P;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
cin >> a[... | 12 |
#include <bits/stdc++.h>
using namespace std;
int d[400], n, b[400];
int main() {
scanf("%d", &n);
for (int i = 0; i < 400; i++) d[i] = 0;
int curr = 0;
for (int xxx = 0; xxx < n; xxx++) {
int b;
scanf("%d", &b);
for (int j = 0;; j++) {
if (d[j] == 9) {
curr -= d[j];
d[j] = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct Seg_tree {
int left, right;
int size;
long long hash1, hash2;
} L[200005 << 2];
int n, m;
int a[200005], b[200005], p[200005];
long long fact_2[200005] = {1}, fact_1[200005] = {1};
long long hash_a_1, hash_a_2;
long long sum_1, sum_2;
void bulid(int step, int l... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 2;
int numOf[maxn];
int lastAcc[maxn];
int main() {
ios_base::sync_with_stdio(false);
memset(numOf, 0, sizeof(numOf));
memset(lastAcc, -1, sizeof(lastAcc));
int n, k;
cin >> n >> k;
vector<int> nums;
int temp;
int cur = 0;
int... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool SR(int &x) { return scanf("%d", &x) == 1; }
bool SR(long long &x) { return scanf("%lld", &x) == 1; }
bool SR(double &x) { return scanf("%lf", &x) == 1; }
bool SR(char *s) { return scanf("%s", s) == 1; }
bool RI() { return true; }
template <typename I, typename... T>
bo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, B = 350;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, m, a[N], p[N], pos[N], L[N], R[N], size;
long long f[N], ans;
inline bool cmp(int i, int j) { return a[i] < a[j]; }
struct block {
int l, r, q[B];
long long k, b;
inline long long calc(i... | 24 |
#include <bits/stdc++.h>
using namespace std;
long long powermod(long long a, long long b, long long c) {
long long ans = 1, tempans = a % c;
while (b > 0) {
if (b & 1 == 1) {
ans = (ans * tempans) % c;
}
tempans = (tempans * tempans) % c;
b = b >> 1;
}
return ans;
}
long long modinverse(l... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, cur, ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x;
if (cur + x > m) {
cur = 0;
ans++;
cur = x;
} else
cur += x;
}
cout << ans + 1;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 150;
const int sz = 1 << 21;
const long long INF = 2e18;
int n, m, b, k[maxn], p[maxn], mask[maxn], x[maxn];
long long dp[sz];
bool cmp(int X, int Y) { return k[X] < k[Y]; }
int main() {
cin >> n >> m >> b;
for (int i = 1; i <= n; i++) {
p[i] = i;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int x[110], y[110];
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (x[i] + x[j] <=... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 2003;
int a[nax] = {0}, n;
int main() {
int tc;
cin >> tc;
while (tc--) {
vector<int> v[27];
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
v[a[i]].push_back(i);
}
int max1 = 0;
for (int i = 1; i <= 26; ++i) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[650];
bool vis[650];
int main() {
int m, t, r, i, j, k, ans = 0, x, z;
bool b;
scanf("%d %d %d", &m, &t, &r);
int w[m + 2];
for (i = 0; i < m; i++) scanf("%d", &w[i]);
if (r > t) {
cout << "-1" << endl;
return 0;
}
for (i = 0; i < 650; i++) a[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e9 + 1;
const double pi = 3.1415926535897932384626433832;
const long long M = 2e18 + 7;
long long bis(long long a[], long long l, long long r, long long x) {
while (l <= r) {
long long m = l + (r - l) / 2;
if (a[m] == x) return m;
if (a[... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long MAX = 300010;
const long long MOD = (long long)1e9 + 7;
const long long INF = 1e9;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-8;
struct Segtree {
vector<long l... | 15 |
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back
using namespace std;
//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __pri... | 9 |
#include <bits/stdc++.h>
using namespace std;
double p[10000009], dp[10000009], ans[30];
int main() {
int n, k;
memset(dp, 0, sizeof(dp));
memset(ans, 0, sizeof(ans));
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%lf", &p[i]);
dp[0] = 1;
for (int i = 0; i < (1 << n); i++) {
double t = 0, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s, p;
char c;
void solve(int x) {
if (x == 1) {
s = "", p = "a", c = 'a';
return;
}
if (x == 2) {
s = "b", p = "ab", c = 'b';
return;
}
if (!(x & 1)) {
solve((x >> 1) - 1);
++c;
s = c + s + c + c;
p = p + c;
return... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
m *= 2;
n *= 2;
char ar[250][250];
for (int i = 0; i < m; i += 2) {
for (int j = 0; j < n; j += 2) {
cin >> ar[i][j];
ar[i + 1][j] = ar[i][j];
ar[i + 1][j + 1] = ar[i][j];
ar[i][j + 1] = ar[i][j];... | 4 |
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
if (a < val) a = val;
}
const long long N = 2 * (long long)1e5 + 10;
long... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int e = 127;
vector<int> v[30][30];
bool d[N][N][N];
bool dp[N][N][N];
int p[N][N];
int main() {
string s, t;
cin >> s >> t;
int n, m, i, j, k;
cin >> n;
string w;
for (i = 1; i <= n; i++) {
cin >> w;
v[w[3] - 97][w[4] - 97].push... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' ||... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int cnt = 0, cnt2 = 0;
cin >> s;
if (s.size() == 1) {
if (isupper(s[0])) {
putchar(tolower(s[0]));
} else
putchar(toupper(s[0]));
return 0;
}
if (islower(s[0]) && s.size() > 1) {
for (int i = 1; i < s.size(); i+... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
vector<long long> prefSum(n);
prefSum[0] = arr[0];
for (int i = 1; i < n; i++) {
prefSum[i] = prefSum[i - 1] + arr[i];
}
map<long long, int>... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 7;
const double eps = 0.000000001;
double mi[N], ma[N], a[N], b[N];
int n;
void read_input() {
for (int i = 1; i <= n; ++i) {
cin >> ma[i];
ma[i] += ma[i - 1];
}
for (int i = 1; i <= n; ++i) {
cin >> mi[i];
mi[i] += mi[i - 1]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int nn, mm;
typedef struct {
int x, s, e;
} ele;
int cmp(ele a, ele b) { return a.x < b.x || (a.x == b.x && a.s < b.s); }
vector<ele> a[2];
template <class T>
int dcdc(T s, T e, int x) {
ele l = *s;
s++;
for (; s != e; s++) {
if (l.e >= s->s) {
... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.