solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;
pair<long long int, long long int> songs[20];
int dp[40000][250][5];
int n, T;
long long int cnt(int usedBM, int timeTaken, int lastGenre) {
if (timeTaken > T) {
return 0;
}
if (timeTaken == T) {
return 1;
}
long long int ans ... | 13 |
#include <bits/stdc++.h>
using namespace std;
map<string, set<string> > map1;
long long int i = 0, j = 0;
bool issuffix(string x, string y) {
if (x.size() >= y.size()) return 0;
i = x.size() - 1;
j = y.size() - 1;
while (i >= 0) {
if (x[i] != y[j]) return 0;
i--;
j--;
}
return 1;
}
int main() {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300, MOD = 777777777;
const int Tohka[] = {
507720408, 412133651, 386543325, 139952108, 289303402, 102404925, 317067177,
396414708, 80515854, 663739304, 317300809, 228877044, 493725043, 715317967,
490300965, 315527373, 743539734, 488329191, 553... | 19 |
#include<bits/stdc++.h>
using namespace std;
//======================
//
// Template OleschY
//
// Die M�glichkeiten der deutschen Grammatik k�nnen
// einen, wenn man sich darauf, was man ruhig, wenn
// man m�chte, sollte, einl�sst, �berraschen.
// - @Gedankenbalsam
//
//======================
template <typename T>
o... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
unordered_map<int, int> f;
for (int i = 0; i < n; ++i) {
int a;
scanf("%d", &a);
f[a]++;
}
int ans = 0;
for (auto p : f) {
ans = max(ans, min... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class heap : public priority_queue<T, vector<T>, greater<T> > {};
const int n = 200047;
int l[n];
int main(void) {
int d, n, m;
scanf("%d%d%d", &d, &n, &m);
vector<pair<int, int> > g;
for (int i = 0; i < m; ++i) {
int a, b;
scanf("%d%d"... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int w1, w2, h1, h2;
cin >> w1 >> h1 >> w2 >> h2;
cout << (w1 + h1 + h2) * 2 + 4 << '\n';
;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
solve();
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct ww {
int x, y, id;
} a[600010];
struct tree {
int l, r, s;
long long sum;
} tr[600010 * 4];
int i, j, k, n, m, id, nn, R, K;
int ans[600010], zhi[600010], li[600010];
long long s, an;
inline bool cc1(const ww &a, const ww &b) { return a.y < b.y; }
inline void u... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
if (P == 0) return 1;
if (P & 1)
return B * POW(B, P - 1);
else
return SQR(POW(B, P / 2));
}
template <class T>
inline T BMOD(T p, T e, T m) {
T ret = 1;
while (e) {
if (e & 1) ret = (ret * p) % m;
p =... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int v[200009];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", v + i);
multiset<int> s;
multiset<int>::iterator it1, it2;
for (int i = 1, a; i <= n; i++) scanf("%d", &a), s.insert(a);
for (int i = 1; i <= n; i++) {
it1 = s.lower... | 9 |
#include <bits/stdc++.h>
using namespace std;
int64_t MOD;
inline void normal(int64_t &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline int64_t modMul(int64_t a, int64_t b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline int64_t modAdd(int64_t a, int64_t b) {
a %= MOD, b %= MOD;
n... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T1, typename T2>
inline void chkmin(T1 &x, const T2 &y) {
if (y < x) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, const T2 &y) {
if (x < y) x = y;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmax(T &_a, T _b) {
if (_b > _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
bool setmin(T &_a, T _b) {
if (_b < _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
T gcd(T _a, T _b) {
ret... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n;
cin >> d;
string a;
cin >> a;
int curr = 0;
int flag = 1;
int jumps = 0;
int i;
for (; true;) {
if (flag == 1) {
i = curr + d;
if (i > n - 1) i = n - 1;
flag = 0;
}
if (i == curr) {
jum... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e2;
int n, m;
vector<int> a, b;
void Assert(const int& value, const int& lowerBound, const int& upperBound) {
assert(lowerBound <= value && value <= upperBound);
}
int main() {
scanf("%d%d", &n, &m);
a.resize(n);
for (int i = 0; i < n; ++i) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
const long long I = 1e18;
int n;
long long s, a[N], l = -1, r = I, c;
bool C(long long k) {
c = 0;
for (int i = 0; i < n; i++)
if (a[i] > k) c += a[i] - k;
return c >= s;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> a[i];... | 4 |
#include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template <typename T, typename... Args>
void DBG(T first, Args... args) {
cerr << first;
if (sizeof...(args)) cerr << ", ";
DBG(args...);
}
void solve() {
long long n;
cin >> n;
string a[n];
map<string, long long> m;
long long e... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<string, bool> was;
string s;
int ans;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
char last = s[s.size() - 1];
if (!was[s]) ans++, was[s] = 1;
s.erase(s.size() - 1, 1);
s = last + s;
}
cout << ans;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2, class T3 = hash<T1>>
using umap = unordered_map<T1, T2, T3>;
template <class T>
using uset = unordered_set<T>;
template <class T>
using vec = vector<T>;
const long long infll = numeric_limits<long long>::max() >> 1;
const long long inf = numeri... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
int j = 0;
for (int i = 0; i < n; i++) {
if (arr[j] < arr[i]) {
j++;
}
}
cout << j;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 6;
vector<int> g[MAX];
int now, n;
int tin[MAX], tout[MAX], vis[MAX], lv[MAX], a[MAX];
void dfs(int u, int h) {
vis[u] = 1;
lv[u] = h;
tin[u] = ++now;
for (int x : g[u]) {
if (!vis[x]) dfs(x, h + 1);
}
tout[u] = now;
}
int bit[MAX];
voi... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int maxN = 4221;
const int maxM = 15000;
int n, n1, n2, m;
int in[maxN];
vector<int> ans[maxM];
class Graph {
private:
int cnt;
int Head[maxN];
int Next[maxM];
int W[maxM];
int V[maxM];
int Depth[maxN];
int cur[maxN];
public:
in... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005], h[100005];
int N, M, K;
long long P;
int day[5003];
int t[100005];
bool check(long long X) {
for (int i = 0; i < M; ++i) {
day[i] = 0;
}
long long sum = 0;
for (int i = 0; i < N; ++i) {
long long T = max(0LL, (h[i] + a[i] * M - X) / P +
... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long n, ar[100005], mr[100005], pr[100005], sr[100005], dr[100005];
vector<long long> vr[100005];
void dfs(long long), func(long long, long long);
vector<long long> ans;
bool comp(long long a, long long b) {
if (dr[a] == dr[b]) return a < b;
return dr[a] < dr[b];
}... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 600000;
int n, a[2200];
int Find(int x) {
for (int i = 1; i <= n; i++)
if (a[i] == x) return i;
}
void solve() {
cin >> n;
bool ok = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] % 2 != i % 2) {
ok = 0;
}
}
if ... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, p;
cin >> n >> p;
if (p == 0) {
cout << __builtin_popcountll(n) << '\n';
return 0;
}
for (int i = 1;; ++i) {
ll rem = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, h, w, tp[N], pos[N], t[N], x[N];
vector<int> vx[N], vy[N];
pair<int, int> ans[N];
bool cmp(int x, int y) { return pos[x] < pos[y]; }
int main() {
scanf("%d%d%d", &n, &w, &h);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", &tp[i], &pos[... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
map<long long int, long long int> m;
string s;
bool check(long long int mid) {
long long int i, j;
long long int sum = 0;
for (auto it = m.begin(); it != m.end(); it++) {
sum = sum + ceil((it->second) * 1.00 / mid);
}
if (sum <= n) return 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Data {
long long st, dr, val;
bool operator<(const Data& other) const { return st < other.st; }
} v[100005];
set<Data> s;
struct Sort {
long long nr, val;
bool operator<(const Sort& other) const { return val < other.val; }
} v1[100005];
long long seed;
long l... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[10004][2];
int main() {
int i, j;
int n, m;
while (cin >> n >> m) {
int flag = 0;
memset(a, 0, sizeof(a));
for (i = 0; i < m; i++) {
int k;
cin >> k;
int ans = 0, cnt = 0;
memset(a, 0, sizeof(a));
for (j = 0; j < k; j++)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int fg[11];
int fg2[11];
int er[11][11];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> te;
for (int i = 0; i < n; i++) {
char a;
cin >> a;
int b = a - '0';
te.push_back(b);
fg[b]++;
fg2... | 11 |
#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int n;
static int count[101];
int i, max = 1;
scanf("%d", &n);
while (n--) {
scanf("%d", &i);
count[i]++;
if (count[i] > max) max = count[i];
}
printf("%d\n", max);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long expo_pow(long long x, long long y) {
if (y == 0) return 1;
y = y % (mod - 1);
x %= mod;
if (y == 0) y = mod - 1;
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
x = (x * x) % mod;
y >>= 1;
}... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > V;
long long myB, myW;
bool myCmp(const pair<long long, long long>& a,
const pair<long long, long long>& b) {
return a.second > b.second;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
long lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long i, j, t = 1;
while (t--) {
long long a[14];
for (i = 0; i < 14; i++) cin >> a[i];
long long b[14];
for (i = 0; i < 14; i++) b[i] = a[i];
long long ans = 0;
for (i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int cnt[26];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long sum = 0;
for (int i = 0; i < n; i++) {
long long t;
cin >> t;
if (t & 1) {
cout << "First";
return 0;
}
}
cout << "Second";
return 0;... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
long long t, a, b;
while (~scanf("%I64d%I64d%I64d", &t, &a, &b)) {
if (t == a) {
if (a == b)
puts(t == 1 ? "inf" : "2");
else
puts("0");
} else if (t > a)
puts(a == b ? "1" : "0");
else ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int NN = 100111;
int val[NN << 1], pre[NN << 1], son[NN << 1][4], dp[NN << 1][4];
int TTT, last, len, bit;
long long n;
bool vt[NN << 1];
char s[NN];
void samadd(int x) {
int end = ++TTT, p = last;
last = end;
val[end] = val[p] + 1;
for (; p != -1 && !son[p][x... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int maxm = 22;
const int maxhash = 1048576 + 10;
int a[maxn], w[maxn][maxm], f[maxn][maxm];
int t[maxn][maxm], now[maxm], s[maxm];
bool mark[maxhash];
int n;
void Change(int id, int x) {
int i;
for (i = 0; i != maxm; i++) {
w[id][... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[200003], par[200003];
int main() {
scanf("%d%d", &n, &m);
for (int k = 1; k <= n; k++) scanf("%d", &arr[k]);
par[n] = -1;
for (int k = n - 1; k >= 1; k--) {
if (arr[k + 1] != arr[k])
par[k] = k + 1;
else
par[k] = par[k + 1];
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
const int m = 1000000007;
vector<int> data(N + 1);
vector<long long> d(N + 1);
for (int i = 0; i < N; ++i) {
cin >> data[i];
data[i]--;
}
for (int i = 0; i < N; ++i) {
d[i + 1] = (d[i] + 1 + 1 - d[data[i]] + d[i] + m... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 9;
long long fp(int n, int k) {
if (k == 0) return 1;
long long hf = fp(n, k / 2);
return k % 2 ? hf * hf % mod * n % mod : hf * hf % mod;
}
int n, a, b, k;
long long invbda, x;
string str;
int main() {
cin >> n >> a >> b >> k;
getchar()... | 10 |
#include <bits/stdc++.h>
int mod = pow(10, 9) + 7;
using namespace std;
struct ans {
long long a;
vector<long long> b;
};
void fill(long long start, long long end, long long dig, vector<long long>& v) {
for (long long i = start; i < end; ++i) {
v.push_back(v[i] * 10 + 0);
v.push_back(v[i] * 10 + 1);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool chkmax(int &x, int y) { return x < y ? x = y, true : false; }
bool chkmin(int &x, int y) { return x > y ? x = y, true : false; }
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int hm, am, dm;
int hy, ay, dy;
int ch, ca, cd;
int main() {
cin >> hy >> ay >> dy;
cin >> hm >> am >> dm;
cin >> ch >> ca >> cd;
int res = 0x3f3f3f3f;
for (int i = 0; i < 205; i++) {
for (int j = 0; j < 205; j++) {
if (ay + i <= dm) continue;
int ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
int k, length;
char s[1000];
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) {
gets(s);
k = 0;
length = strlen(s);
if (length > 4 && strcmp(s + length - 5, "lala.") == 0) {
k++;
}
if (strstr(s, "miao.") ==... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long pw(long long a) {
long long ans = 1;
if (a == 0) {
return 1;
}
if (a == 1) {
return 2;
}
if (a % 2 == 0) {
return ((pw(a / 2) % 1000003) * (pw(a / 2) % 1000003)) % 1000003;
} else {
return ((2) * (pw(--a) % 1000003)) % 1000003;
}
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
int num2 = n * 2;
int num4 = n;
int num1 = 0;
bool ck = true;
for (int i = 0; i < k; ++i) {
cin >> a[i];
if (a[i] >= 4) {
if (num4 >= a[i] / 4... | 11 |
#include <bits/stdc++.h>
int main() {
double vx, vy;
double px, py, a, b, c, d;
double len, vxn, vyn;
double x[8], y[8];
scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &px, &py, &vx, &vy, &a, &b, &c, &d);
len = sqrt(vx * vx + vy * vy);
vxn = vx / len;
vyn = vy / len;
x[1] = b * vxn + px;
y[1] = b * vyn + py;
x... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3fLL;
int main() {
int n;
cin >> n;
int cont = 0, conta = 0;
string s;
for (int i = 0; i < n; i++) {
cont++;
if (cont < 3) {
s += 'a';
conta++;
} else {
s += 'b';
if (co... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 7;
const int INF = 0x7fffffff;
int r[N], sa[N], rk[N], het[N];
int wa[N], wb[N], wx[N], wv[N];
bool ise(int *r, int a, int b, int len) {
return r[a] == r[b] && r[a + len] == r[b + len];
}
void getSa(int n, int m) {
int *x = wa, *y = wb;
for (int... | 17 |
#include <bits/stdc++.h>
using namespace std;
mt19937 mr(time(0));
struct LL {
static long long int m;
long long int val;
LL(long long int v) { val = reduce(v); };
LL(int v) { val = reduce((long long int)v); };
LL() { val = 0; };
~LL(){};
LL(const LL& l) { val = l.val; };
LL& operator=(int l) {
val ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 1;
long long n, m;
vector<long long> topo, vis;
vector<vector<long long> > adj;
pair<long long, long long> e[N];
void dfs(long long cur) {
vis[cur] = 1;
for (long long i : adj[cur])
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], p[N], q[N];
long long ans;
bool cmp(const int i, const int j) { return a[i] < a[j]; }
long long sqr(long long x) { return x * x; }
void solve(int l, int r) {
if (l == r) return;
int m = l + r >> 1;
solve(l, m), solve(m + 1, r);
*p ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long d = 0;
long long a = 1;
for (int i = 2; i <= n; i++) {
long long old_d = d;
d = (3 * a) % int(pow(10, 9) + 7);
a = (old_d + 2 * a) % int(pow(10, 9) + 7);
}
cout << d << endl;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 100000;
int n, s[N + 1];
long long dp[N + 1], t[N + 1];
bool cmp(int a, int b) { return a > b; }
int work(int a, int b, int h, int w) {
if (h >= a && w >= b) {
return 0;
}
memset(dp, 0, sizeof dp);
if (h > a) h = a;
if (w > b... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long N, ans, a[(long long)3e5 + 3];
int getBit(int mask, int i) { return ((mask >> i) & 1) == 1; }
struct Trie {
Trie *z, *o;
int taken;
int under;
Trie() {
z = NULL, o = NULL;
taken = 0;
under = 0;
}
};
void add(Trie *node, int x) {
node->under... | 10 |
#include <bits/stdc++.h>
using namespace std;
class reb {
public:
reb(int v1, int nn1) {
v = v1;
nn = nn1;
}
int v;
int nn;
};
bool men(reb a, reb b) {
if (a.v < b.v)
return true;
else
return false;
}
int main() {
int otv1[100005];
int otv2[100005];
vector<reb> bl;
vector<reb> wh;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 9;
long long N, A, B, K, s, ans;
char S[100002];
long long mpow(long long x, long long y) {
long long ret = 1;
while (y) {
if (y & 1) ret = (ret * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return ret;
}
long long inv(long long x... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int A = 26;
struct Node {
int next[A];
int go[A];
int qry;
vector<pair<int, int> > qryInBor;
int link, term_link;
bool terminal;
Node() {
for (int c = 0; c < A; ++c) next[c] = go[c] = -1;
qry = -1;
link = term_link = -1;
terminal = false;... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
bool mark[maxn], markp[maxn];
int n, m, k, a, b, kk, l, s, t, d[maxn], ans, p[maxn];
vector<int> gr[maxn];
queue<int> q, qq;
void bfs(int h) {
int v = 0;
while ((int)qq.size() != 0) {
v = qq.front();
qq.pop();
for (int i : gr[v]) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
int l1 = s1.size();
int l2 = s2.size();
int st = 0, ctr = 0;
for (int i = 0; i < l1;) {
string s3 = s1.substr(i, l2);
if (s3 == s2) {
ctr++;
i = i + l2;
} else {
i++;
}
}
cout << ... | 4 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
for (int i = 2; i <= n; i++) printf("%d ", i);
puts("1");
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int cnt[n][6];
memset(cnt, 0, sizeof cnt);
;
for (long long i = (0); i < (n); i++) {
string s;
cin >> s;
for (auto c : s) cnt[i][c - '... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAXN = 2e5 + 7;
int mi[MAXN << 2], lazy[MAXN << 2], n, q;
long long sum[MAXN << 2];
void lazy_prop(int id, int l, int r) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string b;
cin >> b;
int num = 0;
int max0 = 0;
for (int i = 0; i < n; i++) {
if (b[i] == '(')
num++;
else {
num--;
}
max0 = max(max0, num);
}
num = max0 / 2;
int num0 = 0;
for (int i = 0; i < n;... | 7 |
#include <bits/stdc++.h>
using namespace std;
long n, k;
int main() {
scanf("%li %li", &n, &k);
if (k > (n - 1) / 2) {
printf("-1");
return 0;
}
printf("%li\n", n * k);
for (long i = 1; i <= n; i++)
for (long j = 0; j < k; j++) printf("%li %li\n", i, (i + j) % n + 1);
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s[1000];
int n, i, j;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < s[i].length(); j++) {
if (s[i][j] == '?') {
if (s[i][0] == '?' && s[i].length() == 1) {
s[i] = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int check(string st) {
for (int i = 1; i < st.size(); i++) {
if (st[i] == st[i - 1]) return 1;
}
for (int i = 2; i < st.size(); i++) {
if (st[i] == st[i - 2]) return 1;
}
return 0;
}
int ypa(string &st) {
int i;
for (i = st.size() - 1; i > 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, k, sx;
char a[5][105];
bool bfs(int sx) {
queue<pair<int, int> > q;
q.push(pair<int, int>(sx, 1));
while (q.size()) {
int x = q.front().first, y = q.front().second;
q.pop();
if (isalpha(a[x][+... | 9 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
vector<set<int>> v(100005);
void solve() {
int n, l;
cin >> n >> l;
while (l--) {
int x, y;
cin >> x >> y;
m[x]++;
m[y]++;
v[x].insert(y);
v[y].insert(x);
}
bool ok = true;
long long ans = 0;
while (ok) {
ok = false... | 4 |
#include <bits/stdc++.h>
using namespace std;
string firstName[100005], lastName[100005];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> firstName[i] >> lastName[i];
string lastUsed = "";
for (int i = 0; i < n; i++) {
int personId;
cin >> personId;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int level[200000];
int par[200000][25];
vector<int> adj[200000];
int st[200000], _time;
int n;
int lca(int u, int v) {
if (level[u] < level[v]) swap(u, v);
int tmp = 1;
for (; (1 << tmp) <= level[u]; ++tmp)
;
--tmp;
for (int i = tmp; i >= 0; --i) {
if (lev... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, x;
cin >> t;
n = t * 2;
vector<long long int> v;
for (long long int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
int z = 0;
for (long long int i = 1; i < n; i++) {
if (v[i] != v[i -... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.14159265359;
const long long Mod = 1000 * 1000 * 1000 + 7;
const long long MaxN = 1000010;
long long a[MaxN];
int b[MaxN];
int s = 1000000;
int flag = 0;
vector<int> v;
int main() {
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
cin ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m, ans = 0;
cin >> n >> m;
vector<vector<long long int> > a(n, vector<long long int>(m));
vector<long long int> ind(n + 1, 0);
for (long long int i = 0; i < n; i++... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
bool operator<(const P &a) const { return y < a.y; }
};
struct S {
int x;
long long y;
};
P v1[105055], v2[150000];
int a, b, c, n, m, i, o[300100], k, d, e, dy[15] = {0, 0, -1, 1, -1, 1, -1, 1},
dx[15] ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 100;
long long dp[N];
int main() {
long long n, l, k;
while (cin >> n >> l >> k) {
memset(dp, 0, sizeof(dp));
map<int, int> f;
vector<int> vec(n);
vector<pair<int, int> > q;
for (int i = 0; i < (n); ++i) s... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long t, temp, ans[10000000];
int main() {
long long pos(1);
cin >> t;
for (int i = 0; i < t; i++) {
cin >> temp;
long long pres(0), v(1), rep(0);
while (pres <= temp) {
long long n = pow(2, v) - 1;
pres = pres + (n * (n + 1)) / 2;
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) {
int l = i - 1, r = i, ll = 1, rr = 1;
while (s[l] != 'L' && l >= 0) ll += (s[l] == 'R'), --l;
while (s[r] != 'R' &... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans, seen;
vector<vector<int>> x;
int n, m, a, b;
void dfss(int curr) {
seen[curr] = 1;
for (int i : x[curr]) {
if (!seen[i]) {
dfss(i);
}
if (seen[i] == 1) {
cout << -1;
exit(0);
}
}
seen[curr] = 2;
ans.push_back(curr... | 7 |
#include <bits/stdc++.h>
using namespace std;
int muv, i;
int main() {
int N, M, K;
cin >> N >> M >> K;
if (K < M)
M = N;
else
M = 1;
string aux;
cin >> aux;
cin >> aux;
if (aux == "head")
muv = -1;
else
muv = 1;
if (K == N && muv == 1) muv = -1;
if (K == 1 && muv == -1) muv = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, sa, sb, x, y;
int a[100], b[100];
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 * 10 + ch - '0';
ch = getchar();
}
retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long infl = 1LL << 60;
char buf[1000000];
string nextLine() {
scanf("%[^\n]", buf);
scanf("%*c");
return string(buf);
}
string next() {
scanf("%s", buf);
return string(buf);
}
int nextInt() {
int tmp;
scanf("%d", &tmp);
re... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
struct data {
int nt, to;
} a[N << 1];
long long jc[N] = {1}, f[N];
int head[N], cnt = 0;
void add(int x, int y) {
a[++cnt].to = y, a[cnt].nt = head[x], head[x] = cnt;
a[++cnt].to = x, a[cnt].nt = head[y], head[y] = cnt;
}
void... | 11 |
#include <bits/stdc++.h>
using namespace std;
int bitct(long long r) { return r == 0 ? 0 : (bitct(r >> 1) + (r & 1)); }
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
template <typename T>
ostream& operator<<(ostream& o, vector<T> v) {
o << "{";
int i = 0, s = v.size();
for (; i + 1 < s... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[2][2000005];
int len;
int m[2000005][2];
int main() {
scanf("%s", s[0]);
strcpy(s[1], s[0]);
len = strlen(s[0]);
int firstone = len - 1;
while (1) {
if (s[0][firstone] == '1')
break;
else
firstone--;
}
for (int i = 0, _e(firstone); i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int> > > v(100005);
vector<int> set1;
vector<int> set2;
vector<int> ans1;
vector<int> ans2;
int s1, s2;
int visited[100005];
void input() {
int i, j, a, b;
string s;
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
scanf("%d %d... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long LLINF = 1LL << 61;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int f[1 << 24];
int a[55], b[2], na[1 << 24];
int n, k, res;
long long s[1 << 24];
inline void add(int &a, const int &b) {
a += b;
if (a >= MOD) a -= MOD;
}
int main() {
int n;
cin >> n... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const int INF = 1e9 + 9;
int n;
pair<double, double> p;
pair<double, double> a[N];
double mx = -1e18, mn = 1e18;
double dist(pair<double, double> a, pair<double, double> b) {
return sqrt((a.first - b.first) * (a.first - b.first) +
(a.secon... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long n, ans = 0;
cin >> n;
for (int i = 1; i <= n; i *= 10) ans += (n - i + 1);
cout << ans << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
const int mod = 1000000007;
const int N = 500 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
int n, m, cnt, flag;
inline int read() {
register int c = getchar(), fg ... | 13 |
#include<bits/stdc++.h>
using namespace std;
int T,a,b;
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d%d",&a,&b);
if(b==1) {
puts("NO\n");
continue;
}
if(b==2) {
printf("YES\n%lld %lld %lld\n",a*1ll,a*1ll*(2ll*b-1),a*2ll*b);
}
else printf("YES\n%lld %lld %lld\n",a*1ll,a*1ll*(1ll*b-1),a*1ll*b... | 2 |
#include <bits/stdc++.h>
struct xxx {
int x, l, r, t, id;
xxx() {}
xxx(int _x, int _l, int _r, int _t, int _id) {
x = _x;
l = _l;
r = _r;
t = _t;
id = _id;
}
} q[201000 * 10], cur[201000 * 10];
int c[201000], n, a[201000], b[201000], wza[201000], wzb[201000], ans[201000];
void add(int x, int... | 16 |
#include <bits/stdc++.h>
using namespace std;
int stu[501], nxt[200010], vto[200010], tot = 0;
void added(int u, int v) { vto[tot] = v, nxt[tot] = stu[u], stu[u] = tot++; }
int d[501], ud[501], vis[501];
int main(int argc, char const *argv[]) {
int n, m, a, b;
scanf("%d%d", &n, &m);
memset(stu, -1, sizeof stu);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if ((a == 0) && (b == 0))
cout << "NO" << endl;
else {
if ((a == b) || (a == (b + 1)) || (b == (a + 1)))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 9e18;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> l(m), r(m);
for (long long i = 0; i < m; i++)... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
long long x;
double y;
};
bool cmp(pt a, pt b) {
if (a.x < b.x) {
return 1;
}
if (a.x > b.x) {
return 0;
}
return a.y > b.y;
}
long long area(pt a, pt b, pt c) {
double ans = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
re... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long int binomial(long long int n, long long int k) {
long long int C[k + 1];
memset(C, 0, sizeof(C));
... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1005;
int a[N][N], b[N][N];
pair<int, int> daun[N * N], lol[N * N];
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for ... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.