solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a;
cin >> a;
long long b[a];
for (long long i = 0; i < a; i++) {
cin >> b[i];
}
long long meow = 0;
for (long long i = a - 1; i > 0; i--) {
if (b[i] < b[i - 1]) {
meow = meow + b[i - 1] - b[i];
}
}
cout << meow;
r... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << 0 << " " << 0 << " " << n << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int dd = 1e5 + 7;
const long long infi = 1e9 + 7;
const long long inf = 1e18;
int main() {
if (0) {
freopen("input", "r", stdin);
freopen("output", "w", stdout);
}
if (0 == 012) {
freopen(
""
".in",
"r", stdin);
freopen(
... | 16 |
#include <bits/stdc++.h>
std::ostream &out = std::cout;
std::istream &in = std::cin;
void rint(int &i) { in >> i; }
template <class... Ts>
void rint(int &i, Ts &...args) {
in >> i;
rint(args...);
}
using uint = unsigned;
using namespace std;
using I = int64_t;
using UI = uint64_t;
using szt = size_t;
int main() {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int myDfs(vector<int> *adj, int S) {
if (adj[S].empty()) {
return 1;
}
int max = 0, len;
vector<int>::iterator it;
for (it = adj[S].begin(); it != adj[S].end(); it++) {
len = myDfs(adj, *it);
if (len > max) {
max = len;
}
}
return (max + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int DV(char c) {
int z;
if (c == '0')
z = 0;
else if (c == '1')
z = 1;
else if (c == '2')
z = 2;
else if (c == '3')
z = 3;
else if (c == '4')
z = 4;
else if (c == '5')
z = 5;
else if (c == '6')
z = 6;
else if (c == '7')
z = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[8][8];
int sum1 = 0, sum2 = 0;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cin >> arr[i][j];
}
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (int(arr[i][j]) >= 65 && int(arr[i][j]) <=... | 1 |
#include <bits/stdc++.h>
using namespace std;
char cad[100002], cad1[100002];
vector<string> v;
bool f() {
int i = 0;
for (i = 0; i < v.size();) {
if ((v[i].length() < 4 || v[i].substr(v[i].length() - 4) != "lios")) break;
i++;
}
if ((i == v.size() || v[i].length() < 3 ||
v[i].substr(v[i].length(... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150005;
pair<pair<int, int>, int> Q[MAXN];
long long ans[MAXN];
bool cmp1(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
return a.first.first < b.first.first;
}
int main() {
int N, K;
scanf("%d%d", &N, &K);
for (int i = 1; i <= N; i++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b;
cin >> a >> b;
int k = a - b;
if (k < 0)
cout << "0";
else if (k == 0) {
cout << "infinity";
} else {
set<int> s;
for (int i = 1; i * i <= k; i++) {
if (k % i == 0)... | 8 |
#include <bits/stdc++.h>
const int M = 1000000007;
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long c, n, d, i, j, k, l, s1, s2, ans, te, sum1, p, q, r, wd, sum, lim,
t, m, x, y;
string s;
cin >> t;
while (t--) {
sum1 = 0;
k = 0;
sum = 0;
c = 0;
vector<long lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
struct DP {
long double s, t;
DP() {}
DP(long double s, long double t) : s(s), t(t) {}
friend bool operator>(DP aa, DP bb) {
if (aa.s != bb.s)
return aa.s > bb.s;
else
return aa.t > bb.t;
}
};
DP dp[N];
struct data {
int s... | 20 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:4294967296")
using namespace std;
struct pnt {
pnt() {}
~pnt() {}
pnt(long double _x, long double _y) {
x = _x;
y = _y;
}
long double x, y;
};
const long double eps = 0.000001;
const long double PI = 3.1415926535897932384626433832795L;
inline bo... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[210000];
int main() {
gets(s);
int tmp = strlen(s);
s[tmp++] = ' ';
s[tmp++] = 0;
string token = "";
bool inquote = false;
for (int i = 0; s[i]; i++) {
if (s[i] == '"') {
if (inquote) printf("<%s>\n", token.data());
inquote ^= 1;
t... | 5 |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF ((1LL<<61)+(1LL<<30)-1)
#define LD long double
#define endl '\n'
#define print(x) "[ " << #x << ": " << x << " ]" << flush
#define wprint(x,y) "[ " << #x << ": " << setw(y) << x << " ]" << flusha
#define printV(v) cout << "[ " << #v << ": "... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
long long dp[N][N], a[N], s[N], ans;
bool check(int n, int m, int x) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
for (int k = j; k <= i; k++) {
long long ss = s[i] - s[k ... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
long long _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> n >> m;
if (n > m) n = m;
if (n % 2)
cout << "Akshat\n";
else
cout << "Malvika\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
set<pair<int, int> > s;
vector<pair<int, int> > v;
int count = 0;
for (int i = 1; i <= n; ++i) {
int a, b;
cin >> a >> b;
s.insert(make_pair(a, b));
v.push_back(make_pair(a, b... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, K, x[N], y[N], choose[N], deg[N];
vector<int> G[N];
vector<int> res;
struct cmp {
bool operator()(const int& k1, const int& k2) const {
return deg[k1] > deg[k2];
}
};
set<int, cmp> S;
void remove(int k1) {
assert(!choose[k1]);
choose[k... | 23 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long MAX = 1e9 + 7;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
int s[10];
char a[10];
void add(int x) {
int res, ans = 0;
s[3] += x;
if (s[3] <= 9)
return;
else {
res = s[3];
s[3] = res % 10;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long z = 2 * n;
long long a[z + 1];
a[0] = 0;
for (long long i = 1; i <= z; i++) cin >> a[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
void rot(int &i, int &j, int t) {
int ni, nj;
if (t == -1) {
ni = j;
nj = n - i + 1;
} else {
ni = m - j + 1;
nj = i;
}
i = ni;
j = nj;
swap(n, m);
}
void inv(int &i, int &j) { j = m - j + 1; }
int main() {
ios_base::sync_with_stdio... | 7 |
#include <bits/stdc++.h>
using namespace std;
char r[5005];
char s[5005];
bool v[5005];
int c;
int n;
int l = 1, t = 1;
vector<int> w, w2;
void dfs(int i) {
if (i > n) return;
if (v[i]) return;
v[i] = true;
w2.push_back(i);
int b = i - c;
int q = t - b;
for (int j = 0, ThxDem = l; j < ThxDem; ++j)
if ... | 19 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
vector<long long int> v(n);
long long sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
}
long long mx = 0;
for (long long int j = 0; j < k; j++) {
long long ans = 0, i = j;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int eps = 1e6 + 5;
const double pi = acos(-1.0);
struct s {
double x, y;
} pre[105];
int main() {
int n, k;
while (~scanf("%d%d", &n, &k)) {
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &pre[i].x, &pre[i].y);
}
double ans = 0;
for (int i =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, one3rd, rem, a, b, c;
int main() {
cin >> n;
rem = n % 3;
one3rd = n / 3;
if (rem == 0) {
if (one3rd % 3 == 0) {
a = one3rd - 1;
b = one3rd - 1;
c = one3rd + 2;
} else {
a = one3rd;
b = one3rd;
c = one3rd;
}
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define fasterInOut ios::sync_with_stdio(false); cin.tie(0);
#define pi acos(-1)
int main() {
// freopen("/home/mimi0007/Desktop/Temp/in", "r", stdin);
fasterInOut;
ll T;
cin >> T;
while(T--) {
ll n,... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod{100000000};
long long int dp[101][101][11][11];
int main() {
memset(dp, 0, sizeof dp);
int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
for (int rem_foot{0}; rem_foot <= n1; ++rem_foot) {
for (int rem_horse{0}; rem_horse <= n2; ++rem_horse) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct edge_type {
int x, y, init, lower, upper;
} edge[20 + 1];
int n, m;
int flow[20 + 1];
int inflow[10 + 1], outflow[10 + 1];
int maxcost, minflow;
bool cmp(const edge_type &x, const edge_type &y) {
if (x.x != y.x) return x.x < y.x;
return x.y < y.y;
}
void dfs(in... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 5;
const int mod = 1e9 + 7;
int dp[101][2];
int n, k, d;
int cache(int sum, int flag) {
if (sum > n) return 0;
if (sum == n) {
if (flag == 1) return 1;
return 0;
}
if (dp[sum][flag] != -1) return dp[sum][flag];
int ans = 0;
for (int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, l, d;
scanf("%lld%lld%lld%lld", &n, &d, &m, &l);
long long t = 1;
while (t < n) {
long long pre = (t - 1) * m + l;
long long nxt = t * m - 1;
if (nxt / d > pre / d) break;
t++;
}
long long ans = (((t - 1) * m + l) / d... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int t;
double r, v, f, s;
int check(double t) {
double dis = v * t;
double len = fmod(dis, 2 * pi * r);
double k = len / r / 2.0;
double dis2 = 2.0 * abs(sin(k)) * r;
if (dis + dis2 > f - s) return 1;
return 0;
}
int main() {
scan... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
long long v[N], dp[N], tree[N * 4];
int n;
vector<long long> vx;
void update(int idx, long long val, int st, int en, int root) {
if (idx < st || idx > en) return;
if (st == en) {
tree[root] = max(tree[root], val);
return;
}
int mi... | 12 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = (int)1e6 + 10;
int par[N];
int sz[N];
bool act[N];
void init() {
for (int i = 0; i < N; i++) par[i] = i, sz[i] = 1, act[i] = false;
}
int fin(int x) {
if (x == par[x]) return x;
return ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1010];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
int c, mx = -1;
for (int i = 0; i < n; ++i) {
c = 1;
for (int j = i; j > 0; --j)
if (a[j] >= a[j - 1])
++c;
else
break;
for (int j =... | 3 |
#include <bits/stdc++.h>
const int maxn = 500001;
int n, r;
long long a[maxn], s;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
long long x, y;
scanf("%I64d%I64d", &x, &y);
a[i] = x ^ y;
s ^= x;
}
for (int i = 0; i < 60; ++i) {
int k = -1;
for (int j = r; j < n; ++j)
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAXN = 2e5 + 105;
const int N = 5000 + 15;
const double EPS = 1e-9;
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
long long i, j, k, n, m;
int parent[MAXN];
vector<int> g[MAXN];
int goodSons[MAXN];
b... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool nb[105][105];
bool mark[105];
int n, m, x, s;
int fl;
queue<int> q;
void bfs(int k) {
q.push(k);
mark[k] = 1;
while (!q.empty()) {
int al = q.front();
q.pop();
for (int i = 1; i <= m; i++) {
if (nb[al][i])
for (int j = 1; j <= n; j++)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1999999999;
const double pi = acos(-1.0);
const double eps = 1e-10;
const unsigned HPOW = 10000007;
const int MAXL = 200100;
struct bit {
unsigned* a;
bit(unsigned* data) { a = data; }
void add(int i, unsigned v) {
i += 5;
while (i < MAXL) {
... | 19 |
#include <bits/stdc++.h>
const int N = 55;
const int MX = 10000001;
const long long mod = 1e9 + 7;
using namespace std;
int n;
int m;
int d[N][1 << 5];
char c[N][N];
void solve() {
cin >> n >> m;
for (int i = 0; i < (1 << 3); i++) d[0][i] = 1e9;
for (int i = 1; i <= n; i++) {
int a1 = 1e9, a2 = 1e9, a3 = 1e9;... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<char, int> > vec(100);
int n;
bool check(vector<bool> &bitmask) {
bool flag = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (vec[i].first == vec[j].first) {
if (vec[i].second != vec[j].second) {
if (bitmask... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void OutN(T x) {
size_t i, len = x.size() - 1;
for (i = 0; i < len; i++) cout << x[i] << " ";
cout << x[len] << '\n';
}
template <typename T>
void Outit(T x) {
auto end = x.end();
end--;
for (auto it = x.begin(); it != end; it++) cout << *i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
while (scanf("%d%d%d", &n, &m, &k) >= 1) {
if (n == m) {
if (n == 2) {
if (k == 1) {
printf("4\n");
printf("1 2 3 4\n");
} else {
printf("%d\n", 2 * k + 1);
for (int i = 0; i < k... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 5;
int n, m, mk[MAX], col[MAX];
vector<int> g[MAX];
void dfs(int u) {
mk[u] = 1;
for (int v : g[u])
if (!mk[v]) dfs(v);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int a, b;
scanf("%d%d", &a, &b);
g[a].p... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n;
int a[n][n];
for (i = 0; i < n; i++) {
a[0][i] = 1;
a[i][0] = 1;
}
for (i = 1; i < n; i++) {
for (j = 1; j < n; j++) {
a[i][j] = a[i - 1][j] + a[i][j - 1];
}
}
cout << a[n - 1][n - 1];
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {
time_... | 14 |
#include <bits/stdc++.h>
int main() {
int n, k, r[201];
scanf("%d%d%d", &n, &k, &r[0]);
for (int i = 1; i <= n * 2; i += 2) {
scanf("%d%d", &r[i], &r[i + 1]);
if (k > 0 && r[i] > r[i - 1] + 1 && r[i] > r[i + 1] + 1) {
k -= 1;
r[i] -= 1;
}
}
printf("%d", r[0]);
for (int i = 1; i <= n ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = -1e8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
const int MAXN = 2010;
const int MAXP = 510;
int n, p;
char str[MAXN], pat[MAXP];
int prv[MAXN];
int dp[MAXN][MAXN];
int main() {
scanf("%s%s", str + 1, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
long long int n, q;
cin >> n >> q;
string s;
cin >> s;
set<pair<long long int, long long int>> st;
for (long long int i = 0; i < n - 1; i++) {
if (s[... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, x, y;
cin >> t;
while (t--) {
cin >> n >> x >> y;
if (x + y <= n) {
cout << 1 << " ";
} else {
cout << min((x + y) - n + 1, n) << " ";
}
if (x + y >= n + 1) {
cout << n << endl;
} else {
cout... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct team {
int sol;
int pen;
} t[100];
bool cmp(struct team a, struct team b) {
if (a.sol - b.sol) return a.sol > b.sol;
return a.pen < b.pen;
}
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> t[i].sol >> t[i].pen;
sort(t, t + n, ... | 3 |
#include <bits/stdc++.h>
int a[22], b[22], c[22];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
c[i] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (a[c[i]] < a[c[j]]) {
int t = c[i];
c[i] = c[j];
c[j... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string nm;
cin >> nm;
int cnt = 0;
if (n == 1) {
if (k > 0)
cout << 0;
else
cout << nm;
return 0;
}
if (k == 0) {
cout << nm;
return 0;
}
if (nm[0] != '1') {
nm[0] = '1';
cnt++... | 2 |
#include <bits/stdc++.h>
using namespace std;
void read(int &digit) {
digit = 0;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
bool type = false;
if (c == '-') type = true, c = getchar();
for (; c >= '0' && c <= '9'; digit = digit * 10 + c - '0', c = getchar())
;
i... | 17 |
#include <bits/stdc++.h>
using namespace std;
template class std::vector<int>;
bool flag = true;
vector<vector<int> > vec;
vector<int> color;
void dfs(int source, vector<bool>& visited, int parent) {
if (!visited[source]) {
visited[source] = true;
if (parent == -1)
color[source] = 0;
else {
co... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double H, L;
cin >> H >> L;
double answer;
answer = ((L * L) - (H * H)) / (2 * H);
cout << fixed << setprecision(8) << answer << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
long long s[2] = {3, 4};
long long temp[2][2];
void maxt(long long a[][2], long long b[][2]) {
memset(temp, 0, sizeof temp);
for (long long i = 0; i < 2; i++) {
for (long long j = 0; j < 2; j++) {
for (long long k = 0; k < 2; k++) {
temp[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
long long int x, y;
x = max(3 * a / 10, (a - ((a / 250) * c)));
y = max(3 * b / 10, (b - ((b / 250) * d)));
if (x > y)
cout << "Misha";
else if (x < y)
cout << "Vasya"... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string M;
cin >> N >> M;
reverse(M.begin(), M.end());
int L = stoi(M);
printf("%d\n", N + L);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x, y = 0, r = 1;
for (int i = 1; i <= n; i++) {
x = (i * (i + 1)) / 2;
y += x;
if (y > n) {
r = i - 1;
break;
}
}
cout << r << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int m, n;
int par[MAXN];
vector<pair<int, int> > edges[MAXN];
long long d[MAXN];
struct Node {
int l, r, w;
};
vector<Node> save;
bool cmp(Node x, Node y) { return (x.w < y.w); }
int root(int u) { return par[u] < 0 ? u : (par[u] = root(par[u])); ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int boy[5005], girl[5005];
int main() {
char ch;
int a, b;
int n, m, res = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ch >> a >> b;
if (ch == 'M') {
for (int j = a; j <= b; j++) boy[j]++;
} else {
for (int k = a; k <= b; k++) girl[k]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int to[2 * 100100], nxt[2 * 100100];
int adj[100100], mk[100100];
int cnt = 0;
void add(int a, int b) {
to[cnt] = b, nxt[cnt] = adj[a], adj[a] = cnt, cnt++;
to[cnt] = a, nxt[cnt] = adj[b], adj[b] = cnt, cnt++;
}
bool rec(int v, int p) {
mk[v] = 1;
int vs[2], cnt = 0... | 15 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long int n;
cin >> n;
auto start = high_resolution_clock::now();
vector<long long int> ar(n);
for (long long int x = 0; x < n; x++) {
cin >> ar[x];
}
long long... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<string> a;
int n, m;
pair<int, int> tl(int i, int j) {
pair<int, int> ret(-1, -1);
if (i + 1 < n && j + 1 < m) {
int ast = 0;
pair<int, int> tmp(-1, -1);
for (int k = 0; k < 2; k++) {
for (int l = 0; l < 2; l++) {
if (a[i + k][j + l] == ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, N = 1477;
queue<int> q;
int n, m, T, cost, dlt[N], cnt = 1, head[N], dis[N], iter[N];
bool vis[N];
struct edge {
int to, nxt, cap, cost;
} e[N << 1];
inline void addedge(int u, int v, int flow, int cost) {
e[++cnt] = (edge){v, head[u], flow, cost}, ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = LONG_MAX;
const long long inf64 = LLONG_MAX;
const long double pi = 3.1415926535897932384626433832795;
char a[10000];
int main() {
gets(a);
int n = strlen(a);
int l = 0;
int ans = 0;
for (int i = 0; i < n - 3; i++)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> p[300000];
int freq[2][10 * 300000];
long long num = 0;
vector<int> mx, my;
void update(int p1) {
if (mx.empty()) {
mx.push_back(p1);
my.push_back(p1);
return;
}
if (p[mx[0]].first == p[p1].first) {
mx.push_back(p1);
} else if (... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int P;
cin >> P;
int re = P - 1;
cout << 2 << " " << re << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
const int MOD = 998244353;
const char nl = '\n';
const int MX = 100001;
void solve() {
int x, y;
cin >> x >> y;
if (x > y)
cout << x + y << nl... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long mod = 1e9 + 7;
char c[1010][1010];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m, k = 0, ans1 = -1, ans2 = -1, a1, a2;
cin >> n >> m;
vector<int> x(n, 0), y(m, 0);
for (int i = 0; i < n; i++)
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long testcases;
cin >> testcases;
for (int tcc = 0; tcc < testcases; tcc++) {
long long sum = 0, flag = 0, ans = 0;
long long i, j, k, w, x, y, z;
long long n, m, l, r, p, t, q;
cin >> x;
string s;
cin >> s;
set<int> s1 ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * (int)1e5;
int n, m, p;
map<int, int> mps, mx[maxn];
vector<int> ans;
int a[maxn], b[maxn];
int sat[maxn];
queue<int> q[maxn];
int main() {
scanf("%d%d%d", &n, &m, &p);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
int dif = 0;
for (i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1005];
vector<pair<int, int> > v, ans;
bool comp(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first)
return a.first > b.first;
else
return a.second > b.second;
}
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie();
cout.tie();
ci... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long a[300000 + 1];
long long sum_a[300000 + 1];
long long b[300000 + 1];
long long sum_b[300000 + 1];
long long query_a(int l, int r) { return sum_a[r] - sum_a[l - 1]; }
long long query_b(int l, int r) { return sum_b[r] - sum_b[l - 1]; }
int main() {
int n, m, ans, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << abs(x2 - x1) + abs(y2 - y1) + ((x2 == x1) || (y2 == y1) ? 0 : 2)
<< '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long ansa = 0, ansb = 0;
int l, r, n;
cin >> n >> l >> r;
long long mxr = pow(2, r - 1);
for (int i = 0; i < (l); i++) {
ansa += pow(2, i);
}
for (int i = 0; i <... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
char a[1000009], b[1000009];
long long num[30], n, rev[1000009], ans = 1;
long long pw(long long u, long long v) {
if (v == 1) return u;
long long res = pw(u, v / 2);
res = (res * res) % mod;
if (v % 2 > 0) res = (res * u) % mod;
return... | 13 |
#include <bits/stdc++.h>
using namespace std;
int L[100005], Size[100005];
int P[100005][20];
int T[100005], n;
vector<int> Graph[100005];
void DFS(int from, int u, int dep) {
T[u] = from;
L[u] = dep;
Size[u] = 1;
for (int i = 0; i < Graph[u].size(); i++) {
int v = Graph[u][i];
if (v == from) continue;
... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
template <class A, class B>
std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) {
st << "(" << p.first << ", " << p.second << ")";
return st;
}
using namespace std;
const int maxnode = 30000 + 5;
const int maxedge = 2100... | 16 |
#include <bits/stdc++.h>
using namespace std;
const string s[2][6] = {{"##", "..", "\\#", "./", "\\.", "#/"},
{"##", "..", ".\\", "/#", "#\\", "/."}};
int n, m, x, y, z, a[110][110], r, c, t;
int main() {
scanf("%d%d%d%d%d", &n, &m, &x, &y, &z);
int r = 0, c = 0;
for (int i = 0; i < x; i++... | 20 |
#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);
}
... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
const char* c = strchr(na + 1, ',');
cerr.write(na, c - na) <... | 8 |
#include <bits/stdc++.h>
bool debug = 0;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
long long v[200100];
int acum[200100];
int pos[200100][2];
int n;
int sz;
long long k;
bool analise(long long x, int i) {
if (x == 0 and i == sz + 1) return 0;
return abs(x) <= k;
}
int main() {
sc... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long w, h, n, k;
char a;
set<long long> q1, q2;
multiset<long long> q3, q4;
multiset<long long>::iterator q5, q6;
set<long long>::iterator k1, k2;
int main() {
cin >> w >> h >> n;
q1.insert(0), q1.insert(w), q3.insert(w);
q2.insert(0), q2.insert(h), q4.insert(h);... | 7 |
#include <bits/stdc++.h>
using namespace std;
int fa[500005], Size[500005], son[500005], top[500005], dfn[500005], n, m, cnt,
head[500005], vet[500005 << 1], Next[500005 << 1], edgenum;
struct nade {
int l, r, tag, sum;
} tree[500005 << 2];
void add(int u, int v) {
edgenum++;
Next[edgenum] = head[u];
head[u... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, s[N];
int main() {
for (; ~scanf("%d", &n);) {
for (int i = 0; i < n; i++) scanf("%d", s + i);
sort(s, s + n);
int result = n, r = n / 2;
for (int i = 0; i < n / 2; i++) {
while (r < n && s[i] * 2 > s[r]) r++;
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool vis[100005];
int ans[100005 * 4], tot[100005], pari[100005], cnt;
vector<int> v[100005];
void dfs(int x) {
int sz, i, j;
vis[x] = 1;
ans[cnt++] = x;
tot[x]++;
sz = v[x].size();
for (i = 0; i < sz; i++) {
j = v[x][i];
if (vis[j]) continue;
dfs(j)... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a[123456];
int32_t main() {
long long n, x;
cin >> n >> x;
for (long long i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
long long ans = 0;
for (long long i = 0; i < n; ++i) {
ans += upper_bound(a + i + 1, a + n, (x ^ a[i])) - a;
ans -= lower_... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2000777;
long long a[N];
long long m, n;
long long parent[N];
long long sz[N];
vector<long long> g[N];
map<pair<long long, long long>, long long> mp;
vector<pair<long long, long long> > v;
void make_set(long long v) {
parent[v] = v;
sz[v] = 1;
}
long... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, y, l, t = 1, e = -1;
string p;
int main() {
cin >> n >> m >> p;
l = p.length();
while (m--) {
scanf("%d", &y);
if (y - e >= l || e == -1)
n -= l;
else if (p[y - e] != p[0])
return puts("0"), 0;
else
n -= y - e;
e =... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[300005];
int col[300005], cnt;
bool comp(vector<int> x, vector<int> y) {
if (x.size() != y.size()) return x.size() > y.size();
int mn = min(x.size(), y.size());
for (int i = 0; i < mn; i++)
if (x[i] < y[i])
return 1;
else
return 0;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(vector<T> &v) {
for (auto &a : v) cin >> a;
}
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> r(n), c(m);
read(r);
read(c);
int xs = 0;
for (auto e : r) xs = xs ^ e;
for (auto e : c) xs ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string input;
cin >> input;
for (int max = input.length() - 1; max >= 1; max--) {
for (int i = 0; i < input.length(); i++) {
for (int j = 0; j < input.length(); j++) {
if ((i != j) && input.substr(i, max) == input.substr(j, max)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, tot, head[100001], w[100001], a[100001];
struct data {
int next, num, w;
} edge[200001];
void adde(int u, int v, int w) {
edge[++tot].next = head[u];
edge[tot].num = v;
edge[tot].w = w;
head[u] = tot;
}
void add(int u, int v, int w) {
adde(u, v, w);
add... | 11 |
#include <bits/stdc++.h>
using namespace std;
const string days[] = {"monday", "tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday"};
int dist, a, b;
string s, d;
int main() {
cin >> s >> d;
a = find(days, days + 7, s) - days;
b = find(days, days + 7, d) - days;
dist = b - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1000 + 10;
long long int n, k, s, f, mid, arr[maxn], dp[maxn];
long long int ABS(long long int a) {
if (a < 0) return -a;
return a;
}
bool t(long long int m) {
if (k >= n - 1) return 1;
for (long long int i = 1; i < n; i++) {
dp[(int)i] = i;... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) {
if (a > b) return true;
return false;
}
int main() {
int n, n1, n2, l;
double s = 0, w = 0;
vector<double> a;
cin >> n >> n1 >> n2;
cout << fixed << setprecision(8);
if (n1 < n2) swap(n1, n2);
for (int i = 0; i < n; i++) {
cin ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* x = new int[n];
for (int i = 0; i < n; i++) cin >> x[i];
sort(x, x + n);
swap(x[0], x[n - 1]);
for (int i = 0; i < n; i++) cout << x[i] << " ";
return 0;
}
| 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.