solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int N = 200006;
char buf[N];
int c[N];
queue<int> q;
int main() {
int n;
scanf("%d", &n);
char temp;
scanf("%c", &c);
scanf("%s", ... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
return __builtin_popcoun... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int a, b;
cin >> a >> b;
int sum = 0;
while (a != 0 && b != 0) {
if (a > b) {
sum += a / b;
a = a % b;
} else {
sum += b / a;
b = b % a;
}
}
cout << s... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int n, m, r, c;
inline long long add(long long a, long long b) { return (a + b) % MOD; }
inline long long sub(long long a, long long b) {
long long c = (a - b) % MOD;
if (c < 0) c += MOD;
return c;
}
inline long long mul(long long a, l... | 15 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
void ndarray(vector<T> &... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int n;
cin >> n;
int count = 0;
for (int i = 0; i < n; i++) {
long long int a, b, c;
cin >> a >> b >> c;
long long int pe1 = x1 * a + y1 * b;
long long int pe2 = x2 * a + y2 ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
for (int j = 0; j <= (i - 1) / 2; j++) swap(s[j], s[i - 1 - j]);
}
}
cout << s;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int k, b, n, x;
int main() {
scanf("%d%d%d%d", &k, &b, &n, &x);
long long sk = 1, ss = 1;
for (int i = 1; i <= n + 1; i++) {
sk *= k;
if (i == n + 1 || ss > x || b * ss + sk > x) {
printf("%d\n", n - i + 1);
break;
} else
ss += sk;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], r = 0, x = 0, y = 0, bs = 0, b[n], z = 0, i, j, k = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1) r++;
}
for (i = 0; i < n; i++) {
cin >> b[i];
if (b[i] == 1) bs++;
}
for (i = 0; i < n; i++) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long g(unsigned long long n) {
return n * (n + 1) * (2 * n + 1) / 3 + n - 3 * n * (n + 1) / 2;
}
unsigned long long f(unsigned long long x) {
return g(x / 2 + 1) * 4 - 4 * (x / 2 * (x / 2 + 1) / 2);
}
int main() {
unsigned long long x;
int t;
cin >> ... | 2 |
#include <bits/stdc++.h>
template <class T>
using pt = std::pair<T, T>;
using namespace std;
vector<long long> b(60);
bool razl(long long a, long long k) {
int i = 0;
while (a != 0) {
if (a % k <= 1) {
if (b[i] != 0 && a % k != 0)
return false;
else if (b[i] == 0)
b[i] = a % k;
}... | 6 |
#include <bits/stdc++.h>
const int N = 300010;
struct Line {
int l, r, id;
Line(int l = 0, int r = 0, int id = 0) : l(l), r(r), id(id) {}
bool operator<(const Line &A) const {
if (r == A.r) return l > A.l;
return r > A.r;
}
} input[N];
bool cmp(Line &A, Line &B) {
if (A.l == B.l) return A.r < B.r;
r... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct pair_hash {
template <class T1, class T2>
std::size_t operator()(const std::pair<T1, T2> &p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ h2;
}
};
int a[1001];
long long day... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int num;
while (scanf("%d", &num) == 1) {
int s[200005] = {};
for (int i = 2; i <= num; i++) {
scanf("%d", &s[i]);
}
int now = num;
vector<int> v;
while (now != 1) {
now = s[now];
v.push_back(now);
}
reverse... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2100000, Mo = 1000000007;
int i, n, t, x, k, cnt, p, st[Maxn], a[Maxn];
int y(int x) {
if (x > n + p) return n + p + 1;
return x;
}
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (i = 1; i <= n; i++) a[i] = i;
for (k = 2; k <= n; k++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long N, i, j, D, P, mn, B, MX, D2;
long long v[300005], ANS, ANS2;
int ok[15000005], nr[15000005];
bool pr[15000005];
long long GCD(long long A, long long B) {
if (B == 0) return A;
return GCD(B, A % B);
}
int main() {
scanf("%lld", &N);
for (i = 1; i <= N; i++... | 10 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int w = 0, f = 1;
char c = ' ';
while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
return w * f;
}
int n, m, a[500005], b[500005], ans;
vector<int> e[500005];
signed main()... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int nn = 1e4 + 8;
vector<int> G[nn];
int c[nn];
int n;
int f[nn];
void dfs(int u) {
f[u] = 1;
for (int v : G[u]) {
dfs(v);
f[u] += f[v] - (c[u] == c[v]);
}
}
int main() {
cin >> n;
for (int i = 2; i <= n; i++) {
int u;
cin >> u;
G[u].push... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 414514;
int n, tt;
int f[N], r[N];
int rt[N], ls[N * 30], rs[N * 30], sz[N * 30];
long long su[N * 30], as;
void add(int &i, int l, int r, int s) {
if (!i) i = ++tt;
if (l == r) {
sz[i] = 1, su[i] = s;
return;
}
if (s <= ((l + r) >> 1))
add... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int a, b;
bool operator<(const node &p) const {
if (b == p.b)
return a, p.a;
else
return b < p.b;
}
};
int main() {
int pp, b, i, j, k, m, n, p, q;
string s;
while (cin >> n) {
deque<int> m1;
for (i = 0; i < n; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int m_inf = INT_MIN;
double binpow(double a, int n) {
double res = 1;
while (n) {
if (n & 1) res = res * a;
a *= a;
n >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
doubl... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int kN = 3e5 + 10;
int N, Q;
int max_read[kN];
vector<int> app_mesg[kN];
vector<pair<int, int> > mesg;
int readed[kN];
int main() {
scanf("%d %d", &N, &Q);
int unread = 0;
int cur_t = 0;
for (int i = 1; i <= Q; i++) {
int op, x;
scanf("%d %d", &op, &x)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (k < n / 2 || n == 1 && k != 0) {
cout << -1 << endl;
} else if (n == 1) {
cout << 1 << endl;
} else {
int first = k - (n / 2 - 1);
cout << first << " " << 2 * first;
for (int i = 0; i < n / 2 - 1; ++i)
... | 7 |
#include <bits/stdc++.h>
char c1[600000][60], c2[600000][60];
int u[120000], v[120000], x[120000], y[120000];
int i, j, m, n, w, z;
inline void getL(int x, int y, char c[][60]);
inline void getU(int x, int y, char c[][60]) {
if (c[x + 1][y] == 'D') return;
if (c[x + 1][y] == 'R') getU(x + 1, y - 1, c);
if (c[x + ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[100][2];
float sum = 0.00000, k;
cin >> n;
cin >> k;
for (int i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
for (int i = 0; i < (n - 1); i++) {
double dist;
dist = sqrt(pow(arr[i + 1][0] - arr[i][0], 2) +
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, w, x, vis[2][100007] = {0}, s, stop = 0, draw = 0, f[100007] = {0};
vector<int> v[100007], res;
void sol(int id, int time) {
if (stop) return;
if (f[id]) draw = 1;
if (vis[time % 2][id]) return;
res.push_back(id);
f[id] = 1;
vis[time % 2][id] = 1;
in... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, cx, cy;
bool f(long long P, long long Q) {
if (cx == 0 && cy == 0) return P == 0 && Q == 0;
long long r1 = (P * cx + Q * cy) % ((cx) * (cx) + (cy) * (cy));
long long r2 = (P * cy - Q * cx) % ((cx) * (cx) + (cy) * (cy));
return r1 == 0 && r2... | 12 |
#include <bits/stdc++.h>
char c[8][9];
int main() {
int i, j, a, m = 0;
for (i = 0; i < 8; i++)
for (j = 0; j < 9; j++) scanf("%c", &c[i][j]);
for (i = 0; i < 8; i++) {
a = 0;
for (j = 0; j < 8; j++) {
if (c[i][j] == 'W') break;
a++;
if (a == 8) m++;
}
}
if (m == 8) {
pri... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
struct SegTree {
long long* t;
void build(long long pos, long long L, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, k, z;
int main() {
cin >> n;
z = n;
while (n > 9) {
n = n / 10;
k++;
}
n++;
for (int i = 1; i <= k; i++) n = n * 10;
cout << n - z;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
cout << n / 2 + n % 2;
}
| 3 |
#include <bits/stdc++.h>
int main() {
int a[10];
int sum = 0;
for (int i = 0; i < 5; ++i) {
scanf("%d", a + i);
sum += a[i];
}
if (sum % 5 || sum / 5 <= 0)
printf("-1\n");
else
printf("%d\n", sum / 5);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
while (cin >> str) {
string ans;
while (str.size()) {
int count = 0;
char maxn = 'a' - 1;
int max_pos = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] > maxn) {
maxn = str[i];
cou... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
struct sa {
int x, y, z;
sa(int x, int y, int z) : x(x), y(y), z(z) {}
sa() {}
};
vector<sa> ans;
vector<int> a[110000];
int v[110000], d[110000];
int n, m;
int dfs(int x, int dep) {
int i, y, z, last = 0;
v[x] = 1... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000, maxl = 600;
double f[maxl + 5];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= min(n, maxl); j++)
f[j] = (f[j + 1] + j) / ((1. + j) * k) +
(f[j] + 0.5 * (1. + j)) * j / ((... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 27 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e10;
string s;
struct node {
int ans;
int o;
int c;
node(int a = 0, int b = 0, int d = 0) {
ans = a;
o = b;
c = d;
}
};
node t[4004000];
node merge(node a, node b) {
node c(0, 0, 0);
c.ans = a.ans + b.ans;
c.o = a.o + b.o;
c.c ... | 12 |
// stryker27
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long int
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define For(b) for(int i=0... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void PrArr(const T a[], int len) {
for (int i = 0; i <= len; i++) cout << a[i] << " ";
cout << endl;
}
template <typename T>
void PrVec(const vector<T> a) {
for (auto it : a) cout << it << " ";
cout << endl;
}
template <class T>
inline void rea... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 100005;
const int mx = 500005;
const int INF = 1000000007;
const int MOD = 998244353;
int n;
char s[mx], _s[mx], t[mx];
int num[mx][30], f[30];
int tp;
vector<int> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int Tc;
for (cin >>... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const long long LINF = 1e18 + 100;
int n;
string s;
int dp[5050][26];
int sum[5050];
int ans;
int comb[5050][5050];
int32_t main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
long long powm(long long a, long long b) {
a %= MOD;
long long ans = 1;
while (b > 0) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n, m, k, l, i, j, ans = 0, x, y;
cin >> n >> m >> k;
int a[n + 2][m + 2];
for (i = 0; i < n + 2; i++)
for (j = 0; j < m + 2; j++) a[i][j] = 0;
for (l = 1; l <= k; l++) {
cin >> x >> y;
a[x][y] = 1;
if (a[x][y - 1] && a[x + 1][... | 3 |
#include <bits/stdc++.h>
using namespace std;
int free(vector<int> r) {
int f = 0;
for (int i = 0; i < r.size(); i++) {
if (r[i] == 0) f++;
}
return f;
}
bool possible(vector<int> r, int m) {
bool ok;
if (free(r) < m)
return false;
else {
for (int i = 0; i < r.size() - m + 1; i++) {
ok =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q = 0;
cin >> q;
while (q--) {
long long int n, m = 0;
cin >> n >> m;
long long int sum = 0;
int k = 1;
while (k <= 10) {
sum += ((k * m) % 10);
k++;
}
long long int d = n / (10 * m);
long long int e = n % (... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005], mx;
void solve() {
long long n, k, cnt = 0;
cin >> n >> k;
for (long long i = 1; i < n + 1; i++) {
cin >> a[i];
if (a[i] != a[i - 1])
cnt++;
else {
mx = max(cnt, mx);
cnt = 1;
}
}
mx = max(cnt, mx);
cout << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
char a[1100000];
int b[1100000];
int main() {
scanf("%s", a);
int l = strlen(a);
if (l & 1) {
l /= 2;
l++;
for (int i = 0; i < l; i++) printf("4");
for (int i = 0; i < l; i++) printf("7");
printf("\n");
return 0;
}
int p = -1;
int q = -1;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 25;
int main(int argc, char *argv[]) {
string s;
int n;
cin >> s;
n = s.length();
int cnt[10] = {0};
for (int i = (0), _b = (n); i < (_b); ++i) cnt[s[i] - '0']++;
cnt[1]--;
cnt[6]--;
cnt[8]--;
cnt[9]--;
int a[] = {1, 6, 8, 9};
do {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int m, cnt[12][12];
int calc2(int n, int k, int add = 0) {
if (n == 0) return k == 0;
if (n < k) return 0;
if (cnt[n][k] != -1 && add == 0) return cnt[n][k];
long long mod = 1;
for (int i = 1; i < n; ++i) mod *= 10;
int ans = 0;
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.1415926536;
const int oo = (int)1e9;
const long long OO = numeric_limits<long long>::max();
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int di[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dj[] = {1, -1, 0, 0, 1, -1, -1, 1};
int f1[] = {0, 0, 0, 1, 1, 1, -1, -1... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 5020, mod = 1e9 + 7;
long long n, mid, ans1, ans2 = 1, ans2t = 2;
int color[max_n];
pair<int, int> a[max_n];
bool flag;
void dfs(int x, int c) {
color[x] = c;
for (int i = 0; i < n; i++) {
if (i != x) {
if (abs(a[x].first - a[i].first) + abs(... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double pipi = 3.1415926535897932384626433832795;
long long mod = 1000000007;
int main() {
int n, rr, vv;
string s;
scanf("%d %d %d", &n, &rr, &vv);
double r = rr;
double v = vv;
for (int i = 0; i < n; i++) {
int s, f;
scanf("%d %d", &s, &f);
do... | 17 |
#include <bits/stdc++.h>
const int _n = 20;
const int _m = 100 + 10;
std::map<char, int> id;
int tot = 0;
int ID(char c) {
if (id[c] == 0) id[c] = ++tot;
return id[c];
}
std::string s[_m];
int ss[_m][2];
int n, ans = 11;
bool vis[_n];
int ok[_m];
std::set<int> G[_n], vv;
void dfs(int idx, int get) {
if (get >= an... | 9 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long del, n, sol;
int main() {
scanf("%I64d", &n);
del = 1;
while (n % del == 0) del *= 3;
sol = n / del + 1;
printf("%I64d\n", sol);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
unsigned long long power(unsigned long long x, unsigned long long y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
unsigned long long gcd... | 6 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int inf = 1e18;
int m_inf = INT_MIN;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
std::cout.unsetf(std::ios::floatfield);
std::cout.precision(15);
int t = 1;
cin >> t;
while (t--) {
int n;
ci... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 500 * 500 + 10;
const int inf = 1e9;
const long long mod = 1e9 + 7;
int getint() {
char c;
while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-')
;
int ret = c - '0', sgn = 0;
if (c == '-') sgn = 1, ret = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long x, long long y) {
if (x < y)
return x;
else
return y;
}
long long min(long long x, long long y, long long z) {
return min(min(x, y), z);
}
bool isspecial(char c) {
if (c == '#' || c == '*' || c == '&')
return true;
else
retu... | 7 |
#include <bits/stdc++.h>
char buf[23];
int main(int argc, char *argv[]) {
int a, b;
scanf("%d%s", &a, buf);
b = 0;
int i;
for (i = strlen(buf) - 1; i >= 0; --i) {
b = b * 10 + buf[i] - '0';
}
printf("%d\n", a + b);
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10;
const long long MS = 4e2 + 10, MN = 2e2 + 10;
long long n;
long long len;
long long sz = 1, tri[27][MS], f[MS], nxt[27][MS], cnt[MS];
long long w[MN];
long long dp[MN];
vector<long long> adj[MN];
struct mat {
long long a[MN][MN];
mat(bool... | 17 |
#include <bits/stdc++.h>
int main() {
char s[108];
int i, sum = 0;
gets(s);
for (i = 0; i < strlen(s); i++) {
if ((s[i] == 'D' && s[i + 1] == 'a' && s[i + 2] == 'n' && s[i + 3] == 'i' &&
s[i + 4] == 'l') ||
(s[i] == 'O' && s[i + 1] == 'l' && s[i + 2] == 'y' &&
s[i + 3] == 'a') ||
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ar[n];
for (int i = 0; i < n; ++i) cin >> ar[i];
vector<string> p;
string s;
if (ar[0] != 0) {
for (int i = 0; i < ar[0]; ++i) s.push_back('a');
p.push_back(s);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, a, ans = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a;
ans += a * i;
}
cout << ans;
}
| 12 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
char s[n][1002];
int i, j, arm_cnt = n;
for (i = 0; i < n; i++) {
scanf("%s", &s[i]);
}
int arm[n][26];
int arm_temp[26];
for (i = 0; i < n; i++)
for (j = 0; j < 26; j++) arm[i][j] = 0;
for (i = 0; i < n; i++) {
for (j = 0; j ... | 1 |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
string s;
int ans = 0;
void solve(string t) {
if (t > s && t.size() >= s.size()) return;
++ans;
if (t.size() < s.size()) {
solve(t + "0");
solve(t + "1");
}
}
int main() {
ios_base::syn... | 4 |
#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
s = 0;
register int f = 0;
register char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
if (f) s = -s;
}
template <class t>
inline void write(t x) {
... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int head = 1;
int last = n * n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n / 2; j++) {
cout << head << " ";
head++;
}
for (int j = 1; j <= n / 2; j++) {
cout << last << " ";
last--;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int x[N], y[N];
double eps = 1e-4;
int main() {
long long n, p, xh = 0, re = 0;
cin >> n >> p;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
double l = 0, r = 1e14, mid;
while (r - l >= eps) {
mid = (l + r) / 2;
double ans = 0;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int add(long long int x, long long int y) {
return (x % 1000000007 + y % 1000000007) % 1000000007;
}
long long int mul(long long int x, long long int y) {
return ((x % 1000000007) * (y % 1000000007)) % 1000000007;
}
long long int sub(long long int x, long long... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long s, x1, x2, t1, t2, p, d;
int main() {
cin >> s >> x1 >> x2;
cin >> t1 >> t2;
cin >> p >> d;
long long s1 = 1e18;
if (d == -1) {
if (x1 > x2) {
if (p >= x1)
s1 = (p - x2) * t1;
else {
s1 = (p + s + (s - x2)) * t1;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, ans[N], v[N], bit[N];
bool ok[N];
pair<int, pair<int, int> > a[N];
map<int, int> mp;
void update(int idx, int v) {
while (idx <= n) {
bit[idx] += v;
idx += idx & -idx;
}
}
int get(int idx) {
int ret = 0;
while (idx > 0) {
ret... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int count = 0, temp;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
temp = v[k - 1];
for (int i = 0; i < n; i++) {
if (v[i] >= temp && v[i] > 0) {
count++;
}
}
cout << count << "\n";... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class n, class second>
ostream &operator<<(ostream &p, pair<n, second> x) {
return p << "<" << x.first << ", " << x.second << ">";
}
template <class n>
auto operator<<(ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value,
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, p1, p2, p3, p4, m;
scanf("%i%i%i%i%i%i", &p1, &p2, &p3, &p4, &a, &b);
m = min(p1, min(p2, min(p3, p4)));
printf("%i\n", (m < a ? 0 : (m <= b ? m - a : b - a + 1)));
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using db = double;
using pii = pair<int, int>;
const int mxn = 100006;
ll n, d, b;
ll a[mxn];
ll c[mxn];
ll cal(ll *a, ll m) {
for (int i = 2; i <= n; ++i) {
ll val = a[i];
int t = max(1LL, (i - 1) / (d + 1) + 1);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, f, s;
cin >> n;
int a[n];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
f = n;
s = 1;
m = abs(a[f] - a[s]);
for (int i = 1; i <= n - 1; i++) {
if (abs(a[i] - a[i + 1]) < m) {
m = abs(a[i] - a[i + 1]);
f = i;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long cubes[n];
for (int i = 0; i < n; i++) {
cin >> cubes[i];
}
for (int i = 0, j = n - 1; i < n / 2; i++, j--) {
if (i % 2 == 0) {
swap(cubes[i], cubes[j]);
}
}
for (int i = 0; i < n; i++) cout << c... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
getchar();
char d;
int flag = 1;
int count_1 = 0;
int count_0 = 0;
char arr[n + 1];
for (int i = 0; i < n; i++) scanf("%c", &arr[i]);
for (int i = 0; i < n; i++) {
d = arr[i];
if (d == '1') {
if (flag ==... | 3 |
#include <bits/stdc++.h>
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-8;
using namespace std;
int n, m;
struct node {
int l, r;
long long sum;
long long lazy;
} T[maxn << 2];
void pushup(int o) { T[o].sum = max(T[o << 1].sum, T[o << 1 | 1].sum); }
void build(int o, int l, int r) {
T[... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long l, r, x, y, t, ans = 0, a[101], b[101], c[10101];
int main() {
int an = 0, bn = 0, n = 0;
cin >> x >> y >> l >> r;
for (a[an++] = t = 1; t <= r / x; a[an++] = t *= x)
;
for (b[bn++] = t = 1; t <= r / y; b[bn++] = t *= y)
;
for (int i = 0; i < an;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int Sz = 2e5 + 5;
int f1[Sz], f2[Sz], n, m;
char s[Sz], t[Sz];
struct AC {
int ch[Sz][26], bo[Sz], tot = 1, nxt[Sz];
int val[Sz];
inline void ins(char *s) {
int u = 1;
for (int i = 0, len = strlen(s); i < len; i++) {
int c = s[i] - 'a', &v = ch[u][... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
int main() {
int k, l, m, n, d;
cin >> k >> l >> m >> n >> d;
int arr[d];
memset(arr, 1, sizeof(arr));
for (int i = k - 1; i < d; i += k) {
arr[i] = 0;
}
for (int i = l - ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int NR = 2e5 + 5;
ifstream in("date.in");
ofstream out("date.out");
multiset<long long> p;
vector<long long> v[NR];
long long t, cnt, cnt2, n, already, sol;
int main() {
long long x, y, i, j;
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; ++i) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, total_score = 0, total_cost = 0;
vector<vector<int> > matrix;
cin >> n >> m >> k;
matrix.resize(n);
for (int i = 0; i < n; ++i) {
matrix[i].resize(m);
for (int j = 0; j < m; ++j) {
cin >> matrix[i][j];
}
}
for (int j... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> x(5000);
vector<vector<int>> dp(5001, x);
vector<int> v;
int k;
int n;
int len;
long long make_dp(int pos, int num, int rem) {
if (dp[num][rem] != -1) return dp[num][rem];
if (rem == 0)
return dp[num][rem] = make_dp(pos + len, num - 1, rem) +
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
void file() {}
int main() {
cout << setprecision(20) << fixed;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
file();
int n;
cin >> n;
vector<lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int Max_Prime = 3e8 + 10;
bitset<Max_Prime> p;
int main() {
int l, r;
cin >> l >> r;
p.set();
for (int i = 3; i * i < r; i += 2) {
if (p[i]) {
for (int j = i * i; j <= r; j += i + i) {
p[j] = false;
}
}
}
int ans = 0;
for (int... | 14 |
#include <bits/stdc++.h>
using namespace std;
int t, n, p;
int g[25][25];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &p);
memset(g, 0, sizeof g);
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
g[i][j] = g[j][i] = 1;
}
g[i][i] = 0;
}
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int jx, ox, jy, oy;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
if (x & 1)
++jx;
else
++ox;
}
for (int i = 1; i <= m; ++i) {
int x;
scanf("%d", &x);
if (x & 1)
++j... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct TT {
long long int a, b;
TT(long long int x = 0, long long int y = 0) {
a = x;
b = y;
}
TT operator+(const struct TT &m) const { return TT(a + m.a, b + m.b); }
} tree[1 << 18];
struct node {
int l, r;
long long int x;
node(int a = 0, int b = 0, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
set<int> output;
void solve() {
map<int, int> diff;
for (int i = 1; i < n; i++) {
diff[a[i] - a[i - 1]]++;
}
if (diff.size() == 1) {
output.insert(a[0] - (a[1] - a[0]));
output.insert(a[n - 1] + (a[n - 1] - a[n - 2]));
} else if (diff... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 100;
vector<int> ve[N];
struct sc {
int x, s;
bool operator<(const sc &a) const { return a.x - a.s > x - s; }
} p[N];
int ma[N * 4], len, lazy[N * 4];
void pushup(int rt) { ma[rt] = min(ma[(rt << 1)], ma[(rt << 1 | 1)]); }
void pushdown(int rt)... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, N = 1013, M = 13, O = 4097;
int inv(int x) { return x < 2 ? 1 : (P - P / x) * 1ll * inv(P % x) % P; }
int n, m, p, g[M][M], f[N][O], s, t;
vector<int> v[N];
void dfs(int x, int y) {
g[x][y] = 1 << x - 1;
for (int j : v[x + n])
if (j - n != y) ... | 20 |
#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
while (b) {
a %= b, swap(a, b);
}
return a;
}
inline long long lcm(long long a, long long b) {
return a * b / max(1LL, gcd(a, b));
}
mt19937 Random((long long)time(0));
inline long long rnd(long long x) { return R... | 8 |
#include <bits/stdc++.h>
using namespace std;
int b[400005], cnt[2750131 + 5];
int mark[2750131 + 5];
vector<int> prime;
void build() {
for (int i = 2; i <= 2750131; i++) mark[i] = i;
for (int i = 4; i <= 2750131; i += 2) mark[i] = 2;
for (int i = 3; i * i <= 2750131; i++)
if (mark[i] == i)
for (int j =... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100], i, ans;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) scanf("%d", &a[i]);
ans = 0;
for (i = 0; i < n; i++)
if (a[i]) {
ans++;
if (i < n - 1 && a[i + 1] || i < n - 2 && a[i + 2]) {
for (i+... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[1005];
long long b[1005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int ans = (a[0] | a[1]) + (b[0] | b[1]);
for (int i = 0; i < n; i++) {
long long a1 = a[... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
int dis[maxn][maxn], dp[maxn][maxn], a[maxn], b[maxn], c[maxn], d[maxn];
int h, t, second, n, m;
char mark[maxn][maxn];
queue<pair<int, int> > q;
pair<int, int> head_hit(pair<int, int> u, int ty) {
if (ty >= u.first) return pair<int, int>(-1, -1... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.