solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int s[MAXN], lim[MAXN], reg[MAXN], m, n;
vector<long long> summax[4 * MAXN], sumreg[4 * MAXN];
vector<pair<int, int> > v[4 * MAXN];
set<pair<pair<int, int>, int> > range;
set<pair<pair<int, int>, int> >::iterator it;
void merge(vector<pair<int, int>... | 23 |
#include <bits/stdc++.h>
using namespace std;
struct Stamp {
int x, y;
Stamp() {}
Stamp(int _x, int _y) { x = _x, y = _y; }
int square() { return x * y; }
};
int main() {
int n, a, b;
cin >> n >> a >> b;
vector<Stamp> s;
int wrong = 0;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0},
dxx[8] = {0, 0, 1, 1, 1, -1, -1, -1}, dyy[8] = {1, -1, 0, 1, -1, 0, 1, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, a, b, c, t, i;
cin >> n >> a >> b >> c >> t;
int ar[n + 5];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[5050];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
if (a[a[a[i]]] == i) return 0 * printf("YES\n");
}
return 0 * printf("NO\n");
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void Solve() {
int n;
cin >> n;
vector<int> vec1(n);
vector<int> vec2(n);
string str;
cin >> str;
int i = 0;
while (i < n && str[i] != '1') {
if (str[i] == '2')
vec1[i] = vec2[i] = 1;
else
vec1[i] = vec2[i] = 0;
i++;
}
if (str[i] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
const int maxn = 150005;
int t[maxn];
int main(void) {
int n, k, q;
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
int type, a;
for (int i = 0; i < q; i++) {
cin >> type >> a;
if (type == 1) {
s.insert(t[a]);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct mydata {
int id;
long long sum;
};
mydata getData(int id, long long sum) {
mydata d;
d.id = id;
d.sum = sum;
return d;
}
bool operator<(const mydata &a, const mydata &b) { return a.sum < b.sum; }
long long ans;
int n, m, k, p;
int row[1000];
int col[1000]... | 12 |
#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;
cin >> n >> m;
vector<long long int> vec1, vec2;
for (long long int i = 0; i < n; i++) {
long long int x;
cin >> x;
vec1.push_back(x);
}
for (long... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long int);
long long int gcd(long long int, long long int);
set<long long int> divs(long long int);
void swap(long long int& x, long long int& y);
const long long int N = 1000;
long long int modPow(long long int x, long long int y, long long int n) {
if... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long p = 520040728;
long long h[1000005], b[1000005], n, sum;
char s[1000005];
long long get(long long x, long long y) {
return (h[y] - h[x - 1] * b[y - x + 1] % p + p) % p;
}
long long ok(long long x, long long y) {
if (!x || (y - x != 1 && s[x + 1] == '0') ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
long long int res = 1;
a = a % 1000000007;
while (b > 0) {
if (b & 1) {
res = (res * a) % 1000000007;
b--;
}
a = (a * a) % 1000000007;
b >>= 1;
}
return res;
}
long long int gcd(lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, z, a, x;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> x;
if (x == 1) a++;
for (; x > 1; a++) x = (x + 3) / 4;
z = max(z, a);
}
printf("%d", z);
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int MAXV = 60;
const int MAXB = 17;
int n, ar[MAXN], dp[MAXN][1 << MAXB], par[MAXN][1 << MAXB], ans[MAXN];
int primes[MAXB], ind[MAXV], cnt;
vector<int> fact[MAXV];
vector<int> good[1 << MAXB], aft[1 << MAXB];
void init() {
for (int i = 2; i < ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.);
const long long MOD = 1000000007;
vector<pair<int, int> > gao(int *x, int n, int *X, int *use, int &U, int &len) {
int i, j, k;
for (i = 0; i < n; i++) X[i] = x[i];
int mx = *max_element(X, X + n);
len = 0;
whi... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct Nodemu {
int l, r;
int id;
bool operator<(const Nodemu& x) const {
if (l == x.l) return r < x.r;
return l < x.l;
}
} nodemu[100005];
struct Nodeac {
int l, r;
int count;
int id;
bool operator<(const Nodeac& x) const {
if (l == x.l) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
void answer(string s) {
cout << s << endl;
exit(0);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
vector<int> d(n, 0);
vector<vector<int> > a(n, vector<int>(0, 0));
for (int i = int(0); i < int(n); i++) cin >> d[i];
for (int i = int(0); i < int(n); i++) {... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
int ans = 1e9;
for (int j = 1; j < 64300; j++) {
ans = min((n - j) / j + ((n - j) % j > 0) + j - 1, ans);
}
cout << ans << endl;
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long int vallagena(long long int n) {
long long int s = 0;
while (n > 0) {
if (n % 10 == 4 || n % 10 == 7) {
s = s * 10 + n % 10;
}
n /= 10;
}
return s;
}
int main() {
long long int a, b;
cin >> a >> b;
a++;
while (vallagena(a) != vall... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
char array[n][m];
int a = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a == 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, a[5005], i = 0, j, count = 1, p = 1;
scanf("%ld", &n);
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
sort(a, a + n);
for (j = 0; j <= n; j++) {
if (j == 0)
continue;
else {
if ((a[j] == a[j - 1]) && (j < n))
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int x[4], y[4];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
if (n <= 1)
cout << -1;
else {
bool is = false;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (x[i] != x[j] && y... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[41][65][65][65];
int dx[] = {0, 0, 0, 1, -1};
int dy[] = {0, 1, -1, 0, 0};
int r(int num, int m1, int m2, int m3) {
int x = num / m;
int y = num % m;
if (y == m) return 0;
if (x == n) {
int cnt = 0;
for (int k = (0); k < (n); ++k)
if (... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 21;
int used[SIZE][SIZE], cnt, n, m;
string h, v;
void dfs(int r, int c) {
used[r][c] = 1;
cnt++;
if (h[r] == '>') {
if (c < m - 1 && !used[r][c + 1]) dfs(r, c + 1);
} else {
if (c > 0 && !used[r][c - 1]) dfs(r, c - 1);
}
if (v[c] == 'v'... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int q, n, r;
cin >> q;
while (q--) {
cin >> n >> r;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int ans = 1, pos = n - 1;
for (int i = n - 2; i >= 0; i--) {
if (a[i] == a[pos]) continue;
if (a[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
int mx = 0, sum = 0;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
mx = max(tmp, mx);
sum += tmp;
}
cout << max((sum + m) / n + ((sum + m) % n > 0), mx) << ' ' << mx + m;
}
int main() {
ios::sync_wit... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> pr;
void S(long long n) {
vector<bool> prime(n + 1, true);
for (long long p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (long long i = p * 2; i <= n; i += p) prime[i] = false;
}
}
for (long long p = 2; p <= n; p++)
if (prime[p])... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int N, T;
void solve() {
long long int K;
cin >> N >> K;
long long int a[N];
long long int sum = 0;
for (long long int i = 0; i < N; i++) {
cin >> a[i];
sum += a[i];
}
if (K == 0) {
cout << sum << '\n';
return;
}
sort(a, a + N);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, M = 2e6 + 10, inf = 0x3f3f3f3f;
const long long Linf = 0x3f3f3f3f3f3f3f3f;
inline int read() {
bool sym = 0;
int res = 0;
char ch = getchar();
while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
while (isdigit(ch)) res = (res << 3) + (... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool conn[555][555];
int inv[555], ouv[555];
int link[555];
int n, m;
bool vis[555];
bool dfs(int pos, int rt) {
for (int i = 1; i <= n; ++i) {
if (conn[pos][i] && i != rt && !vis[i]) {
vis[i] = 1;
if (link[i] == -1 || dfs(link[i], rt)) {
link[i] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T read_value(string s) {
T result;
istringstream sin(s);
sin >> r... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[14000];
bool ok;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i)
if (a[i] % 2 == 0)
cout << a[i] / 2 << "\n";
else if (!ok) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, a[maxn];
int nxt[maxn], pre[maxn], pos[maxn], vis[maxn];
long long sum;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= 1e6; i++) pos[i] = n + 1;
for (int i = n; i >= 1; i--) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int a = -1;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') {
a = i;
break;
}
}
if (a == -1) {
for (int i = 0; i < s.length(); i++) {
if (i != s.length() - 1) cout << s[i];
}
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, total, a, b[15], k, i, ad;
int main() {
cin >> n >> m;
ad = n;
while (n--) {
cin >> a;
b[10 - (a % 10)]++;
total += (a / 10);
}
for (i = 1; i < 10; i++) {
k = min(m, b[i] * i);
m -= k;
total += (k / i);
}
cout << min(ad * 10, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long d1, d2, d3;
long long s = 0;
cin >> d1 >> d2 >> d3;
if (d1 > d2) {
swap(d1, d2);
}
s += d1;
s += (s + d3 + d2) < (s + d1 + 2 * d3) ? d3 + d2 : d1 + 2 * d3;
if (2 * (d1 + d2) < s) {
s = 2 * (d1 + d2);
}
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 3e5 + 5;
const long long MOD = 1000000007;
const long long MOD2 = 2010405347;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
long long k, n, a, b;
cin >> k >> n >> a >> b;
k -= n * a;
if (k > 0) {
cout << n << endl;
} else {
k = -k;
++k;
long long diff = a - b;
long long turns = (k + diff - 1) / di... | 6 |
#include <bits/stdc++.h>
using namespace std;
int M, T, R, W, ans;
int bit[30000];
bool ok[30000], flag = true;
void update(int x, int v) {
for (; x < 30000; x += (x & -x)) bit[x] += v;
}
int query(int x) {
int sum = 0;
for (; x; x -= (x & -x)) sum += bit[x];
return sum;
}
int main() {
if (0) {
freopen(
... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> mp;
int ans[2]{0};
int flag = 0;
void dfs(int ver, int x, int pr) {
ans[x & 1]++;
for (auto i : mp[ver]) {
if (i != pr) dfs(i, x + 1, ver);
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int n, p = 1, k, x, l, y, ans = 0, o = 0;
vector<long long int> v;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
o = n;
if (n < 5) {
n *= (n - 1);
n /= 2;
cout << n;
return 0;
}
x = n;
l = 5;
k = 0;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
long long int ans = 0;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) ans = max(ans, a[i] | a[j] | a[k]);
}
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const double eps = 1e-9;
const double pi = acos((double)-1.0);
const int mod = (int)1e9 + 7;
void add(int &x, int y) {
if ((x += y) >= mod) {
x -= mod;
}
}
int mult(int x, int y) { return (long long)x * y % mod; }
vector<pair<int, int> >... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
const long long INF = 1e18;
template <typename T>
inline bool chkmax(T &aa, T bb) {
return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T &aa, T bb) {
return aa > bb ? aa = bb, true : false;
}
struct debugger {
... | 17 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
int n;
int comb[101][101];
long long getCount(int arr[], int len) {
long long d[101][10] = {0};
for (int i = arr[9]; i <= len; ++i) d[i][9] = 1;
for (int i = 0; i <= len; ++i) {
for (int j = 8; j >= 1; --j) {
for (int k = arr[j]; k <= i; ++k) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, c = 0;
cin >> n;
long long int a[n];
vector<long long int> v;
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
long long int x = a[n - 1];
for (i = n - 1; i >= 0; i--) {
if (x == a[i]) {
c++;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[5005];
int flag[1000005];
int g[1000005];
int main() {
int n, m, i, j, k, l;
scanf("%d %d", &n, &m);
memset(g, 0, sizeof(g));
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
for (i = 1; i <= n; i++) {
for (j = i + 1; j <=... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long M = 1e9 + 7;
int n;
long long pre[2][N];
long long post[2][N];
long long m3[N];
string s;
void prework() {
for (int i = 0; i < n - 1; ++i) {
pre[0][i + 1] = pre[0][i];
pre[1][i + 1] = pre[1][i];
if (s[i] == 'a') {
p... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, a[500005], val[500005], b[500005], pos[500005];
vector<int> ans;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int tc, m;
cin >> tc;
while (tc--) {
ans.clear();
cin >> n >> m;
for (int i = 0; i < n; i++) val[i] = 0;
for (i... | 13 |
#include<bits/stdc++.h>
using namespace std;
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
#define ll long
int main(){
fast();
ll t; cin>>t;
while(t--){
ll n,k;
cin>>n>>k;
ll p, q;
q=k%n;
if(q==0) q=n;
ll h = n/2;
if(k<=h... | 4 |
#include <bits/stdc++.h>
using namespace std;
double v, e, t[200010], p[200010];
int par[200010];
vector<int> g[200010];
void dfs(int at, int pai) {
par[at] = pai;
for (int x : g[at])
if (x != pai) dfs(x, at), t[at] += p[x];
e += t[at] * p[at];
}
int main() {
int n, i, q, x, a, b;
double prob;
scanf("%d... | 14 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000010], dp[1000010], res;
int n;
int main() {
ios ::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
unsigned long long t = 0;
if (i > 1)
(res += (dp[i - 1] ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, b[N];
long long ans = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
long long x;
scanf("%I64d", &x);
for (; x; x -= x & -x) b[i]++;
}
int cnt[2] = {1, 0};
long long s = 0;
for (int i = n; i >= 1; i--) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6e5 + 10, MAXM = 4e6 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const long long llINF = LLONG_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
int n, m;
int a[MAXN], q[MAXN];
int l[MAXN], r[MAXN];
int t[MAXN];
int block[MAXN];
int num[MAXN], cnt, tt;
s... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, d, days[223456], mx;
pair<int, int> a[223456];
queue<pair<int, int> > k;
bool cmp(int a, int b) { return a > b; }
priority_queue<int, vector<int>, decltype(&cmp)> zero(cmp);
int main() {
cin >> n >> m >> d;
for (int i = 0; i < n; i++) {
cin >> a[i].first;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
string S[50];
string gen(int i) {
char str[3];
str[2] = 0;
str[0] = 'A' + (i / 10);
str[1] = 'a' + (i % 10);
return string(str);
}
int main(int argc, char** argv) {
std::ios::sync_with_stdio(false);
cin >> N >> K;
for (int i = 0; i < N; i++) S[i] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, arr[2000], x = 0, wel;
bool b = true;
cin >> n;
for (i = 0; i < n; ++i) {
cin >> arr[i];
}
wel = arr[0];
while (wel != 0) {
wel++;
x++;
wel = wel % n;
}
for (i = 0; i < n; ++i) {
if (i % 2 == 0) {
arr[i] = (... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[502][502];
long long dp[2][502][502];
int cal(int i, int j, int k, int l) { return abs(i - k) + abs(j - l); }
long long solve(int n, int m) {
long long ret = (s[0][0] == s[n - 1][m - 1]);
dp[0][0][n - 1] = ret;
for (int i = 1; i < (n + m) / 2; i++) {
ret = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[100], b[100], n, m, i;
string s;
int main() {
scanf("%d", &n);
cin >> s;
for (i = 0; i < s.size() && m < n; i++) {
if (a[s[i]] == 0) {
a[s[i]] = 1;
b[m++] = i;
}
}
if (m == n) {
printf("YES");
} else {
printf("NO");
return 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool umin(T1& x, const T2& y) {
return (x > y ? (x = y, true) : false);
}
template <typename T1, typename T2>
bool umax(T1& x, const T2& y) {
return (x < y ? (x = y, true) : false);
}
template <typename T>
void read(T& x) {
char ch;... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
bool vis[N], g[N];
int f[N], a[N], ab;
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (vis[x])
g[x] = 1;
else {
vis[x] = 1;
f[x] = i;
}
}
for (int... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int s, f, c, r;
};
vector<node> vec[420];
pair<int, int> st[420];
int f[420][420];
int n, m, a[420], tops, mx[420][420];
long long ans;
int main() {
scanf("%d %d", &n, &m);
for (register int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (register int i =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
if (a % 5 != 0) {
cout << a / 5 + 1 << endl;
} else {
cout << a / 5 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b, c, i, j, n, m, temp;
cin >> n;
string s;
cin >> s;
for (i = 0; i < n; i++) {
if (s[i] == '0') {
a++;
}
}
if (a > n / 2) {
cout << 2 * a - n;
} else
cout << n - 2 * a;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2048;
const int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
int h, w;
bool ma3x[MAXN][MAXN];
bool a[MAXN][MAXN], b[MAXN][MAXN];
int num[MAXN][MAXN], color;
queue<pair<int, int> > q;
vector<int> vec;
void read() {
scan... | 15 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const double pi = acos(-1.0);
int n;
int x[2], y[2];
int color() {
return (min(x[0], x[1]) % 2 + 2) % 2 * 2 + (min(y[0], y[1]) % 2 + 2) % 2 + 1;
}
int main() {
cout << "YES\n";
cin >> n;
for (long long(i) = (0); (i) < (n); ++(i)) {
for (long... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int N = 100100;
int n = 11;
long long a[N];
long long suff[N];
multiset<long long> ms;
long long Solve(long long curr) {
long long to = (1ll << 40) - 1ll;
to ^= curr;
multiset<long long>::iterator l = ms.... | 14 |
#include <bits/stdc++.h>
using namespace std;
string s;
int sm, ff, ss, x;
int main() {
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '#') sm++;
if (s[i] == '(') ff++;
if (s[i] == ')') ss++;
if (ss + sm > ff) {
cout << -1;
return 0;
}
}
x = sm - 1;
if (ff <= ss || ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long mod2 = 1e9 + 9;
double eps = 1e-9;
int n, m;
const int size = 1e5 + 1;
int trip[size];
void clear_que(deque<pair<int, int> > &dq, int durat, int time) {
pair<int, int> last_removed;
while (1) {
last_removed = dq.front();
dq.pop... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 14;
int n, m, ans, dp[maxn][maxn];
string s, p;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m >> s >> p;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
dp[i][j] = max({0, dp[i - 1][j] - 1, dp[i][j - 1] - ... | 10 |
#include <bits/stdc++.h>
int main() {
char a[110];
gets(a);
int n = strlen(a), i, len = 0, u = 0, c = 0, d = 0;
for (i = 0; i < n; i++) {
if (n >= 5) len = 1;
if (a[i] >= 'A' && a[i] <= 'Z') u = 1;
if (a[i] >= 'a' && a[i] <= 'z') c = 1;
if (isdigit(a[i])) d = 1;
}
puts((len == 1 && u == 1 &&... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 505, maxm = 29;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m, c[maxn];
bitset<maxn> dp[maxn];
int main() {
int i, j;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) scanf("%d", c + i);
dp[0][0] = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500 * 1000 + 13;
int main() {
int q;
scanf("%d", &q);
vector<int> t(q), x(q), y(q);
for (int i = 0; i < q; ++i) {
scanf("%d%d", &t[i], &x[i]);
if (t[i] == 2) scanf("%d", &y[i]);
}
vector<int> p(N);
iota(p.begin(), p.end(), 0);
vector<in... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s = 1;
cin >> n;
int x = n * n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n / 2; j++) {
cout << s++ << " " << x-- << " ";
}
cout << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int c;
int n;
void fun(int x) {
if (x <= n) {
c++;
} else
return;
fun(10 * x + 0);
fun(10 * x + 1);
}
int main() {
cin >> n;
c = 0;
fun(1);
cout << c << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cout.tie(0);
cout.tie(0);
;
long long tt = 1;
while (tt--) {
long long n, m;
cin >> n >> m;
long long a[n];
long long c, ans = 0;
long long j = 0;
for (long long i = 0; i < n; i++) cin >> a[i];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s[2], d[2];
map<string, int> m;
void rec() {
if (m.find(s[0] + s[1]) != m.end()) {
if (m[s[0] + s[1]]) {
cout << "YES\n";
exit(0);
}
return;
}
m[s[0] + s[1]] = 0;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
if (s[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, multiset<int>> mp;
int k, n;
cin >> k >> n;
set<string> st;
for (int i = 0; i < k; ++i) {
string s;
int num;
cin >> s >> num;
string temp = s;
reverse(s.begin(), s.end());
if (temp < s)
st.insert(temp);
el... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
tuple<int, int, int, int> ar[N];
long long n, s, all, ost, sum;
long long check(long long h) {
long long a = h * s, rez = 0, tmp = ost;
for (int i = 0; i < n; ++i) {
long long need = get<1>(ar[i]);
if (a) {
if (get<0>(ar[i]) > 0 && t... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, a[1000009], b[1000009], p[1000009], ans, cn, t, x, y, z,
mx, mn, s, lo, hi, mid, cost, res, flag;
int main() {
while (scanf("%d %d %d", &n, &m, &x) != EOF) {
ans = x;
cost = 0;
for (i = 0; i < n; i++) {
scanf("%d", &b[i]);
}... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
int ans[1000010];
int main() {
scanf("%d", &n);
int now = 1;
if (n & 1) now = 2;
for (int i = 1; now <= n; i++, now += 2) {
int dis = n - now;
ans[i] = ans[i + dis] = now;
}
if (now & 1)
now = 2;
else
now = 1;
for (int i = (now == 1) ?... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[100005];
int x = 0, y = 0, count = 0;
bool wallA = false, wallB = false, checked = false;
cin >> n;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'U')
y++;
else if (s[i] == 'R')
x++;
if (x != y) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef TUAN_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
if (fabs(d) < eps) return 0;
return d > eps ? 1 : -1;
}
const int state = 1111;
const int child = 55;
struct acauto {
int ac[state][child];
int fail[state], flag[state], top;
int w[128];... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long int l, r;
cin >> l >> r;
if (l <= r / 2) {
cout << r % (r / 2 + 1) << '\n';
} else {
cout << r % l << '\n';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100500;
const int MaxP = 9632;
const int MaxK = 6;
const int MaxM = MaxP * MaxK;
bool fd[MaxN];
int p[MaxP], pn;
int mp[MaxK][MaxK];
int res[MaxN];
int N, K;
struct Node {
int cnt;
Node* next[10];
} memo[MaxM], *cur, *root;
Node* new_node() {
cur->cnt... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100010;
int n;
pair<int, int> p[2][M];
int maxp[M], maxs[M], minp[M], mins[M];
inline long long s(long long x) { return x * x; }
inline long long g(int x) {
for (int i = 1; i <= n; ++i) {
maxp[i] = max(maxp[i - 1], p[x][i].second);
minp[i] = min(minp... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long ans[505];
int main() {
long long n, a, b;
cin >> n >> a >> b;
ans[1] = 1;
long long sum = 1, c = 1, ma = 50000;
for (int i = 2; i <= n; i++) {
if (b > 0) {
b--;
c = sum + 1;
} else if (a > 0) {
if (c + 1 > sum) {
} else {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
bool ckmin(T &a, U b) {
return b < a ? a = b, true : false;
}
template <typename T, typename U>
bool ckmax(T &a, U b) {
return b > a ? a = b, true : false;
}
int n, rt, tot = 0;
multiset<int, greater<int>> st;
vector<int> res, size;
vec... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &u) {
u = 0;
char c = getchar();
long long flag = 0;
while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
u = (u << 3) + (u << 1) + (c ^ 48), c = getchar();
if (flag) u = -u;
}
bool checkmi... | 15 |
#include <bits/stdc++.h>
using namespace std;
int checkVowel(char s) {
string v = "aeiou";
for (int i = 0; i < 5; i++) {
if (s == v[i]) {
return 1;
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.si... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline", \
"03")
const int maxn = 110;
const int mod = 1000000007;
const int mod2 = 998244353;
const double eps = 1e-9;
long long qpow(long long b, int e) {
if (!e) return 1;
if (e... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
long long int i, n, f = 0;
cin >> n;
string a[n], k;
for (i = 0; i < n; i++) cin >> a[i];
;
for (i = 0; i < n; i++) {
if (a[i][0] == 'O' && a[i][1] == 'O') {
a[i][1] = '+';
a[i][0] = ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int a[100005];
inline int read() {
int x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0',... | 23 |
#include <bits/stdc++.h>
using namespace std;
int segmented_tree_max[100001 * 17], segmented_tree_min[100001 * 17],
lazy[100001 * 17];
int a[100001], n, q;
vector<pair<int, int> > apl;
vector<int> updator_apl[100001 + 1], updator_remove[100001 + 1];
void bulid(int id = 1, int l = 0, int r = n) {
if (r - l < 2) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
cin >> test;
while (test--) {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
vector<int> temp;
int flag = 1;
set<int> s;
for (int i = 0; i < ... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return x + FIXED_RANDOM;
}
};
int pw[300005];
int hs[300005];
set<int> lens;
unordered_map<int, int, c... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct triplet {
int x, y, z;
};
bool cmp(triplet &a, triplet &b) {
if (a.x > b.x) return true;
if (a.x < b.x) return false;
if (a.y < b.y) return true;
return false;
}
bool in_parl(int idx, vector<triplet> v, int seats, int votes) {
v[idx].x += votes;
if (v[i... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
int main() {
int n, a, b;
cin >> n;
vector<pair<int, int>> v;
int t = 0;
for (int i = 0; i < n; i++) {
cin >> a >> b;
t += b;
v.push_back({a, b});
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int f[105][105], n, k, m, maxn, p[105], sum, ss, ans;
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) scanf("%d", &f[i][j]);
if (m <= k && n <= k) {
ans = k + 1;
for (int ii = (1 << m) - 1; ii >= 0; ii--) {... | 14 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vi = vector<lli>;
using pii = pair<lli, lli>;
using vvi = vector<vi>;
using vii = vector<pii>;
using vvii = vector<vii>;
template <class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& v) {
return s << '(' << get<0>(v) << ','... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.