solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int m;
int total = 0;
int a[105];
int x, y;
int main() {
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a[i];
total += a[i];
}
cin >> x >> y;
int cnt = 0;
for (int i = 0; i < m; i++) {
cnt += a[i];
if (cnt >= x && cnt <= y && total - cnt >= x && ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
bool chmin(T1 &a, T2 b) {
return b < a && (a = b, true);
}
template <class T1, class T2>
bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
using ll = long long;
int c[111][111];
int main() {
int n, m;
cin >> n >> m;
for (int ... | 2 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int inread() {
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();
}
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long primes[100], m;
int main() {
cin >> n;
long long tmp = n;
for (long long i = 2; i * i <= n; i++)
if (tmp % i == 0) {
primes[++m] = i;
while (tmp % i == 0) tmp /= i;
}
if (tmp > 1) primes[++m] = tmp;
if (m <= 1) {
puts... | 11 |
//#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
... | 21 |
#include <bits/stdc++.h>
using namespace std;
int comparei4(const void* a, const void* b) {
pair<pair<int, int>, pair<int, int> >
*x = (pair<pair<int, int>, pair<int, int> >*)a,
*y = (pair<pair<int, int>, pair<int, int> >*)b;
if (x->second.first != y->second.first)
return x->second.first - y->second.... | 0 |
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 300005
using namespace std;
int n,m,blo,a[N],b[N];
int t[N],ans[N],cnt[N],res;
struct que{int l,r,id,bel;}q[N];
inline int qr()
{
char a=0;int w=1,x=0;
while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
while(a<='9'&&... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 5;
const int MAXP = 4e3 + 5;
int n, tot;
int pri[MAXN], phi[MAXN], sum[MAXN];
int f[MAXN], pc[MAXN], cnt[MAXN];
bool bo[MAXN];
void init() {
scanf("%d", &n);
for (int i = 2; i <= n; ++i) {
if (!bo[i]) {
pri[tot++] = i;
phi[i] = i -... | 19 |
#include <bits/stdc++.h>
using namespace std;
int Read() {
char c;
while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
;
bool neg = (c == '-');
int ret = (neg ? 0 : c - 48);
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
return neg ? -ret : ret;
}
int main() {
for (int i = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 0x3fffffff;
int n, a[N], b[N], sum[N], T, mx, ans;
inline int Max(const int &a, const int &b) { return a > b ? a : b; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
mx = Max... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, b[100005 << 2], cnt = 0, K, num[100005], to[100005], Q, Ans[100005];
struct point {
int r, a, id;
bool operator<(const point &o) const {
return (r == o.r) ? a < o.a : r < o.r;
}
} a[100005];
int sum[100005 << 2];
inline int lowbit(int x) { return x & (-x); ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)5e5 + 7;
int n, m;
long long w[maxn];
vector<int> V[maxn];
int du[maxn];
queue<int> Q;
long long dp[maxn];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> w[i];
}
for (int i = 1; i <= m; i++)... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF32 = 1E9;
const long long INF64 = 4E18;
const long long M = 1E9 + 7;
const double EPS = 1E-9;
const double PI = 2 * acos(0);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& p) {
os << "[ ";
for (T x : p) os << x << " ";
os << "]" <... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int B = 17;
const int N = 1 << B;
const long long int M = (int)1e9 + 7;
const long long int inv2 = (int)5e8 + 4;
nam... | 18 |
#include <bits/stdc++.h>
int n, k, f[1000010];
char s[1000010];
using namespace std;
void getf(char *s) {
int j = 0;
for (int i = 2; i <= n; i++) {
while (j && s[i] != s[j + 1]) j = f[j];
if (s[i] == s[j + 1]) j++;
f[i] = j;
}
}
bool work(int i, int cir) {
int x = i / cir;
if (i % cir)
return ... | 14 |
#include <bits/stdc++.h>
int main() {
int i, c = 0, j, n, k;
scanf("%d", &n);
int a[n][2];
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
scanf("%d", &a[i][j]);
}
}
scanf("%d", &k);
for (i = 0; i < n; i++) {
if (k >= a[i][0] && k <= a[i][1]) {
printf("%d", n - i);
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
string ask(int x, int y) {
cout << x << " " << y << endl;
fflush(stdout);
string ans;
cin >> ans;
return ans;
}
bool in(int x, int y) { return 0 <= x and x <= 1e9 and y >= 0 and y <= 1e9; }
int main() {
cin >> n;
long long l = 1, r = 2e9;
string str =... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool used[21];
int U[21], V[21], P[21], way[21], minv[21];
int n, m, res, ar[21][21], fri[21][21], sat[21][21];
int hungarian(int i) {
int j, i0, i1, j0, j1, cur, delta;
P[0] = i, j0 = 0;
for (j = 0; j <= m; j++) minv[j] = (1 << 27), used[j] = false;
do {
used[j... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> qual;
vector<int> price;
int quality, pri;
for (int i = 0; i < n; ++i) {
cin >> pri >> quality;
price.push_back(pri);
qual.push_back(quality);
}
int k = 0;
for (int i = 0; i < n; ++i)
if (qual[i] !=... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int inf = 1e9 + 7;
int main() {
int a, b, c;
cin >> a >> b >> c;
int x, y, z;
cin >> x >> y >> z;
int h = 0;
if (a >= x) h += ((a - x) / 2);
if (b >= y) h += ((b - y) / 2);
if (c >= z) h += ((c - z) / 2);
int p = 0;
if (a < x) p ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y / 2;
x = (x * x) % p;
}
return res;
}
void solve() {
string s;
cin >> s;
char a = s[0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n;
cin >> n;
if ((n ^ (n - 1)) == ((n << 1) - 1))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _ = 1;
while (_--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<bool> used(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> b(n, 1e9);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p) {
long long ans = 1;
while (p) {
if (p & 1) ans = (ans * base) % (1000000007LL);
base = (base * base) % (1000000007LL);
p /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, x, c, i;
cin >> n;
long long int ar[n];
for (i = 0; i < n; i++) cin >> ar[i];
sort(ar, ar + n);
long long int cnt = 0;
for (int i = 0; i < n; i++) {
if (ar[i] % ar[0] == 0) {
cnt++;
}
}
if (cnt == n) {
cou... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
mt19937 ggen;
int n;
long long l;
long long a[100010];
string s[100010];
struct node {
int nxt[26];
int lnk;
int pr;
int ch;
long long w;
long long sw;
node();
int link();
int next(int ch);
long long weight();
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 7;
const int N = 1e6 + 10;
vector<int> a, dd;
int n;
void xuly() {
dd.resize(n, 0);
int l = oo;
int kq = 0;
for (int i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1]) {
if (l == oo) l = i;
} else {
if (l == oo) continue;
d... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int M = 3000 + 10;
struct EDGE {
int u;
int v;
int l;
int r;
} edge[M];
int n, m;
int pa[M];
int Find(int u) { return u == pa[u] ? u : (pa[u] = Find(pa[u])); }
int ans = 0;
bool solve(int l, int r) {
for (int i = 1; i <= n; i++) {
pa[i] = i;
}
for (i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int idlers, works;
long long int total_time = 0;
scanf("%d %d", &idlers, &works);
vector<pair<int, int>> arr(idlers);
vector<bool> arr_work(works, 0);
vector<int> arr_times;
int trabajos = 0;
for (int i = 0; i < idlers; i++) {
cin >> arr[i].... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int f(int k) {
if (k == 0) return 1;
long long int res = f(k - 1);
return 4 * res % 1000000007 * res % 1000000007;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int k;
cin >> k;
long long int res = f(k - 1);
cout << 6 * res %... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, x, y, z;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d %d %d", &x, &y, &z);
if (x == y && x >= z) {
printf("YES\n");
printf("%d %d %d\n", x, z, z);
} else if (x == z && x >= y) {
printf("YES\n");
print... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x;
int times;
};
const int N = 105 * 2;
int num[N];
int cont[N];
vector<int> g[N];
int xx[2][105];
int b[N];
int main() {
int n;
while (cin >> n) {
for (int i = 10; i <= 99; i++) g[i].clear();
memset(cont, 0, sizeof(cont));
memset(xx, 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> v;
for (int i = 0; i < n; i++) {
vector<int> t(m);
copy_n(istream_iterator<int>(cin), m, t.begin());
v.push_back(*min_element(t.begin(), t.end()));
}
cout << *max_element(v.begin(), v.end());
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct p {
int h, should_be;
} P[100005];
int n;
p *sorted[100005];
int cmp(p *a, p *b) {
if (a->h != b->h)
return a->h < b->h;
else
return a - P < b - P;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &P[i].h);
sorted[i] = &P[i... | 8 |
#include <bits/stdc++.h>
int a;
int b;
int c;
int main() {
scanf("%d%d", &a, &b);
while (b > 0) {
c *= 10;
c += b % 10;
b = b / 10;
}
printf("%d", a + c);
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
long long int modpow(long long int a, long long int b, long long int mod) {
long long int res = 1;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
res %= mod;
a = a * a;
a %= mod;
}
return res;
}
long long int p(l... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int n, a[maxn], b[maxn], nexta[maxn], nextb[maxn];
bool cp() {
for (int i = 1; i <= n; i++)
if (nexta[i] != nextb[i]) return false;
return true;
}
int main() {
cin >> n;
int d = 1;
for (int i = 1; i <= n; i++) {
cin >> a[d];
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long int a;
scanf("%d", &n);
int odd = 0, even = 0;
for (int i = 0; i < n; ++i) {
scanf("%lld", &a);
if (a % 2)
odd++;
else
even++;
}
if (!odd)
printf("Second\n");
else
printf("First\n");
}
| 3 |
#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(l... | 17 |
#include <bits/stdc++.h>
long double pi = 2 * acosl(0.0);
int test_case_number, test_case = 1;
struct edge_structure {
int vertex_1, vertex_2, weight;
};
std::vector<edge_structure> edges;
std::vector<std::vector<int>> weight_id(5e5 + 10, std::vector<int>());
std::vector<int> parent;
int parent_finder(int vertex) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
map<char, int> mp;
string tar = "Bulbasaur";
for (int i = 0; i < s.length(); i++) {
mp[s[i]]++;
}
int mn = 1e9;
mp['u'] = mp['u'] / 2;
mp['a'] = mp['a'] /... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long tmp, k, arr[1000005], h, brr[1000005], l, r, n, m, mid, x, y, ans,
sum;
vector<long long> v[1000005];
bool cek(long long x) {
for (long long i = 1; i <= n; i++) brr[i] = 0;
long long last = x, need = 0;
for (long long i = x; i > 0; i--) {
last = min(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
set<int> s;
int f[1000010], c[1000010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", f + i);
s.insert(f[i]);
if (i == f[i]) c[i] = ++m;
}
if (s.size() != m)
puts("-1");
else {
printf("%d\n", m);
for (in... | 9 |
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void solve(){
ll n;
cin>>n;
ll count = 0;
ll c[3] = {0};
ll arr[n];
for(int i = 0; i < n; i++){
cin>>arr[i];
c[arr[i]%3]++;
}
for(int i = 0; i < 4; i++){
if(c[i%3] > n/3){
count +=... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int M = 1e9 + 7;
long long int cdiv(long long int a, long long int b) {
return (a % b == 0) ? a / b : a / b + 1;
}
long long int myMod(long long int a, long long int b) {
long long int r = a % b;
return r < 0 ? r + b : r;
}
long long int ModPow(long long int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100];
int total = 0;
int main() {
scanf("%d", &n);
if (n == 1 || n % 2 == 0) {
printf("-1\n");
return 0;
}
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = n - 1; i > 0; i -= 2) {
total += max(a[i], a[i - 1]);
a[i... | 9 |
#include <bits/stdc++.h>
const int N = 100001;
long long o, u, n, m, k, x, s[N], S[N], c, h, t;
int main() {
scanf("%lld%lld%lld", &n, &k, &m);
for (int i = 1; i <= n; i++) {
scanf("%lld", &x);
if (!c || s[c] != x)
s[++c] = x, S[c] = 1;
else
S[c]++;
if (S[c] == k) c--;
}
for (int i =... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int k;
int co[10] = {0};
char c;
cin >> k;
for (int i = 0; i < 16; i++) {
cin >> c;
if (c != '.') co[c - '0']++;
}
for (int i = 0; i < 10; i++) {
if (co[i] > 2 * k) {
cout << "NO";
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
if (n == 2) {
cout << -1;
return 0;
}
vector<vector<int> > o;
while (n > 1 && n != 4) {
o.push_back({n, n - 1, 1});
o.push_bac... | 20 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long a, b, maxx, ans;
int main() {
unsigned long long i, j, k;
cin >> a >> b;
maxx = 1 << 30;
maxx <<= 33;
for (i = 1; i < maxx; i = i << 1 | 1)
for (j = 1; j <= (i >> 1); j <<= 1) {
k = i - j;
if (k >= a && k <= b) ans++;
}
cou... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (true) {
a %= b;
if (a == 0) return b;
b %= a;
if (b == 0) return a;
}
}
bool isB(long long n) {
n = abs(n);
while (n > 0) {
if (n % 10 == 8) return true;
n /= 10;
}
return false;
}
bool isP... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int flip(char a, char b, char c, char d) {
map<char, long long int> m;
long long int res;
m[a]++, m[b]++, m[c]++, m[d]++;
if (m.size() == 1) res = 0;
if (m.size() == 2) {
if (m.begin()->second == 1 || m.begin()->second == 3)
res = 1;
else
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, h[100005], par[100005][20];
vector<int> ke[100005];
struct node {
int a[11];
void reset() {
for (long long i = (0); i <= (10); i++) a[i] = 1000000007;
}
void add(int val) {
a[10] = val;
sort(a, a + 11);
}
} val[100005], gt[100005][20];
boo... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1E-7;
int main() {
int n;
scanf("%d", &n);
int m = (n / 2) * (n - n / 2);
printf("%d\n", m);
for (int i = 1; i <= n / 2; ++i)
for (int j = n / 2 + 1; j <= n; ++j) printf("%d %d\n", i, j);
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
int i, n, m, j, c1, c2, c3, c4, c5;
int main() {
scanf("%d %d %d %d %d", &c1, &c2, &c3, &c4, &c5);
if ((c1 + c2 + c3 + c4 + c5) % 5 != 0 || c1 + c2 + c3 + c4 + c5 == 0)
printf("-1");
else
printf("%d", (c1 + c2 + c3 + c4 + c5) / 5);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
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 ret = 1;
while (b) {
if (b & 1) r... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, k, temp1, temp2;
int main() {
scanf("%d%d", &n, &k);
if (k == 1 && n > 1 || k > n) return printf("-1\n"), 0;
if (k == 1 && n == 1) return printf("a\n"), 0;
k = k - 2;
n -= k;
temp1 = n % 2;
temp2 = n / 2;
for (int i = 0; i < temp2; i++) printf("ab");
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 55, mod = 998244353;
int n, m, b[N], st[N], ed[N], f[M << 1][N], g[M << 1][N], sum[N << 1], fac[N],
inv[N];
int fpow_(int a, int b, int res = 1) {
for (; b; b >>= 1, a = 1ll * a * a % mod) {
if (b & 1) {
res = 1ll * res * a % mod;
... | 24 |
#include <bits/stdc++.h>
using namespace std;
int t, q, s;
int main() {
cin >> t >> s >> q;
int ans = 0;
while (s < t) {
s += s * (q - 1);
++ans;
}
cout << ans << endl;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline void rd(_T& _a) {
int _ch, _f = 0;
while (!isdigit(_ch = getchar())) _f = _ch == '-';
_a = _ch - '0';
while (isdigit(_ch = getchar())) _a = _a * 10 + _ch - '0';
if (_f) _a = -_a;
}
template <class _T>
inline _T dmin(const _T _a, const _T... | 14 |
#include <bits/stdc++.h>
using namespace std;
namespace {
const vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23};
constexpr int NUM_P = 7;
const int MAX = 1000002;
const int MAX_V = 1024;
const int MAX_DIVS = 300;
int dist[MAX_V][MAX_V];
int cost[MAX_V][MAX_DIVS];
vector<int> adj[MAX_V];
void Chmin(int& a, int b) ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 2e9;
const long long inf_ll = 2e18;
int Gcd(int p, int q) { return q == 0 ? p : Gcd(q, p % q); }
int Pow(int p, int q) {
int ans = 1;
while (q) {
if (q & 1) ans = ans * p;
p = p * p;
q >>= 1;
}
return ans;
}
inline long long read() {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int F() {
register int aa, bb, ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
while (ch = getchar(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - '0';
return bb ? aa : -aa;
}
const int... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000;
const int MAX_R = 1000000;
const int INF = 1 << 30;
int ls[MAX_N], rs[MAX_N], cs[MAX_R + 1], as[MAX_N];
int main() {
int n;
scanf("%d", &n);
int maxr = 0;
for (int i = 0; i < n; i++) {
int l, r;
scanf("%d%d", &l, &r);
ls[i] = l, r... | 9 |
#include <bits/stdc++.h>
using namespace std;
string scanInt() {
string v;
char c;
while (!isdigit(c = getchar()))
;
v.push_back(c);
while (isdigit(c = getchar())) v.push_back(c);
return v;
}
int shift;
string integer, decimal, newdeci;
string finint, findeci;
string::iterator decipop;
char grabdeci() {... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string t;
cin >> t;
string s = "";
for (int i = 0, j = 0; i < k; i++) {
for (; j <= s.length(); j++) {
bool good = true;
for (int l = 0; l < t.length(); l++) {
if (j + l == s.length()) {
s +... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long verifica(long long a) {
long long sum = 0;
while (a % 2 == 0 && a > 1) {
sum = sum + a / 2;
a = a / 2;
}
return sum + a * (a - 1) / 2;
}
int main() {
long double a = 2.0, b = -2.0, aux = 1.0;
unsigned long long c;
cin >> c;
vector<long long... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int h, m;
cin >> h >> m;
for (int i = 0;; i++) {
if (h / 10 == 7 || h % 10 == 7 || m / 10 == 7 || m % 10 == 7) {
cout << i;
return 0;
}
m -= x;
if (m < 0) {
h--;
m += 60;
}
if (h < 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long double eps = 0.0000000001;
const long long INF = 0x3fffffffffffffff;
long long t[105], n, k, Max, has, tmp;
signed main() {
ios::sync_with_stdio(false);
cin >> n >> k;
for (long long i = 1; i <= n; ++i) {
cin >> tmp;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void KhanhCute() {
int n;
cin >> n;
long long res = 0;
while (n >= 10) {
int x = n / 10;
n -= x * 9;
res += x * 10;
}
cout << res + n << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin >> q;
while (q--) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int kolplus, kolminus;
int seq[101];
int res[101];
int len;
int main() {
char q = ' ';
while (q != '=') {
scanf("? %c ", &q);
if (q == '=') break;
if (q == '+') {
kolplus++;
seq[len] = 1;
}
if (q == '-') {
kolminus++;
s... | 10 |
#include <bits/stdc++.h>
using namespace std;
void QuickSort(vector<string> &S, vector<int> &A, int left, int right) {
int i, j;
string middle;
i = left;
j = right;
middle = S[(i + j) / 2];
do {
while (S[i] < middle) {
i = i + 1;
}
while (S[j] > middle) {
j = j - 1;
}
if (i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
return x * x;
}
const double pi = acos(-1.0), eps = 1e-9, e = exp(1.0);
const int INF = 1000 * 1000 * 1000 + 7, MAXN = 100005, MOD = 1000000007,
MAXBIT = 30, pHash = 53;
const long long INFL = 1e+18;
void prepare(string s) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t[N], tree[N * 16], lazy[N * 16];
long long l[N], r[N];
vector<long long> vc;
void push_up(int rt) { tree[rt] = tree[rt << 1] + tree[rt << 1 | 1]; }
void push_down(int rt, int l, int r) {
int m = (l + r) >> 1;
if (lazy[rt] == 1) {
lazy[rt ... | 15 |
#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;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
long long int ans = a[n - 1], max = a[n - 1];
for (int i = n - 2; i >= 0; i--) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int cmx = 1e4 + 5;
int n;
string s;
int dp[cmx][2];
set<string> ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
n = s.size();
if (n <= 6) {
cout << 0 << '\n';
return 0;
}
dp[n - 1][1] = 1;
if (n > 7) dp[n - ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, p, cot = 0;
scanf("%d %d", &n, &p);
int m = 2 * n + p;
for (int i = 1; i <= m; i++) {
for (int j = i + 1; j <= n; j++) {
if (cot == m) break;
cot++;
printf("%d %d\n... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int read() {
int x = 0, f = 1;
char str = getchar();
while (str < '0' || str > '9') {
if (str == '-') f = -1;
str = getchar();
}
while (str >= '0' && str <= '9') {
x = x * 10 + str - '0';
str = getchar();
}
return x *... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct x {
char a[15];
int n1;
int n2;
int flag;
} xx[1000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> xx[i].a;
cin >> xx[i].n1;
cin >> xx[i].n2;
if (xx[i].n1 >= 2400 && (xx[i].n2 > xx[i].n1)) {
xx[i].flag = 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
long long f[MAXN][2], dat[MAXN];
inline int read() {
int x = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
int main() {
ios::sync_with_s... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string s;
cin >> s;
long long int sum = 0;
std::vector<long long int> v;
long long int count = 1;
for (long lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int arr[200200];
string in;
int n, m;
bool is_ok() {
int dist = 0;
for (int i = 0; i < n; i++) {
if (arr[i]) {
dist = 0;
} else {
dist++;
}
if (dist >= m) {
return false;
}
}
return true;
}
int main() {
cin.sync_with_stdio(fal... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int M = 1010;
double dp[N][N * M];
int n, m, a[N];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i <= n * m; i++) dp[0][i] = m - 1;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j ... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const ... | 17 |
#include <iostream>
using namespace std;
int main(){
int cases;
cin>>cases;
while(cases--){
int n,k;
cin>>n>>k;
int arr[n][2];
for(int i = 0 ; i < n ; i++){
cin>>arr[i][0]>>arr[i][1];
}
int check = 0;
for(int i = 0 ; i < n ; i++){
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double pi = acos(-1.0), eps = 1e-9;
const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
int n;
double U, e[N], ans;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cout << setprecision(10) << fixed;
cin >> n >> ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void swap(long long int *a, long long int *b) {
long long int temp = *a;
*a = *b;
*b = temp;
}
void findmax(long long int *a, int stop) {
int maxi = 1;
for (int i = 1; i <= stop; i++) {
if (a[i] >= a[maxi]) {
maxi = i;
}
}
for (int j = maxi; j < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long sum;
bool isPossible(vector<int> pile, long long sec) {
long long pileidx = n - 1;
for (int i = 0; i < m; i++) {
long long amount = sec;
while (pileidx >= 0 && pile[pileidx] == 0) {
pileidx--;
}
amount -= (pileidx + 1);
whil... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = static_cast<int>(1e9);
const long long INF_LL = static_cast<long long>(4e18);
const double pi = acos(-1.0);
template <class T>
inline T& smin(T& x, const T& y) {
return x > y ? ... | 20 |
#include <bits/stdc++.h>
const int MAXN = 2005;
const double eps = 1e-8;
int n, a, b;
double pa[MAXN], pb[MAXN];
double ca, cb;
int tot[MAXN][2];
double f[MAXN];
void Calc() {
for (int i = 1; i <= n; i++) {
f[i] = f[i - 1];
tot[i][0] = tot[i - 1][0];
tot[i][1] = tot[i - 1][1];
if (f[i] < f[i - 1] + pa... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, l, sum, i;
char str[2005];
cin >> n;
cin >> str;
l = strlen(str);
if (l < 4)
cout << "0" << endl;
else {
i = 0;
sum = 0;
while (i + n < l) {
i = i + n;
if (str[i - 1]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 31;
long long timer, cc, cc1;
void boost() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
long long ncr[1005][5];
void compute() {
long long i, j;
for (i = 0; i < 1005; i++) {
for (j = 0; j < 5; j++) {
if (j == 0 || i == j) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e2 + 4;
vector<pair<int, int>> v[N];
int ma[N][N][68];
int solve(int a, int b, int ch) {
int node = a;
assert(ch < 30);
if (ma[a][b][ch] != -1) return ma[a][b][ch];
int here = 0;
for (auto it : v[node]) {
if (ch > it.sec... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, D, N;
cin >> A >> B >> C >> N;
D = N - A - B + C;
if (D < 1 or A < C or B < C) D = -1;
cout << D << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 10;
int s = 0;
int n, m, k;
int ans[N];
pair<int, pair<int, int> > p[N];
bool check(double mid) {
for (int i = 0; i < n; i++) {
double q1 = s, q2 = k, q3 = p[i].second.first;
if (q1 * q2 / q3 <= mid) {
ans[s] = p[i].second.second +... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool secdes(const pair<long long int, long long int>& a,
const pair<long long int, long long int>& b) {
if (a.second == b.second) {
return a.first > b.first;
} else {
return a.second > b.second;
}
}
bool sir(const pair<long long int, long long int>... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O0")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
long long n, m, a, b, k, temp, x, y;
const int MAXN = 100000 + 11;
inline void read(vector<long long>... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string a;
cin >> n >> a;
string min = a;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < n; j++) {
a[j]++;
if (a[j] > '9') a[j] = '0';
}
for (int k = 0; k < n; k++) {
a = a.substr(1, n - 1) + a[0];
if (a <... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int vis[N];
set<int> G[N], s;
void bfs(int x) {
queue<int> q;
q.push(x);
s.erase(x);
while (q.size()) {
int now = q.front();
q.pop();
if (vis[now]) continue;
vis[now] = 1;
for (auto p = s.begin(... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int read() {
int x = 0, flag = 1;
char c = getchar();
while ((c > '9' || c < '0') && c != '-') c = getchar();
if (c == '-') flag = 0, c = getchar();
while (c <= '9' && c >= '0') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.