solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> t(n);
for (int i = 0; i < n; i++) cin >> t[i];
int a = 0, b = n - 1, t_a = 0, t_b = 0;
while (a < b) {
if (t_a < t_b)
t_a += t[a++];
el... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 10;
struct Point {
int x, y;
Point(int _x = 0, int _y = 0) : x(_x), y(_y){};
bool operator<(const Point &other) const {
if (x != other.x) return x < other.x;
return y < other.y;
}
Point operator-(const Point &other) {
return Point(x... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char s[111];
char a[11], b[11];
int to[200];
int ret[N], ct;
int main() {
int i, j;
int x = 0, y = 0;
for (i = 0; i <= 9; i++) to[i + '0'] = i;
for (i = 'A'; i <= 'Z'; i++) to[i] = i - 'A' + 10;
scanf("%s", s);
int len = strlen(s);
x = y ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a[6], mx = 0, mn = 100000000, n, ans, ck;
for (int i = 0; i < 6; i++) scanf("%I64d", &a[i]);
for (int i = 0; i < 6; i++) {
n = a[i] + a[(i + 1) % 6] + a[(i + 2) % 6];
if (n < mn) {
mn = n;
ck = i % 2;
}
}
ans = mn... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
const long long int INF = 9e18;
const long long int mod = 1e9 + 7;
long long int n, p, q, r, a[N], seg[4 * N], segx[4 * N];
void build(long long int low, long long int high, long long int pos) {
if (low == high) {
seg[pos] = a[low];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<pair<int, int> > p;
int x = n;
for (int i = 2; i <= n; i++) {
if (x % i == 0) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int MOD = 1e9 + 7;
long long dp[maxn][3];
void init() {
dp[1][1] = 1, dp[1][2] = 0;
for (int i = 2; i <= 1000000; i++) {
if (i & 1) {
dp[i][1] = (dp[i - 1][2] + 1 + dp[i - 1][1]) % MOD;
dp[i][2] = dp[i - 1][2];
} else... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n - 1; i++)
if (n % i == 0) ans++;
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
namespace NTT {
const int MAX_DEG = 10, EXP_MULT = 119ULL, EXP = 23;
unsigned long long NTTMod = (EXP_MULT << EXP) + 1, NTTBuild[1 << MAX_DEG][2],
rt[(1 << MAX_DEG) + 1];
unsigned long long modPow(unsigned long long a, unsigned long long p) {
if (!p) re... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
int team1 = 0, team2 = 0;
cin >> s1 >> s2;
for (int i = 0; i < s1.size(), i < s2.size(); i++) {
if (s1[i] == '[') {
if (s2[i] == '(')
team1++;
else if (s2[i] == '8')
team2++;
} else if (s1[i] == '(') {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
int high_digit[100];
int high_digit_label[100];
int Process(int i) {
int x = a[i];
int cnt = 0;
int high = -1;
while (x) {
if (x & 1) {
++high_digit[cnt];
high_digit_label[cnt] = i;
}
++cnt;
x = x >> 1;
}
return ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e6 + 5;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int p[MX], a[MX], sz;
void init() {
for (int i = 2; i < MX; i++) {
if (!a[i]) {
p[sz++] = i;
for (long long j = (long long)i * i; j < MX; j += i) a[j] = 1;
}
... | 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() {
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
long long a[n];
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >>... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int hy, ay, dy;
int hm, am, dm;
int h, a, d;
scanf("%d %d %d", &hy, &ay, &dy);
scanf("%d %d %d", &hm, &am, &dm);
scanf("%d %d %d", &h, &a, &d);
int bans = (1 << 29);
for (int ab = 0; ab <= 310; ++ab) {
for (int db = 0; db <= 310; ++db) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, m, q;
int g[44][44];
int cnt1[44][44][44][44], cnt2[44][44][44][44];
bool check2(int r, int c, int a, int b) {
if (r + a - 1 > n) return false;
if (c + b - 1 > m) return false;
for (int i = r; i < r + a; i++)
for (int j = c; j < c +... | 11 |
#include <bits/stdc++.h>
using namespace std;
int h[1010];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
int ans = 1, de = 1, num = 1, su = 5000;
for (int i = 1; i <= 1000; i++) {
int w = i - k;
de = num = 0;
int j;
for (j = 1; j <= n; j++) {
w +=... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int N, M;
long long L;
long long A[MAXN];
string S[MAXN];
map<string, long long> score;
map<string, int> prefix;
string idx[MAXN];
long long P[MAXN];
long long mat[MAXN][MAXN];
long long temp[MAXN][MAXN];
long long dp[MAXN];
long long temp2[MAXN];
void... | 17 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
const long long inf = 4e18;
const int infi = 2e9;
int i, j, n, m, k, qq = 1, fr, to, w, x, y, mod = 998244353;
char ch;
vector<vector<int> > g, ans;
int max_pos;
void dfs(int secon... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double m1, m2, m3, m4, m5, w1, w2, w3, w4, w5, hs, hu;
double a, b, c, d, e;
int sum = 0, x;
cin >> m1 >> m2 >> m3 >> m4 >> m5 >> w1 >> w2 >> w3 >> w4 >> w5 >> hs >> hu;
a = max((0.3 * 500), (((1 - (m1 / 250)) * 500) - (50 * w1)));
b = max((0.3 * 10... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<char, string> sol;
sol['2'] = "2";
sol['3'] = "3";
sol['4'] = "223";
sol['5'] = "5";
sol['6'] = "35";
sol['7'] = "7";
sol['8'] = "2227";
sol['9'] = "2337";
int n;
cin >> n;
string s;
cin >> s;
string ans = "";
for (int i = 0; i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
char s[1000001];
unordered_map<int, int> f;
int main() {
long long ans = 0;
scanf("%d", &n);
while (n--) {
scanf("%s", s);
int msk = 0;
for (int i = 0; s[i]; ++i) msk ^= 1 << (s[i] - 'a');
ans += f[msk];
for (int one = 1; one < 1 << 26; one ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const long long int MOD64 = (long long int)(1e18) + 7;
const int INF = 0x7fffffff;
const long long int INF64 = 0x7fffffffffffffff;
using namespace std;
const int maxn = 1e+5;
struct abc {
long long pos;
long long sp;
} ver[maxn * 2 + 5];
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
vector<long long> trial_division(long long n) {
vector<long long> factorization;
while (n % 2 == 0) {
factorization.push_back(... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int inf = 1000000000;
int main() {
int n;
scanf("%d", &n);
int n1 = n / 2;
int n2 = n - n1;
vector<int> pow3(n2 + 1);
pow3[0] = 1;
for (int i = 1; i <= n2; i++) pow3[i] = 3 * pow3[i - 1];
int d[maxn][3];
for (int i = 0; i < n; i+... | 15 |
#include <bits/stdc++.h>
int main() {
int n, k, c = 0;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++)
if (k % i == 0 && k / i <= n) c++;
printf("%d", c);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T x, T y) {
if (y == 0) return x;
return gcd(y, x % y);
}
class AVasyaAndSocks {
public:
void solve(std::istream &cin, std::ostream &cout) {
int n, m;
cin >> n >> m;
int cnt = 0, ans = 0;
while (n) {
cnt++;
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mul(long long x, long long y) {
x = (x % 10000000000 + 10000000000) % 10000000000,
y = (y % 10000000000 + 10000000000) % 10000000000;
return ((((x >> 20) * y % 10000000000) << 20) + (x & ((1 << 20) - 1)) * y) %
10000000000;
}
long long two(long long... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long Floor(long long A[], long long l, long long r, long long key) {
int m;
while (r - l > 1) {
m = l + (r - l) / 2;
if (A[m] <= key)
l = m;
else
r = m;
}
return l;
}
int main() {
long long n, m, i, j, ans_a, ans_b, ans, ma, q, score_a... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
if (b == 0 && a == n - 1 && a != 0) {
cout << -1;
return 0;
}
if (b == 0 && a < n - 1) {
for (int i = 0; i < n - a; i++) cout << 1 << " ";
int t = 2;
for (int i = n - a; i < n; i++) {
cout << ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
scanf("%d", &n);
int ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &t);
ans1 = ans1 | t;
}
for (int i = 0; i < n; i++) {
scanf("%d", &t);
ans2 = ans2 | t;
}
printf("%d\n", ans1 + ans2);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxv = 1000000 + 10;
const int maxn = 50000 + 10;
const int maxm = 5000 + 10;
int n, m;
int a[maxn], b[maxn], l[maxm], r[maxm], ans[maxm];
int f[maxv], g[maxn];
int main() {
f[0] = 0;
for (int i = 1; i < maxv; i++) f[i] = f[i - 1] ^ i;
scanf("%d%d", &n, &m);... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, a, sum = 0;
cin >> n >> h;
for (int i = 0; i < n; i++) {
cin >> a;
if (a > h) {
sum++;
}
sum++;
}
cout << sum;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
pair<int, int> v[3005];
vector<int> g[6005];
map<int, int> ind, f;
int dp[6005][6005];
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
for (; t; t--) {
cin >> n;
ind.clear();
f.clear();
for (int i = 1; i... | 15 |
#include <bits/stdc++.h>
int main() {
int n, i, x;
int a[200003];
std::map<int, int> b;
std::cin >> n;
for (i = 0; i < n; ++i) {
std::cin >> a[i];
}
for (i = 0; i < n; ++i) {
std::cin >> x;
++b[x];
}
for (i = 0; i < n; ++i) {
auto it = b.lower_bound(n - a[i]);
if (it == b.end()) {
... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<long long>::max();
const long long mod = 1000 * 1000 * 1000 + 7;
void s... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int size = 110000, mod = 1000000009;
const double pi = acos(-1.0);
vector<int> ar;
int main() {
int n, h, i, a, t1, t2, ans = 1000000000, id;
cin >> n >> h;
for (int i = 1; i < n + 1; i++) {
cin >> a, ar.push_back(a);
if (ans > a) ans = a, id = i;
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int need = 1999 - (n % 1999);
int ans = (n + 2000 * need) / 1999;
printf("2000\n");
for (int i = 0; i < 1998; i++) printf("0 ");
printf("%d %d\n", -need, ans);
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, k = 1, sum = 0;
cin >> a >> b;
if (a > b) {
int temp = a;
a = b;
b = temp;
}
while (a != b) {
a++;
sum += k;
if (a == b) {
cout << sum;
return 0;
}
b--;
sum += k;
k++;
}
cout << sum;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
while (~scanf("%I64d%I64d", &n, &k)) {
long long sum = k * (k - 1) / 2;
if (sum < 0) {
printf("-1\n");
continue;
}
long long q = -1;
for (long long i = 1; i * i <= n; i++) {
long long qq = n / i;
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int h[100001], endTime[100001];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &h[i]);
endTime[i] = h[i];
}
int best = 0;
for (int i = 1; i <= n; ++i) {
best++;
best = min(best, h[i]);
endTime[i] = best;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
deque<pair<int, int> > q;
int mp[1005][1005];
int d[4][1005][1005];
int n, m, k;
int min(int x, int y) {
if (x < y) return x;
return y;
}
void dfs(int c) {
while (!q.empty()) {
pair<int, int> u = q.front();
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, j, k, n, m, a, b, c;
scanf("%d", &n);
vector<pair<int, int> > arr(n);
for (i = 0; i < n; i++) {
scanf("%d", &j);
arr[i] = (make_pair(j, i + 1));
}
sort(arr.begin(), arr.end());
c = 0;
for (i = 1; i < n; i++) {
if (arr[i - 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, q, t1[800000];
long long w[800000], a[800000], t2[800000];
void build(int left, int right, int p) {
if (left == right) {
t1[p] = w[left];
t2[p] = w[left] * (left - a[left]);
t2[p] %= 1000000007;
return;
}
int mid = (left + right) >> 1;
b... | 17 |
#include <bits/stdc++.h>
int main() {
int tasks;
std::cin >> tasks;
for (int o = 0; o < tasks; ++o) {
int n;
std::cin >> n;
int res = 0;
std::vector<int> a(n);
std::vector<int> b(n);
std::vector<int> need_change;
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
if (a[i] <= n... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
class SegTree {
private:
const ll NEUT = 0;
vector<ll> seg, tag;
int h = 1;
ll len(int i) { return h >> (31 - __builtin_clz(i)); }
void apply(int i, ll v) {
seg[i] = (seg[i] + v * len(i)) % MOD;
if (i < h) tag... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1][n + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) cin >> a[i][j];
}
int res[n + 1];
res[1] = (int)sqrt(1LL * a[1][2] * a[1][3] / a[2][3]);
res[n] = (int)sqrt(1LL * a[n - 2][n] * a[n - 1][n] / a... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const double PI = acos(double(-1));
const double INF = 1e10;
const double EPS = 1e-8;
inline double sqr(double x) { return x * x; }
namespace G3 {
struct PT3 {
double x, y, z;
PT3() {}
PT3(double x, double y, doubl... | 20 |
#include <bits/stdc++.h>
using namespace std;
int N, A[200001];
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%d", &A[i]);
sort(A, A + N);
int r = -1, j = 0;
for (int i = 0; i < N; i++)
while (j < N && A[j] - A[i] <= 5) {
j++;
r = max(r, j - i);
}
printf("%d\n", r);
}
| 4 |
#include <bits/stdc++.h>
int ar[1001];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
int cnt = 0, mov;
for (mov = 1;; mov++) {
if (mov & 1) {
for (int i = 0; i < n; i++)
if (ar[i] != -1 and ar[i] <= cnt) {
ar[i] = -1;
cnt++;
... | 4 |
#include <bits/stdc++.h>
int quick_power(int a, int b, int Mod) {
int ans = 1;
while (b) {
if (b & 1) {
ans = 1ll * ans * a % Mod;
}
b >>= 1;
a = 1ll * a * a % Mod;
}
return ans;
}
const int Maxn = 2500;
const int Maxm = 100000;
const int Mod = 1000000007;
int n;
int a[Maxn + 5];
int sum;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int dp[70000][18][4];
int initial[140000];
vector<pair<int, int> > trans[4][4];
void pre() {
trans[0][0] = {{0, 0}};
trans[0][1] = {{1, 1}, {2, 2}};
trans[0][2] = {{2, 2}};
trans[0][3] = {{3, 3}, {2, 3}};
trans[1][1] = {{3, 2}};
trans[1][2] = {{3, 3}, {2, 3}};
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
return x * x;
}
template <typename T>
inline T abs(T x) {
return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int S = 16 * 13;
const int Mod = 1e9 + 7;
typedef class Matrix {
public:
int r, c;
int a[S][S];
Matrix() {}
Matrix(int r, int c) : r(r), c(c) {}
Matrix operator*(Matrix b) {
Matrix rt(r, b.c);
for (int i = 0; i < r; i++) {
for (int j = 0; j < ... | 22 |
#include <bits/stdc++.h>
using namespace std;
char p[1005][1005];
long long q[1005][1005], vis[1005][1005] = {0}, n, m;
void dfs(long long x, long long y) {
if (x < 1 || x > n || y < 1 || y > m || vis[x][y] == 1 || q[x][y] == 0)
return;
vis[x][y] = 1;
dfs(x + 1, y);
dfs(x - 1, y);
dfs(x, y + 1);
dfs(x, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4005;
int n;
long long ans = 0;
struct Point {
int x, y, k;
Point() {}
Point(int x, int y) : x(x), y(y), k(0) {}
Point(int x, int y, int k) : x(x), y(y), k(k) {}
inline int scene() const {
if (!x) return k * 8 + (y > 0 ? 4 : 8);
if (!y) re... | 19 |
#include <bits/stdc++.h>
using namespace std;
int c[101][101];
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n, 0), b(m, 0);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i == n - 1 && j < m -... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
map<string, int> mp;
map<int, string> pm;
bool vis[maxn];
long long cur;
long long cnt = 1;
int a[maxn][maxn];
inline void DFS(int x) {
vis[x] = 1;
for (int i = 1; i <= cnt; i++)
if (!vis[i] && a[x][i]) {
cur = i;
vis[i] = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long n, a[10000];
void doc() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
}
bool kt() {
for (int i = 1; i <= n; i++)
if (a[i] != i - 1) return false;
return true;
}
void xl() {
long k1 = abs(a[1] - 0);
for (int i = 1; i <= n; i++) {
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[25][3];
int bestsum, bc0, bc1;
map<pair<int, int>, pair<int, int> > dp;
void find(int half, int code, int s0, int s1, int s2, int pos, int limit) {
if (pos == limit) {
int p1 = s1 - s0;
int p2 = s2 - s0;
pair<int, int> pp;
if (!half) {
p... | 15 |
#include <bits/stdc++.h>
int cnt = 0, ans = 0, n, k;
std::queue<int> tmp;
std::vector<int> vec[1000005];
int h[1000005], to[2000005], ver[2000005];
int dep[1000005], du[1000005];
inline int read() {
register int x = 0, f = 1;
register char s = getchar();
while (s > '9' || s < '0') {
if (s == '-') f = -1;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mx[100000][2];
vector<int> vtx[100000];
bool isc[100000];
int n, m, d, ans = 0;
int f(int x, int y) {
mx[x][0] = make_pair((isc[x] ? 0 : -1000000000), -1);
mx[x][1] = make_pair(-1000000000, -1);
for (int i = 0, _n = vtx[x].size(); i < _n; i++)
if (v... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = signed long long int;
using pi = pair<int, bool>;
using vp = vector<pi>;
const int N = 1e6 + 100;
vp ms[2];
struct trie {
trie *sons[2]{nullptr, nullptr};
int val = -1;
void purge() {
if (sons[0] != nullptr) {
sons[0]->purge();
}
if (sons[... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long s[1 << 18], n, a[1 << 18][18], b[18][1 << 18], r[1 << 18],
bc[1 << 18];
char c[18][18];
map<vector<long long>, vector<long long> > ma;
long long cl(const vector<long long>& v) {
long long r = 0;
for (long long i = 0; i < (1 << n); i++) s[i] = 1;
for (lon... | 24 |
#include <bits/stdc++.h>
using namespace std;
int jk = 1e9;
long long xy1[4] = {0, 0, -1, 1};
long long xy2[4] = {1, -1, 0, 0};
long long n1, m1;
int main() {
long long test, i, j, xy, flag = 0, n, count, u, d, o1 = 0, o2 = 0, s, e, x,
y, m, l, z, r, max1, x1, y1, k, x2, y2, z1, sum, f,
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
int ans = 1;
int j = 1;
for (int i = 0; i < n - 1; i++) {
ans += j;
ans %= n;
j++;
ans = ans == 0 ? n : ans;
cout << ans << " ";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int m, k;
cin >> m >> k;
vector<int> have(k);
vector<int> runOut(k, 0);
bool firstRunOut = false;
bool unknownRunOut = true;
int stolen = 0;
for (int i = 0; i < k; i++) {
cin >> have[i];
}
for (int i = 0; i < m - 1; i++) {
int d, b... | 13 |
#include <bits/stdc++.h>
using namespace std;
char I[8][10], buffer[10];
int to[8], n, k;
int f() {
int mn = INT_MAX, mx = 0, x;
for (int i = 0; i < (n); i++) {
for (int j = 0; j < (k); j++) buffer[to[j]] = I[i][j];
sscanf(buffer, "%d", &x);
mn = min(mn, x);
mx = max(mx, x);
}
return mx - mn;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010];
int la, ra;
void update(int i, int delta) {
for (; i < n; i = i | (i + 1)) {
a[i] += delta;
}
}
int get(int i) {
int res = 0;
for (; i >= 0; i = (i & (i + 1)) - 1) {
res += a[i];
}
return res;
}
int main(void) {
int q;
scanf("%d%d",... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long pre[51], suf[51], sum[51], ansx[51], a[5001];
int main() {
int n, m, i, j, k;
long long dp, ans = LLONG_MIN;
scanf("%d%d", &n, &m);
for (int x = 1; x <= n; x++) {
scanf("%d", &k);
for (i = 1, dp = 0, ansx[x] = LLONG_MIN; i <= k; i++) {
scanf(... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edge[6000];
int c[3000];
int sz[3000];
vector<int> dfs(int src) {
sz[src] = 1;
vector<int> ret;
for (int i = 0; i < edge[src].size(); i++) {
int u = edge[src][i];
vector<int> temp = dfs(u);
sz[src] += sz[u];
for (int i = 0; i < temp.size();... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i;
string s;
cin >> s;
string ans;
int count_at = 0;
int len = s.size();
for (i = 0; i < len; i++) {
if (i < len - 1 && s[i] == 'a' && s[i + 1] == 't') {
ans.push_back('@');
count_at++;
i++;
} else if (i < len - 2 && ... | 5 |
#include <bits/stdc++.h>
const int MAXN = 20010;
int n, Q;
std::vector<std::pair<int, int> > V[MAXN];
int fa[MAXN], sz[MAXN], dep[MAXN], fae[MAXN];
int ff[16][MAXN];
void dfs(int u) {
sz[u] = 1;
for (auto t : V[u]) {
int i = t.second, v = t.first;
if (v != fa[u]) {
ff[0][v] = fa[v] = u, fae[v] = i;
... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int m;
cin >> m;
int n = s.size();
int sum[n + 1][3];
sum[0][0] = sum[0][1] = sum[0][2] = 0;
for (int i = 1; i <= n; ++i) {
if (s[i - 1] == 'x') {
sum[i][0] = sum[i - 1][0] + 1;
sum[i][1] = sum[i - 1][1];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int count = 0;
for (long long int i = s.size() - 1; i >= 0; i--) {
if (s[i] == '0')
count++;
else {
if (s[i] == '1' && count > 0)
count--;
else {
if (s[i] == '1' && count == 0) s[i]... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
int dp[2][maxn][maxn * maxn];
int pd[maxn][maxn * maxn];
int a[maxn];
int n;
int sum;
inline void input();
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
input();
}
inline void input() {
cin >> n;
for (int i = 1; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
int res = 0;
int i = 0, j = 0;
vector<pair<int, int> > rr;
while (i < a.size() && ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string num;
cin >> num;
int len = num.size();
for (int i = 0; i < len;) {
if ((num[i] != '1') && (num[i] != '4')) {
cout << "NO" << endl;
return 0;
} else if (num[i] == '1' && num[i + 1] != '4') {
i++;
} else if (num[i] == ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long int a[maxn], b[maxn];
int main() {
ios::sync_with_stdio(false);
long long int n, p;
cin >> n >> p;
long double ans = 0;
cout << fixed << setprecision(10);
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
for (int i = 0; i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, m, k, dp[1 << 23], a[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
dp[a[i] ^ ((1 << 23) - 1)] = a[i];
}
for (int i = (1 << 23) - 1; i >= 0; i--) {
if (dp[i] == 0) {
for (in... | 14 |
#include <bits/stdc++.h>
using namespace std;
int tot = 1;
int e[500001], nxt[500001], cost[500001], g[500001];
int gap[500001], d[500001], cnt[500001], rev[500001];
int q[500001];
int c[500001];
int n, m;
int S, T, N;
int stk[500001];
void add(int u, int v, int w) {
e[tot] = v;
nxt[tot] = g[u];
c[tot] = w;
rev... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans, cnt;
string a, t;
vector<pair<int, pair<int, string> > > v;
bool cmp(pair<int, pair<int, string> > a, pair<int, pair<int, string> > b) {
if (a.first * 1ll * b.second.first > b.first * 1ll * a.second.first)
return true;
return false;
}
int main(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int num[100003][4];
int nnum[300010];
int num1[100003];
int min(int a, int b, int c) {
if (nnum[a] <= nnum[b] && nnum[a] <= nnum[c]) {
return a;
} else if (nnum[b] <= nnum[a] && nnum[b] <= nnum[c])
return b;
else
return c;
}
int main() {
int n;
int i, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, i, x, ans = 0;
bool b1[109], b2[109];
vector<int> v1[109], v2[109];
void dfs1(int i);
void dfs2(int i);
void dfs1(int i) {
b1[i] = 1;
for (int j = 0; j < v1[i].size(); j++)
if (!b2[v1[i][j]]) dfs2(v1[i][j]);
}
void dfs2(int i) {
b2[i] = 1;
for (int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void onedig(int a) {
if (a == 0)
cout << "zero";
else if (a == 1)
cout << "one";
else if (a == 2)
cout << "two";
else if (a == 3)
cout << "three";
else if (a == 4)
cout << "four";
else if (a == 5)
cout << "five";
else if (a == 6)
co... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9 + 1337);
const long long LINF = (long long)(4e18);
const double EPS = (double)(1e-11);
double f[2][1010];
vector<double> prob;
double prob_stay(int n, int k) { return (double)(k) / n; }
double prob_next(int n, int k) { return (double)(n - k) / n; }... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10000020;
int bufpos;
char buf[MAXSIZE];
void init() {
buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
bufpos = 0;
}
int readint() {
int val = 0;
for (; !isdigit(buf[bufpos]); bufpos++)
;
for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + b... | 19 |
#include <bits/stdc++.h>
int n;
int ans = 0x3f3f3f3f;
int gcd(int a, int b) {
if (a == 1 || b == 1) return a + b - 2;
if (a == 0 || b == 0) return n;
return a / b + gcd(b, a % b);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) ans = std::min(ans, gcd(n, i));
printf("%d\n", ans);
return 0;
}
| 11 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
using namespace std;
const int N = 1e6 + 5;
vector<pair<int, int> > ad[N], dl[N];
int n, k, m, l, r, c, p, up;
long long a[N], b[N];
void add(long long *bit, int x, long long a) {
while (x < N) bit[x] += a, x += x & -x;
}... | 12 |
#include <bits/stdc++.h>
using namespace std;
void dout() { cerr << '\n'; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << " " << H;
dout(T...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char c[103][103], ans[103][103], sym[63];
int main() {
ios_base... | 9 |
#include <bits/stdc++.h>
using namespace std;
int mint;
struct tree {
int l, r;
int ls, rs;
int w, tag;
tree() {}
tree(int L, int R, int LS, int RS, int W, int TAG) {
l = L;
r = R;
ls = LS;
rs = RS;
w = W;
tag = TAG;
}
} tr[5000004];
int a[100004];
int n, k, cnt;
int up, td[400004];
... | 15 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, pair<long long, long long> > memo;
long long cube_root(long long n) {
long long lo = 0, hi = 1e6;
while (lo < hi - 1) {
long long mid = (lo + hi) / 2;
if (mid * mid * mid > n)
hi = mid;
else
lo = mid;
}
return lo;
}
p... | 14 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int r = 0, t = 1, c = getchar();
while (c < '0' || c > '9') {
t = c == '-' ? -1 : 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
r = r * 10 + c - 48;
c = getchar();
}
return r * t;
}
const int N = 510, M = 1000010, mod = 99824435... | 14 |
#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265359;
long long inf = 1000000000000000007;
long long mod = 1000000007;
long long mod1 = 998244353;
const bool multi = 1;
long long last[300007];
long long maxi[300007];
vector<long long> v[300007];
signed main() {
ios_base::sync_with_stdio(0);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int cost[25][25], occ[25], f[25][(1 << 20) + 5], d[1 << 20];
int n;
int a[400005];
inline long long int calcCost(int x, int y) {
long long int cnt = 0;
long long int res = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == x) cnt++;
if (a[i] == y) res += ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s[2000];
vector<int> go(int lo, int hi, int b) {
vector<int> um;
for (int i = 0; i < hi - lo + 2; i++) {
um.push_back(0);
}
if (hi - lo >= 1) {
int j = lo;
while ((int)s[lo].size() > b && j < hi && s[j + 1][b] == s[lo][b]) j++;
vecto... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, k;
int p[N], s[N], mx[N];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%d", p + i);
for (int i = 0; i < n; i++) {
scanf("%d", s + i);
mx[s[i]] = max(mx[s[i]], p[i]);
}
int id, ans = 0;
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int K = 40;
long long l[2], r[2], left_border[2] = {0, 0}, right_border[2] = {0, 0},
powof2[K], ans;
void pair_it(long long cnt_l, long long cnt_r) {
if (l[1] == r[1] && l[1] % 2 == 1) {
ans =
max(ans, min(cnt_l, left_border[1]) + 1... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void read() {}
template <typename T, typename... Ts>
inline void read(T& A, Ts&... As) {
T x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int to, next;
} q[300005 << 1];
int head[300005];
int cnt = 0;
void add_edge(int from, int to) {
q[cnt].to = to;
q[cnt].next = head[from];
head[from] = cnt++;
}
vector<int> E[300005];
int dep[300005];
int Par[300005];
bool vis[300005];
void init() {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(T& n) {
return n.size();
}
template <class T>
string toString(T n) {
ostringstream ost;
ost << n;
ost.flush();
return ost.str();
}
int toInt(char s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
int solve(vecto... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.