solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int INF = 2147483600;
const int MAXN = 500010;
int Q, N, K;
int Nod... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353, N = 2e5 + 9;
int a[N];
int main() {
int n, len = 1, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
set<pair<int, int> > st1, st2, st3;
for (int i = 2; i <= n + 1; ++i) {
if (a[i] == a[i - 1]) {
... | 12 |
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long int
#define mod 998244353
inline int inc(int a,int b){return a+b<mod?a+b:a+b-mod;}
inline int dec(int a,int b){return a<b?a-b+mod:a-b;}
inline int mul(int a,int b){return (int)((ll)a*b%mod);}
inline int pow(int a,int b)
{
int res=1;
while(... | 21 |
#define ll long long
#define dn double
#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define mod 1000000007
#define sob(v) v.begin(),v.end()
#define sobr(v) v.rbegin(),v.rend()
#defi... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 888;
int n;
char s[maxn];
bool valid(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }
int nxt[maxn], stk[maxn], stop = 0;
int main() {
while (1 == scanf("%d", &n)) {
gets(s);
string er = "", ans = "";
int fd = 0, ss =... | 10 |
#include <bits/stdc++.h>
using namespace std;
int check(int x1, int y1, int x2, int y2) {
if (x2 < x1 || y2 < y1) return 0;
printf("? %d %d %d %d\n", x1, y1, x2, y2);
fflush(stdout);
int ret;
scanf("%d", &ret);
return ret;
}
pair<pair<int, int>, pair<int, int> > Search(int x1, int y1, int x2, int y2) {
in... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int l, r, d;
cin >> l >> r >> d;
if (d < l)
cout << d << endl;
else {
if (r % d == 0)
cout << (r + d) << endl;
else
cout << (d - r % d) + r << endl;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
long long fac[1] = {1}, inv[1] = {1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mp(long long a, long long b) {
long long r... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, a, b, c, ans, P;
pair<long long, long long> ar[3333];
double k1, k2;
double tmp, last;
vector<double> A;
map<pair<double, double>, bool> mp;
int main() {
scanf("%I64d", &n);
for (i = 0; i < n; i++) scanf("%I64d%I64d", &ar[i].second, &ar[i].first);
s... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 100;
const long long oo = 1e9;
long long n;
long long a[N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
cin >> n;
long long maxn ... | 10 |
#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 9223372036854775807;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline void randomizer3000() {
unsigned int seed;
asm("r... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> a, b;
map<pair<int, int>, int> p;
int main() {
ios_base::sync_with_stdio(0);
int n, x, y;
long long ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
ans += (a[x]++ + b[y]++ - p[make_pair(x, y)]++);
}
cout << ans << endl;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
char ch = getchar();
int f = 1;
while ((ch != '-') && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-')
f = 0, x = 0;
else
x = ch - 48;
ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000100;
const int Mod = 1e9 + 7;
int cost[MaxN];
int lp[MaxN];
int phi[MaxN];
vector<int> pr;
int N, K;
std::pair<int, int> a[MaxN];
void calc_sieve() {
phi[1] = 1;
for (int i = 2; i <= N; ++i) {
if (lp[i] == 0) {
lp[i] = i;
phi[i] = i ... | 20 |
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
const int MAXN = 1000005;
const int MOD = 998244353;
int n, sol;
int dp[MAXN], sum[MAXN];
int add (int x, int y) {x += y; if (x >= MOD) return x - MOD; return x;}
int sub (int x, int y) {x -= y; if (x < 0) return x + ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long linf = 1LL << 62;
const unsigned long long ulinf = 1ULL << 63;
const double eps = 0.000001;
const double pi = 3.14159265358979323846;
template <class T>
T abs(T a) {
return a >= 0 ? a : -a;
}
template <class T>
T sqr(T a) {
re... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, h, i, cnt;
int main() {
scanf("%d", &n);
while (cnt <= n) {
h++;
cnt += (h * (h + 1)) / 2;
}
printf("%d\n", h - 1);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 3e5 + 7;
struct node {
long long fir, sec;
} f[df];
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], cnt[df],
ans;
inline long long read() {
long long x = 0, y = 1;
char ch = getchar();
while (ch > '9' ||... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x = 0, f = 1;
register char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = 0;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + (ch ^ '0');
ch = getchar();
}
return f ? x : -x;
}
const int N = 1e2 ... | 22 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <int MOD>
struct Modular {
int val;
Modular() : val(0){};
Modular(int _val) : val(_val % MOD){};
void norm() {
val %= MOD;
if (val < 0) val += MOD;
}
Modular& operator+=(const ... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long fpow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) {
ans *= a;
ans %= mod;
}
a *= a;
a %= mod;
b >>= 1;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000 + 7;
const double esp = 1e-13;
const double pi = 3.141592653589;
int suma, sumb, n;
char x;
int main() {
ios ::sync_with_stdio(false);
cin >> n;
suma = sumb = 0;
for (int i = (1), _b = (n); i <= _b; i++) {
cin >> x;
if (x == ... | 0 |
#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... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char s[N];
int x[N], y[N], z[N];
int main() {
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; i++) {
if (i) {
y[i] += y[i - 1];
x[i] += x[i - 1];
z[i] += z[i - 1];
}
if (s[i] == 'y') {
y[i]++;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
const int INF = (int)1E9 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int NMAX = 2010;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int id;
vector<Node*> neighbours;
Node(int i) : id(i) {}
};
int main() {
int n, m;
cin >> n >> m;
vector<Node*> nodes;
for (int i = 0; i < n; i++) {
nodes.push_back(new Node(i));
}
for (int i = 0; i < m; i++) {
int x, y;
cin >> x ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v[100009];
int visited[100009];
int parent[100009];
int DFS(int start) {
visited[start] = 1;
int i, s = v[start].size(), ans = 0;
for (i = 0; i < s; i++) {
if (visited[v[start][i]] == 0) {
parent[v[start][i]] = start;
ans = DFS(v[... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int MAXN = 1e6 + 10;
int lp[MAXN];
long long d[MAXN];
void solve() {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
string Next() {
string S;
cin >> S;
return S;
}
int NextInt() {
int n;
scanf("%d", &n);
return n;
}
long long NextLong() {
long long n;
scanf("%lld", &n);
return n;
}
const int N = (int)5e2 + 10;
int n, k, a[N];
bool dp[2][N][N];
int main() {
n = NextInt... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 100;
string s;
long long n;
bool mark[N];
void chap() {
for (long long i = 0; i < n; i++) {
cout << s[i];
if (mark[i]) cout << " ";
}
cout << "\n";
}
bool check(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * f;
}
int n, Q, mp[2][100... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct cc {
int a;
int b;
} xx[100005];
bool vis[100005];
int ss[100005];
vector<cc> vec;
bool cmp(cc x, cc y) { return x.b < y.b; }
int main() {
int n, m, i, j, k, sum;
long long ans;
while (~scanf("%d%d", &n, &m)) {
ans = 0;
sum = 0;
memset(vis, fals... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int MOD = (int)(1e9)+7, INF = 0x3f3f3f3f;
void bayo() {
int n, m;
cin >> n >> m;
int a[n][m], ans[n][m], l[n], r[n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
sort(a[i], a[i]+m);... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
long long n, m, w, a[200005];
long long dif[200005];
bool isok(long long k) {
for (int i = 0; i < (n + 1); i++) {
if (i)
dif[i] = a[i] - a[i - 1];
else
dif[i] = a[i];
}
long long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dp[500][500];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
bool is = 0;
for (int div = 1; div <= m; div++) {
for (int i = 0; i < 500; ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 1;
const long long INFLL = 1e18 + 1;
struct Graph {
struct edge {
int c, f, link, to, ind;
int c2 = 0;
edge() {}
edge(int c, int f, int link, int to, int ind)
: c(c), f(f), link(link), to(to), ind(ind) {}
};
vector<vector<... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[4][4], count, count2, flag = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) cin >> arr[i][j];
}
for (int i = 1; i < 4; i++) {
for (int j = 1; j < 4; j++) {
count = 0;
count2 = 0;
if (arr[i][j] == '#')
... | 3 |
#include <bits/stdc++.h>
const int mod = 998244353;
using namespace std;
void solve() {
int n;
cin >> n;
int sum = n / 10;
if (n % 10 == 9) sum++;
cout << sum << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
return... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[1000010], ans, b[1000010];
int vis[1000010], viss[1000010];
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
while (m--) {
int x, y;
cin >> x >> y;
a[x].push_back(y);
b[y].push_back(x);
}
for (int i = 1; i <= n; i+... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, a[110], b[110];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[i] = i;
}
x = n;
while (1) {
if (x == 1) {
cout << b[1] << "\n";
break;
}
if (a[1] <= m) {
for (int j = 1; j <= x - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long sum[maxn << 2], lazy[maxn << 2], a[maxn];
long long maxs[maxn << 2], len[maxn << 2], mins[maxn << 2];
void push_up(int id) {
sum[id] = sum[(id << 1)] + sum[(id << 1 | 1)];
maxs[id] = max(maxs[(id << 1)], maxs[(id << 1 | 1)]);
mins[... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c;
cin >> r >> c;
if (r == 1 && c == 1) {
cout << 0;
return 0;
}
if (c == 1) {
for (int i = 0; i < r; i++) cout << i + 2 << '\n';
return 0;
}
int rs[r], cs[c], x = 1;
for (int i = 0; i < r; i++) {
rs[i] = x;
x++;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
int n = s.length();
if (n == 1) {
cout << s << endl;
} else {
for (int i = 0; i < n;) {
int j = i;
while (j < n ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long t, n;
long long x[305];
long long ys(long long a) {
long long all = 0;
for (long long i = 2; i * i <= a; i++) {
if (i * i == a)
all++;
else if (a % i == 0)
all += 2;
}
return all;
}
int main() {
cin >> t;
while (t--) {
memset(x,... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, indexx[2005], low[2005], belong[2005];
int cnt, bcc;
int sz[2005], s[2005], dp[2005], f[2005][2005];
stack<int> st;
vector<int> a[2005], g[2005], all;
void visit(int u, int p) {
indexx[u] = low[u] = ++cnt;
st.push(u);
for (auto v : g[u]) {
if (v == p) co... | 19 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "( " << v.first << ", " << v.second << ")";
return o... | 14 |
#include <bits/stdc++.h>
int min(int a, int b) {
if (a < b) {
return a;
}
return b;
}
int max(int a, int b) {
if (a > b) {
return a;
}
return b;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
int tower1 = 2 * n, tower2 = 3 * m;
if (tower2 < tower1) {
int common = tower2 / 6;
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 100;
const double PI = 3.1415926536;
vector<long long> v;
long long n, m, k, t, sum, r, l, d, b[1111], c, a[1111], p, e;
long long ans;
map<int, string> mp;
bool f;
string s;
queue<long long> q;
bool check(long long x) {
for (int i = 0; i < n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int main() {
int n, m;
scanf("%d%d", &n, &m);
if (n == 1 && m == 1) {
puts("1");
return 0;
}
if (n % 2 == 0) {
if (m <= n / 2)
printf("%d\n", m + 1);
else
printf("%d\n", m - 1);
} else {
if (n / 2 + 1 == m)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const double eps = 1e-9;
int n;
double t;
struct Node {
double s, e;
bool operator<(const Node &a) const { return s < a.s; }
} nd[N];
int main() {
int i, j;
cin >> n >> t;
double x, a;
for (i = 1; i <= n; i++) {
cin >> x >> a;
a /= 2;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n], b[n], c[n];
set<long long> s[4];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long long i = 0; i < n; i++) {
cin >> b[i];
s[b[i]].insert(a[i]);
}
for (long long i = 0; i < n; i++) {... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a[2000][2000];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> b(n);
for (auto &x : b) cin >> x;
sort(b.begin(), b.end(), greater<long long>());
long long l = 0;
long long total = 0;
... | 6 |
#include <bits/stdc++.h>
const int N = 100010;
char s[N];
std::vector<int> vec0, vec1;
void print(bool flag) {
puts(flag ? "tokitsukaze" : "quailty");
exit(0);
}
int findLeft(std::vector<int> &vec, int l, int r) {
if (l > r) {
return -1;
}
auto u = std::lower_bound(vec.begin(), vec.end(), l);
if (u != v... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1005];
int cnt;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 0) cnt++;
}
if ((cnt == 1 && n != 1) || (cnt == 0 && n == 1))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string x;
cin >> x;
int answer = n;
for (int i = 0; i * 2 < n - 1; i++) {
if (x.substr(0, i + 1) == x.substr(i + 1, i + 1)) {
answer = min(answer, n - i);
}
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> state;
state.reserve(n);
for (int i = 0; i < n; ++i) {
int c;
cin >> c;
if (c > 0) state.push_back(c);
}
vector<int> want;
want.reserve(n);
for (int i = 0; i < n; ++i) {
int c;
cin >> c;
if ... | 5 |
#include <bits/stdc++.h>
inline int read() {
int x;
char c;
while ((c = getchar()) < '0' || c > '9')
;
for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';) x = x * 10 + c - '0';
return x;
}
int h[100000 + 5], a[100000 + 5], u[5000 + 5];
int main() {
int n, m, k, p, i;
long long l, r, mid, ans, s;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
int col[MAX_N], val[MAX_N];
long long dp[MAX_N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> val[i];
for (int i = 1; i <= n; i++) cin >> col[i];
while... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)(1e5) + 7;
const int INF = (int)(2e9) + 7;
const long double eps = 1e-15;
int main() {
int x, y, c;
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 5; ++j) {
cin >> c;
if (c) {
x = i;
y = j;
}
}
cout << abs(... | 0 |
#include <bits/stdc++.h>
using namespace std;
set<long long> st;
long long ans1 = 0, ans2 = 0;
void prepro() {
st.insert(0);
for (int i = 0; i <= 35; i++) {
st.insert(1ll << i);
}
}
void solve(long long a, long long b, bool fg) {
long long c, d, ta = a;
set<long long>::iterator it = st.lower_bound(a);
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t, x, y, xt, yt, count = 0;
string s;
cin >> t >> x >> y >> xt >> yt >> s;
for (int i = 0; i < t; i++) {
char direction = s[i];
if (direction == 'N' && y < yt) {
y++;
count ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5;
int n, val[N + 5], cnt[N + 5], x, sum[N + 5], las[2 * N + 5], ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &val[i]), cnt[val[i]]++;
for (int i = 1; i <= n; i++)
if (cnt[i] > cnt[x]) x = i;
int lim = sqrt(n) + 1;
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int t[1000000];
int l[1000000];
int main() {
int n, L, p;
cin >> n >> L >> p;
int ret = 0;
for (int i = 0; i < n; i++) {
cin >> t[i] >> l[i];
if (i == 0 && t[i] > 0) {
ret += (t[i]) / p;
}
if (i > 0) {
ret += (t[i] - t[i - 1] - l[i - 1]) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, l, r, i, sum, d[200200];
int main() {
cin >> n >> k;
for (i = 0; i < n; ++i) {
scanf("%d", d + i);
sum += d[i];
}
for (i = 0; i < n; ++i) {
l = max(1LL, k - sum + d[i]);
r = min(d[i], k - n + 1);
printf("%d ", d[i] - r + l - 1);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, cnt = 2, A[105];
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
for (int i = 1; i < n; i++) {
if (A[i + 1] - A[i] > m * 2) cnt++;
if (A[i + 1] - A[i] >= m * 2) cnt++;
}
printf("%d", cnt);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
int n = 0;
int m = 0;
cin >> n >> m;
long long sumx = 0;
vector<int> xi(n, 0);
vector<int> yi(n, 0);
vector<pair<int, int> > a;
vector<vector<int> > g(n, vector<int>());
for (int i = 0; i < n; i++) {
ci... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10] = {0};
char t[100050], b[100050];
scanf("%s", b);
scanf("%s", t);
for (int i = 0; t[i] != '\0'; i++) {
a[t[i] - '0']++;
}
for (int i = 9, j = 0; b[j] != '\0' && i != 0; j++) {
if (a[i] == 0) {
i--;
j--;
continue... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long max_n = 1e6;
long long n, k, vis[max_n];
struct node {
long long v, id, c;
} a[max_n];
bool cmp(node a, node b) {
if (a.v == b.v)
return a.id > b.id;
else
return a.v > b.v;
}
bool cmp2(node a, node b) { return a.id < b.id; }
int32_t main() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, k;
map<int, int> dp[N], sta;
long long ans;
void pre(int x) {
int pr = 2;
dp[0][1] = 0;
sta[1] = 0;
while (x > 1) {
if (pr > sqrt(x)) {
sta[x]++;
break;
}
int cnt = 0;
while (x % pr == 0) x /= pr, cnt++;
... | 11 |
#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;
vector<long long> v;
long long ans[n + 5];
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end(), gr... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long a[N];
int vis[N];
long long ans = 0;
int n, q;
int l, r;
void solve() {
int fg = 0;
for (int i = 1; i <= n; ++i) {
if (fg % 2 == 0) {
if (a[i - 1] < a[i] && a[i] > a[i + 1]) {
ans += a[i];
++fg;
vis[i] =... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct P {
long long x, y, z;
bool operator<(const P &a) const { return x > a.x; }
};
int a, b, c, i, k, o[10002], d, e, dy[15] = {0, 0, -1, 1, -1, 1, -1, 1},
dx[15] = {-1, 1, 0, 0, 1, 1, -1, -1};
int l[51];
long long x, y, z, n, m, v1... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, l, r, sz, i, n;
int main() {
cin >> a >> b >> c >> d >> l >> r;
for (i = l; i <= r; i++) {
n = i;
if (n % a % b % c % d == n) sz++;
}
cout << sz;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, i = 0, ans = 0;
while (cin >> a) {
ans += i * a;
i++;
}
cout << ans << endl;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long sum = 0;
long long mid = n / 2;
for (long long i = 0; i < mid; i++)
sum += (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1]);
if (n... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e6 + 10;
const long long int inf = 1e9 + 10;
const long double Pi = 3.14159265;
long long int f(long long int n) { return bitset<64>(n).to_ullong(); }
long long int f(string n) { return bitset<64>(n).to_ullong(); }
long long int n, m;
string s[N];
v... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int M = 1e6 + 6;
struct edge {
int a, b, e, i;
bool operator<(const edge &ed) const {
if (e != ed.e) return e < ed.e;
return i < ed.i;
}
};
int n, m;
int par[N];
edge edg[M];
int find(int x) {
if (par[x] == ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long a[20];
long long b[20][20];
long long dp[(1LL << 19)][20];
int32_t main() {
cin >> n >> m >> k;
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long long i = 0; i < k; i++) {
long long x, y, c;
cin >> x >> y >> c;
... | 10 |
#include <bits/stdc++.h>
int a[2000005][2], m, n, c[2000005];
char s[20];
int main() {
m = 1;
int T;
for (scanf("%d", &T); T--;) {
char op;
scanf(" %c", &op);
if (op == '+') {
scanf("%s", s);
n = strlen(s);
int p = 1;
for (int i = n - 1; i >= 0; i--) {
int x = (s[i] - '... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1)
cout << -1;
else
cout << n << ' ' << (n + 1) << ' ' << n * (n + 1);
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const int MAX_N = int(1e6) + 10;
int n, m, k, result;
int f[MAX_N], g[MAX_N], s[MAX_N];
int pow_mod(int a, int b) {
int ret = 1;
for (; b; b >>= 1, a = 1LL * a * a % MOD) {
if (b & 1) {
ret = 1LL * ret * a % MOD;
}
}
retur... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300030, mod = 998244353;
inline int read() {
int x = 0, f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int n, m, a... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long int tc = 1;
long long int n, m, k, a, b, c, d, x, y, i, j,
cnt = 0, sum = 0, ans = 0, res = 0, maxi = INT_MIN, mini = INT_MAX;
vector<long long int> graph[101];
vector<long long int> adj;
vector<long long int> arr(101);
void solve() {
cin >> n >> m;
while ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const int _OO = -1 * OO;
const double EPS = (1e-9);
const double pi = 3.14159265;
using namespace std;
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dx8[8] ... | 7 |
#include <bits/stdc++.h>
long long a[105], b[105];
int heroA[105], heroB[105];
long long ha[105], hb[105];
int answer[105];
int qa[105], qb[105];
int queue[105];
int isLeft(int p, int queue[]) {
for (int j = 1; j <= p; j++) {
b[j] = a[j];
heroB[j] = heroA[j];
hb[j] = ha[j];
}
int size = 0;
for (int ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
int a[5];
int main() {
int n;
cin >> n;
int ave = n / 3;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
a[(int)(s[i] - '0')]++;
}
int x = a[0] - ave, y = a[1] - ave, z = a[2] - ave;
if (!x && !y &&... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
scanf("%d", &n);
int a[n];
for(int i=0; i<n; i++) {
scanf("%d", &a[i]);
}
sort(a,a+n);
set<int> b;
for(int i=0; i<n; i++) {
for(int j=i+1; j<n; j++) {
int area = abs(a[i]-a[j]);
b.insert(area);
}
}
printf("%d\n", (int)b.size());
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, opt[30][30], ans;
int main() {
cin >> n;
getchar();
for (int i = 1; i <= n; i++) {
string s;
getline(cin, s);
int len = s.length();
int l = s[0] - 'a' + 1, r = s[len - 1] - 'a' + 1;
for (int j = 1; j <= 26; j++)
if (opt[j][l] != 0) opt... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
long long j = 0;
long long n = a.length();
while (a[n - j - 1] == '0') j++;
string b(a.begin(), a.end() - j);
string c(b);
reverse(c.begin(), c.end());
if (b == c)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
long long int claws[MAXN];
int main() {
int n;
scanf("%d", &n);
int sum = n;
for (int i = 0; i < n; i++) scanf("%I64d", &claws[i]);
int man = n - 1;
long long int kill = man - claws[man];
for (int i = n - 1; i >= 0; i--) {
if (i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000 + 5;
int n, m;
char a[MAXN];
int res;
char g[MAXN][MAXN];
char s[MAXN];
char s1[MAXN];
char s2[MAXN];
int xx, yy;
int dx, dy;
bool succeed(char nn, char s, char w, char e) {
int x = xx;
int y = yy;
if (g[x][y] == 'E') return true;
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int main(int argc, char* argv[]) {
int n, k;
cin >> n >> k;
vector<int> val = vector<int>(n, 0);
for (int i = 0; i < val.size(); i++) {
cin >> val[i];
}
vector<int> pows = vector<int>(k + 1, 0);
pows[0] = 1;
for (int... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int k = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> primes(100, 0);
for (int i = 2; i < 100; i++) {
for (int j = 2; j * i < 100; j++) {
primes[i * j] = 1;
}
}
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 5 * 1e3 + 7;
int a[maxx], pos[maxx], dp[maxx][maxx];
int main() {
ios::sync_with_stdio(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++)
pos[i] = lower_bound(a + 1, a ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[8], x, y, z, maxx;
for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
if (a[1] + a[2] + a[3] > a[2] + a[3] + a[4]) {
maxx = a[1] + a[2] + a[3];
x = a[1];
y = a[3];
z = a[5];
} else {
maxx = a[2] + a[3] + a[4];
x = a[2];
y... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, a, b, i, j, x, y, t;
scanf("%d", &t);
while (t--) {
v.clear();
int flag = 0, flag2 = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &a);
v.push_back(a);
}
for (i = 0; i < v.size(); i++) {
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<vector<int> >;
using VS = vector<string>;
using SS = stringstream;
using PII = pair<int, int>;
using VPII = vector<pair<int, int> >;
template <type... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n;
cin >> n;
int64_t *a = new int64_t[n + 1];
int64_t sum = 0;
for (int64_t i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum % 3 != 0) {
cout << 0;
return 0;
}
int64_t *dp = new int64_t[n + 2];
int64_t current... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.