solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
// Problem: B. The Great Hero
// Contest: Codeforces - Codeforces Round #700 (Div. 2)
// URL: https://codeforces.com/contest/1480/problem/B
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Author: masked_huh
// Created: 08-02-2021 12:41:11
/*Success isn't permanent, failure isn't fatal,
it's the courage to contin... | 1 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
int m;
long long dp[15][15];
long long ans;
long long amount[15];
bool isLucky(int x) { return x == 4 || x == 7; }
void plus(long long &a, long long b) {
a += b;
a %= mod;
}
void search(int limit, int current, int position, long long total) {
if (position... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long gcd(long long x, long long y) {
while (y) x %= y, swap(x, y);
return x;
}
pair<long long, long long> operator+(pair<long long, long long> a,
pair<long long, long long> b) {
return pair<long long, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, P = 1e9 + 7;
inline void write(long long x) {
if (x > 9) write(x / 10ll);
putchar(x % 10ll + '0');
}
struct miaow {
int l, r;
mutable long long sum;
miaow(int l = 0, int r = 0, long long sum = 0) : l(l), r(r), sum(sum) {}
inline bool opera... | 18 |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pip pair<int,pii>
#define ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 2;
int N, M;
long long k;
int par[MX], sz[MX];
long long n, c;
int arr[1001][1001], R[1001][1001], ans[1001][1100];
vector<pair<int, pair<int, int> > > v;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool valid(int x, int y) { return min(x, y) >=... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int k;
long long int go(long long int i) { return i * (i - 1) / 2; }
int main() {
scanf("%lld", &k);
if (k == 0) putchar('a');
for (char a = 'a'; a <= 'z' && k; a++) {
int i = 1;
while (go(i + 1) <= k) i++;
k -= go(i);
for (int j = 0; j < i; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
set<int> s[100010];
set<int>::iterator it1, k;
set<int>::iterator it2;
pair<int, int> a[100010];
int ned[100010];
int tec[100010];
struct P {
int x1, x2, x3;
};
vector<P> ans;
int main() {
ios_base::sync_with_stdio(0);
int n, m, sum = 0;
cin >> n >> m;
for (int i ... | 16 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 55;
const int P = 1e9 + 7;
int F[N][N][N][N][2];
int main() {
function<LL(int, int)> com = [&](int n, int k) {
static vector<vector<LL>> C(N, vector<LL>(N, -1));
if (C[n][k] != -1) return C[n][k];
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a[150][150];
int cnt[10];
int n;
int getscore(int id, bool flag, int s) {
if (a[flag][id] == -1) return 0;
int sum;
if (a[0][id] == -1 || a[1][id] == -1 || a[0][id] < a[1][id])
sum = cnt[id];
else
sum = cnt[id] + s;
int score = 500;
for (int i = 2; i... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = ge... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, temp, max = 0;
int a[51], b[51];
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
cin >> m;
for (i = 0; i < m; i++) cin >> b[i];
int count = 0;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (b[i] % a[j] == 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Matrix {
long long val[17][17];
void init() {
for (int i = 0; i < 17; i++) {
for (int j = 0; j < 17; j++) {
val[i][j] = 0;
}
val[i][i] = 1;
}
}
Matrix operator*(const Matrix &a) const {
Matrix ans;
for (int i = 0; i <... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6005;
int a[MAXN];
bool isprime(int n) {
int len = sqrt(n * 1.0);
for (int i = 2; i <= len; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++) a[i] = 1;
int m = (n + 1)... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
const int inf = 2e9;
char ma[maxn << 1];
int mp[maxn << 1];
inline void manacher(string &s, int len) {
int p = 0, r = 0, mid = 0;
ma[p++] = '$', ma[p++] = '#';
for (int i = 0; i < len; i++) ma[p++] = s[i], ma[p++] = '#';
for (int i = 0; i <... | 10 |
#include <bits/stdc++.h>
using namespace std;
void file() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
file();
long long testCases = 1;
while (testCases--) {
long long n, p;
cin >> n >> p;
vector<long long> v(n);
for (long long i = 0; i < n; i++) cin >> v[i];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int t = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1) t++;
}
cout << t << endl;
if (n == 1) {
cout << 1;
} else {
for (int i = 1; i < n; i++) {
if (a[i] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
int m;
cin >> m;
int ma = -1;
for (int i = 0; i < m; i++) {
int c;
cin >> c;
ma = max(c, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int s, n;
cin >> s >> n;
vector<pair<int, int> > ve;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
ve.push_back(make_pair(a, b));
}
sort(ve.begin(), ve.end());
int flag = 1;
for (int i = 0; i < n; i++) {
if (s <= ve[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a < b ? a : b; }
int dp[200005], leap[200005];
queue<int> p;
int main() {
int i, j, m, n, ans, temp, pre;
memset(leap, 0, sizeof(leap));
cin >> n >> m;
if (m > n)
pre = m;
else
pre = n;
pre = pre * 2;
for (i = 0; i <= pre... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct kom {
string n;
int x;
int x1;
int x2;
};
bool cmp(kom a1, kom a2) {
if (a1.x != a2.x)
return a1.x > a2.x;
else if (a1.x1 != a2.x1)
return a1.x1 > a2.x1;
else
return a1.x2 > a2.x2;
}
kom a[51];
int main() {
cin >> n;
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50;
const int Mod = 1e9 + 7;
int n, m;
int fa[N], sz[N], id[N];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
char S[N][N];
int G[N], dp[1 << 23], coe[1 << 23];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", S[i] ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout.precision(10);
cout << fixed;
int N, A, D;
cin >> N >> A >> D;
double last = 0.0;
for (int i = 0; i < N; ++i) {
int t, v;
cin >> t >> v;
double cur;
double L = 0.5 * v * v / A;
double T = 1.0 * v / A;
if (L < D) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int ans(int a, char ch) {
int mxlen = a;
int done = 0;
int pnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] != ch) done++;
while (done > a) {
if (s[pnt] != ch) done--;
pnt++;
}
mxlen = max(mxlen, i - pnt + 1);
}
return... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
bool f = true;
for (int i = 0; i < 8; i++) {
cin >> str;
for (int j = 1; j < str.length(); j++) {
if (str[j] == str[j - 1]) {
f = false;
}
}
}
if (f)
cout << "YES";
else
cout << "NO";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
const long long INF = 1e9 + 7;
int n, m, a[N];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
int ans1 = 0, ans2 = 0;
ans2 = *max_element(a + 1, a + n + 1) + m;
while (m) {
int pos = min_elemen... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 35;
int main() {
int n, m, x, i, shift[1000][5], flag1, q, ind, j, i2, i1;
char a[MaxN][MaxN], obr;
int f[55];
for (i = 0; i < 55; i++) {
f[i] = -1;
}
ind = 0;
cin >> n >> m >> x;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
int n, m;
cin >> n >> m;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
int last = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int temp = last;
if (i % 2 == 0) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int MAX = 1020;
int an[MAX];
int dp1[MAX], dp2[MAX][MAX];
int s1[MAX], s2[MAX][MAX];
int sum[MAX][MAX];
void print2(int n, int i);
void print1(int n) {
if (n == 0) return;
int j = s1[n];
print2(n - 1, j);
printf("%d %d\n", j, n);
assert(j != n);
}
voi... | 12 |
#include <bits/stdc++.h>
const int MAX = 2e5 + 11;
using namespace std;
int N, A[MAX], P[MAX], SZ[MAX], R[MAX];
vector<pair<int, int>> E;
static int get(int x) { return P[x] = (x == P[x]) ? x : get(P[x]); }
static void add(int x, int y, int w) {
int a = get(x);
int b = get(y);
if (a == b) {
return;
}
if (... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, m;
float sum = 0;
cin >> n >> m;
vector<float> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) sum += v[j] / (j + 1);
sum ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100, M = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline long long read() {
char ch = getchar();
long long f = 1, x = 0;
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && c... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
map<int, int> mp;
int val;
int vect[100];
for (int i = 0; i < n; ++i) {
cin >> vect[i];
}
vector<int> v;
for (int i = 0; i < m; ++i) {
cin >> val;
mp[val] = 1;
}
for (int i = 0; i < n; ++i) {
if (mp... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static const int L = 233333;
static char sxd[L], *sss = sxd, *ttt = sxd;
if (sss == ttt) {
ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
if (sss == ttt) {
return EOF;
}
}
return *sss++;
}
inline char readchar() {
char c = gc()... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int limit = 1e6;
long long int fab[limit + 1], inv[limit + 1];
long long int binpow(long long int n, long long int pow) {
long long int ans = 1ll;
while (pow) {
if (pow % 2 == 1) {
ans = (ans * n) % mod;
}
pow /... | 14 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* na... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> rats;
vector<string> child;
vector<string> man;
string s1, s2, cap;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
if (s2 == "rat")
rats.push_back(s1);
else if (s2 == "woman" || s2 == "child")
... | 1 |
#include <bits/stdc++.h>
using namespace std;
// Hi
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int tt;
cin>>tt;
while(tt--){
int n;
cin>>n;
vector<int> a(n);
for(auto &i:a)cin>>i;
if(is_sorted(a.begin(),a.end())){
cout << 0 << '\n';
}else... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N], b[N], ans = 0;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] *= (n + 1ll - i) * i;
}
for (int i = 1; i <= n; i++) cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k;
long long int n, m;
map<long long int, long long int> mp;
cin >> n;
for (i = 0; i < n; i++) {
cin >> m;
mp[m]++;
}
long long int count = 0;
map<long long int, long long int>::iterator p = mp.begin();
while (p != ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long v[N], f[N][2], g[N][2];
int main() {
int n;
long long ans = 0;
scanf("%d", &n);
for (int i = 2; i <= n; i++) scanf("%d", &v[i]);
for (int i = 2; i <= n; i++) {
if (v[i] >= 1)
f[i][0] = max(f[i - 1][0], f[i - 1][1]) + (v[... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long nums[200200], acum[200200];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lld", &nums[i]);
multiset<long long> aux;
for (int i = n - 1; i >= 0; i--) {
acum[i] = nums[i] + acum[i + 1];
aux.insert(acum[i]);
}
long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, pr;
double p[100010];
int main() {
double ans = 0;
scanf("%I64d%I64d", &n, &pr);
for (int i = 0; i < n; i++) {
long long l, r;
scanf("%I64d%I64d", &l, &r);
p[i] =
((r - l + 1) - 1.0 * ((r / pr) - ((l - 1) / pr))) / (1.0 * (r - l + 1));... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n, d;
cin >> n >> d;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
w... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tree[100005], Lson[100005 * 40], Rson[100005 * 40], Val[100005 * 40];
int g[100005], a[100005], tot;
void Insert(int &rt, int ot, int l, int r, int x, int v) {
rt = ++tot;
Lson[rt] = Lson[ot];
Rson[rt] = Rson[ot];
Val[rt] = Val[ot] + v;
if (l == r) retur... | 16 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int l, r;
cin >> l >> r;
cout << (l >= ((r + 2) / 2) ? "YES" : "NO") << '\n';
;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
while (t--) {
solve();
}
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[21][21], i, j;
bool check(int j1, int j2) {
int i, j, k;
for (i = 1; i <= n; i++) {
swap(a[i][j1], a[i][j2]);
k = 0;
for (j = 1; j <= m; j++)
if (a[i][j] != j) k++;
swap(a[i][j1], a[i][j2]);
if (k != 2 && k != 0) return false;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
int m, s;
cin >> m >> s;
if (m > 1 && s == 0 || m * 9 < s) {
cout << "-1 -1" << endl;
return 0;
}
if (m == 1) {
cout << s << " " << s << endl;
return 0;
}
string temp;
int s2 = s, ct = 0;
while (s2 > 9) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, p1[2010], p2[2010], inv1[2010], inv2[2010], sum;
vector<pair<int, int> > swps;
void slv(int posx, int y) {
if (p1[posx] == y) return;
int x = p1[posx], posy = inv1[y], tgtx = inv2[x];
if (tgtx < posx) {
slv(tgtx, x);
slv(posx, y);
return;
} else i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, a = 0, b = 0;
cin >> x;
string s, s1;
for (int i = 0; i < x; ++i) {
cin >> s >> s1;
if (s1 == "soft")
a++;
else
b++;
}
int i = 0, c;
if (b > a) swap(a, b);
while ((i * i / 2 < b) || ((i * i + 1) / 2) < a) i++;
co... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long arr[100005], arrsort[100005];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
arrsort[i] = arr[i];
}
sort(arrsort, arrsort + n);
for (int i = 1; i < n; i++) {
arr[i] += arr[i - 1];
arrsort[i] += arrsort[i - ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
int main() {
long long n;
cin >> n;
int t[n];
for (long long i = 0; i < (long long)n; i++) cin >> t[i];
vector<long long> v;
long long z = 0;
for (long long i = 0; i < (long long)n; i++) {
if ... | 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); }
struct ZAlgo {
string s;
int n;
vector<int> z;
void init(int _n) {
n = _n;
s = string(n, '?');
z = vector<int>(n, -1);
}
void calc() {
int l = 0, r = 0;
for (int i... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, x, y, height = 0, wtf = 0, result = 0;
cin >> a >> b >> x >> y;
height = b + y;
wtf = a + 2;
result = (height + wtf) * 2;
cout << result << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
long long ans = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i], a[i] = abs(a[i]);
sort(a.begin(), a.end());
int r = 0;
for (int l = 0; l < n; l++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void no() {
cout << "NO";
exit(0);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n * 2);
for (int i = 0; i < n * 2; i++) {
char c;
cin >> c;
if (c == '+')
a[i] = -... | 9 |
#include <bits/stdc++.h>
int IntMaxVal = (int)1e20;
int IntMinVal = (int)-1e20;
long long LongMaxVal = (long long)1e20;
long long LongMinVal = (long long)-1e20;
using namespace std;
template <typename T>
struct argument_type;
template <typename T, typename U>
struct argument_type<T(U)> {};
template <typename T1, typena... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct Seg {
int Max, Lazy;
};
Seg A[(35000 + 2) << 3];
int n, k, a[(35000 + 2)], Pre[(35000 + 2)], g[(35000 + 2)],
f[(50 + 1)][(35000 + 2)];
void init() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
memset(g, 0, sizeof(g));
for (in... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long A = INT_MAX, B = INT_MAX, C = INT_MAX, AB = INT_MAX, AC = INT_MAX,
BC = INT_MAX, ABC = INT_MAX;
for (int i = 0; i < n; i++) {
long long c;
string s;
vector<bool> ma(3, false);
cin >> c >> s;
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
template <typename T>
using v = vector<T>;
using pi = pair<lli, lli>;
using vi = v<lli>;
using vvi = v<vi>;
using vp = v<pi>;
using vvp = v<vp>;
constexpr lli INF = numeric_limits<lli>::max();
void input() {}
template <typename T, typename... Ts>
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int tab[1234], kar[1234], c[1243], ans[1234];
void bsort(int *tab, int nt) {
int i, j, t;
for (i = 1; i < nt; i++)
for (j = 1; j < nt; j++)
if (c[tab[j]] < c[tab[j - 1]])
t = tab[j], tab[j] = tab[j - 1], tab[j - 1] = t;
}
int main(void) {
int i, j, n... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N];
int n, m, c;
bool win() {
if (!a[1]) return false;
for (int i = 2; i <= n; i++)
if (a[i] < a[i - 1] || !a[i]) return false;
return true;
}
int main() {
cin >> n >> m >> c;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int l[1000000];
int n, m;
int main() {
cin >> n >> m;
a[0] = 0;
l[0] = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
bool f = 1;
for (int i = 1; i <= n; i++) {
l[i] = l[i - 1] + f * (a[i] - a[i - 1]);
f = !f;
}
l[n + 1] = l[n] + f * (m... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 20;
int a[N], dpL[N], dpR[N], n, sum;
vector<int> ans;
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];
iota(dpL, dpL + n, 0);
for (int i = 1; i < n; i++) {
i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
int j = 0;
int n = s.length();
for (int i = 0; i < n; i++) {
if (s[i] <= j + 'a') {
s[i] = j + 'a';
j++;
}
if (j == 26) break;
}
if (j != 26)
cout << -1;
else
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
int ans = 0;
while (cin >> s) {
int cnt = 0;
for (int i = 0; i < s.size(); ++i)
if (isupper(s[i])) ++cnt;
ans = max(ans, cnt);
}
cout << ans << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[302][302], used[302][302];
queue<pair<int, int>> q;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
bool ok = true;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)... | 4 |
#include <bits/stdc++.h>
long long fast_pow(long long target, long long p);
int t, cot;
char a[105];
int flag[256];
int que[30];
int main() {
scanf("%d", &t);
while (t--) {
for (int i = 0; a[i]; i++) a[i] = 0;
cot = 0;
for (int i = 97; i < 123; i++) flag[i] = 0;
scanf("%s", a);
for (int i = 0; a... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void amax(X& x, const Y& y) {
if (x < y) x = y;
}
template <class X, class Y>
void amin(X& x, const Y& y) {
if (x > y) x = y;
}
const int INF = 1e9 + 10;
const long long INFL = 1e18 + 10;
const int MAX = 1e6 + 10;
const int MAXP = 1e6;
long l... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, i, counter = 0, even_at_odd = 0, odd_at_odd = 0, even = 0, odd = 0,
even_at_even = 0, odd_at_even = 0;
strin... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
const long long int MOD = 998244353;
vector<int> adj[MAX_N];
long long int pow2[MAX_N];
long long int dp1[MAX_N], dp2[MAX_N], dp3[MAX_N];
long long int inv[MAX_N];
long long int ans[MAX_N];
long long int power(long long int a, long long int n) {
if ... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
unordered_map<int, int> f, g;
vector<int> p;
for (int i = 0; i < n; ++i) {
int a, b;
scanf("%d%d", &a, &b);
++f[a];
++g[b];
p.push_back(a);
p.push_back(b);
}
sort(p.begin(), p.end());
p.er... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 5 + 1e5;
const int INF = 1e9;
bool isPrime[N], T[N];
vector<int> primes;
vector<pair<int, int>> ans;
vector<int> te;
void sieve(int n) {
memset(isPrime, 1, sizeof isPrime);
isPrime[0] = isPrime[1] = 0;
for (int i = 2; i * i... | 17 |
#include <bits/stdc++.h>
const double E = 2.7182818284590452353602874713527;
using namespace std;
vector<int> vc[10000];
int visit[100000], a, k, ara[10000], ar[10000], mp[100000];
queue<int> qu;
void bfs(int node) {
int i, u, sz, v;
qu.push(node);
while (!qu.empty()) {
u = qu.front();
qu.pop();
sz = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, l, m, p;
vector<int> le;
long long re;
int main() {
scanf("%d%d%d", &n, &k, &l);
m = n * k;
le.resize(m);
for (int i = (0); i < (m); i++) scanf("%d", &le[i]);
sort(le.begin(), le.end());
p = 0;
while (p < m && (le[p] - le[0] <= l)) p++;
if (p < n) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<long> s;
vector<long>::iterator it;
long visited[100002];
vector<long> adj[100002];
int main() {
memset(visited, 0, sizeof(visited));
long i, j, el, k, n;
cin >> n;
for (long int i = 2; i < n + 1; i++) {
cin >> el;
adj[el].push_back(i);
}
long ans... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
con... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, k;
string s;
char c;
cin >> n >> k >> s;
vector<bool> let(26, 0);
for (int i = 0; i < k; i++) {
cin >> c;
let[c - 'a'] = 1;
}
long long cnt = 0, ans = 0;
for (char c : s) {
if (let[c - 'a'])
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 502;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int mat[4][4] = {{4, 3, 6, 12}, {7, 5, 9, 15}, {14, 1, 11, 10}, {13, 8, 16, 2}};
int ans[N][N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
while (cin >> n) {
if (n == 3) {
cout ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, num;
int v[1024];
memset(v, 0, sizeof(int) * 1024);
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &num);
v[num]++;
}
int sum = 0;
while (n > 0) {
for (int i = 0; i < 1024; i++) {
if (v[i] > 0) {
n--;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long p[4 * 100010], n, s, cnt1, cnt2, t1, t2, mx, mx1, mx2;
vector<pair<int, int> > p1, p2;
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) {
cin >> p[i] >> t1 >> t2;
if (t1 >= t2) {
cnt1 += p[i];
mx = mx + p[i] * 1LL * t1;
p1.pus... | 11 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int a[100005];
int cnt[500][100005];
int num[500];
int main() {
int i, j, n, T, up, x, y, ret;
scanf("%d%d", &n, &T);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
m[a[i]]++;
}
map<int, int>::iterator it;
up = 0;
for (it = m.begin(); ... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s[300005], sol, b[300005], ans[300005];
int n, m, mini;
bool p;
bitset<300005> taj;
const int inf = 1e9;
void check(string t, bool f) {
int br = 0;
bitset<300005> sad;
for (int i = 0; i < n; ++i) {
int br1 = 0, br2 = 0;
for (int j = 0; j < m; ++j) {
... | 13 |
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i, j, k) for (int i = j; i <= k; ++i)
#define DF(i, j, k) for (int i = j; i >= k; --i)
using namespace std;
template <typename T> inline void read(T &n) {
T w = 1; n = 0;
char ch = getchar();
while (!isdigit(ch) && ch ... | 24 |
#include <bits/stdc++.h>
using namespace std;
bool flag[3607][3607];
bool vis1[3607], vis2[3607];
int f[3607][3607], g[3607][3607], c[3607][3607];
int pre[3607];
int cnt1, cnt2;
int n, m, k;
int main() {
scanf("%d%d%d", &n, &m, &k);
c[0][0] = 1;
for (int i = 1; i <= n || i <= m; i++) {
c[i][0] = 1;
for (i... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l;
while (cin >> n >> l) {
int res = 0xffff;
int m;
for (int i = 0; i < n; i++) {
cin >> m;
if (l % m == 0 && l / m < res) res = l / m;
}
cout << res << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename A, typename B>
ostream &operator<<(ostream &out, pair<A, B> p) {
return out << '(' << p.first << ", " << p.second << ')';
}
template <typename A,
typename B = typename enable_if<!is_same<A, string>::value,
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, t, z = -1, x = 0, y = 0;
cin >> n >> k >> t;
if (t <= k)
cout << t;
else if (t - k <= n - k)
cout << k;
else if (t - k > n - k)
cout << n + k - t;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int cnt = 0;
vector<int> V1;
V1.push_back(2);
V1.push_back(3);
V1.push_back(5);
V1.push_back(7);
V1.push_back(11);
V1.push_back(13);
V1.push_back(17);
V1.push_back(19);
V1.push_back(23);
V1.push_back(29);
V1.push_back(31);
... | 6 |
#include <bits/stdc++.h>
template <class T>
void cxk(T& a, T b) {
a = a > b ? a : b;
}
template <class T>
void cnk(T& a, T b) {
a = a < b ? a : b;
}
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', c... | 21 |
#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(int n) {
bool prime[n + 1];
int a[n + 1];
int x = 1;
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
a[p] = x;
prime[p] = false;
for (int i = p * p; i <= n; i += p) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long k = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
k = k * 10 + ch - '0';
ch = getchar();
}
return k * f;
}
inline void... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double pi = acos(-1.0);
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
templ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
vector<pair<long long, long long> > graph[100010];
struct subset {
int parent;
int rank;
};
struct Node {
int u, v;
long long w;
Node() {}
Node(int _u, int _v, long long _w) {
u = _u;
v = _v;
w = _w;
}
bool operator<(c... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
bool vis[MAXN];
int main() {
int n;
cin >> n;
int a[n + 1];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int fdv = a[n - 1];
vis[fdv] = 1;
a[n - 1] = 0;
for (int i = 0; i < n; i++) {
if (a[i] and !vis[a[i]] and (fd... | 3 |
#include <bits/stdc++.h>
using std::max;
using std::swap;
using std::vector;
const int MAXN = 1e5 + 10;
int n, a, b, da, db;
vector<int> e[MAXN];
int d[MAXN], f[MAXN], g[MAXN], len;
void dfs(int u, int fa) {
register int v;
f[u] = g[u] = 0;
for (register int i = 0; i < (int)e[u].size(); ++i) {
v = e[u][i];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, w, t, te, z[400010], coun, l, r;
vector<int> b, e, s;
int main() {
cin >> n >> w;
if (w == 1) {
cout << n;
return 0;
}
if (w > n) {
cout << 0;
return 0;
}
cin >> t;
for (int i = 1; i < n; i++) {
cin >> te;
b.push_back(te - t);
... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
const int INF = (int)1E9 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897... | 10 |
#include <bits/stdc++.h>
int d[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int a, b, res = 0;
scanf("%d %d", &a, &b);
while (a <= b) {
int x = a;
while (x) res += d[x % 10], x /= 10;
a++;
}
printf("%d\n", res);
}
| 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.