solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int L[30][200000 + 5], R[30][200000 + 5];
bool binary_search(int n, int pos) {
if (!L[n][0]) return false;
int l = 1, r = L[n][0];
while (l <= r) {
int m = (l + r) / 2;
if (pos >= L[n][m] && pos <= R[n][m]) return true;
if (pos > R[n][m])
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
stack<int> monostack;
int i, ans = 0;
while (cin >> i) {
while (!monostack.empty() && i > monostack.top()) {
ans = max(ans, monostack.top() ^ i);
monostack.pop();
}
if (!monostack.empty()) {
if (i == mono... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n;
cin >> n >> k;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> cnt(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j + k <= n) {
bool can = t... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100000 + 5;
const double eps = 1e-7;
inline long long dcmp(double x) { return abs(x) < eps ? 0 : (x > 0 ? 1 : -1); }
struct Line {
long long A, B, C;
inline bool onLine(double x, double y) {
return dcmp(A * x + B * y + C) == 0;
}
} line[maxn... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[10], ta[10];
int b[10];
int pm[200010], tt = 0;
bool v[1000010];
inline void GetPrime(int m) {
for (int i = 2; i <= m; ++i) {
if (!v[i]) pm[++tt] = i;
for (int j = 1; j <= tt && i * pm[j] <= m; ++j) {
v[i * pm[j]] = 1;
if (i % pm[... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int minx, maxx, miny, maxy;
minx = miny = 10000009;
maxx = maxy = -10000009;
int i, n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
minx = min(x + y, minx);
miny = min(x - y, miny);
maxx = max(x + y... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
int get(int n) {
int r = 0;
while (n) {
r += n % 10;
n /= 10;
}
return r;
}
int main() {
int n;
cin >> n;
set<int> r;
f... | 4 |
#include <bits/stdc++.h>
const long double eps = 1e-9;
const double pi = acos(-1.0);
const long long inf = 1e18;
using namespace std;
int n, a[5], b[5], sum = 0, ans = 0;
void action1() {
int num = a[1] / 3;
ans += 2 * num;
a[1] -= 3 * num;
a[3] += num;
}
void action2() {
int num = a[2] / 3;
ans += 2 * num;... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
multiset<int> g[N];
vector<int> cycle, odd;
inline void dfs(const int &v) {
while (g[v].size()) {
auto to = *g[v].begin();
g[v].erase(g[v].begin());
g[to].erase(g[to].find(v));
dfs(to);
}
cycle.push_back(v);
}
int main() {
io... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
int x, w;
};
node p[204857];
inline bool cmp(node a, node b) { return a.x < b.x; }
set<int> dp;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].w);
sort(p, p + n, cmp);
for (int i = 0; i < n; i++) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long s[100000];
long long n, k, a, b;
int g1(int st, int end, long long x) {
if (st > end) return -1;
int mid = (st + end) / 2;
if (s[mid] >= x) {
int lans = g1(st, mid - 1, x);
if (lans == -1) return mid;
return lans;
}
return g1(mid + 1, end, x)... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 202;
int n, m;
int a[maxN][maxN];
int adj[maxN], deg[maxN];
bool marked[maxN];
vector<int> odd, EC;
stack<int> S;
void DFS(int u) {
marked[u] = true;
if (deg[u] & 1) odd.push_back(u);
for (int v = 1; v <= n; ++v)
if (a[u][v] == 1 && !marked[v]) DF... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4;
int T, n;
int c[N];
deque<int> q;
int main() {
for (int i = 0; i < N; i++) {
scanf("%d", c + i);
n += c[i];
}
if (c[0])
q.push_back(0), c[0]--;
else if (c[1])
q.push_back(1), c[1]--;
else if (c[2])
q.push_back(2), c[2]--;
els... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long int d[maxn];
long long int n;
long long int a, S;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a;
for (int i = 0; i < n; i++) {
cin >> d[i];
S += d[i];
}
for (int i = 0; i < n; i++) {
lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
int r, c;
string str[555];
int dr[] = {1, -1, 0, 0};
int dc[] = {0, 0, 1, -1};
bool valid(int a, int b) {
if (a >= 0 and a < r and b >= 0 and b < c) return true;
return false;
}
int main(int argc, char const *argv[]) {
cin >> r >> c;
for (int i = 0; i < r; i++) cin ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 20;
int n, m, star;
char a[N][N];
int dx[] = {+1, -1, 0, 0};
int dy[] = {0, 0, +1, -1};
bool invalid(int x, int y) {
return min(x, y) < 0 or x >= n or y >= m or a[x][y] == '.';
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
bool a[n][m];
for (long long i = 0; i < n; ++i) {
for (long long j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
long long ans = 0;
for (long long i = 0; i < n; ++i) {
long long c0 = 0, c1 = 0;
for (lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
vector<vector<pair<int, int>>> adj;
vector<bool> vis;
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
inline long long int mexp(long long int x, long long i... | 8 |
#include <bits/stdc++.h>
#define nl '\n'
#define pb push_back
#define ll long long
#define VMAX 100001
#define NMAX 35005
#define INF 10000000000000000
using namespace std;
ifstream f("pirati.in");
ofstream g("pirati.out");
const int MOD=1000000007;
int n;
ll dp[205][205];
int dist[205][205];
long long lgpow(ll a,ll b... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int tc;
scanf("%lld", &tc);
while (tc--) {
long long int n, m, sum = 0, fst = 0;
scanf("%lld%lld", &n, &m);
for (long long int i = 0; i < n; i++) {
long long int a;
scanf("%lld", &a);
if (i == 0)
fst = a;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int i, k, b;
} st[200005];
vector<P> v[200005];
int read();
int gcd(int a, int b) {
while (b ^= a ^= b ^= a %= b)
;
return a;
}
bool check(int k1, int b1, int k2, int b2) {
if (k1 == k2) return b1 == b2;
return (b2 - b1) % gcd(k1, k2) == 0;
}
int ma... | 20 |
#include <bits/stdc++.h>
using namespace std;
bool myAssert(bool b);
void testDrivenDevelopment();
int start(int argc = 0, char const *argv[] = NULL);
int n, m;
vector<int> *g;
bool *isvisited;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int *a;
lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a[maxn];
bool eq[maxn];
int cnt[maxn], tmp[maxn];
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int odd = 0;
memset(cnt, 0, sizeof(cnt));
for (int i = 1; i <= n; i++) cnt... | 17 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
long long l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
if (l1 > l2) swap(l1, l2), swap(r1, r2);
long lon... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
while (n--) {
long long q;
scanf("%lld", &q);
int a, b;
scanf("%d%d", &a, &b);
double ap = 1.0 * a / 1, bp = 1.0 * b / 2;
if (q % 2 == 0) {
if (ap >= bp)
printf("%lld\n", q / 2 * b);
else... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void no() {
cout << -1 << endl;
exit(0);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
if (m == 0) no();
vector<set<int>> g(n);
vector<int> s;
for (int i = 0; i < m; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> c(n, 0);
for (int i = 0; i <= n - 1; i++) cin >> a[i];
pair<int, int> mi;
pair<int, int> ma;
mi.first = a[0];
mi.second = 0;
ma... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e14;
class min_cost_flow {
private:
int N;
struct edge {
int to;
long long cap, cost;
int rev;
};
vector<vector<edge>> G;
vector<long long> h, dist, prevv, preve;
public:
min_cost_flow(int n) {
N = n;
G = vector<vect... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int SZ1 = 35001, SZ2 = 51;
int a[SZ1], cn[SZ1], dp[SZ2][SZ1];
int cl, cr, f;
void clr() {
fill(cn, cn + SZ1, 0);
f = cl = 0;
cr = -1;
}
void add(int i) { f += (int)(cn[a[i]]++ == 0); }
void del(int i) { f -= (int)(--cn[a[i]] == 0); }
void up... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long k[50000], ans = 0, avg = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < (n); ++i) {
cin >> k[i];
avg += k[i];
}
avg /= n;
for (int i = 0; i < (n); ++i) {
ans += abs(k[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int v[200010], n, k;
class C_AIB {
private:
int aib[200010];
int v[200010];
public:
C_AIB() {
for (int i = 1; i <= n; ++i) aib[i] = v[i] = 0;
}
int maxx;
int query(int pos) {
int res = 0;
for (; pos > 0; pos -= (pos & (-pos))) res += aib[pos];
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dp[55][55][55];
pair<long long, long long> power[55];
bool ok(long long threshold, int n) {
for (int i = 0; i < 55; i++)
for (int j = 0; j < 55; j++)
for (int k = 0; k < 55; k++) dp[i][j][k] = 1000000000000000000LL;
dp[0][0][0] = 0;
for (int i = 0;... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int mx = 1e3 + 1;
short dp[mx][101][101][2][2], n, p;
string s, ans;
short rec(int pos, int last, int prev_last, int pal, int big) {
if (pos == n) {
return pal == 0 && big;
}
auto &ret = dp[pos][last][prev_last][pal][big];
if (~re... | 9 |
#include <bits/stdc++.h>
using ll = long long;
const ll modp = 998244353;
const int N = 1010;
using namespace std;
struct Mat {
int n, m;
ll data[64][64];
inline ll *operator[](int x) { return data[x]; }
inline const ll *operator[](int x) const { return data[x]; }
Mat() : n(64), m(64) {
for (int i = 0; i ... | 19 |
#include <bits/stdc++.h>
int value(int boy, int girl, int game) {
int b;
int r;
int sum;
b = 0;
r = 0;
sum = 0;
while (b <= boy) {
while (r <= girl) {
if (b + r == game)
sum++;
else if (b + r > game)
break;
r++;
}
r = 0;
b++;
}
return (sum);
}
int main... | 3 |
#include <bits/stdc++.h>
using namespace std;
char f(char c) {
if (c == 'a' || c == 'e' || c == 'u' || c == 'o' || c == 'i')
return '>';
else
return '<';
}
int main() {
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); i++) s[i] = f(s[i]);
for (int i = 0; i < t.size(); i++) t[i] = f(t[i]);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 36) {
cout << -1;
} else {
while (n > 0) {
if (n == 1) {
cout << 4;
n--;
} else {
cout << 8;
n -= 2;
}
}
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mn, mx, mn2 = 105, mx2 = 0;
int a[110];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> mn >> mx;
for (int i = 0; i < m; i++) {
cin >> a[i];
if (a[i] < mn2) mn2 = a[i];
if (a[i] > mx2) mx2 = a[i];
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int readint() {
int x = 0;
bool f = 0;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return f ? -x : x;
}
const ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, ma;
double val[105];
int he[105], ne[105 * 105], to[105 * 105], w[105 * 105], c[105 * 105], tot = 1;
inline void addedge(int x, int y, int z, int co) {
to[++tot] = y;
ne[tot] = he[x];
he[x] = tot;
w[tot] = z;
c[tot] = co;
to[++tot] = x;
ne[tot] = ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000 + 100;
int n, m, ans = 0;
int a[MAXN];
int nxt[MAXN], pos[MAXN];
void init() {
for (int i = 1; i <= n; i++) pos[i] = n + 1;
for (int i = n; i >= 1; i--) nxt[i] = pos[a[i]], pos[a[i]] = i;
}
bool have[MAXN];
int next[MAXN];
set<pair<int, int> > S... | 10 |
#include <bits/stdc++.h>
using namespace std;
string st;
long n, s[200000][3], ap, av;
bool nice(string st) {
long s1, s2;
s1 = s2 = 0;
for (int i = 0; i < st.size(); i++)
if (st[i] == '4')
++s1;
else if (st[i] == '7')
++s2;
if (s1 == s2 && s1 + s2 == st.size()) return true;
return false;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, k, k1, c = 20, c1 = 50, c2 = 120;
cin >> n;
long long a[n], dp[n];
dp[0] = 20;
cin >> a[0];
cout << dp[0] << endl;
for (i = 1; i < n; i++) {
cin >> a[i];
k = upper_bound(a, a + i + 1, a[i] - 90) - a;
k1 = upper_bound... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[15][15], n, m, a1, a2, g[15][15][1 << 15], f[1 << 15],
las[15][15][1 << 15], pre[1 << 15], cur, tmp;
int now, inv, cnt;
pair<int, int> lap[1 << 15];
int gets() {
int v = 0;
char ch;
bool f = 0;
while (!isdigit(ch = getchar()))
if (ch == '-') f = 1;
v... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
const int INF = (1 << 29);
const double EPS = 1e-13;
const double Pi = acos(-1.0);
int n, m;
long long f[maxn], b[maxn], F[maxn];
long long a[maxn];
int main() {
while (cin >> n >> m) {
memset(F, -1, sizeof(F));
for (int i = 1; i <= n; i+... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 10;
set<pair<int, int> > st;
int n, k, q, t[N];
int main() {
cin >> n >> k >> q;
for (int i = 0; i < n; ++i) cin >> t[i];
while (q--) {
int type, id;
cin >> type >> id;
id--;
if (type == 1) {
if (st.size() < k)
st... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, i, g[120000], tree[120000], ans, s[120000];
long long sum[120000], f[120000], b;
long long back(int x) {
long long ans = 0;
while (x > 0) {
ans += sum[x];
x -= x & (-x);
}
return ans;
}
void add(int x, long long p) {
while (x <= n) {
sum[x] +... | 9 |
#include <bits/stdc++.h>
using namespace std;
int vst[1 << 23];
int arr[30];
int n, mn = 30;
void rec(int mask, int ind) {
if (vst[mask] || __builtin_popcount(mask) >= mn) {
return;
}
vst[mask] = 1;
if (ind == n) {
mn = min(mn, __builtin_popcount(mask));
return;
}
int m = mask | (1 << ind), i, j... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool Solve(long long start, long long n, long long d,
const vector<long long>& a, const vector<long long>& x,
const vector<long long>& y) {
vector<long long> kyanq(n, -1);
kyanq[0] = start;
do {
long long maxim = -1, ansI = -1, ansJ = -1;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
const long long linf = (long long)1e18 + 10;
class segments_tree {
private:
int l, r;
pair<int, int> mx;
segments_tree *left, *right;
public:
segments_tree(int l, int r) : l(l), r(r) {
mx = make_pair(0, -1);
left = right = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
long long T;
string str;
bool flag = true;
T = 1;
while (T--) {
long long n, i, j, k, s = 0, ans = 0, p = 1, x, y, z, a, b, c1 = 0, c2 = 0;
cin >> n;
if (n % 10 == 0) {
cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline string to_str(const _T& a) {
ostringstream os("");
os << a;
return os.str();
}
int main() {
int p, n;
scanf("%d %d", &p, &n);
set<int> s;
bool conflict = false;
int i = 1;
for (; i <= n; ++i) {
int t;
scanf("%d", &t);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define INP(arr,n) for(int a=0;a<n;a++)cin>>arr[a]
#define OTP(arr,n) for(int a=0;a<n;a++)cout<<arr[a]<<" "
#define ll long long int
#define pb(v,a) v.push_back(a)
int main() {
IOS;int t=0;cin>>t;
while(t--) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const double PI = 3.14159265359;
enum dir {
DOWN = 0,
UP,
RIGHT,
LEFT,
DOWN_RIGHT,
DOWN_LEFT,
UP_RIGHT,
UP_LEFT
};
int dir_r[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dir_c[] = {0, 0, 1, -1, 1, -1, 1, -1};
bool vis[100000];
vector<vector... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000;
int N, Q;
int V[MAXN + 10], C[MAXN + 10];
long long A, B;
long long dp[MAXN + 10];
const long long INF = numeric_limits<long long>::max();
long long calc_dp() {
for (int c = 1; c <= N; c++) {
dp[c] = -INF;
}
dp[0] = 0;
int mc[2] = {0... | 12 |
#include <bits/stdc++.h>
using namespace std;
int g[6][6];
int num[5] = {0, 1, 2, 3, 4};
int sum(int x, int y) { return g[num[x]][num[y]] + g[num[y]][num[x]]; }
int main() {
int i, j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
scanf("%d", &g[i][j]);
}
}
int ans = -1;
do {
ans = max(... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
long long dx[4] = {-1, 0, 0, +1};
long long dy[4] = {0, -1, +1, 0};
const long long LINF = 1e18;
const ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const long long MOD = 1000000007;
struct Seg_tree {
int left, right;
long long lazy, sum[6];
} T[N << 2];
int n, q, a[N];
long long i_pow_j[N][6];
long long sum[N][6] = {0};
long long C[6][6];
long long s[N][6];
void Init() {
for (int i = 0; i < ... | 17 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, x, y;
cin >> n >> x >> y;
string s;
cin >> s;
long long ans = 0, a = 0, b = 0;
reverse(s.begin(), s.end());
cerr << s << endl;
for (long long i = 0; i < y; i++) {
if (s[i] == '1') {
ans++;
}
}
cerr << ans;
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const* argv[]) {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int& i : v) {
cin >> i;
}
int res = 0, f = 0;
for (int i = 1; i < n; ++i) {
while (v[i]) {
k -= i;
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans, sx, sy;
int X[MAXN], Y[MAXN];
long ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int a, b, m, n, i, j, k, l, cnt = 0, ans, Min;
char c[113];
cin >> n;
for (i = 1; i <= n; i++) {
cin >> c[i];
if (c[i] == '8') {
cnt++;
}
}
ans = n / 11;
Min = min(ans, cnt);
cout << Min << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
const int mod = 998244353;
int n, m;
int s[100100][3];
int p[3];
int r[1 << 17];
int c[3][1 << 17];
long long int pow(int x, int y) {
if (y == 0) return 1;
long long int r = pow(x, y / 2);
r *= r;
r %= mod;
if (y % 2 == 1) {
r *= x;
r %= mod;
}
return r;
}
void conv(int s,... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5 + 10;
int n, k;
char s[N];
int sumdigit;
long long fac[N], inv[N], facinv[N];
long long pow_mod(long long a, long long b, long long p) {
long long t = 1;
for (; b; b >>= 1, a = a * a % p)
if (b & 1) t = t * a % p;
r... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int N, M, Q, to[maxn], w[maxn], delta[maxn];
long long dis[maxn];
vector<int> g[maxn];
queue<int> q[maxn];
inline void init() {
memset(dis, 0x3f, sizeof dis);
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
gr... | 26 |
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
unsigned long long MOD = int(1e9 + 7);
int n, l;
unsigned long long dp[(int)(4e3 + 5)][(int)(2e2 + 5)];
int a[(int)(2e2 + 5)], b[(int)(2e2 + 5)];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l;
memset(dp, 0, sizeof(... | 10 |
#include <bits/stdc++.h>
using namespace std;
const string notes[12] = {"C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "B", "H"};
bool strange = 1;
void print(string *given) {
int s1 = 0, s2 = 0, s3 = 0;
int ss1 = 0, ss2 = 0;
while (given[0] != notes[s1]) {
s1++;
}
whi... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mod;
int f[100010];
int find(int x) { return (x == f[x] ? x : f[x] = find(f[x])); }
int siz[100010];
bool vis[100010];
int power(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b = b >> 1;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int c = 1, a[200005], l[200005], r[200005], f[500005], g[500005], h[200005],
o[200005];
char *s[200005], t[200005];
vector<int> e[200005];
struct bxt {
int t[26], f;
} b[200005];
inline void insert(int u) {
int v = 1;
for (char *i = s[u]; *i; ++i) {
if (b[v].t... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<int> x[1001];
string name[1001];
char s[1001];
void dfs(int &n, int &i) {
int nn = n;
string tmp;
while (1) {
if (s[i] >= 'A' && s[i] <= 'Z') {
tmp += s[i];
i++;
} else {
if (s[i] == ',' || s[i] == ':') {
n++;
i++;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<long long, long long>> coll(n);
for (int i = 0; i < n; i++) cin >> coll[i].first >> coll[i].second;
long long ans = 0;
for (int i = 0; i < n; i++) {
if (i == 0)
ans++;
else if (i == n - 1)
ans++;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
static bool constexpr dbg = 0;
ll constexpr NM = 2.1e5;
ll n, res;
struct N {
ll vis, sum, a;
N *nx;
};
N pos[NM], neg[NM];
ll a[NM];
ll cvis;
void dfs(N *p) {
if (p->vis == cvis) {
p->sum = -1;
return;
} else ... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e5 + 15;
const unsigned long long num = ULLONG_MAX;
unsigned long long pw[64];
inline void calc() {
pw[0] = 1;
for (int i = 1; i < 64; ++i) {
pw[i] = pw[i - 1] << 1;
}
}
unsigned lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[";
for (auto vv :... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int K = 110;
const int N = 100010;
const int M = 1000000007;
int x, t, a, b, da, db;
int main() {
ios::sync_with_stdio(0);
cin >> x >> t >> a >> b >> da >> db;
for (int s1 = 0; s1 < 2; ++s1)
for (int s2 = 0; s2 < 2; ++s2)
for (int i = 0; i < t; ++i)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<string> se;
int main() {
int n;
string s;
cin >> n;
while (n--) {
cin >> s;
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
se.insert(s);
}
cout << se.size();
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
string strs[202];
bool pref[102];
bool sref[102];
int sla, slb;
string fullstr;
bool check() {
memset(pref, 0, sizeof(pref));
memset(sref, 0, sizeof(sref));
for (int i = 0; i < 2 * n - 2; i++) {
string& custr = strs[i];
size_t slen = custr.length();
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, dp[10007][4];
set<string> S;
string str;
int rec(int pos, int prev, string back) {
if (pos == n && prev != n - 1) return 1;
int &ret = dp[pos][pos - prev];
if (ret != -1) return ret;
int now1 = 0, now2 = 0, now3 = 0;
string st;
if (pos + 2 <= n) {
st ... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC optimization("O3")
using namespace std;
const unsigned long long mod = 1000000007;
const long long inf = ((1ll << 31ll) - 1ll);
const long long INF = (((1ll << 59ll) - 1ll) * 2ll) + 1ll;
const long double ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int fir[N], to[N * 2], nxt[N * 2], ecnt;
void add_edge(int u, int v) {
to[++ecnt] = v;
nxt[ecnt] = fir[u];
fir[u] = ecnt;
}
int dep[N];
void dfs(int node, int fa) {
dep[node] = dep[fa] + 1;
for (int e = fir[node]; e; e = nxt[e]) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
long long fac[1000000];
long long invfac[1000000];
long long powermod(long long b, long long p) {
if (p == 0) return 1;
long long x = powermod(b, p / 2);
x = (x * x) % M;
return (p % 2 == 1 ? b * x : x) % M;
}
long long inv(long long x) { retu... | 14 |
#include <bits/stdc++.h>
char local = 'O';
using namespace std;
int main() {
long long n;
cin >> n;
string s = "abcd";
for (long long i = 0; i < n; i++) cout << s[i % 4];
cout << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k;
cin >> k;
int a[n];
int s = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++)
if (a[i] >= a[k - 1] && a[i] > 0) {
s++;
}
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x = 0;
int main() {
cin >> n >> m;
int a = m / n, ans = 0;
if (a * n != m) {
cout << -1;
return 0;
}
if (a == 1) {
cout << 0;
return 0;
}
for (int i = 2; i <= 3; i++) {
while (a % i == 0) {
a /= i;
ans++;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long maxm = 0;
long long nmbr = INT_MAX;
map<long long, bool> vstd;
class graph {
public:
map<long long, list<pair<long long, long long>>> adj;
void input(long long n) {
long long x, y, z;
for (long long i = 1; i < n; i++) {
cin >> x >> y >> z;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool check(int mask, int pos) { return mask & (1 << pos); }
int SET(int mask, int pos) { return mask | (1 << pos); }
int FLIP(int mask, int pos) { return mask ^ (1 << pos); }
string to_binary(int mask) {
string str;
fo... | 14 |
#include <bits/stdc++.h>
int main() {
int d1, d2, d3, sum;
scanf("%d%d%d", &d1, &d2, &d3);
if (d1 + d2 < d3) {
sum = 2 * (d1 + d2);
} else if (d2 + d3 < d1) {
sum = 2 * (d2 + d3);
} else if (d1 + d3 < d2) {
sum = 2 * (d1 + d3);
} else {
sum = d1 + d2 + d3;
}
printf("%d", sum);
return 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int tr, dw, q, cnt;
int main() {
cin >> tr >> dw >> q;
while (dw < tr) {
dw *= q;
cnt++;
}
cout << cnt;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 11;
long long val[N], p[N];
long long pwr(int b, int p) {
if (!p) return 1;
long long ans = pwr(b, p >> 1);
ans = ans * ans % 1000003;
if (p & 1) ans = ans * b % 1000003;
return ans;
}
int Li(int i, long long x) {
int ans = p[i];
for (int j = 0; ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
long long b[a.size() + 1];
b[0] = 0;
b[1] = 0;
char c = a[0];
int m;
for (int i = 0; i <= (a.size() - 2); i++) {
if (a[i] == a[i + 1])
b[i + 2] = b[i + 1] + 1;
else
b[i + 2] = b[i + 1];
}
cin >> m;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int const N = 600010;
char in[N];
int vis[N], n, k;
bool can = false;
int maior = 0;
int solve(int i) {
if (i >= n) return 0;
if (i == n - 1)
can = true;
else {
for (int j = maior + 1; j <= i + k; j++) {
maior = max(maior, i + k);
if (in[j] == '.' ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
for (int z = 0; z < T; z++) {
int a[3];
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
sort(a, a + 3);
cout << a[2] << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::sort;
using s... | 19 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) {
return a;
}
int g = gcd(b, a % b);
return g;
}
int main() {
int t = 1;
cin >> t;
while (t--) {
int n, k;
scanf("%d %d", &n, &k);
int a[n];
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a +... | 6 |
#include <bits/stdc++.h>
using namespace std;
namespace mod {
long long const modul = 1000000009;
long long sum(long long x, long long y) { return (x + y) % modul; }
long long sub(long long x, long long y) {
if (x > y) {
return (x - y) % modul;
} else {
return (modul + x - y) % modul;
}
}
long long mpl(lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500009;
vector<int> e[maxn], f;
int n, a, b, ans, root;
void dfs(int u, int fa, int dep) {
if (e[u].size() == 1) {
f.push_back(dep);
return;
}
for (int i = 0; i < e[u].size(); i++)
if (e[u][i] != fa) dfs(e[u][i], u, dep + 1);
}
int main() ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long sy, a, b;
int n;
long long L[200005], R[200005];
long long smt[800005];
long long x, y;
void build(int idx, int l, int r) {
if (l == r) {
smt[idx] = R[l] - L[l];
return;
}
int m = (l + r) / 2;
build(idx << 1, l, m);
build(idx << 1 | 1, m + 1, r);... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const int mod = 1e9 + 7;
int CASE = 1;
const int mxn = 1e4;
const long long infll = 1e18;
const int infi = 1e9;
bool prime(long long n) {
if (n <= 1) return false;
if (n == 2 or n == 3) return true;
if (n % 2 == 0 or n % 3 == ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[1000001];
int main() {
int n, q, r, pos1 = 1, pos2 = 2, s;
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++) a[i] = 0;
for (int i = 0; i < q; i++) {
scanf("%d", &s);
if (s == 1) {
scanf("%d", &r);
if (r > 0) {
pos1 = (pos1 + r) %... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
if (s1.size() != s2.size()) {
cout << "NO";
return 0;
}
int f = 0, s = 0;
for (char a : s1)
if (a == '1') ++f;
for (char a : s2)
if (a == '1') ++s;
if (f > 0 && s > 0) {
cout << "YES\n";
} el... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.