solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;
lli a[(int)(1e5 + 5)];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
cout << 1 << " " << 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double E = exp(1);
char box[100][100];
int row, col, letters[50];
int call(int x, int y) {
memset(letters, 0, sizeof(letters));
letters[box[x][y] - 'a'] = 1;
if (y + 1 < col) letters[box[x][y + 1] - 'a'] = 1;
if (x + 1 < row)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n;
cin >> n;
map<long long, long long> m;
vector<long long> v;
for (long long i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
v.push_back(i);
}
}
for (long long j = 0; j < v.size(); j++) {
long long i = v[j];
long... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<int, int> p[8];
int b = 1, i, *t = (int*)&p;
char n[] = "0468:>177;3=599?468:133>";
for (i = 0; i < 16; cin >> t[i++])
;
sort(p, p + 8);
for (i = 0; i < 24; i += 2)
if (t[n[i] - '0'] == t[n[i + 1] - '0'] != i < 16) b = 0;
cout << (b ?... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t-- > 0) {
int n;
cin >> n;
bool good = true;
vector<int> a;
vector<pair<int, int>> rs(n, {-1, -1});
for (int i = 0; i < n; i++) {
int x;
cin >> x;
x--;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, maxp = 300005;
int n, stp, inf, maxx, anss;
int v[maxn], c[maxn], l[maxn], r[maxn], f[maxp], chs[maxp], vis[maxp],
ans[maxn], last[maxp];
vector<int> p[maxp];
void getnew(int x) {
if (vis[x] != stp) {
vis[x] = stp, f[x] = inf, chs[x] = 0;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T t) {
for (const auto &it : t) cout << it << ' ';
cout << "\n";
}
const double Pi = acos(-1.0);
const int Mod = 1e9 + 7;
const int Eps = 1e-9;
const int Inf = 1 << 28;
const int Maxx = 1e5 + 10;
int main() {
ios::sync_with_stdio(false... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 1000 * 1000 + 10;
long long hash1[MN], hash2[MN], p_pow[MN], p = 31;
void get_hash(string &s, long long *hash) {
for (int i = 0; i < s.size(); i++) {
hash[i] = (s[i] - 'a' + 1ll) * p_pow[i];
if (i) hash[i] += hash[i - 1];
}
}
bool is_eq(int i, int... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
string t, s;
string nxt(string a) {
int n = a.size() - 1;
while (n >= 0) {
if (a[n] == 'z')
n--;
else {
a[n] = (char)a[n] + 1;
for (int i = n + 1; i < a.size(); i++) {
a[i] = 'a';
}
return a;
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int _MAX(int a, int b) { return a > b ? a : b; }
int _MIN(int a, int b) { return a > b ? b : a; }
int Scan() {
int res = 0, flag = 0;
char ch;
if ((ch = getchar()) == '-')
flag = 1;
else if (ch >= '0' && ch... | 10 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
const int mod = 998244353;
int n;
char str[MAXN];
int low[MAXN];
int cnt[MAXN][26];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vector<int> ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, p;
scanf("%I64d%I64d", &n, &p);
char a[50][20];
for (long long int i = 0; i < n; i++) cin >> a[i];
long long int b[50];
long long int num = 0;
b[n - 1] = 1;
for (long long int i = n - 2; i >= 0; i--) {
if (strlen(a[i]) > 4)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long aa, long long bb) {
if (bb == 0)
return aa;
else
return gcd(bb, aa % bb);
}
long long lcm(long long a, long long b) {
if (a * b == 0) return 0;
return (a * b) / gcd(a, b);
}
long long prime(long long x) {
if (x <= 1) return 0;
for... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t, n, m, k;
cin >> t;
while (t--) {
pair<long long, long long> a, b;
cin >> n >> k;
cin >> a.first >> a.second;
cin >> b.first >> b.second;
if (a > b) swap(a, b);
long long cu... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
long long int i, k = 1;
for (i = 1; i <= b; i++) k *= a;
return k;
}
int main() {
long long int n, k, v, start, end, x, i, s;
scanf("%I64d %I64d", &n, &k);
start = 1, end = n;
while (end - start > 1) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k;
cin >> n >> m >> k;
if (k == 1 || n < k) {
long long ans = 1;
for (int i = 1; i <= n; i++) {
ans *= m;
ans %= 1000000007;
}
cout << (ans % 1000000007) << endl;
} else if (n == k) {
long long ans = 1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
int n, m, k;
char ara[105][105];
int dp[120][120][15];
char pr[120][120][15];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(pr, 's', sizeof pr);
memset(dp, -1, sizeof dp);
cin >> n >... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long oo = (long long)1e9;
template <typename T>
using V = vector<T>;
inline void fastInOut() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline bool taxi(string &s) {
return ((s[0] == s[1] && s[1] == s[3] && s[3] == s[4] && s[4] == s[6] &&
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, parent[200009], p;
int Find(int i) {
if (parent[i] == i) return i;
parent[i] = Find(parent[i]);
return parent[i];
}
void Union(int i, int j) {
int x, y;
x = Find(i);
y = Find(j);
parent[x] = y;
}
int main() {
int q, i, a[200009];
cin >> q;
while (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const long long INF = 1e18;
const int irand(int lo, int hi) {
return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
const long long lrand(long long lo, long long hi) {
return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
te... | 12 |
#include <bits/stdc++.h>
struct event {
long long time;
int type;
int idx;
bool operator<(const event& other) const {
if (time == other.time)
if (type == other.type)
return idx > other.idx;
else
return type > other.type;
return time > other.time;
}
};
int N;
long long P;
lo... | 15 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<vector<int> > g(n);
vector<int> degree(n);
for (int i = 0, u, v; i < n - 1; i++) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
int main() {
scanf("%d", &n);
if (n & 1) {
printf("0\n");
return 0;
}
ans = n / 2 / 2;
if (n % 4 == 0) ans--;
printf("%d\n", ans);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[300000 + 5];
struct node {
int ans, za, ya, zl, yl, len;
long long z, y, tag;
};
struct Seg {
node s[300000 * 4 + 5];
node upd(node x, node y) {
node k;
k.len = x.len + y.len;
k.z = x.z;
k.y = y.y;
k.zl = x.zl;
if (x.zl == x.len &... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 5 == 0) {
cout << n / 5;
} else {
cout << (n / 5) + 1;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)2 * 1e9;
const int MOD = (int)1e9 + 7;
const int MAX_N = 100000;
const long double pi = 3.1415926;
const long double eps = 1e-6;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, cnt = 0, p;
cin >> n;
for (int i = 0; i < n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long int n, k, p[100001], c[256];
int main() {
for (int i = 0; i < 256; ++i) c[i] = -1;
scanf("%ld %ld", &n, &k);
for (long int i = 0; i < n; ++i) scanf("%ld", p + i);
for (long int i = 0; i < n; ++i) {
if (c[p[i]] == -1) {
long int st = max(0L, p[i] - k +... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int NMAX = 1e5 + 5;
int n, m;
long long dp[NMAX];
int main() {
int i;
cin >> n >> m;
if (n > m) swap(n, m);
dp[0] = 2;
for (i = 0; i <= m; i++) {
dp[i + 1] = (dp[i] + dp[i + 1]) % mod;
dp[i + 2] = (dp[i] + dp[i + 2]) % mod;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int z = 998244353;
void zf(string &s, int z[]) {
z[0] = s.length();
int l = 0, r = 0;
for (int i = 1; i < s.length(); i++) {
if (i > r) {
l = r = i;
while (r < s.length() && s[r - l] == s[r]) {
r++;
}
z[i] = r - l;
r--;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 100005;
int x;
int n, d, a[maxn], b[maxn], c[maxn], to[maxn], one[maxn];
int getNextX() {
x = (x * 37LL + 10007) % 1000000007;
return x;
}
void initAB() {
int i;
for (i = 0; i < n; i = i + 1) {
a[i] = i + 1;
}
for (i = 0... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXL = 1000010;
char s[MAXL], s2[MAXL];
int dp[MAXL], k, d;
int ord[MAXL], pre[MAXL][21];
bool vis[MAXL];
void dfs(int q) {
if (dp[q] != -1) return;
dp[q] = MAXL;
dfs(ord[q] - 1);
if (dp[ord[q] - 1] != MAXL) dp[q] = dp[ord[q] - 1] + 1;
}
int tmpL[MAXL];
vo... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
{
int foot = n / 36, inch = 0;
if (n % 36 != 0 && n % 36 != 35) {
n -= 36 * (n / 36);
inch = n / 3;
if (n % 3 == 2) {
inch++;
}
} else {
if (n % 36 == 35) {
foot++;
}
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int const M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, max = 0;
cin >> n;
string s, t, z;
cin >> s;
for (long long i = 0; i < n - 1; i++) {
t = s[i];
t += s[i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int a[n + 4];
int c1 = 0;
int c2 = 0;
for (int i = 0; i < n; i++) {
a[i] = s[i];
if (s[i] == '<') {
c1++;
}
if (s[i] == '>') {
c2++;
}
}
a[n] = s[0];
bool cyc = false;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, val, dp[2000005], pp[2000005];
string s, a[2000005], b[2000005];
long long rec(long long x) {
if (x >= n) return 1;
if (dp[x] != -1) return dp[x];
long long j, i, f, k, ans = 0, vv;
for (j = 0; j < m; j++) {
k = a[j].size();
f = k;
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node {
int lastIndex;
string s;
};
string s;
priority_queue<node> q;
int k;
bool operator<(node x, node y) {
if (x.s == y.s) return s[x.lastIndex + 1] > s[y.lastIndex + 1];
return x.s > y.s;
}
int main() {
int i;
while (cin >> s) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 2e3 + 10;
const long long MX5 = 2e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
return (... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool getmin(T& a, const T& b) {
return b < a ? (a = b, true) : false;
}
const double INF = (1 << 30);
const double eps = 1e-9;
const unsigned long long base = 4;
inline int dcmp(const double& x) {
return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:2759095000")
using namespace std;
const long long MOD = 998244353;
const long long MOD1 = 7340033;
const long long BAS = 2500;
const long long dy[] = {1, -1, 0, 0};
const long long dx[] = {0, 0, 1... | 18 |
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, pair<long long, long long> > &a,
const pair<long long, pair<long long, long long> > &b) {
if (a.first == b.first)
return (a.second.second < b.second.second);
else
return (a.first < b.first);
}
int main() {
lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, f, a1, a2, a3, m;
cin >> t;
while (t--) {
cin >> n;
long long int a[n];
map<long long int, long long int> mp;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]] = i;
}
long long int res[n]... | 1 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
long long ans = 0;
for (long long i = 0; i <= min(a, d); i++) {
long long tmp = i * e + min({(d - i), b, c}) * f;
ans ... | 0 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
const int BASE = 31;
const int ha = 1e9 + 7;
unsigned long long sm[MAXN], pw[MAXN];
char str[MAXN];
int n, m;
inline unsigned long long calc(int l, int r) {
return sm[r] - sm[l - 1] * pw[r - l + 1];
}
int f[MAXN], g[MAXN], h[MAXN];
char S[MAXN], T[MAXN];
unsigned lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, vector<long long int>> v;
map<long long int, bool> vis;
void dfs(long long int x, map<long long int, vector<long long int>>& v,
map<long long int, bool>& vis) {
if (vis[x] == 0) {
cout << x << " ";
vis[x] = 1;
}
for (long long int i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] != 'b') {
s = s.substr(i);
break;
}
}
long long ans = 0, counter = 1;
for (int i = 0; i < s.length(); i++) {
if (s[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n;
int a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> n;
string s;
vector<int> pos;
vector<int> neg;
int good = 0;
for (int i = 0; i < n; ++i) {
cin >> s;
int b = 0;
int min_b = 0;
for (char c : s)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i < n; i++) {
for (int j = i; j < n; j++) {
int x = i ^ j;
if (x < j || x > n || i + j <= x) continue;
ans++;
}
}
cout << ans << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long x, y;
cin >> x >> y;
vector<long long> v;
v.push_back(1);
for (long long i = 0; i < 31; i++) {
v.push_back(v[v.size() - 1] * 2);
}
long long a, b;
long long clx, cly;
a =... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long x;
cin >> x;
vector<long long> ans;
int count = 0;
while (1) {
long long k = (int)(log2(x)) + 1;
long long m = 1 << k;
m--;
x = x ^ m;
count++;
ans.push_bac... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_SIZE = 1000130;
const long long MOD = 1e9 + 7;
long long maxp[MAX_SIZE - 5];
long long bin_pow(long long a, long long n) {
if (n == 0) return 1;
if (n == 1) return a % MOD;
long long pw = bin_pow(a, n / 2);
if (n % 2 == 0) return (pw * pw) % MOD;... | 12 |
#include <bits/stdc++.h>
int n, i, flg, k, ans, a[1011];
int main() {
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
while (1) {
flg = 1;
for (i = 2; i <= n; ++i)
if (a[i] >= a[1]) flg = 0;
if (flg) break;
k = 2;
for (i = 3; i <= n; ++i)
if (a[i] > a[k]) k = i;
+... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], dp[200005], vis[200005];
std::vector<int> v[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
dp[i] = n;
vis[i] = 0;
if (i - a[i] >= 0) v[i - a[i]... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long d[3000010], vis[3000010], n, m, k;
queue<int> q;
struct node {
long long x, y;
} p[3000010];
long long SPFA() {
for (int i = 1; i <= k; i++) d[i] = 1e18, vis[i] = 0;
while (!q.empty()) q.pop();
q.push(1), vis[1] = 1, d[1] = 0;
while (!q.empty()) {
in... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int d[N][2 * N], ok[N][2 * N], det[2 * N];
int n, m, l, k, x, y, t, w;
int main() {
cin >> t;
while (t--) {
cin >> n >> k >> l;
memset(d, 0, sizeof(d));
memset(ok, 0, sizeof(ok));
for (int i = 0; i < 2 * k; i++) ok[0][i] = 1;
for (... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MAXN = 200005;
vector<int> add[MAXN], rem[MAXN], ret;
set<pii> G;
int n, k, r[MAXN], l[MAXN];
bool visted[MAXN];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
while (cin >> n >> k) {
ret.clear();
G.... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 3;
const int maxm = 1e6 + 3;
const int mod = 1e9 + 7;
const int oo = 1e9 + 5;
const long double pi = 3.141592653589793238462643383279502884;
void input() {
if (fopen("abc"
".inp",
"r")) {
freopen(
"abc"
".... | 13 |
#include <bits/stdc++.h>
const int M = 1000000007;
long long n, i, j, ans = 1, f[10002][60], inv[60];
int k;
long long d(long long i, long long j) {
int u, v, w;
long long Ans = 0, x;
for (u = 0; u <= k; u++)
for (v = 0; v <= j; v++) f[u][v] = 0;
f[0][j] = 1;
for (u = 0; u < k; u++)
for (v = 0; v <= j... | 14 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "Ofast"
int n, pointer, ans = 0;
vector<int> kangaroos;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
kangaroos.resize(n);
for (int i = 0; i < n; i++) cin >> kangaroos[i];
sort(kangaroos.begin(), kanga... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool sortfn(string a, string b) {
int la = a.size(), lb = b.size();
for (int i = 0; i < la && i < lb; i++) {
if (a[i] != b[i]) {
return a[i] < b[i];
}
}
if (la == lb) return false;
if (la < lb) {
int i = la, j = 0;
while (i < lb && b[i] == a[... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T, size_t N>
int SIZE(const T (&t)[N]) {
return N;
}
template <typename T>
int SIZE(const T &t) {
return t.size();
}
string to_string(const string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[200001];
bool visited[200001] = {false};
long long dp[200001] = {0};
long long c[200001] = {0};
long long a[200001] = {0};
long long zero = 0;
long long dfs(long long s) {
long long result = 0;
if (a[s] == 1)
result++;
else
result--;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n, a[101];
scanf("%d", &n);
int maxn = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
maxn = max(maxn, a[i]);
}
long long ans = 0;
for (int i = 0; i < n; ++i) {
ans += maxn - a[i];
}
printf("%l... | 0 |
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 10, MAXV = 1e6 + 10;
;
int n, ans;
int last[MAXV], tree[MAXV];
inline void upd(int &a, int b) {
a = a + b >= MOD ? a + b - MOD : a + b;
return;
}
inline int lowbit(int x) { return x & (-x); }
inline int query(int x) {
int ans = 0;
fo... | 12 |
#include <bits/stdc++.h>
int pomae() {
size_t n;
scanf("%zu", &n);
std::vector<int> a(n);
for (auto& ai : a) scanf("%d", &ai);
std::sort(a.begin(), a.end());
int x = a.back();
a.pop_back();
int y = a.back();
a.pop_back();
if (a.empty()) return 0;
int m = a.size();
return std::min(m, std::min(x, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mx[] = {1, -1, 0, 0};
const int my[] = {0, 0, 1, -1};
struct RECT {
int upb;
int leb;
int rib;
int dob;
int col;
};
vector<RECT> rectangulos;
int corr[55][55], act = 1, an, al, color[55][55], n, dir = 0, sec = 0, nxt;
bool mrk[55][55];
void exp(int xi, i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
long long s = 0;
int n;
cin >> n;
vector<int> arr(n, 0);
for (int i = 0; i < n; i++) cin >> arr[i], s += arr[i];
if (s & 1) {
cout << "NO" << endl;
return 0;
}
unordered_ma... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = pow(10, 18) + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
int arr[2 * n];
n = 2 * n;
int vv = 0;
if (k == 0) {
for (int i = 0; i < n; i += 1) arr[i] = n - i;
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const double pi = (3.141592653589);
const int N = 2e5 + 10;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed;
cout.precision(10);
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n;... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> arr;
void solve() {
cin >> n;
long long ans = (n / 2) + 1;
cout << ans;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e3 + 10;
int n;
int a[N], sum[N];
bool vis[N / 2][100][100];
int f[N / 2][100][100];
int dfs(int l, int r, bool pos, int k) {
if (r - l + 1 < k) return 0;
int ret;
if (!pos) {
int d = (n - r) - (l - 1);
if (vis[l][d][k]) return f[l][d][k];
v... | 17 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &p) {
in >> p.first >> p.second;
return in;
}
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long n, a;
cin >> n >> a;
vector<long long> d((size_t)n + 2, 0), c((size_t)n + 2, 0),
e((size_t)n + 2, (long long)2e9);
for (long long i = 1; i <= n; i++) {
cin >> d[i] >> c[i];
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long sum = 0, mx = -1e10;
for (long long i = 0; i < n; i++) {
long long num;
cin >> num;
sum += num;
mx = max(num, mx);
}
bool ok = true;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
struct DisjointSetUnion {
using S = std::size_t;
std::unordered_map<T, T> xs;
std::unordered_map<T, S> ws;
DisjointSetUnion() = default;
template <class RandomIt>
DisjointSetUnion(RandomIt ix, RandomIt iy) {
for (auto it = ix; it != iy; ++... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long calc(long long x1, long long y1, long long x2, long long y2) {
long long top = (x1 - x2) * (-y1);
long long bot = (y1 - y2);
if (bot == 0 || top % bot != 0) return -1;
return top / bot + x1;
}
int main() {
vector<pair<int, int> > vec;
int n, m;
cin >... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
long long t;
t = 1;
while (t--) solve();
return 0;
}
void solve() {
long long n, a[105];
char c;
cin >> n;
for (long long i = 1; i <= n; ++i) {
cin >> c;
a[i] = c - '0';
}
lon... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500004;
int a[N], w[N], n, f[22][N];
int fa[22][N];
int mn(int x, int y) { return w[x] < w[y] ? x : y; }
int lg[N], g = -1;
int que(int x, int y) {
if (x < 1) return 1;
int h = lg[y - x + 1];
return mn(f[h][x], f[h][y - (1 << h) + 1]);
}
int main() {
s... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long m, w;
int bi[1000];
int pos = 0;
int main() {
cin >> w >> m;
while (m) {
bi[++pos] = m % w;
m /= w;
}
for (int i = 1; i <= pos; i++) {
if (bi[i] != 1 && bi[i] != w && bi[i] != w - 1 && bi[i] != 0) {
cout << "NO";
return 0;
}
... | 11 |
#include <bits/stdc++.h>
long long s[33], w[33][9][9];
const int p = 1000000007;
void prework(int x) {
memset(w, 0, sizeof(w));
for (int i = 0; i <= 8; i++) w[0][i][0] = 1;
w[0][1][4] = 1;
w[0][2][7] = 1;
w[0][2][8] = 1;
w[0][3][5] = 1;
w[0][3][6] = 1;
w[0][4][1] = 1;
w[0][4][2] = 1;
w[0][5][3] = 1;... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
int k;
vector<int> A;
bool get(long long l, long long r) {
cout << l + 1 << " " << r + 1 << endl;
string s;
cin >> s;
if (s[0] == 'Y') {
if (r == l)
exit(0);
else
return 1;
} else {
return 0;
}
}
int main() {
ios_base::s... | 13 |
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define endl "\n"
const ll mod = 1e9+7;
#define fi first
#define ss second
using ii = pair<ll,ll>;
#define pb push_back
#define mp make_pair
void solve()
{
ll n;cin>>n;
ll a[n];... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long mcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long a, b;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
double eps = 1e-8;
long long mod = 998244353;
const int INF = 0x3f3f3f3f, inf = 0x3f3f3f3f;
const int MAXN = 2e3 + 10;
const int N = 1e3 + 10;
int num[2550], cnt = 0;
int lim[50], lct = 0;
long long f[24][2520][50];
long long n, m;
long long gcd(long long a, long long b) {
... | 17 |
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << (x) << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int maxn=1e6+7,inf=0x3f3f3f3f,mod=1e9+7;
int l[maxn],n;
int k;
struct node
{
int dis,len;
bool operator < (const node &rhs) const
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
string s;
cin >> s;
int f = 0;
for (int i = 0; i < n - p; i++) {
if (s[i] != '.' && i + p < n && s[i + p] != '.') {
if (s[i] != s[i + p]) {
f = 1;
}
} else if (s[i] == '.' || s[i + p] == '.') {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int d[1005][1005];
struct pa {
int x, y;
int len;
} a[1005];
int min1(int a, int b, int c) {
int m = min(a, b);
m = min(m, c);
return m;
}
int main() {
memset(d, 1, sizeof(d));
for (int i = 0; i < 1005; ++i) d[i][i] = 0;
int n, m, l;
cin >> n >> m >> l;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
long long k = 0;
long long a[200000], b[200000];
long long c[200000], d[200000];
vector<pair<long long, long long> > S;
bool ccmp(long long x, long long y) { return c[x] > c[y]; }
struct SegmentTree {
struct nd {
long long l, r;
long lo... | 25 |
#include <bits/stdc++.h>
using namespace std;
void dfs(set<long long> &visited, long long x,
map<long long, set<long long>> &g, bool &ans, long long parent) {
if (g[x].size() != 2) ans = false;
for (auto a : g[x]) {
if (visited.find(a) == visited.end() && a != parent) {
visited.insert(a);
d... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9, mod = 1e9 + 7;
int cnt[N], fact[N], inv[N], dp[N];
int pow2(int a, int m) {
if (m == 0) return 1;
int ret = pow2(a, m >> 1);
ret = 1ll * ret * ret % mod;
if (m & 1) ret = ret * 1ll * a % mod;
return ret;
}
void preprocess() {
fact[0] = 1;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int com[105][105];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
com[j][i] = co... | 8 |
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include ... | 8 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> q;
inline long long read() {
char c = getchar();
long long x = 0, f = 1;
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') {
f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + c - '0';
c =... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 105;
string arr[MAX];
int n, m;
int mark[MAX];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
mark[i] = 0;
}
long long po... | 13 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
long long le;
long long ri;
long long ans;
} Struct;
long long n, m, l, r, idx, L, R, val, dist[200001], h[200001], pref[200001];
Struct st, SegTree[800001];
void upd(long long low, long long high, long long pos) {
if (idx < low || idx > high) retur... | 15 |
#include <bits/stdc++.h>
using namespace std;
string s;
string gg[10010];
int dxx[100010];
int dyy[100010];
int n, m;
int xxx[] = {0, -1, 1, 0};
int yyy[] = {-1, 0, 0, 1};
int stx;
int sty;
int cnt;
int check(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
int ok(int x, int y) {
int a = x;
int b = y;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long MAX = 100010LL;
template <typename T>
T power(T x, T y, long long m = MOD) {
T ans = 1;
x %= m;
while (y > 0) {
if (y & 1LL) ans = (ans * x) % m;
y >>= 1LL;
x = (x * x) % m;
}
return ans % m;
}
long l... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long mxn = 1e5 + 7;
const long long inf = 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
long long i, j, k, a, b, c, d, n, m, t, u, v, w, x, y, z;
long long ans = 0, cnt = 0;
map<long l... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
using namespace std;
int n, a[105], ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int j = 1; j <= n; ++j) {
int tmp = 0;
for (int i = j; i <= n; ++i) {
tmp ^= a... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.