solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
vector<long long> a[1005];
long long w[1005], b[1005], vis[1005], wt, n, m, x, y;
vector<long long> con[1005];
long long c = 0, dp[1004][1005];
void dfs(long long v) {
vis[v] = 1;
con[c].push_back(v);
for (auto x : a[v])
if (vis[x] == 0) dfs(x);
}
long long f(long... | 8 |
#include <bits/stdc++.h>
using namespace std;
static const int M = 100004, MX = M * 40;
int n, K;
int Rt[M], Lp[MX], Rp[MX], Sum[MX], tot;
void Insert(int l, int r, int &p, int a) {
if (!p) p = ++tot;
Sum[p]++;
if (l != r) {
int mid = l + r >> 1;
if (a <= mid)
Insert(l, mid, Lp[p], a);
else
... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool query1(int a, int b){
cout << "1 " << a << " " << b << endl;
int x; cin >> x; assert(x != -1); return x;
}
bool query2(int a, vector<int> v){
if(v.empty()) return 0;
cout << "2 " << a << " " << v.size();
for(int& num : v) cout << " " << num;
cout << endl; int x... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 1e5 + 10;
char s1[MAXSIZE];
char s2[MAXSIZE];
char s3[MAXSIZE];
int n, t;
int d1, d2;
int sd;
int main() {
scanf("%d %d", &n, &t);
getchar();
fgets(s1, n + 1, stdin);
getchar();
fgets(s2, n + 1, stdin);
int same, diff;
same = diff = 0;
fo... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct apple {
int be, to, v;
} edge[N * 2];
int t[N], vist[N], size[N];
int k, n;
long long minans, maxans;
void addedge(int x, int y, int v) {
edge[++k].to = y;
edge[k].be = t[x];
t[x] = k;
edge[k].v = v;
}
void dfs(int x) {
int p, xx;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000009], dp[10000009];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
int low = 0;
for (int i = 23; i >= 0; i--) {
int x = low + (1 << i);
fill(dp, dp + min(x, 10000001), 0);
for (int j = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], dp[100005], res = 0;
int main() {
cin >> n;
for (int(i) = (1); (i) <= (n); ++(i)) cin >> a[i];
for (int(i) = (1); (i) <= (n); ++(i)) {
dp[a[i]] = dp[a[i] - 1] + 1;
res = max(res, dp[a[i]]);
}
cout << n - res << "\n";
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
if (n * m & 1)
cout << (n * m + 1) / 2 << '\n';
else
cout << (n * m) / 2 << '\n';
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int m = 1000000007;
int main() {
long long int x, k;
cin >> x >> k;
if (x == 0)
cout << "0" << endl;
else {
x = x % m;
long long int ans = 1;
long long int ans1;
long long int b = 2;
while (k > 0) {
if ((k) % 2 != 0) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long n, k;
long long a[2][200005];
long long solve(long long n, long long v) {
long long i, b;
long long x, y;
x = 1;
for (i = 0; i < n && a[v][i] == -1; i++) x = x * (i == 0 ? 1 : k - 1) % mod;
y = x;
b = 0;
for (; i < n;... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
const double eps = 1e-6;
int n, m, a, b;
double ya[maxn], yb[maxn], lu[maxn];
double t;
struct point {
public:
double x, y;
point(){};
point(int _x, int _y) : x(_x), y(_y){};
} pa[maxn], pb[maxn];
double dist(point a, point b) {
return t = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int d[55][55];
int func(int x, int y, int r) {
if (max(x, y) + r > 50) return 0;
int sum = 0;
for (int i = 0; i < r; i++) {
if (d[x + i][y]) sum++;
if (d[x][y + i + 1]) sum++;
if (d[x + i + 1][y + r]) sum++;
if (d[x + r][y + i]) sum++;
}
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, i;
string l, r;
vector<int> graph[200005];
bool vis[200005];
int f(int x) {
if (x < n) return x;
return x - n;
}
bool BFS() {
vector<int> Q, temp;
Q.push_back(0);
vis[0] = true;
int i = 0;
for (int level = 0; level <= n; ++level) {
while (i < Q.s... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int permutation1[100000], permutation2[100000];
void solve1(int k) {
if (k == 0) return;
int t = 1 << (31 - __builtin_clz(k));
for (int i = (t); i < (k + 1); i++) {
permutation1[i - 1] = (t << 1) - i - 1;
permutation1[(t << 1) - i - 2] = i;
}
solve1... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int MOD = 1e9 + 7;
const int N = 1e6 + 6;
int baad[N];
int getLIS(vector<int>& vec, int frm, int to) {
int ret = 0;
vector<int> dp(to - frm + 5, INF);
dp[0] = -INF;
for (int i = frm; i <= to; i++) {
if (baad[i]) continue... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int T = 1;
cin >> T;
while (T--) {
int n, x, ans = INT_MAX, f = 0;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == x) f = 1;
ans = min(ans, x / a[i] + (x % a[i] > 0));
}
if... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks")
#pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx")
using std::lower_bound;
using std::max;
using std::min;
using std::vector;
const int MAXN = 6e3 + 50;
vector<int> E[MAXN];... | 14 |
#include <bits/stdc++.h>
using namespace std;
int operationN, number;
char text[1100005], newText[1100005];
int main() {
int best = 1000000, print = -1, printj;
scanf("%d%d", &operationN, &number);
if (number == 1) {
if (operationN == 1)
printf("0\nT");
else
printf("IMPOSSIBLE");
return 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i += 2) {
for (int j = 0; j < i; j++) {
if (s[i] < s[j]) {
swap(s[i], s[j]);
}
}
}
cout << s << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1005], b[1005], c[1005], d[1005];
map<pair<int, int>, int> mp;
int n;
void init() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", a + i, b + i);
}
for (int i = 1; i <= n; ++i) {
scanf("%d%d", c + i, d + i);
}
for (int i = 1; i <= n;... | 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 500010;
long long t, n, cnt, x, x2, m, a[maxn], b[maxn], tag[maxn], ans[75], pos,
c[maxn], l, r, mid, y, z, mx, k, mod1 = 1000000007, mod2 = 998244353, cnt1,
... | 24 |
#include <bits/stdc++.h>
using namespace std;
long long mulmod(long long a, long long b, long long c) {
long long x = 0, y = a % c;
while (b > 0) {
if (b % 2 == 1) {
x = (x + y) % c;
}
y = (y * 2) % c;
b /= 2;
}
return x % c;
}
int modulo(int a, int b, int c) {
long long x = 1, y = a;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s[33] = {
"111111101010101111100101001111111", "100000100000000001010110001000001",
"101110100110110000011010001011101", "101110101011001001111101001011101",
"101110101100011000111100101011101", "100000101010101011010000101000001",
"111111101010101010... | 7 |
#include <bits/stdc++.h>
using namespace std;
namespace tree_split2 {
const int N = 310000;
int k;
struct graph {
int Begin[N * 2], to[N * 2], Next[N * 2], e, weight[N * 2];
void add(int u, int v) {
to[++e] = v;
Next[e] = Begin[u];
Begin[u] = e;
}
void add(int u, int v, int w) {
to[++e] = v;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
short int n;
string s;
cin >> n >> s;
short int i = 0;
while (i < n) {
if (s[i] != 'o') {
cout << s[i];
++i;
} else {
if (i == n - 1) {
cout << 'o';
break;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long v[100005];
int main() {
long long i, n, ans = 1;
long long sum;
cin >> n;
for (i = 0; i < n; i++) cin >> v[i];
sort(v, v + n);
sum = v[0];
for (i = 1; i < n; i++) {
if (sum <= v[i]) {
ans++;
sum += v[i];
}
}
cout << ans << "\n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s.size() <= 10)
cout << s << endl;
else {
cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
string s;
int l, r;
char c1, c2;
cin >> n >> m >> s;
while (m--) {
cin >> l >> r >> c1 >> c2;
for_each(s.begin() + l - 1, s.begin() + r, [c1, c2](char &c) {
if (c == c1) c = c2;
});
}
cout << s << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int nr, d, aux, vn[10];
int verif(int i);
int main() {
int i;
cin >> nr;
aux = nr;
while (aux != 0) {
vn[aux % 10] = 1;
aux /= 10;
}
if (nr == 1)
cout << "1\n";
else {
d = 0;
for (i = 1; i * i < nr; i++) {
if (nr % i == 0 && verif(i) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int lg = 22;
const long long int N = 1e6 + 5;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;
template <typename T>
T power(T x, T y, long long int m) {
T ans = 1;
while (y > 0) {
if (y & 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int t, v, next;
} a[100010];
struct hhhh {
int s, t, v;
} h[210];
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
q;
int dis[10000010];
int head[110], from[110], fa[110], size[110], id[110], n, m, A, B,... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int m;
cin >> m;
v.push_back(m);
}
vector<int> v1;
for (int i = 1; i <= 3; i++) v1.push_back(count(v.begin(), v.end(), i));
int w = *min_element(v1.begin(), v1.end());... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, q;
cin >> n >> p;
int a[101] = {0};
while (p--) {
cin >> q;
a[q] = q;
}
cin >> p;
while (p--) {
cin >> q;
a[q] = q;
}
int b = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == 0) {
b = 1;
break;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' || c ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int lst[100005], to[200005], pre[200005], tot;
int f[100005], num[200005], cur_cnt, mx, ans, cnt;
long long val[200005];
map<long long, int> app;
inline void add_edge(int u, int v) {
to[tot] = v;
pre[tot] = lst[u];
lst[u] = tot++;
}
inline void add(int x) {
if (!num... | 21 |
#include <bits/stdc++.h>
using namespace std;
int t;
long long a, b, c, d;
class FastIO {
private:
struct control {
int ct, val;
control(int Ct, int Val = -1) : ct(Ct), val(Val) {}
inline control operator()(int Val) { return control(ct, Val); }
} _endl, _prs, _setprecision;
char in[1000000], *p, *pp,... | 13 |
#include <bits/stdc++.h>
void fileio_in_out() {
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
}
void fileio_txt() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int n, ans = 0, a, b, c;
int i, j, k, l;
int f[1111111];
int calc(int n) {
int i;
if (!f[n])
for (i = 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, ar[1010], vis[1010];
int x, y, sum, ans = 1e9;
vector<pair<int, int>> v[1010];
void tap(int z) {
if (z == y) {
ans = min(ans, sum);
return;
}
for (int i = 0; i < v[z].size(); i++)
if (vis[v[z][i].first] == 0)
sum += v[z][i].second, vis[z] = 1,... | 0 |
#include <bits/stdc++.h>
int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
using namespace std;
long long power(long long a, long long p, long long M) {
long long r = 1;
a = a % M;
while (p > 0) {
if (p % 2) r = (r * a) % M;
a = (a * a) % M;
p /= 2;
}
return r % M;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char A[100005], B[100005], C[100005];
int main() {
int c1, i, j, k, m, n, t, count, q, c, c_a, c_b;
char ch;
cin >> n;
cin >> t;
for (i = 0; i < n; i++) C[i] = '0';
scanf(" %s", A);
scanf(" %s", B);
q = 0;
for (i = 0; i < n; i++) {
if (A[i] == B[i]) q+... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
int l = s.length();
long long ans = 0, power = 1;
int i = l - 1;
while (i >= 0) {
int temp_i = i;
long long p = 10;
long long num = s[i--] - '0';
int... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 103, mod = 1000000007;
long long dp[27][M], a[M][22], sum = 0;
char s[M];
int main() {
long long x, y;
long long n, k, cos = 0;
cin >> n >> k;
cin >> s + 1;
for (int i = 1; i <= n; i++) {
x = s[i] - 0x61;
for (int j = i; j > 1; j--) {
d... | 11 |
#include <bits/stdc++.h>
using namespace std;
int s[5030], vis[5030];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
memset(vis, 0, sizeof(vis));
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
vis[s[i]] = 1;
}
int res = 0;
for (int i = 1; i <= n; i++) {
if (!vis[i]) re... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << "YES\n";
for (int i = 0; i < n; ++i) {
int a, b, c, d;
cin >> a >> b >> c >> d;
a = abs(a), b = abs(b);
cout << 1 + 2 * (a % 2) + (b % 2) << "\n";
}
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
int q[250 * 1000];
int ar[700 * 1000];
int main(void) {
int n;
scanf("%d", &n);
vector<int> a(n);
int m = 1000 * 1000 * 1000, M = 1;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
m = min(m, a[i]);
M = max(M, a[i]);
}
if (M - m > 200 * 1000 || m... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long n, k;
cin >> n >> k;
long arr[n + 1];
for (int i = 1; i <= n; i++) arr[i] = i;
long m = 2;
int f = 1;
while (k > 0) {
if (f) {
arr[m] = arr[m - 1] + k;
k--... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, x;
cin >> t >> x;
for (int i = 0; i < t.length(); i++) {
if (t[i] != x[t.length() - i - 1]) {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n;
cin >> n;
long long int k = 1;
if (n == 1) {
cout << 1;
return 0;
} else if (n == 0) {
cout << 1;
return 0;
} else
for (i = 1; i < n; i++) {
k = (3 * k) % (1000000 + 3);
}
cout << k;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c, d, k, x = 0;
int rage(int x) { return min(n, max(1, x)); }
int find(int a[], int x) {
int l = 0, u = n - 1, mid;
while (l < u) {
mid = l + (u - l) / 2;
if (a[mid] != -1 && a[mid] <= x)
l = mid + 1;
else
u = mid;
}
l = min(l, n - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long n, m;
cin >> n >> m;
long long mat[n][m];
for (long long i = 0; i < (long long)n; i++) {
for (long long j = 0; j < (long long)m; j++) {
cin >> mat[i][j];
}
}
vector<lon... | 5 |
#include <bits/stdc++.h>
using namespace std;
int db;
vector<int> sor;
bool ellenorzes() {
vector<int> ell = sor;
for (int i = 2; i < sor.size(); i++) {
if (sor[i] - sor[i - 1] + 1 == sor[i - 1] - sor[i - 2]) {
sor[i]++;
db++;
continue;
}
if (sor[i] - sor[i - 1] == sor[i - 1] - sor[i -... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char S[N], T[N];
const int BLOCK = 100;
int BIG(int k) {
string s(S), t(T);
s = t + "#" + s;
int n = s.size(), m = t.size();
vector<int> p(n);
for (int i = 1; i < n; i++) {
int j = p[i - 1];
while (j > 0 and s[i] != s[j]) {
j =... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101001;
long long dp[N];
int main(int argc, const char* argv[]) {
long long n;
cin >> n;
dp[0] = 1;
dp[1] = 2;
int k = 2;
while (1) {
dp[k] = dp[k - 1] + dp[k - 2];
if (dp[k] > n) {
cout << k - 1 << endl;
break;
}
++k;
... | 8 |
#include <bits/stdc++.h>
template <typename T, typename _T>
inline bool chk_min(T &x, const _T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T, typename _T>
inline bool chk_max(T &x, const _T y) {
return x < y ? x = y, 1 : 0;
}
const int P = 1e9 + 7;
const int N = 2e5 + 5;
int fac[N], ifac[N];
long long s[... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a[500], b[500];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
int k = 512, i;
for (i = 0; i < k; i++) {
int sum = 0;
... | 8 |
#include <bits/stdc++.h>
#pragma warning(disable : 4786)
#pragma warning(disable : 4996)
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char s[N];
int main() {
scanf("%s", s + 1);
int n = strlen(s + 1);
int fr = 0;
for (int i = 1; i <= n; i++) {
if (s[i] == 'a' && fr)
break;
else if (s[i] != 'a') {
fr = 1, s[i]--;
}
}
if (fr == 0) s[n] = 'z';
print... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, x, y;
string A, B;
cin >> A >> B;
for (x = 0; A[x] == B[x];) x++;
for (y = B.size(); y >= 0 && A[y + 1] == B[y];) y--;
printf("%d\n", x > y ? x - y : 0);
for (i = y + 1; i <= x; i++) cout << i + 1 << " ";
cout << endl;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const double PI = acos(-1);
const long long MOD = 4e9 + 7;
using namespace std;
int n;
void solvepar() {
cout << "First" << endl;
for (long long i = 1; i < 2 * n + 1; i++) {
if (i <= n)
cout << i << " ";
else
cout << i ... | 20 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 1010000;
const long long INF = (long long)1e18 + 10;
int size[ms];
int c = 1;
int to[ms][26];
long long k;
std::string txt;
void addString(std::string str) {
int on = 0;
for (auto ch : st... | 20 |
#include <bits/stdc++.h>
using namespace std;
string s, s2, virus;
pair<string, int> dp[102][102][102];
int p[302];
int main() {
cin >> s >> s2 >> virus;
virus += '#';
for (int i = 0; i <= s.size(); i++) {
for (int j = 0; j <= s2.size(); j++) {
if (i < s.size() && j < s2.size() && s[i] == s2[j]) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, flag;
int vis1[(1000 + 5)], vis2[(1000 + 5)], vis[(1000 + 5)], u[(5000 + 5)],
v[(5000 + 5)], ok[(1000 + 5)], dis[(1000 + 5)], cnt[(1000 + 5)];
vector<int> edge1[(1000 + 5)], edge2[(1000 + 5)], e[(1000 + 5)], w[(1000 + 5)];
void dfs1(int u) {
vis1[u] = 1;
f... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long inf = (1ll << 60);
const double PI = acos(-1);
const long long iinf = 2147483647;
const long long mod = 1e9 + 7;
const long long maxn = 5e5 + 5;
long long pw(long long x, long long p) {
long long ret = 1;
whi... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 18;
const long long NN = (1 << N);
int n;
long long tot;
long double dp[NN][N];
bool vis[NN][N];
long double prob[N][N];
const long double EPS = 1e-9;
inline long double maior(long double a, long double b) {
if (a - b < EPS) return b;
return a;
}
lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int rdi() {
int d;
scanf("%d", &d);
return d;
}
inline char rdc() {
scanf(" ");
return getchar();
}
inline string rds() {
string s;
cin >> s;
return s;
}
inline double rddb() {
double d;
scanf("%lf", &d);
return d;
}
template <class T>
inline bo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A[5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) cin >> A[i][j];
}
int Q[5] = {0, 1, 2, 3, 4};
long long int prod, max = 0;
do {
prod = 0;
prod = A[Q[0]][Q[1]] + A[Q[1]][Q[0]] + 2 * A[Q[2]][Q[3]] +
2 * A[... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int bk[555], cnt[555], ans;
char s[MAX], p[MAX];
int main() {
cin >> (s + 1);
cin >> (p + 1);
int len1 = strlen(s + 1);
int len2 = strlen(p + 1);
if (len2 > len1) {
puts("0");
return 0;
}
for (int i = 1; i <= len2; i++) bk[p[i]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int n;
int pref[maxn][2];
string s;
int binary(int x, bool sto) {
int lo = x + 1, hi = n, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (pref[mid][sto] - pref[x][sto]) {
hi = mid;
} else {
lo = mid + 1;
}
}
retu... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
long long add(long long x, long long y) { return (x + y) % MOD; }
long long sub(long long x, long long y) { return (x - y + MOD) % MOD; }
long long mult(long long x, long long y) { return (x * y) % MOD; }
const int N = (int)1e6 + 7;... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> arr;
arr.resize(m);
for (int i = 0; i < m; i++) cin >> arr[i];
int pl;
cin >> pl;
int ans = 0;
for (int i = 0; i < m; i++) {
int dif = 0;
for (int j = 0; j < n; j++)
dif += abs(((arr[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;
long long h[20];
long long dp[20][20][20];
long long num[20][20][20];
long long hl[20][20][20];
vector<long long> v;
long long rec(long long i, long long j, long long k) {
if (i == n - 1) {
if (j > 0)
return 2000000000000000005;
else
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[10000010], b[10000010], n, m;
int nume[10000010], deno[10000010];
int no_prime[10000010];
void facto(int x, int v[]) {
for (int i = 2; i * i <= x && no_prime[x]; i++)
while (x % i == 0) v[i]++, x /= i;
if (x > 1) v[x]++;
}
void get_number(int x, int v[]) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
void init_cin() {
ios_base::sync_with_stdio(false);
cin.tie(0);
}
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int ans = min(a[0], a[n - 1]);
for (int i = 0; i + 1 < n; i++) {
ans = min(ans, max(a... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 4e5 + 10;
const long long M = 3e8 + 1;
const long long big = 1e18;
const long long shift = 1000;
cons... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long fun(long long n) {
long long val = 5, ans = 0;
while (val <= n) {
ans += n / val;
val = 5 * val;
}
return (ans);
}
int main() {
long long n;
scanf("%lld", &n);
;
long long lo = 5, hi = 1e6, ans = 0;
while (hi >= lo)... | 5 |
#include <bits/stdc++.h>
using namespace std;
char ch[200010], st[200010], ch1[200010];
long a[200010], mn, mx, cnt, cnt1, i, j, k, x = 1, y, fg, n, m, t, sm,
res[200010];
int main() {
while (~scanf("%ld", &n)) {
sm = 0;
for (i = 0; i < n; i++) {
scanf("%ld", ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, len;
int arr[101];
int main() {
int i, j, k, t, a, b;
cin >> n;
for (i = 0; i < n; i++) cin >> arr[i];
int cur = -350;
int penalty = 0;
sort(arr, arr + n);
int cnt = 0;
int ans = 0;
i = 0;
int f = 1;
for (i = 0; i < n; i++) {
if (cur + ar... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
pair<long long, long long> dq[MAXN];
long long dp[MAXN], tdp[MAXN];
int dqh, dqt;
int n, m, d;
int a, b, t;
vector<pair<int, int> > ab;
void dowork(int currtime, int lasttime) {
sort(ab.begin(), ab.end());
int absz = ab.size();
int abidx = 0;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool findPrime(long long n) {
if (n == 1) return 0;
if (n == 2 || n == 3) return 1;
if (n % 2 == 0 || n % 3 == 0) return 0;
long long i = 5, k = 2;
while (i * i <= n) {
if (n % i == 0) return 0;
i = i + k;
k = 6 - k;
}
return 1;
}
signed main() {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool comp[3000010];
void sieve(int n) {
for (int i = 2; i <= n; ++i) {
if (!comp[i]) {
for (int j = i + i; j <= n; j += i) {
comp[j] = true;
}
}
}
}
void solve() {
int n;
cin >> n;
for (int m = 1; m <= 1000; ++m) {
int val = n * m +... | 0 |
#include <bits/stdc++.h>
using namespace std;
int bit[200005];
int getsum(int x) {
int sum = 0;
while (x > 0) {
sum += bit[x];
x -= (x & -x);
}
return sum;
}
int n;
void update(int x, int num) {
while (x <= n) {
bit[x] += num;
x += (x & -x);
}
}
inline void initBIT() {
memset(bit, 0, sizeo... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
bool use[10];
vector<string> ans;
char buf[32];
int toint(const string &s, int f, int t) {
return atoi(s.substr(f, t - f).c_str());
}
void check(strin... | 12 |
#include <bits/stdc++.h>
using namespace std;
char str[1000005];
char integer[1000005];
char decimal[1000005];
int main() {
scanf("%s", str);
int len = strlen(str);
bool havepoint = false;
int pointpos = len;
for (int i = 0; i < len; ++i) {
if (str[i] == '.') {
havepoint = true;
pointpos = i;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, a, b, xx, yy, o, i;
long long gcd(long long p, long long q) {
if (!q) return p;
return gcd(q, p % q);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> x >> y >> a >> b;
long long gg = gcd(max(a, b), min(a, b));
a /= gg;
b /= g... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[200010];
int pos;
long long ans = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
if (p[i] == m) pos = i;
}
int cnt = 0;
for (int i = pos + 1; i < n; i++)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(1000);
int c = 1;
for (int i = 0; i < k; i++) {
int x;
cin >> x;
for (int j = 0; j < x; j++) {
int y;
cin >> y;
a[y] = c++;
}
}
vector<pair<int, int>> p;
for (int i = 1; i ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
const int MAXE = 100005;
const int INF = 0x3f3f3f3f;
int row[MAXN], col[MAXN];
int idc[MAXN], idr[MAXN];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
memset(row, 0, sizeof(row));
memset(col, 0, sizeof(col));
memset(idc, 0, sizeof(i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
double x[200][3];
double c[3];
double f() {
double ma = -1;
for (int i = 0; i < n; i++) {
double sum = 0;
for (int j = 0; j < 3; j++) sum += ((x[i][j] - c[j]) * (x[i][j] - c[j]));
ma = max(ma, sum);
}
return ma;
}
double ts(int k) {
if (k == 3)
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long binpow(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
long long binpowmod(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y... | 4 |
#include <bits/stdc++.h>
using namespace std;
static const int maxn = 100000 + 10;
inline int read() {
int k = 0, f = 1, c = getchar();
while (c > '9' || c < '0') {
if (c == '-') f = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
k = k * 10 + c - '0';
c = getchar();
}
return k * f;
}
st... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, rez = "";
cin >> s;
int l = s.length();
int* sum = new int[l];
sum[l - 1] = 0;
for (int i = 0; i < l - 1; i++) {
sum[i] = 0;
for (int j = 0; j < i; j++) sum[i] += s[j] - '0';
if (i == 0) {
if (s[0] != '1') sum[i] += s[0] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debug(vector<T> &array) {
for (long long i = 0; i < array.size(); i++) {
cout << array[i] << " ";
}
}
template <typename T>
T max(T &a, T &b) {
return a > b ? a : b;
}
template <typename T>
T min(T &a, T &b) {
return a > b ? b : a;
}
t... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18;
class Node {
public:
pair<long long int, long long int> nums;
};
vector<vector<Node>> tree;
vector<vector<long long int>> values;
void build(int index, int l, int r, int i, vector<vector<Node>> &tree) {
if (l > r) {
return;
}
if (l == ... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:20000000")
using namespace std;
double __begin;
template <typename T1, typename T2, typename T3>
struct triple {
T1 a;
T2 b;
T3 c;
triple(){};
triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {}
};
template <typename T1, typename T2, typename T3>
bool ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
int a[30][30];
int n, m;
bool check() {
for (int i = (0); i < (n); ++i) {
int cnt = 0;
for (int j = (0); j < (m); ++j) cnt += a[i][j] != j + 1;
if (cnt > 2) return 0;
}
return 1;
}
int main() {
cin >> n >> m;
for (int i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
int x, y;
friend bool operator<(const node &a, const node &b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
} a[200005];
int main() {
scanf("%d", &n);
int x;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
a[i].x... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long Inf = 1ll << 60ll;
namespace io {
char buf[(1 << 23)], *p1 = buf, *p2 = buf, c;
int f;
template <typename T>
T read() {
T x = 0;
f = 0;
c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin), p1 == p2)
?... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int conta0[200100];
int conta1[200100];
long long int fat[200100], inv_fat[200100];
long long int mul_inv(long long... | 15 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll t, n, m, x, a;
cin >> t;
while (t--) {
cin >> a >> n >> m;
while (n && a > 20) {
a = a / 2 + 10;
n--;
}
while (m && a > 0) {
a = a - 10;
m--;
}
if (a > 0)
cout << "NO\n";
e... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, e;
cin >> n >> e;
vector<vector<int> > teams(n);
vector<pair<int, int> > E(e);
for (int i = 0; i < e; ++i) {
cin >> E[i].first >> E[i].second;
--E[i].first;
--E[i].second;
}
int T = 1... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.