solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 5;
vector<pair<long long, pair<long long, long long>>> H;
vector<pair<pair<long long, long long>, long long>> V;
vector<pair<long long, long long>> s[2 * N];
pair<pair<long long, long long>, pair<long long, long long>> a[N];
long long T[2 * N];
lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 50;
int k, n;
string s;
void solve() {
int ans = 0;
cin >> n;
while (n > 0) {
n -= 5;
ans++;
}
cout << ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, x, y, T, ans, big, cas, num, len, an, bn, ans_num, cur;
bool flag;
map<string, int> mp;
vector<int> st[10002];
int vis[10002];
int tmp[10002];
string a, b, rev[10002];
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) st[i].clear();
mp.clear();... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long m = 998244353;
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
long long mod_inverse(long lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1005;
long long C[N][N], tp[N], a[N];
int main() {
int i, j;
for (int i = 0; i < N; i++) C[i][0] = 1;
for (int i = 1; i < N; i++)
for (int j = 1; j < N; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
tp[0] = 1;
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long a[101], n;
long long f(long long s, long long e) {
long long an = 1, ss = a[s] + a[e];
for (long long i = s + 1; i <= e - 1; i++)
if (a[i] >= 0) {
ss += a[i];
an = 0;
}
return ss;
}
vector<long long> ans;
void ff(long long l, long long r,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string g, h, l;
int no = 0, a = 0;
cin >> g >> h >> l;
sort(g.begin(), g.end());
sort(h.begin(), h.end());
sort(l.begin(), l.end());
if (g.size() + h.size() == l.size()) {
for (int i = 0; i < l.size(); i++) {
if (l[i] == '0') continue;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[1013];
int main() {
long long n, cnt = 0;
cin >> n;
for (int i = 0; i < 2 * n; i++) {
cin >> a[i];
}
for (int i = 0; i < 2 * n; i++) {
long long k = i;
if (i + 1 < n && a[i] == a[i + 1]) {
i++;
continue;
}
for (int j = i... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct perem {
long long t = 0, l = 1, p = -1, q = 0;
};
ifstream fin("AAtest.in.txt");
long long n, k, m, c, vas, cc = 1000000;
vector<long long> vv;
string s;
vector<vector<long long>> la;
vector<perem> pr;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.ti... | 16 |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long MAXN = 1e+2 + 7;
const long long MOD = 1e+9 + 7, INF = 0x7f7f7f7f7f7f7f7f;
const int INF... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int n;
int d[100005];
int rem[30];
int main() {
scanf("%s", s);
n = strlen(s);
memset(rem, -1, sizeof(rem));
char bg = 'a' - 1;
int f = 0;
for (int i = 0; i < n; ++i) {
rem[s[i] - 'a'] = i;
if (bg < s[i]) {
bg = s[i], f = i;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 5;
long long int dp[maxn], t[maxn], a, n, kam[maxn], v, m;
int main() {
cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
t[a]++;
}
for (int i = 1; i < maxn; i++) {
for (int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[200001], n, k, i, j;
int main() {
scanf("%d%d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
while (k >= 1 && a[k] == a[k - 1]) k--;
j = 0;
for (i = k + 1; i <= n; i++)
if (a[i] != a[k]) j = 1;
if (!j)
printf("%d\n", k - 1);
else
pri... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int ans = 0;
getline(cin, str);
int len = str.length();
for (int i = 0; i <= len - 1; i++) {
if (isupper(str[i])) {
ans += str[i] - 64;
}
if (islower(str[i])) {
ans -= str[i] - 96;
}
}
cout << ans << endl;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[1001], n, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++)
if (a[i] == 1) sum++;
cout << sum << endl;
for (int i = 1; i < n; i++)
if (a[i + 1] == 1) cout << a[i] << " ";
cout << a[n] << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> ar[200];
int main() {
int n, k, m;
vector<pair<int, int> > res;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> ar[i].first;
ar[i].second = i;
}
sort(ar, ar + n);
m = 0;
for (int i = 0; (i < k) && (ar[n - 1].first - ar[0].first > 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, w, x, v;
long long ans;
pair<double, double> a[N], b[N];
inline int cmp(pair<double, double> x, pair<double, double> y) {
return x.first < y.first || (x.first == y.first && x.second > y.second);
}
void CDQ(int l, int r) {
if (l == r) return;... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
vector<vector<long long> > vars(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
vars[i].pu... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
string s[n];
for (int i = (0); i < (n); i++) {
cin >> s[i];
}
unordered_map<char, int> u;
for (int i = 0; i < n; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 2;
bool np[N];
int p[N], pi[N];
int getprime() {
int cnt = 0;
np[0] = np[1] = true;
pi[0] = pi[1] = 0;
for (int i = 2; i < N; ++i) {
if (!np[i]) p[++cnt] = i;
for (int j = 1; j <= cnt && i * p[j] < N; ++j) {
np[i * p[j]] = true;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
long double success[100001];
long double fac[301];
double choose(int n, int k) {
if (k < 0 || k > n) return 0;
return fac[n] / (fac[k] * fac[n - k]);
}
void solve() {
int n, k, m;
cin >> n >> m >> k;
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = fac[i ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
int oo = 0x3f3f3f3f;
double inf = 1.0 / 0.0;
int main() {
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
while (q--) {
int l, r;
cin >> l >> r;
}
string s = "";
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<tuple<int, int, int>> maxg;
int explore(vector<int> &s, vector<int> &dp, int dec,
vector<tuple<int, int, int>> &g) {
if (dp[dec] != -1) {
return dp[dec];
}
bool flag = true;
int max1 = -1;
int max2 = -1;
int max3 = -1;
for (... | 10 |
#include <bits/stdc++.h>
using db = double;
const int N = 100007;
const db eps = 1e-10, inf = 1e10;
int n, m, fa[N], dep[N], size[N], son[N], top[N], vis[N];
db ans = inf, t, c[N], ed[N];
struct line {
int x, id, o;
db t, c;
} b[N];
db cal(const line& x) { return dep[x.x] + (t - x.t) * c[x.id]; }
int operator<(cons... | 25 |
#include <bits/stdc++.h>
using namespace std;
int jogfol[100001];
int timarr[100001];
int main() {
int aa, tim;
cin >> aa >> tim;
int a[aa + 1];
for (int z = 1; z < aa + 1; z++) {
cin >> a[z];
}
for (int z = 1; z < aa + 1; z++) {
if (a[z] != 0) {
int plas = 0;
timarr[z] = min(z + tim, aa... | 6 |
#include <bits/stdc++.h>
using namespace std;
void task();
int main() {
task();
return 0;
}
const int N = (int)1e5 + 10;
const int MODULO = (int)1e6 + 3;
int sz[20010];
int a[20010][210];
int tans[210];
bool used_nums[210];
int ind[210];
vector<vector<int> > sets;
void task() {
int n;
scanf("%d", &n);
int up ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 1000;
typedef struct P {
int x, y;
P(int x, int y) : x(x), y(y) {}
P() {}
} P;
const P operator-(const P &a, const P &b) { return P(a.x - b.x, a.y - b.y); }
const long long... | 21 |
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<pair<long long, long long>> &p, vector<bool> &vis, long long x,
long long N) {
vis[x] = true;
for (long long i = 0; i < N; i++)
if (!vis[i] && (p[i].first == p[x].first || p[i].second == p[x].second))
dfs(p, vis, i, N);
}
int32_t main(... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MN = 211;
long long m, n, k;
long long p[MN][MN], priority[MN];
pair<long long, long long> order[MN];
char res[MN];
long long f[MN][MN];
const long long INF = 1000111000111000111LL;
long long solve() {
memset(f, 0, sizeof f);
f[0][0] = 1;
for (long lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool customS(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
if (a.second == b.second) return a.first < b.first;
return a.second < b.second;
}
bool customS2(vector<int> a, vector<int> b) {
int t1 = a.size(), t2 = b.size();
return t1 < t2;
}
class CompareDist {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, num, Father[100000 + 5], res[100000 + 5], b[100000 + 5],
d[100000 + 5], Trace[100000 + 5];
pair<int, int> e[100000 + 5];
vector<int> t[1000000 + 5], tmp, c[100000 + 5];
map<pair<int, int>, vector<int> > my_map;
void Init();
void Process();
int main() {
Init(... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
double check(double mid) {
double ans = 0.0;
double x = 0.0, y = 0.0;
double hamada = 0.0;
for (int i = 0; i < n; i++) {
hamada += a[i] - mid;
x = max(x, hamada);
if (hamada < 0) hamada = 0.0;
ans = max(ans, (x, hamada));
}
... | 12 |
#include <bits/stdc++.h>
struct myc {
int x, y, a, b;
};
std::deque<bool> m[305][305];
std::vector<myc> sol[2];
char s[100009];
int nrlin, nrcol;
int destL[2], destC[2];
inline void baga(int sursaL, int sursaC, int dest0L, int dest0C, int dest1L,
int dest1C, int t) {
destL[0] = dest0L;
destC[0] =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long n = s.length();
long long h = 0;
long long sharp = 0;
long long lastsharp = -1;
for (long long i = 0; i < n; i++) {
if (s[i] == '(') {
h++;
} else if (s[i] == ')') {
h--;
} else if (s[i] == '#'... | 7 |
#include <bits/stdc++.h>
int main() {
char str[10000];
int j = 0;
gets(str);
int len = strlen(str);
for (int i = 0; i < len;) {
int j = 0;
bool read_alpha = false;
bool read_char = false;
while (isalpha(str[i])) {
read_alpha = true;
printf("%c", str[i++]);
if (i >= len) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int cnt, sum, ans;
bool vis[1000005];
vector<int> e[1000005];
vector<int> v;
void dfs(int x) {
if (vis[x]) return;
vis[x] = 1;
cnt++;
for (int i = 0; i < e[x].size(); i++) dfs(e[x][i]);
}
int main() {
scanf("%d%d%d", &n, &m, &k);
while (m--) {
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) {
if (ch == '-') f = -1;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + ch - 48;
}
return x * f;
}
const int N = 101;
const int S = 26;
char str[N + 3... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
char c[a.length() + 1];
int i = 1;
int k = 0;
c[k++] = a[0];
while (a[i] < b[0] && i < a.length()) {
c[k++] = a[i];
i++;
}
c[k++] = b[0];
c[k] = '\0';
cout << c;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, T2 y) {
if (x < y) x = y;
}
ostream &operator<<(ostream &a, const vector<int> &b) {
for (auto k : b) cout << k << ' ';
... | 19 |
#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T>
void read(T &x) {
x = 0;
int c = getchar();
int flag = 0;
while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int len = str.length();
int arr[len];
memset(arr, 0, sizeof arr);
for (int i = 0; i < str.length(); i++) {
if (i == 0) {
arr[i] = 1;
continue;
}
if (str[i] == str[i - 1])
arr[i] = arr[i - 1] + 1;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, v[300];
bool vis[300][300], F[300];
vector<pair<int, int> > edge;
void print() {
for (int i = 0; i < edge.size(); ++i)
printf("%d %d\n", edge[i].first + 1, edge[i].second + 1);
exit(0);
}
void addEdge(int a, int b) {
if (a > b) swap(a, b);
if (vis[a... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, n, c = 0, d;
int arr[10000];
cin >> x >> n;
for (int i = 0; i < x; i++) {
cin >> arr[i];
if (arr[i] + n <= 5) c++;
}
d = c / 3;
cout << d;
c = 0;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20, MAXB = 1 << MAXN;
int dp[MAXB], a[MAXN][MAXN];
int sum[46], mx[46], mv[46], dx[46];
char s[MAXN][MAXN + 1];
int sz;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", s[i]);
for (int i = 0; i < n; i++)
for ... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<string> names;
int sum = 0;
int main() {
string str;
while (getline(cin, str)) {
if (str[0] == '+')
names.push_back(str);
else if (str[0] == '-') {
str[0] = '+';
for (int i = 0; i < names.size(); i++)
if (names[i] == str) names.e... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
const long long inf = 1e18 + 7;
long long n, mOd;
long long a[N];
int main() {
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
void voi() {
int n, a[205];
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
int g = 0;
bool f = 1;
for (int j = i; j <= n; j++) {
if (a[j] != ++g) {
f = 0;
break;
}
}
for (int j = 1; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool leap(int x) {
if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0)
return true;
else
return false;
}
int main() {
int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, ar[6];
int y1, y2, m1, m2, d1, d2, m1a;
long long days = 0;
scanf("%d:%... | 5 |
#include <bits/stdc++.h>
const int N = 5e6 + 6;
int n, x, a[N], len;
inline int pow(int x, int k, int mod) {
long long res = 1, r = x % mod;
for (; k; k >>= 1, r = r * r % mod)
if (k & 1) res = res * r % mod;
return res;
}
int main() {
scanf("%d%d", &n, &x);
if (n == 1 && x <= 2) {
puts("-1");
ret... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, k, Ti = 0, idx, a, b, t;
bool flag;
string s;
int main() {
cin >> n >> k >> s;
idx = a = b = 0;
for (int i = 0; i < n; i++) {
flag = 1;
for (int j = idx; j < n; j++) {
if (s[j] == 'a')
a++;
else
b++;
t = min(a, b);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 7007;
int n, k[2], moves[2][MXN], cnts[2][MXN];
int dp[2][MXN];
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < 2; i++) {
cin >> k[i];
for (int j = 0; j < k[i]; j++) cin >> moves[i][j];
}
memset(dp, -1, sizeof(d... | 12 |
#include <bits/stdc++.h>
char c;
void consumirInteiro() {
while (c >= '0' && c <= '9') {
printf("%c", c);
c = getchar();
}
}
void consumirDots() {
for (int i = 0; i < 3; i++) c = getchar();
printf("...");
}
int main() {
char space = 0;
c = getchar();
while (c != '\n') {
if (c >= '1' && c <= '9... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct arr {
char c;
int u;
int v;
};
struct arr q[1005];
int main() {
int n, k, i, m = 0, j, t, l = 99999999, p = 0, s = 0;
int a[1005];
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> a[i];
m = max(m, a[i] + (k * (n - i - 1)));
}
for (i = m; i >=... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50000 + 10, MOD = (int)1e9 + 7, MAXLOG = 31;
struct Trie {
int prev, size, son[2], num[MAXLOG];
} t[MAXN * MAXLOG];
int n, m, a[MAXN], I2, Tohka, tot = 1;
int Pow(int a, int b) {
int d = 1;
for (; b; d = (b & 1) ? (long long)d * a % MOD : d,
... | 19 |
#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], b[N];
map<int, int> m;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<char> s(n, '\0');
for (int... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int sub(int x, int y, int p) {
x -= y;
return (x < 0) ? (x + p) : x;
}
int mul(int x, int y, int p) { return (ll)x * y % p; }
int get(int x, int k, int p) {
return sub(mul(mul(x, x, p), mul(x, x, p), p), mul(x, k, p), p);
}
unordered_map<int, int... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, q;
scanf("%d%d%d", &n, &b, &q);
int ans1 = 0, ans2 = n * q;
while (n != 1) {
int temp = 1;
while (temp <= n) temp *= 2;
temp /= 2;
ans1 += 2 * b * (temp / 2) + (temp / 2);
n = n - temp + temp / 2;
}
printf("%d %d\n", an... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool isprim(int n) {
if (n == 2) return 1;
if (n % 2 == 0 || n < 2) return 0;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0) return 0;
return 1;
}
int main() {
vector<int> myvec;
int n, counter = 0;
cin >> n;
for (int i = 2; i <= n; i++)
if (isp... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
bool check(string a, string b) {
if (a.size() < b.size()) return false;
int start1 = 0, start2 = 0;
while (1) {
if (start2 == b.size()) return true;
if (start1 == a.size()) return false;
if (a[start1] == b[start2]) {
star... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if (x > 0 && y > 0) cout << "0 " << x + y << " " << x + y << " 0";
if (x < 0 && y > 0) cout << x - y << " 0 0 " << y - x;
if (x > 0 && y < 0) cout << "0 " << y - x << " " << x - y << " 0";
if (x < 0 && y < 0) cout << x + y <... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int a = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) a = a * 10 + (ch ^ 48), ch = getchar();
return a * f;
}
int n, q, num[100009], tr[100009], a[100009], dp[100009],... | 17 |
#include <bits/stdc++.h>
int main() {
int a, b, x1, x2, y1, y2;
int s, a1, b1;
while (scanf("%d%d", &a, &b) != EOF) {
if (a < 0) {
a1 = -a;
} else
a1 = a;
if (b < 0) {
b1 = -b;
} else
b1 = b;
s = a1 + b1;
if (a >= 0 && b >= 0) {
x1 = 0;
y1 = s;
x2 ... | 2 |
#include <bits/stdc++.h>
const int N = 1e5;
struct Node {
long long l, r;
mutable bool v;
Node(long long _l, long long _r = 0, bool _v = 0) : l(_l), r(_r), v(_v) {}
};
inline bool operator<(const Node& x, const Node& y) { return x.l < y.l; }
std::set<Node> s;
long long n;
inline void read(long long& x) {
x = 0;... | 15 |
#include <bits/stdc++.h>
struct solver {
int mod, inv_10_mod_mod;
int64_t ans;
struct edge {
int node, digit;
bool constexpr operator==(edge e) const { return node == e.node; }
};
struct edge_hash {
size_t operator()(edge e) const { return e.node; }
};
std::vector<std::unordered_set<edge, edge... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline long long read();
const int N = 1e5 + 2;
int n, tp, t[N];
long long x[N], sum;
queue<int> c[62];
void Work() {
n = read();
for (int i = 1; i <= n; ++i) {
x[i] = read();
sum ^= x[i];
for (int j = 60; j >= 0; --j)
if ((x[i] >> j) & 1) {
c[... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, a[10000], b[10000], ans;
int main(int argc, char const *argv[]) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = 1; j <= n; j++) {
if (a[i] == a[j] && b[i] > b[j]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char arr[1001];
int main() {
int i, odd = 0, hash[26] = {0};
scanf("%s", arr);
for (i = 0; i < strlen(arr); i++) hash[arr[i] - 'a']++;
for (i = 0; i < 26; i++)
if (hash[i] % 2 != 0) odd++;
if (odd <= 1)
printf("%s", "First");
else {
if (odd % 2 != 0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
long long p, pos1, pos2, q, x, l, ans = 0, r, y, z, k, n, m, t, d, c = 0;
vector<int> f;
long long int mn = 0x3f3f3f3f, len, cnt = 1, mx = -1000;
int main() {
cin >> n >> m;
cin >> x;
vector<long long int>::iterator it1, it2;
vector<long long... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool isLeap(T y) {
return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);
}
template <class T>
inline T gcd(T a, T b) {
return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
return ((a) / gcd((a), (b))... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pr(vector<T> &v) {
for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " ";
cout << '\n';
;
}
template <typename T>
void pr(vector<vector<T>> &v) {
for (int i = 0; i < (int)(v).size(); i++) {
pr(v[i]);
}
}
template <typename T>... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(nam... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
vector<int> G[N], son[N];
int n, m, h[N], a[N], v[N];
set<pair<int, int> > st;
void dfs(int u, int fa) {
v[u] = h[u];
if (u ^ fa) v[u] = min(v[u], v[fa]);
st.insert(make_pair(h[u], u));
set<pair<int, int> >::iterator A, B = st.begin();
A = B;... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int vis[1000001];
int top = 0;
int v[1000001];
int anss[1000001];
int rnd() {
static int KEY = 12345678;
return KEY += KEY << 2 | 1;
}
struct Treap {
struct node {
pair<int, pair<int, int> > val;
int key, size;
node *c[2];
node(pair<int, pair... | 14 |
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int32_t main() {
unsigned long long n, l, r;
cin >> n >> l >> r;
l -= 1;
r -= 1;
vector<unsigned long long> a(n);
vector<unsigned long long> b(n);
for (unsigned long long i = 0; i < n; i++) cin >> a[i];
for (unsigned long long i = 0;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110000;
const int MAXS = 256;
int n;
char a[MAXN];
int sa[MAXN], rnk[2 * MAXN], rnk1[2 * MAXN];
int st[MAXS], cnt[MAXN], tmp[MAXN];
int height[MAXN], top;
struct Node {
int id, val;
Node(int i = 0, int v = 0) : id(i), val(v) {}
} sta[MAXN];
int main() {... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline string toString(long long x) {
string ans = "";
bool negtive = x < 0;
x = abs(x);
while (x) ans.push_back(x % 10 + '0'), x /= 10;
if (ans.size() == 0) ans = "0";
if (negtive) ans.push_back('-');
for (long long i = 0; i < ans.size() / 2; i++)
swap(an... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, i, cnt = 0;
scanf("%d%d", &n, &h);
int a[n];
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < n; i++) {
if (a[i] > h) {
cnt += 2;
} else
cnt++;
}
printf("%d\n", cnt);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 1e6 + 5;
long long len[nax], allow[nax];
vector<long long> w;
long long ans = 0;
const int magic = 100 * 1000;
int main() {
int n;
long long R;
scanf("%d%lld", &n, &R);
for (int i = 0; i < n; ++i) scanf("%lld", &len[i]);
for (int i = 0; i < n; ++i)... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
vector<vector<long... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long i, k, n, x, p;
while (cin >> n) {
string s;
cin >> s;
p = 0;
for (i = 0; i < n; i++) {
if (s[i] == '<')
p++;
else
break;
}
for (i = n - 1; i >= 0; i--) {
if (s[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 2000 + 10;
const long long IM = 1e15 + 37;
const long double PI = 3.1415926535897932384;
inline void PP(long long n) { cout << n << " "; }
void PV(vector<long long> v) {
for (long long i = 0; i < v.size(); i++) cout << v[i]... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, x, t = 0, ans = 0;
cin >> n;
vector<int> v;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
for (i = 0; i < v.size(); i++) {
if (v[i] >= t) {
ans++;
t += v[i];
}
}
cout << a... | 5 |
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#inc... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long n;
cin >> n;
long long g = 1;
while (n) {
if (n == 3) {
cout << g << ' ' << g << ' ' << (g << 1) + g;
n = 0;
}
long long m = n >> 1;
for (long long j = 0; j < n - m; j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool prime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
if (prime(n)) {
cout << "1\n";
} else if (n % 2 == 0 || prime(n -... | 8 |
#include <bits/stdc++.h>
int n, i, j, Len;
char Str[200], Std[200];
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", Str);
if (i) {
for (j = 0; j < Len; j++)
if (Str[j] != Std[j]) break;
Len = j;
} else {
Len = strlen(Str);
strcpy(Std, Str);
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int INF = numeric_limits<int>::max();
int INF2 = numeric_limits<long long>::max();
int n, m, k;
int b[105][105];
int a1[105], a2[105];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) cin >> b[i][j];
int res = INF, temp, tem... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int main() {
int n, a, b;
cin >> n >> a >> b;
int cur = 1;
if (a > b) swap(a, b);
for (int i = 0; i <= n / a; i++) {
if ((n - a * i) % b == 0) {
while (i--) {
int mod = cur;
while (cur < mod + a) ans.push_back((cur++ - mo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int m, i, n, k, a[250];
int main() {
scanf("%d%d", &n, &k);
m = 2 * n + 1;
for (i = 1; i <= m; ++i) scanf("%d", &a[i]);
for (int j = 1; j <= n; ++j) {
i = j * 2;
if (a[i] - a[i - 1] > 1 && a[i] - a[i + 1] > 1 && k) --a[i], --k;
}
for (int i = 1; i < m; +... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100001];
int dp[100001];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = n; i >= 1; i--) dp[arr[i]] = 1 + dp[arr[i] + 1];
int resultat = n + 1;
for (int i = 0; i <= n; ++i)
resultat = min(resultat, i + (n - i - dp... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
out << "(" << obj.first << "," << obj.second << ")";
return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
typename map<T, T1>::cons... | 9 |
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)
#define For(i, l, r) for(int i = (l), i##e = (r); i < i##e; i++)
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, K, a[N];
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, coup = 0;
long long mat[21] = {0};
cin >> n;
int res[n];
for (int i = 0; i < n; i++) {
cin >> res[i];
mat[res[i] + 10]++;
}
for (int i = 0; i < 10; i++) coup = coup + mat[i] * mat[20 - i];
for (int i = 0; i < mat[10]; i++) c... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int a[200005];
vector<long long int> v;
int main() {
long long int n, d = 0, k = 0, l, mid, c = 0, x = 0, i = 0, m, f = 0, j = 0,
j1, sum = 0, s = 0, mx = 100000000000000000;
cin >> n;
m = n;
for (i = 1; i < m; i++) {
d = log2(n - i)... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int setBit(int num, int idx, int value = 1) {
return (value) ? (num | (1 << idx)) : (num & ~(1 << idx));
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int cntBits(int num) {
int ret = 0;
while (num) {
if (num % 2) ret+... | 4 |
#include <bits/stdc++.h>
const int MAXL = 2000000;
const int AUX_SIZE = 10;
struct Trie {
int cover[MAXL], ch[MAXL][AUX_SIZE];
int cnt;
inline int idx(const char c) { return c - '0'; }
inline void insert(const char* s) {
int cur = 0;
for (int i = 0; s[i]; i++) {
int t = idx(s[i]);
if (ch[cur... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a, ans, t, in[1000005];
char c;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c >> a;
if (c == '+')
in[a]++, t++;
else {
if (in[a] == 0)
ans++;
else
in[a] = 0, t--;
}
if (ans < t) ans = t;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int g;
multimap<float, int> m;
multimap<float, int>::iterator it;
int i;
int stat = 0;
int temp;
double f;
int n;
int a[1001][3];
int s;
cin >> n;
cin >> s;
for (i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<string> explr;
string dest;
bool solve(string cur) {
if (cur == dest) return true;
if (explr.count(cur)) return false;
explr.insert(cur);
int xrow, xcol;
for (int i = 0; i < 4; i++)
if (cur[i] == 'X') {
xrow = i / 2;
xcol = i % 2;
}
strin... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.