solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
vector<string> s(h);
for (int i = 0; i < h; i++) {
cin >> s[i];
}
int ans = (s[0][0] == '*');
int i = 0;
int j = 0;
while (i < h - 1 || j < w - 1) {
if (j == w -... | 10 |
#include <bits/stdc++.h>
using namespace std;
int arr[100000];
int main() {
int k, l, m, n, d, i, c = 0;
cin >> k >> l >> m >> n >> d;
for (i = 1; i <= d; i++) {
if ((k * i) > d) {
break;
} else {
int s = k * i;
arr[s] = 1;
}
}
for (i = 1; i <= d; i++) {
if ((l * i) > d) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int solve(void) {
int n; cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
if (arr[0] == arr[1] && arr[0] != arr[2])
return (3);
if (arr[0] == arr[2] && arr[0] != arr[1])
return (2);
if (arr[1] == arr[2] && arr[0] != arr[1])
return (1);
for ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, ans = 0, power = 10;
cin >> n;
for (long long i = 1;; i++) {
if (n >= power) {
ans += power / 10 * 9 * i;
} else {
long long num = n - power / 10 + 1;
ans += num * i;
break;
}
power *= 10;
}
cout <<... | 4 |
#include <bits/stdc++.h>
int min(int a, int b) { return a < b ? a : b; }
int aa[1000000], n;
int kk[1000000];
long long bb[1000000], qq[1000000];
int solve(long long b) {
int i, j, k_;
long long a;
a = 0;
k_ = n;
for (i = 0, j = 0; j < n; j++) {
long long q;
a += aa[j];
while (a > b) a -= aa[i++];... | 16 |
#include<iostream>
#include<cstdio>
#define Maxn 300005
using namespace std;
int a[Maxn],t[Maxn],c[Maxn],l[Maxn],r[Maxn];
const int Max=1e9+1e6;
inline int read()
{
char c=getchar(); int x=0;
while(c<48) c=getchar();
while(c>47) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x;
}
int main()
{
int T=read();
for(int t... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <class T>
inline bool ckmin(T &a, T b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool ckmax(T &a, T b) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int tot = a + b + 1;
for (int g = tot - a; g <= tot; g++) cout << g << " ";
for (int g = b; g >= 1; g--) cout << g << " ";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
int a, b;
cin >> a >> b;
long long total = 1;
while (1) {
if (total <= a) {
a -= total;
total++;
} else {
cout << "Vladik";
return 0;
}
if (total <= b) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, maxr = INT_MIN, maxc = INT_MIN, minr = INT_MAX, minc = INT_MAX,
c = 0;
cin >> n >> m;
char a[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
if (a[i][j] == 'B') {
c++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ps(long long s) {
double t = sqrt((double)s);
for (long long i = (long long)t + 2; i >= t - 2; i--)
if (i * i <= s) return (i + 1);
return (0);
}
long long ct(long long start, long long end) {
if (end < start) return (0);
if (start < 0) start = 0;
... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
const int MOD = 786433;
const int INF = 1000000001;
const int MAXN = 400;
const long double EPS = 1e-11;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
using namespace std;
double workTime() { return double(clock()) / CLOCKS_PER_SEC; }
voi... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool vis[11];
int con[11];
struct Point {
int x, y;
Point() {}
Point(int a, int b) {
x = a;
y = b;
}
} pR[11], pB[11];
bool judge(Point &a, Point &b, Point &c, Point &d) {
if (!(min(a.x, b.x) <= max(c.x, d.x) && min(c.y, d.y) <= max(a.y, b.y) &&
mi... | 8 |
#include <bits/stdc++.h>
static long long gcd(long long x, long long y) {
return y == 0 ? x : gcd(y, x % y);
}
static long long pwm(long long x, long long n, long long m) {
long long r = 1;
while (n) {
if (n & 1) r = r * x % m;
x = x * x % m;
n >>= 1;
}
return r;
}
const int maxn = 105;
int n, K, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, i, j, idx, ex, c;
cin >> n >> t;
int b[66];
for (i = 0; i < 66; i++) b[i] = 0;
int nb = n * (n + 1) / 2;
while (t > 0) {
b[0] += 1024;
for (i = 0; i < n; i++)
for (j = 0; j < i + 1; j++) {
idx = i * (i + 1) / 2 + j;
... | 7 |
#include <bits/stdc++.h>
int main() {
double a, b;
scanf("%lf%lf", &a, &b);
double res = 0.0;
double tmp;
bool find = false;
int i = int(a / b - 1);
if (i % 2 == 1) i--;
if (i >= 2) {
tmp = (a - b) / (double)i;
if (tmp > 0) {
res = tmp;
find = true;
}
}
i = int(a / b);
if (... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long x, k;
int tot, tot2;
long long a[22222];
int b[22222];
long long ans[111111];
void fillnum(long long n, long long m) {
if (tot2 > 100000) return;
if (n == 0) {
ans[tot2] = 1;
tot2++;
} else if (b[n] == 0) {
for (int i = 1; i <= m; i++) {
an... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
int KingX[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int KingY[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int KnightX[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int KnightY[] = {-1, 1, -2, 2, -2, 2, -1, 1};
template <class T>
inline T ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int games[60][60];
int winsto[60][60];
bool getsToWinTo(int i, int j) {
for (int ii = 1; ii <= 60; ii++) {
if (winsto[i][ii] && winsto[ii][j]) return true;
}
return false;
}
int main() {
int n;
cin >> n;
int a, b;
memset(games, 0, sizeof(games));
int t =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);
double ABS(double x) { return x > 0 ? x : -x; }
int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
struct Point {
double x, y;
void put() { printf("(%.0lf,%.0lf)\n"... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct query {
int l, r, id;
query() : l(0), r(0), id(0){};
query(int l, int r, int id) : l(l), r(r), id(id){};
};
int n, t, a[202020], num[1000001], bb[202020], ll, rr;
vector<query> qq[400];
long long ans[202020], cur = 0;
bool cmp(query q1, query q2) {
if (q1.r <... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch = getchar();
long long nega = 1;
while (!isdigit(ch)) {
if (ch == '-') nega = -1;
ch = getchar();
}
long long ans = 0;
while (isdigit(ch)) {
ans = ans * 10 + ch - 48;
ch = getchar();
}
if (nega == -1) return ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
static char buf[1000000], *p1 = buf, *p2 = buf;
inline int read() {
register int x = 0;
register char a =
p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
? EOF
: *p1++;
while (a < '0' ... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long int sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
return a + sum(args...);
}
long long int par[200005];
long long int find_par(long long int node) {
if (par[node] == node)
return node;
else
return par[node] = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
if (fu) v = -v;
}
int n, m, t, q, L[1... | 9 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int st;
int ed;
} node;
node mark[150];
int ini[150], n, k, cnt, belong[150];
long long solve() {
long long num = 0;
while (ini[1] != k) {
for (int i = 1; i <= cnt; i++) {
if (mark[i].st == -1) continue;
if (ini[mark[i].st] == k) con... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct zawodnik {
int l, r, t, c;
};
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<zawodnik> zaw(m);
for (int i = 0; i < m; ++i) {
cin >> zaw[i].l >> zaw[i].r >> zaw[i].t >> zaw[i].c;
--zaw[i].l;
--zaw[i].r;
}
vector<... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ans = 0, a[20];
int main() {
long long n;
scanf("%I64d", &n);
a[0] = 1;
a[1] = 0;
a[2] = 0;
a[3] = 0;
a[4] = 1;
a[5] = 0;
a[6] = 1;
a[7] = 0;
a[8] = 2;
a[9] = 1;
a[10] = 1;
a[11] = 2;
a[12] = 0;
a[13] = 1;
a[14] = 0;
a[15] = 0;
do {... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if (a[i].first == a[i].second) {
cout << a[i].first << " " << a... | 3 |
#include <bits/stdc++.h>
int main() {
int t, count = 0, count1 = 0;
char a[200005];
scanf("%d", &t);
scanf("%s", a);
for (int i = 0; i < t; i++) {
if (a[i] == '0')
count++;
else
count1++;
}
if (count1 > count)
printf("%d", (t - (2 * count)));
else
printf("%d", (t - (2 * count... | 1 |
#include <bits/stdc++.h>
using namespace std;
void gett() { cerr << (clock()) / (double)CLOCKS_PER_SEC << "\n"; }
long long powr(long long a, long long b, long long mod) {
long long x = 1 % mod;
a %= mod;
while (b) {
if (b & 1) x = (x * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return x;
}
long long... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int k = 0;
for (int i = 1; i < n - 1; i++) {
if (s[i - 1] == s[i]) {
k++;
if ((s[i - 1] != 'R') && (s[i + 1] != 'R')) {
s[i] = 'R';
} else if ((s[i - 1] != 'G') && (s[i + 1] != 'G'))... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int MAXN = 2e5 + 10;
vector<int> idx;
string s;
long long hash_val1[MAXN], hash_val2[MAXN];
long long power_table[MAXN];
long long mod = 1e9 + 9;
void init(const strin... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1005][1005], nei[1005][1005], jmp;
bool u[1005][1005];
vector<pair<int, int> > inter;
int gcd(int a, int b) { return ((b == 0) ? a : gcd(b, a % b)); }
void dfs(int l, int c) {
if (!a[l][c] || u[l][c]) return;
u[l][c] = true;
if (l > 0) dfs(l - 1, c);
if ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long tavan(long long x, long long y) {
long long res = 1;
while (y) {
res *= y % 2 ? x : 1;
res %= ((long long)1e9 + 7);
x *= x;
x %= ((long long)1e9 + 7);
y /= 2;
}
return res;
}
int n, m, k;
vector<long long> vec;
long long ans, tvn2[((lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int p1[100];
int inv_p1[100];
int p2[100];
int tmp[100], p[100];
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &p1[i]), p1[i]--;
for (int i = 0; i < n; i++) scanf("%d", &p2[i]), p2[i]--;
for (int i = 0; i < n; i++) inv_p1[p1[... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[2];
cin >> str;
int c = 0;
for (int i = 0; i < 5; i++) {
char str1[2];
cin >> str1;
if (str[0] == str1[0]) {
c = 1;
break;
} else if (str[1] == str1[1]) {
c = 1;
break;
}
}
if (c == 1)
cout <<... | 0 |
#include <bits/stdc++.h>
int main() {
int t;
std::cin >> t;
while (t--) {
int n, a, b, c, d;
std::cin >> n >> a >> b >> c >> d;
if (n * (a + b) < (c - d) || (c + d) < n * (a - b))
std::cout << "No" << std::endl;
else
std::cout << "Yes" << std::endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 10;
int ar[sz], p[sz], n, dot[sz * 4];
void build(int nu, int l, int r) {
if (l == r)
dot[nu] = ar[l];
else {
int mid = (l + r) >> 1;
build(nu * 2, l, mid);
build(nu * 2 + 1, mid + 1, r);
dot[nu] = max(dot[nu * 2], dot[nu * 2 + 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
char s[510000], opt[510000];
int sum[510000 << 2];
int mmi[510000 << 2];
int col[510000 << 2];
vector<int> idx;
void push_up(int root) {
sum[root] = max(sum[root << 1], sum[root << 1 | 1]);
mmi[root] = min(mmi[root << 1], mmi[root << 1 | 1]);
}
void push_down(int... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2};
int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};
void prtn(long long i) { cout << i << "\n"; }
vector<vector<long long> > v;
bool check(vector<long long> v) {
set<long long> s;
for (auto i : v) s.insert(i);
if (s.size() == 1)
retur... | 3 |
#include <bits/stdc++.h>
int kq(int n, int k) {
int kq;
if (k % (n - 1) != 0)
kq = n * (k / (n - 1)) + k % (n - 1);
else
kq = n * (k / (n - 1)) - 1;
return kq;
}
int main() {
int i, t, a[1000][2];
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d %d", &a[i][0], &a[i][1]);
}
for (i = 0; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mk make_pair
int main()
{ ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
string s;
cin>>s;
ll count=... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 101616;
vector<int> mlfe[MXN];
int dp[MXN];
void input();
int n;
void qarbal(int f) {
for (int i = 2; i <= f; i++)
if (mlfe[i].empty()) {
mlfe[i].push_back(i);
for (int j = 0; j * i <= f; j++) mlfe[i * j].push_back(i);
}
}
int mx_mlfe(i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[100010], h[100010];
int main() {
int T, n, r, x;
scanf("%d", &T);
while (T--) {
int ans = 0;
scanf("%d%d", &n, &r);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
n = unique(a + 1, a + 1 + n) - a - 1;
for (int i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 4;
const int MXD = 200;
const int INF = (int)1e6 + 41;
void solve() {
int n, m;
long long l, r;
cin >> n >> m >> l >> r;
vector<int> numD(N, 0);
vector<vector<int>> div(N);
vector<int> divMaxY(N, 0);
for (int i = 1; i < N; i++) {
f... | 22 |
#include <bits/stdc++.h>
using namespace std;
int i, N, D, H;
int main() {
scanf("%d%d%d", &N, &D, &H);
if (2 * H < D || N > 2 && D == 1) return puts("-1");
for (i = 1; i <= H; i++) printf("%d %d\n", i, 1 + i);
for (i = 1; i <= D - H; i++) printf("%d %d\n", i + (i > 1) * H, 1 + H + i);
for (i = 1; i < N - D; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long b[n + 1];
long long g[m + 1];
long long bma = 0;
long long bsma = 0;
long long bsum = 0;
for (long long i = 1; i <= n; i++) {
cin >> b[i];
if (b[i] > bma) {
bsma = bma;
bma = b[i];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> V(n), T(n);
for (int i = 0; i < n; i++) cin >> V[i];
for (int i = 0; i < n; i++) cin >> T[i];
priority_queue<long long, vector<long long>, greater<long long> > pq;
long long sum = 0;
for (int i = 0; i < n; i++)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, b, mx, co, mx1;
char c[200][200];
queue<pair<int, int> > q;
queue<int> q1;
bool d;
int main() {
cin >> a >> b;
for (int i = 1; i <= a; i++)
for (int j = 1; j <= b; j++) cin >> c[i][j];
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= b; j++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[1002];
vector<int> cg;
int n, m, k;
int c;
bool markc[1002];
int mx = 0;
bool mark[1002];
int Q = 0;
int EQ = 0;
int answ = 0;
void dfs(int x) {
mark[x] = true;
EQ = (int)(g[x].size());
Q++;
for (int i = 0; i < g[x].size(); i++) {
int v = g[x][i];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void start() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <class T>
istream& operator>>(istream& in, vector<T>& a) {
for (auto& i : a) in >> i;
return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& a) {
for (auto& i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int vis[1005][1005];
int a[105][2];
int n;
int valid(int x, int y) { return (x >= 1 && x <= 1000 && y >= 1 && y <= 1000); }
void dfs(int x, int y) {
vis[x][y] = 1;
for (int i = 0; i < n; i++) {
if (!vis[a[i][0]][a[i][1]] && (a[i][0] == x || a[i][1] == y))
dfs(... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
vector<pair<long long int, long long int>> a;
vector<int> ind;
long long int s;
void show() {
for (auto i : a) cout << i.first << " ";
cout << endl;
for (auto i :... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e8 + 5;
const long long l_inf = 9e18 + 5;
template <typename T, typename T2>
ostream &operator<<(ostream &s, const pair<T, T2> &p) {
return s << p.first << ' ' << p.second << ' ';
}
template <typename T, typename T2>
istream &operator>>(istream &s, pair<T... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a[2], b[2];
for (int i = 0; i < 2; i++) {
cin >> a[i];
}
for (int i = 0; i < 2; i++) {
cin >> b[i];
}
sort(a, a + 2);
sort(b, b + 2);
if (a[1] == b[1] && (a[0] + b[0]) == a[1])... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
if (n == 2) return cout << "-1", 0;
if (n == 1) return cout << "1", 0;
cout << 10 << endl << 15 << endl;
for (long long i = 1; i <= n - 2; i++) cout << 6 * i << endl;
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int a[102];
bool print1(int x) {
if (x == 0) {
return false;
}
switch (x) {
case 1:
printf("ten");
break;
case 2:
printf("twenty");
break;
case 3:
printf("thirty");
break;
case 4:
printf("forty");
bre... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
solve();
}
const int MAXN = 10100;
int n;
int l, r;
int a[MAXN];
int b[MAXN];
bool used[MAXN];
int sum[MAXN];
int good_cnt[MAXN];
inline void add(int value, int good) {... | 19 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long pi[1000005];
string p;
void kmp() {
long long now;
pi[0] = -1;
now = -1;
for (long long i = 1; i < p.size(); i++) {
while (now != -1 && p[i] != p[now + 1]) now = pi[now];
if (p[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, r;
int w[330];
bool burn[800];
for (int i = 0; i < 800; i++) burn[i] = false;
cin >> m >> t >> r;
for (int i = 1; i <= m; i++) cin >> w[i];
int num = 0, ans = 0;
bool flag = true;
w[m + 1] = 301;
for (int i = m; i > 0; i--) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == i)
cout << k << ' ';
else
cout << 0 << ' ';
}
cout << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline long long read() {
int ch = getchar(), f = 1;
long long ans = 0;
for (; ch < '0' || ch > '9'... | 21 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
long lo... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)5e3 + 10;
int d[maxn][maxn];
int num[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num[i];
}
int kol = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (num[i] > num[j] && i < j) ko... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
string s;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'o')
b += a;
else if (s[i - 1] == 'v')
a++, c += b;
}
cout << c;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string A, B;
cin >> A >> B;
int ac4 = 0, ac7 = 0, bc4 = 0, bc7 = 0;
for (int i = 0; i < A.size(); ++i)
if (A[i] == '4')
ac4++;
else
ac7++;
for (int i = 0; i < B.size(); ++i)
if (B[i] == '4')
bc4++;
else
bc7++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int cnt[30];
int main() {
long long int n, k, i;
string s;
cin >> n >> k;
cin >> s;
for (i = 0; i < s.length(); i++) {
cnt[int(s[i]) - 65]++;
}
sort(cnt, cnt + 26);
reverse(cnt, cnt + 26);
long long int ans = 0, tmp1 = 0;
for (i = 0; i < 26... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 1000000;
int n;
char a[N + 5];
vector<pair<int, bool> > v;
int dp[N + 1];
pair<pair<int, int>, int> stk[N];
int top;
int main() {
scanf("%s", a + 1);
n = strlen(a + 1);
for (int i = 1, ie; i <= n; i = ie + 1) {
ie = i;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int kol_d(int a) {
int s = 0;
int b = int(sqrt(double(a)));
for (int i = 1; i <= b; i++)
if (a % i == 0) s += 2;
if (long(b * b) == a) s--;
return s;
}
int main() {
int a, b, c;
long long s = 0;
scanf("%d%d%d", &a, &b, &c);
vector<int> d(a * b * c + 1,... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans(vector<vector<int> > &dp, int n, int f, int limit, int x) {
if (dp[n][f] != x) {
return dp[n][f];
}
if (n == 1) {
return dp[n][f] = f;
}
int min_1 = INT_MAX;
if (f + 1 <= limit) {
min_1 = min(min_1, 0 + ans(dp, n - 1, f + 1, limit, x));
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct i128 {
static const long long INF = 1e18;
long long h, l;
i128() {}
i128(long long _h, long long _l) : h(_h), l(_l) {
if (l >= INF) {
l -= INF;
h++;
} else if (l <= -INF) {
l += INF;
h--;
} else if (h > 0 && l < 0) {
... | 14 |
#include <bits/stdc++.h>
int n, m, k, l[810000], r[810000], d[810000], num[810000], ic[810000];
long long x[810000], da[810000];
int add(int ll, int rr, int l, int r, int no) {
if (ll > r || l > rr) return 0;
if (ll <= l && r <= rr) {
++ic[no];
return 0;
}
add(ll, rr, l, (l + r) >> 1, 2 * no),
add... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500100;
map<int, int> id;
int n;
int head[maxn], nxt[maxn << 1], ver[maxn << 1], tot = 1, d[maxn],
vis[maxn << 1];
int vcnt, val[maxn];
int cnt;
inline void addedge(int a, int b) {
nxt[tot] = head[a];
ver[... | 16 |
#include <bits/stdc++.h>
using namespace std;
int calc(int n, int t) {
if (t == 2) {
cout << n - 1 << endl;
for (int i = 1; i < n; i++) {
cout << i << " " << i + 1 << endl;
}
} else {
vector<pair<int, int> > vec;
vec.push_back(make_pair(1, 2));
vec.push_back(make_pair(2, 3));
vec.p... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9;
const int inf = (int)1e9 + 5;
const int base = 1000 * 1000 * 1000;
const int maxn = 50005;
const long double pi = acosl(-1.0);
const long double eps = 1e-9;
void error() { exit(1); }
void solve() {
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
long long int fpow(long long int x, long long int y) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = (res % mod * x % mod) % mod;
x = (x... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
void solve();
void precalc();
clock_t start;
bool doing = true;
int main() {
int t = 1;
cout.sync_with_stdio(0);
cin.tie(0);
precalc();
cout.precision(10);
cout << fixed;
start = clock();
int testNum = 1;
while (... | 17 |
#include <bits/stdc++.h>
using namespace std;
int getint() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return f * x;
}
int n, m;
struct node {
in... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[105];
int n;
int i;
while (cin >> n) {
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (i = 0; i < n; i++) cout << a[i] << " ";
cout << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 0x3f3f3f3f;
int n, m, s[1000002], dis[102][102], now, ans = 1, pos, pd[1000002];
char p[102][102];
int main() {
memset(dis, 0x3f, sizeof(dis));
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> p[i][j];
if (p[i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n;
vector<int> a(n);
for (int _n = n, i = 0; i < _n; ++i) {
cin >> a[i];
}
vector<int> l(n), r(n);
for (int _n = n, i = 0; i < _n; ++i) {
if (i == 0) {
if (a[i] == 0)
l[i] = 0;
else
l[i] = 1000 ... | 4 |
#include <bits/stdc++.h>
using namespace std;
string cad;
int cnt[1000000], q, fr, to;
int main() {
cin >> cad;
for (int i = 0; i < cad.size() - 1; i++) {
cnt[i + 1] = cnt[i];
if (cad[i] == cad[i + 1]) cnt[i + 1]++;
}
cin >> q;
for (int i = 0; i < q; i++)
cin >> fr >> to, cout << cnt[to - 1] - cnt... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5;
int n;
vector<vector<int> > g;
bool vis[sz];
int dfs(int u) {
vis[u] = true;
int x = 1;
for (int v : g[u])
if (!vis[v]) x += dfs(v);
return x;
}
int main() {
scanf("%d", &n);
g.resize(n);
for (int i = 0; i < n - 1; ++i) {
int u, v, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, init, cnt = 0;
bool flag = true;
scanf("%d", &n);
int arr[n + 1];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
if (arr[i] == 1 && flag) {
init = i;
flag = false;
}
}
arr[n] = -1;
for (int i = init; i < n; i+... | 2 |
#include<bits/stdc++.h>
using namespace std;
int T,n,a[1000005];
long long k,x;
void solve(int now,long long rk,int num,int len) {
if(now==n+1)return;
long long sum=1;
int p=now;
if(len>=63) {
a[now]=1+num;
solve(now+1,rk,num+1,len-1);
} else {
for(int i=1; i<=len-2; i++)sum*=2;
while(sum) {
if(rk<=sum)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b, min = 1000001;
cin >> n >> m >> a >> b;
if (n * a < min) min = n * a;
int x1 = n / m;
if (n % m == 0)
if (x1 * b < min) min = x1 * b;
if (n % m != 0 && (x1 + 1) * b) min = (x1 + 1) * b;
int x2 = x1 * b + (n - (x1 * m)) * a;
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long na[100], pa[100];
vector<long long> v;
int getnumofones(long long ans) {
int cnt = 0;
while (ans) ans &= ans - 1, cnt++;
return cnt;
}
map<int, pair<long long, long long> > mp;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> na... | 13 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long mask = ((1LL) << 40) - 1;
long long n, m;
long long answer = 0;
vector<long long> nums;
vector<long long> response;
string numToStr(long long x) {
string s = "";
while (x) {
if (x & 1)
s = s + '1';
else
s = s + '0';
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool debug = false;
vector<int> ans;
int a[1005];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
if (i > n - k) {
ans.push_back(i);
}
}
for (int j = n - k; j >= 1; j--) {
for (vector<int>::it... | 10 |
#include <bits/stdc++.h>
using namespace std;
void gt(int &a, int b) {
if (a < b) a = b;
}
string n2s(int a) {
stringstream ss;
ss << a;
return ss.str();
}
string getKey(int v, int h) { return n2s(v) + "-" + n2s(h); }
int s[14000000]{0};
int main() {
int ans = 0;
int n;
cin >> n;
for (int i = 1; i <= n;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n % 2) {
printf("black\n");
} else {
printf("white\n1 2\n");
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, arr[200105], b[200105], pos = 1, ans = 0;
long long check(long long* cost) {
for (long long i = b[n] + 1; i <= n; i++) {
if (cost[i] != (-1000000)) {
if (cost[i] + b[n] > 0) return 0;
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(... | 10 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, char> > cts;
int sz[1010];
char val[1010];
int id[1010];
int ufind(int a) {
while (id[a] != a) {
int p = id[a];
a = id[a];
id[p] = a;
}
return a;
}
void uunion(int a, int b) {
int p = ufind(a);
int q = ufind(b);
if (p == q) r... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7;
const double EPS = 1e-9;
struct Prob {
long double pf;
int ss, ls, st, lt;
void in() { cin >> ss >> ls >> st >> lt >> pf; }
bool operator<(const Prob &nd) const {
return lt * pf * (1 - nd.pf) < nd.lt * nd.pf * (1 - pf);
}
} a[N];
struct ... | 20 |
#include <bits/stdc++.h>
using namespace std;
void bad(string mes = "impossible") {
cout << mes;
exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
string ans = "";
while (x > 0) {
ans += char('0' + x % st);
x /= st;
}
reverse(ans.begin(), ans.end());
return ans.empty() ? "0" : ans;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, s;
int i = 0, j;
cin >> s >> t;
for (j = 0; j < t.length(); j++) {
if (s[i] == t[j]) i++;
}
i++;
cout << i << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m;
const int N = 1003, K = 105;
int dp[N][K];
int main() {
cin >> n >> k >> m;
int pwk = 1 % k;
for (int i = 0; i < n; ++i) {
if (i) {
for (int j = 1; j < k; ++j) {
dp[i][j] += dp[i - 1][j];
if (dp[i][j] >= m) dp[i][j] -= m;
}... | 14 |
#include <bits/stdc++.h>
namespace solution {
class SolutionInterface {
public:
virtual int run() = 0;
protected:
virtual void pre_calc() {}
virtual bool action() = 0;
virtual void init(){};
virtual bool input() { return false; };
virtual void output(){};
SolutionInterface() {}
private:
};
} // name... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
int main() {
int n, a;
cin >> n >> a;
if ((a + 2) % 2 == 0) {
int aa[N];
for (int i = n, j = 0; j < n / 2; i = i - 2, j++) {
aa[j] = i;
if (aa[j] == a) {
j += 1;
cout << j;
}
}
} else
cout << a /... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.