solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
int main(void) {
int B, b, m, L[200] = {};
scanf("%d%d", &b, &m);
for (int i = 0; i < m; i++) {
scanf("%d", &B);
for (int j = 1; j <= b; j++) {
if (L[j]) break;
if (j >= B) L[j] = B;
}
}
for (int i = 1; i <= b; i++) printf("%d ", L[i]);
putchar('\n');
retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int long long inf = numeric_limits<int long long>::max();
struct __io {
__io() {
ios_base::Init i;
ios_base::sync_with_stdio(0);
cin.tie(0);
}
} __io;
signed main() {
int long long t;
cin >> t;
while (t--) {
int long long n;
cin >> n;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
char s[maxn][2];
int d[maxn];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %d", s[i], &d[i]);
}
int number0 = 0, number1 = 1023;
for (int i = 0; i < n; i++) {
if (s[i][0]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ans = 0;
int inp;
for (int i = 0; i < n; i++) {
cin >> inp;
int temp = (inp + k - 1) / k;
ans += temp;
}
cout << (ans + 1) / 2 << endl;
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
#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;
int LIM1 = 1e4 + 101;
int LIM = 3e5 + 10;
int tree[300020];
int MAXI = 3e5 + 5;
void update(in... | 7 |
#include <bits/stdc++.h>
bool flag[1000000];
int ans[12005], ed;
int main() {
int i, j, t, k;
memset(flag, true, sizeof(flag));
flag[0] = flag[1] = 0;
ed = 0;
for (i = 2; i < 1000000; ++i) {
if (flag[i]) {
for (j = 2; j * i < 1000000; ++j) {
flag[i * j] = false;
}
if (i > 10) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int w[55][55];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> w[i][j];
}
}
cin >> a >> b;
int ans = n * m;
for (int i = 1; i + a - 1 <= n; i++) {
for (int j = 1; j + b - 1 <= m; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> adj[10004];
void dfs(int node, int parent, int len) {
if (len == 2) {
k++;
return;
}
for (auto child : adj[node]) {
if (child != parent) dfs(child, node, len + 1);
}
}
int main() {
scanf("%d", &n);
int x, y;
for (int i = 0; i ... | 2 |
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
typedef long long ll;
#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second
template<typename T, typename U> bool ckmin(T &a, const U &b){ return b < a ? a = b, true : fal... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[1000007];
long long int arr[1000007];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n, i, j, k, i1, i2;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> arr[i];
i1 = lower_bound(arr, arr + i, arr[i] + 1 - 90) - arr;
i2... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1);
int dcmp(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
template <class T>
class Point {
public:
T x, y;
Point() { x = y = 0; }
Point(T a, T b) : x(a), y(b) {}
};
temp... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int w[maxn];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
memset(w, 0, sizeof(w));
int temp;
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
w[temp]++;
}
int step = 0;
for (int i = 0; i <= 1e6; i++)... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
int n,x,sum=0,temp;
cin>>n;
int a[3]={0};
for(int i=0;i<n;i++)
{
cin>>x;
if(x%3==0)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct ITree {
vector<int> T;
int p = 1;
ITree(int n = 0) {
while (p < n) p *= 2;
T.resize(2 * p - 1, 0);
}
int par(int x) { return (x - 1) / 2; }
void add(int l, int v) {
l += p - 1;
T[l] += v;
while (l > 0) {
l = par(l);
T[l] +=... | 7 |
#include <bits/stdc++.h>
using namespace std;
bitset<100000001> bs;
unsigned int n, A, B, C, D, ans;
void zad(unsigned int x) {
unsigned int sum = A * x * x * x + B * x * x + C * x + D, o = n;
while (o / x) ans += sum * (o /= x);
return;
}
int main() {
scanf("%u %u %u %u %u", &n, &A, &B, &C, &D);
zad(2), zad(... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, n, x;
cin >> t;
while (t--) {
cin >> x;
n = 360 % (180 - x);
if (n == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = INT_MAX;
void files() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int a[MAXN], Min[MAXN];
int main() {
int Max = -1, answer = 0, n;
cin >> n;
for (int i = 1; i < n + 1; i++) cin >> a[i];
Mi... | 4 |
#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;
int a[n], f = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] != 1) f = 1;
}
sort(a, a + n);
if (f) {
cout << "1 ";
for (int i = 0; i < n - 1; i++... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
void reverseStr(string& str) {
int n = str.length();
for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]);
}
void printval(long long n, long long total) {
if (total =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
using pi = pair<int, int>;
int n;
int a[MAXN], b[MAXN];
vector<int> reduce(int x) {
vector<pi> bv;
for (int j = 0; j < n; j++) bv.emplace_back(-b[j], j);
sort(bv.begin(), bv.end());
vector<int> v;
for (int i = 0; i < bv.size() && i < x; i++) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long i, n, x;
vector<long long> v;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
for (i = 0; i < n; i += 2) cout << v[i] << " ";
if (n % 2 == 0) {
for (i = n - 1; i >= 0; i -= 2) cout << v... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long double x, y;
cin >> x >> y;
if (x == y) {
cout << "=";
return 0;
}
long double r1 = (long double)y * (long double)log2(x);
long double r2 = (long double)x * (long double)log2(y);
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
int tn, tm, res;
cin >> tn >> tm;
n = ((tn) < (tm) ? (tn) : (tm));
m = ((tn) > (tm) ? (tn) : (tm));
if (n == 1) {
cout << m << endl;
return 0;
}
if (n == 2) {
res = (m / 4) * 4;
if (m % 4 == 1)
res += 2;
else if... | 5 |
#include<bits/stdc++.h>
#define ll long long
#define N
#define mod 998244353
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define lowbit(i) ((i)&(-i))
#def... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, string> > pr;
string ins;
for (int i = 0; i < n; i++) {
cin >> ins;
pr.push_back(pair<int, string>(ins.length(), ins));
}
sort(pr.begin(), pr.end());
for (int i = 0; i < n - 1; i++) {
string t = pr[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
bool p[maxn];
char s[maxn];
void is_prime() {
memset(p, true, sizeof(p));
p[0] = p[1] = false;
for (int i = 2; i * i <= maxn; i++) {
if (p[i]) {
for (int j = i * i; j <= maxn; j += i) p[j] = false;
}
}
}
int main() {
is_pri... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans;
int main() {
int i, j, k;
while (~scanf("%d", &n)) {
k = 0;
ans = 0;
for (i = 1; i < n; i++) {
k = i;
bool flag = false;
for (j = 1; j < n - 1; j++) {
int o = k - 1;
if (o % n == 0) {
flag = true... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
pair<int, int> a[maxn];
pair<int, int> b[maxn];
int da[maxn];
int db[maxn];
int va[maxn];
int vb[maxn];
int n, m;
int Chk(pair<int, int> x, pair<int, int> y) {
if (x.first == y.first && x.second != y.second) return x.first;
if (x.first == y.second &... | 5 |
#include <cstring>
#include <iostream>
#include <vector>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int maxn = 505 + 7;
int a[maxn][maxn],vis[maxn];
int b[maxn * maxn];
vector<pair<int,int> >res;
int n;
int dfs(vector<int>&vec) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char c;
vector<char> line;
while (cin >> c) {
line.push_back(c);
}
int s = line.size();
vector<int> result;
for (int i = 0; i < s; i++) {
if (line[i] == '.') {
result.push_back(0);
} else {
if (line[i + 1] == '.') {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
set<int> se[5005];
char arr[500005];
queue<int> que;
int main() {
int n;
scanf("%d", &n);
int num = n / 3;
int a = 0, b = 0, c = 0;
scanf("%s", arr);
int st = 0;
while (st < n) {
if (arr[st] == '0') a++;
if (arr[st] == '1') b++;
if (arr[st] == '2')... | 3 |
#include <bits/stdc++.h>
using namespace std;
int degree[70000], s[70000];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
queue<int> Q;
for (int i = 0; i < n; ++i) {
cin >> degree[i] >> s[i];
if (degree[i] == 1) Q.push(i);
}
vector<pair<int, int> > edges;
while (!Q.emp... | 3 |
#include <bits/stdc++.h>
char a[110];
int t[26];
int n;
int change(int s, int e) {
int i;
int flag = 0;
for (i = 0; i < n; i++) {
if (t[i] == 0) {
t[i] = 1;
a[s] = 'a' + i;
a[e] = 'a' + i;
flag = 1;
break;
}
}
if (flag == 0) a[s] = a[e] = 'a';
return flag;
}
int check()... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i;
long long arr[100000];
int s = 0;
for (i = sqrt(n); i >= 1; i--) {
if (n % i == 0) {
int x = n / i;
long long ans = 2 + (x - 1) * i;
ans = ans * x;
ans = ans / 2;
arr[s] = ans;
s++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1000005;
const string S = "aeiou";
int n, dic[26];
string u, sa[MX][5];
vector<pair<string, string>> fi, se;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < 5; i++) dic[S[i] - 'a'] = i;
while (n--) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 1e6 + 100;
const int inf = 1e9 + 100;
int n, w, m, a[N], seg[N << 2];
long long fen[N];
void change(int dex, int val, int v = 1, int s = 0, int e = N) {
if (dex < s || e <= dex) {
return;
}
if (e - s == 1) {
seg[v] = val;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct base {
long double r, i;
base(long double x = 0, long double y = 0) : r(x), i(y) {}
base operator+(const base &a) const { return base(r + a.r, i + a.i); }
base operator-(const base &a) const { return base(r - a.r, i - a.i); }
base operator*(const base &a) c... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
long long t, a, b, ans, d, tem;
while (cin >> t >> a >> b) {
d = gcd(a, b);
if (t / b < a / d)
ans = min(t, min(a, b) - 1);
else {
d = a / d * b;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int MAXN = 200001;
int n, k;
int t[MAXN];
long long s[MAXN];
long double f[MAXN];
long double sp[MAXN];
long double s2[MAXN];
int st[MAXN], b[MAXN];
int stc;
const long double e = 1e-10;
inline long double g(int l, int r) {
return ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m;
char a[100005];
int main() {
scanf("%s", a);
int ans = 9999999, len = strlen(a);
for (i = 'a'; i <= 'z'; i++) {
int p0 = 0, p = -1;
for (i0 = 0; i0 < len; i0++) {
if (a[i0] == i) {
p0 = max(p0, i0 - p);
p = i0;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> f;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
long long ans = 0;
while (n--) {
string s;
cin >> s;
vector<int> cnt(26, 0);
for (char c : s) cnt[c - 'a']++;
int mask = 0;
for (int i = 0; i < 26; ++i)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct vert {
int next;
int comp;
};
int main() {
int n, i, l, comp_counter, j, q;
cin >> q;
while (q--) {
cin >> n;
vector<vert> G(n);
vector<int> C;
for (i = 0; i < n; i++) {
cin >> G[i].next;
G[i].next--;
G[i].comp = -1;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
static char ch;
bool sgn = false;
while (ch = getchar(), ch < '0' || ch > '9')
if (ch == '-') sgn = true;
int res = ch - 48;
while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
return sgn ? -res : res;
}
const int INF... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<long long> b(n / 2);
for (auto& e : b) cin >> e;
vector<long long> a(n);
for (int i = 0; i < n / 2; ++i) {
if (i > 0) {
a[i] = max(a[i - 1], a[i - 1] - b[i - 1] + b... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
const int MOD = 1e9 + 7;
struct Point {
long long x, y;
} p[MAX];
Point operator-(Point A, Point B) { return (Point){A.x - B.x, A.y - B.y}; }
long long operator^(Point A, Point B) { return A.x * B.y - A.y * B.x; }
vector<Point> v;
int which(const... | 8 |
#include <bits/stdc++.h>
using namespace std;
char mapp[105][105] = {};
char Generating(int len1, int len2) {
for (int i = 'a'; i <= 'z'; i++) {
if (len1 == 0 && len2 == 0)
return i;
else if (len1 == 0 && len2 != 0 && mapp[len1][len2 - 1] != i &&
mapp[len1 + 1][len2 - 1] != i)
return ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long sum = 0;
char n;
map<char, long long> k;
int main() {
while ((n = getchar()) != '\n') {
k[n]++;
}
for (auto it = k.begin(); it != k.end(); ++it) {
sum += (it->second) * (it->second);
}
cout << sum;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
int Max = 1e6 + 100;
for (int i = 0; i < m; i++) {
int l, r;
scanf("%d%d", &l, &r);
Max = min(Max, r - l + 1);
}
cout << Max << endl;
int sign = 0;
for (int i = 0; i < n; i++) {
cout << sign << " ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, v;
cin >> n >> v;
vector<pair<int, int> > ingredients(n);
cin >> ingredients[0].first;
int total = ingredients[0].first;
for (int i = 1; i < n; i++) {
cin >> in... | 3 |
#include <bits/stdc++.h>
using namespace std;
constexpr int max_n = 5e5 + 5, mod = 1000696969;
int tab[max_n];
long long hash_pref[max_n], hash_pref_2[max_n], hash_pref_3[max_n],
power[max_n], power_2[max_n], power_3[max_n];
vector<int> zliczanie[max_n];
map<long long, int> hash_cnt, hash_cnt_2, hash_cnt_3;
int mai... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, l, k;
double dp[201][201][201];
int a[201];
double p[201];
int main() {
scanf("%d %d %d", &n, &l, &k);
for (int(i) = 0; (i) < (int)(n); (i)++) {
cin >> p[i];
p[i] /= 100.0;
}
for (int(i) = 0; (i) < (int)(n); (i)++) scanf("%d", &a[i]);
dp[0][0][0] = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int a[200200], n;
int t[200200 * 4];
void build(int v, int l, int r) {
if (l == r) {
t[v] = a[l];
return;
}
int mid = (l + r) >> 1;
build(v + v, l, mid), build(v + v + 1, mid + 1, r);
t[v] = max(t[v + v], t[v + v + 1]);
}
void update(i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[10], b[10], td[10], mina = 1e9, minb = 1e9;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mina = min(mina, a[i]);
td[a[i]]++;
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
minb = min(minb, b[i]);
td[b[i]]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string a[8];
int b[8];
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> p(0);
for (int i = 0; i < k; ++i) {
p.push_back(i);
}
int best = 1000000000;
do {
for (int i = 0; i < n; ++i) {
string s(k... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
long long n, k, x, z, sum = 0;
cin >> n >> k;
z = 5 - k;
for (int i = 0; i < n; i++) {
cin >> x;
if (x <= z) sum++;
}
cout << sum / 3 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e3 + 5, mod = 1e9 + 7, MOD = 1e9 + 7, mod2 = 998244353;
void shof_anta_ray7_fen() {
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
sum += abs(x);
}
cout << sum;
}
int main() {
ios::sync_with_stdio(0);... | 0 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> X, pre;
unordered_map<int, int>::iterator it;
int Find(int u) {
it = pre.find(u);
if (it == pre.end()) {
X[u] = 0;
return u;
}
int v = it->second;
int tmp = Find(v);
X[u] ^= X[v];
return pre[u] = tmp;
}
bool join(int a, int b, i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1.5e5 + 6.66;
const int inf = 1e9 + 7;
int seg[MAXN * 4], laz[MAXN * 4];
int a[MAXN], b[MAXN];
int n, m, h;
void shift(int id, int val) {
seg[id] += val;
laz[id] += val;
}
void shift(int id) {
shift(id << 1, laz[id]);
shift(id << 1 | 1, laz[id]);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
void solve() {
long long int m, n;
cin >> m >> n;
long long int mn[n];
long long int x = 0;
memset(mn, -1, sizeof(mn));
for (long long int i = 0; i < m; i++) {
long long int a[n];
for (long long int j = 0; j < n; j++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
pair<long double, long double> point[N];
long double check(long double r, long long n) {
long double mn = -1e8, mx = 1e8;
for (long long i = 0; i < n; i++) {
long double x =
(point[i].second * r * 2) - (point[i].second * point[i]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve(int n) {
int i, s, r, l, j, k, a[1100];
scanf("%d", &k);
if (n > k) swap(n, k);
if (k == 1 || n == 1)
printf("%d", k + n - 1);
else if (n == 2) {
if (k % 4 == 0) printf("%d", k);
if (k % 4 == 1) printf("%d", k + 1);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, ans = 0, k;
cin >> n >> m;
while (m-- > 1) {
cin >> k;
if (k % 2 && n % 2) ans = !ans;
}
cin >> k;
if (k % 2) ans = !ans;
if (ans % 2)
cout << "odd";
else
cout << "even";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (a == 0) return b;
return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long int m) {
T ans = 1;
while (b > 0) {
if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
b /= 2;
a = ((a % m) * (a % m)) % m... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int d, w, next;
};
long long g1[200010], g2[200010];
long long ans;
node w[200010];
bool vst[200010];
int rd[200010];
int n, rc;
void insert(int st, int ed, int wi) {
++rc;
w[rc].d = ed;
w[rc].w = wi;
w[rc].next = rd[st];
rd[st] = rc;
}
bool judge(... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string a, b;
cin >> a >> b;
int c = 0, d = 0;
for (int i = 0; i < a.length(); i++)
if (a[i] == '1') c++;
for (int i = 0; i < b.length(); i++)
if (b[i] == '1') d++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
template <typename T>
bool chmax(T &x, const T &y) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, y;
scanf("%lld", &x);
scanf("%lld", &y);
if (y == 0) {
puts("No");
exit(0);
}
if (y == 1) {
if (x == 0)
puts("Yes");
else
puts("No");
exit(0);
}
long long now = y - 1;
if (x < now) {
puts("No");... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> e[100005];
int k, x;
long long dp[100005][3][30];
const long long mod = 1e9 + 7;
void dfs(int u, int par = 0) {
dp[u][0][0] = dp[u][1][1] = dp[u][2][0] = 1;
long long tmp[3][30];
for (int i = 0; i < e[u].size(); i++) {
int v = e[u][i];
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
string s;
cin >> s;
vector<bool> ans(s.size());
for (int i = 0; i < (int)s.size(); ++i) {
int j = i;
while (j < (int)s.size() && s[j] == s[i]) {
++j;
}
if (s[i] == 'b' && j ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = 80;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
struct edge {
int go, cost, f, c;
};
int edges;
int a[N + 2][N + 2], num[N + 2][N + 2];
int first[... | 7 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
int tmp;
std::cin >> tmp;
if (tmp % 2 == 0) {
std::cout << tmp - 1 << " ";
} else {
std::cout << tmp << " ";
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int negative_infinite = 0xcfcfcfcf;
const int mod = 1e9 + 7;
const int MAXN = 1007;
int n, m;
int a[MAXN];
int main() {
cin >> n >> m;
while (m--) {
int x;
cin >> x;
a[x]++;
}
int ans = INF;
for (int i = 1; i <= n; i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
string s;
while (t--) {
cin >> n;
cin >> s;
int size = n;
bool found = false;
for (int i = 0; i < size; i++) {
if (s[i] == '8' && (size - i) >= 11) found = true;
}
if (found)
cout << "YES" << e... | 0 |
#include <bits/stdc++.h>
using namespace std;
int add(int a, int b, int MOD) {
if ((a += b) >= MOD) a -= MOD;
return a;
}
int mul(int a, int b, int MOD) { return 1ll * a * b % MOD; }
int qpow(int a, int b, int MOD) {
int r = 1;
for (; b; b >>= 1) {
if (b & 1) r = mul(r, a, MOD);
a = mul(a, a, MOD);
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, t, k;
int a[MAXN];
int calmin[MAXN], calmax[MAXN];
int main(int argc, const char* argv[]) {
cin >> n >> t >> k;
for (int i = 1; i <= t; i++) {
cin >> a[i];
}
int cmin = 0, cmax = 0;
for (int i = 1; i <= t - 1; i++) {
calmi... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mxlli = 1e18;
const int mxint = 1e9 + 7;
int solv() {
int n, m, k;
cin >> n >> m >> k;
int z = ((n * m) / 2) - k;
char c[n][m];
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) c[i][j] = '*';
if ((n % 2 == 1 and m % 2 == 1)) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, arr[100010];
void Debug() {}
void Read() {
cin >> N;
for (int i = 1; i <= N; ++i) cin >> arr[i];
sort(arr + 1, arr + N + 1);
}
void Solve() {
for (int i = 1; i <= N; ++i)
if (arr[i] > arr[i - 1]) arr[i] = arr[i - 1] + 1;
cout << arr[N] + 1 << "\n";
}
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> l(m), ans(m), R(m);
bool can = true;
for (int i = 0; i < m; ++i) {
cin >> l[i];
if (i + l[i] > n) {
can = false;
break;
}
}
int la... | 5 |
#include <bits/stdc++.h>
using namespace std;
int num[2010];
long long count_winscore[5010], A_score[10010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &num[i]);
sort(num, num + n);
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++) count_winscore[num[i] - num[j]]++;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, h, o, a;
int main() {
scanf("%d%d", &n, &h);
o = 0;
while (n--) {
scanf("%d", &a);
o += a > h ? 2 : 1;
}
printf("%d\n", o);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
int sum = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) {
sum = sum + a[i][j... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
string t(n, '?');
for (int i = 0; i < k - 1; ++i) {
t[2 * i] = '(';
t[2 * i + 1] = ')';
}
for (int i = 0; i <= n / 2 - k; ++i) {
t[2 * k - 2 + i] = '(';
t[n - 1 - i] = ')';
}
vec... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e3 + 7;
const int MOD = 1e9 + 7;
int n;
int dp[34][2][2][2];
int sum[34][2][2][2];
int x, y, k;
int dfs(int pos, int limx, int limy, int limk, int &t) {
if (pos == -1) return 1;
int &st = sum[pos][limx][limy][limk];
if (~dp[p... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int add(int a, int b) {
if ((a += b) >= mod) a -= mod;
return a;
}
inline int mult(int a, int b) {
long long t = 1ll * a * b;
if (t >= mod) t %= mod;
return t;
}
namespace matrix {
template <int N, int M>
class matr {
public:
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int MAXN = 24;
const int MAXA = 514;
const int INF = 1029384756;
class Isap {
public:
static const int MXN = MAXA * 4;
class Edge {
public:
int v, f, re;
Edge() { v = f = re = -1; }
Ed... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 262144;
const long long inf = 4e18;
struct lazyseg {
vector<long long> a;
lazyseg() : a(2 * maxn, inf) {}
void update(int l, int r, long long v, int x = 1, int xl = 0,
int xr = maxn - 1) {
if (r < xl || xr < l) return;
if (l <= x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0;
cin >> t;
for (int i = 0; i < t; i++) {
int n = 0;
cin >> n;
char s[n];
cin >> s;
int count1 = 0;
int count2 = 0;
int ans = 0;
for (int j = 0; j < n; j++) {
if (s[j] == '(')
count1++;
else if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
set<int> gSetka;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
set<int> setka;
setka.insert(0);
for (int i = 0; i < n; ++i) {
int cur;
cin >> cur;
set<int> newSetka;
gSetka.insert(cur);
newSetka.insert(cur);
for (auto it = s... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
template <typename T>
void amin(T &x, T y) {
if (y < x) x = y;
}
template <typename T>
void amax(T &x, T y) {
if (y > x) x = y;
}
vector<int> g[maxn];
vector<pair<int, int>> adj[maxn];
bool vis[maxn];
long long int dis[maxn];
int par[maxn];
int... | 2 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int> > arr;
for (int i = 1; i <= n; i++) {
int elem;
cin >> elem;
if (elem == 0) continue;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int roundup(long long int x, long long int a) {
return (x < 0 ? x - x % a : x + 4 - x % a);
}
long long int rounddown(long long int x, long long int a) {
return (x < 0 ? x - 4 - x % a : x - x % a);
}
int main() {
long long int a, b, x1, y1, x2, y2, yy1, yy2,... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool sub(char s1[], char s2[], int m, int n) {
if (m == 0) return true;
if (n == 0) return false;
if (s1[m - 1] == s2[n - 1]) return sub(s1, s2, m - 1, n - 1);
return sub(s1, s2, m, n - 1);
}
int main() {
char s1[] = "heidi";
char s2[1000];
cin >> s2;
int m ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int num[maxn];
int pos[maxn];
int vis[maxn];
int main() {
memset(vis, -1, sizeof(vis));
int n, x;
scanf("%d%d", &n, &x);
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
vis[num[i]] = 1;
}
sort(num, num + n);
pos[0] = num[0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, p;
long long a[100005];
long long ans[10005];
long long sum1;
int main() {
scanf("%d %d", &n, &p);
scanf("%lld", &a[0]);
sum1 = a[0];
ans[0] = a[0];
for (int i = 1; i < n; i++) {
scanf("%lld", &a[i]);
sum1 += a[i];
ans[i] = ans[i - 1] + a[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
scanf("%lld", &n);
long long int ar[n];
for (long long int i = 0; i < n; i++) scanf("%lld", &ar[i]);
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < n - 1; j++) {
if (ar[j] > ar[j + 1]) {
cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[1000];
int i, j = 0, k, l, a[1000], m, n, t;
cin >> s;
l = strlen(s);
for (i = 0; i < l; i++) {
if ((i % 2) == 0) {
a[j] = (int)s[i];
j++;
}
}
for (m = 1; m < j; m++) {
for (n = 0; n < (j - m); n++) {
if (a[n] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, i, cnt = 0, a, sum;
cin >> k;
for (i = 19; cnt <= k; i++) {
sum = 0;
for (a = i; a > 0; a /= 10) {
sum += (a % 10);
}
if (sum == 10) {
cnt++;
}
if (cnt == k) {
break;
}
}
cout << i;
return 0;
}
| 1 |
#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
s = 0;
register int f = 1;
register char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
s *= f;
return;
}
template <class t, cla... | 8 |
#include <bits/stdc++.h>
const int MAX = 1e5 + 11;
using namespace std;
int N, L, X, Y, A[MAX];
set<int> all;
static bool can(int v) {
for (int i = 0; i < (N); ++i) {
if (all.count(v + A[i])) {
return true;
}
}
return all.count(v) > 0;
}
int main() {
scanf("%d%d%d%d", &(N), &(L), &(X), &(Y));
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
template <class T>
inline void read(T &n) {
char c;
int flag = 1;
for (c = getchar(); !(c >= '0' && c <= '9' || c == '-'); c = getchar())
;
if (c == '-')
flag = -1, n = 0;
else
n = c - '0';
... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.