solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long int fact[300005];
long long int sum(long long int a, long long int b) {
return ((a % 998244353) + (b % 998244353)) % 998244353;
}
long long int diff(long long int a, long long int b) {
return (((a + 998244353) % 998244353 - (b + 998244353) % 998244353) +
... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void SMG() {
for (int i = 0; i <= 100000; i++)
if (i % 3 != 0 and i % 10 != 3) v.push_back(i);
int t;
cin >> t;
while (t--) {
int k;
cin >> k;
cout << v[k - 1] << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0... | 0 |
#include <bits/stdc++.h>
constexpr static int ___maxN = 200010;
char ch;
template <typename Num>
void read(Num& x) {
for (ch = getchar(); !isdigit(ch); ch = getchar())
;
for (x = 0; isdigit(ch); x = x * 10 + (ch ^ 48), ch = getchar())
;
}
template <typename Num, typename... List>
void read(Num& x, List&... ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 9;
int n;
long long ans;
map<int, int> tree, us;
map<int, vector<int> > q;
void add(int v) {
if (us[v] == 1) return;
us[v] = 1;
for (; v < M; v |= v + 1) tree[v] += 1;
}
int get_sum(int v) {
int res = 0;
for (; v >= 0; v = (v & (v + 1)) - 1) re... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100100;
long long a[N];
map<long long, long long> mp;
map<long long, long long> mp2;
bool Ok() {
for (auto x : mp)
if (x.second > mp2[x.first]) return false;
return true;
}
int main() {
long long n, k;
cin >> n >> k;
if (k == 1) return 0 * ... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct treap {
struct Node {
int y;
long long a, h, mx;
Node *L, *R;
Node(long long A, long long H) {
L = R = NULL;
a = A;
h = mx = H;
y = rand();
}
};
typedef Node *Treap;
Treap root;
treap() { root = NULL; }
void des... | 12 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void print(bool x) {
if (x == true)
cout << "Ya ";
else
cout << "Tidak ";
}
void solve() {
int A, B, C, D;
cin >> A >> B >> C >> D;
if (A == 0 && D == 0) {
if (B % 2... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 5;
const long long INF = 1e15;
long long dp[MAXN][MAXN][MAXN], p[MAXN][MAXN], c[MAXN];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >>... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[(long long int)(1e5 + 5)],
d((long long int)(1e5 + 5)), l((long long int)(1e5 + 5)),
dp((long long int)(1e5 + 5)), pw((long long int)(1e5 + 5), 1);
vector<vector<long long int>> up((long long int)(1e5 + 5),
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int absolut(int x) {
if (x < 0) return -x;
return x;
}
int n, m;
vector<pair<int, int> > g[1000000];
int visto[1000000];
int valor[1000000];
int busca(int u, int val) {
if (visto[u]) {
if (valor[u] != val) return absolut(valor[u] - val);
return 0;
}
visto[... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acosl(-1);
const int maxn = 200010;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long double eps = 1e-6;
const long double EPS = eps;
int T, n;
bool eq(long double a, long double b) { return abs(a - b) < EPS; }
int dcmp(long double... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, a, b, v, n, m, val = 0;
cin >> k >> a >> b >> v;
n = (a + v - 1) / v;
while (n > 0) {
val++;
m = min(b, k - 1);
b -= m;
n -= m + 1;
}
printf("%d\n", val);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
struct matrix {
int row, col;
long long v[102][102];
};
matrix mul(matrix mat, matrix mat2) {
matrix r;
r.row = mat.row;
r.col = mat.col;
for (int i = 0; i < r.row; i++) {
for (int j = 0; j < r.col; j++) {
long long sum = 0;
for (int k = 0; k < m... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos((long double)-1);
inline long double get() {
double x;
scanf("%lf", &x);
return x;
}
inline long double m(long double x) {
x -= (int)(x / (2 * pi)) * (2 * pi);
while (x >= 2 * pi) x -= 2 * pi;
while (x < 0) x += 2 * pi;
return x;
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<double> amount(101, 0);
void bfs(vector<vector<int>> &g) {
queue<int> q;
q.push(1);
++amount[1];
while (!q.empty()) {
int out = q.front();
q.pop();
double left = 0;
if (amount[out] >= 1) {
left = amount[out] - 1;
amount[out] = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> binary(int num) {
vector<int> re;
while (num) {
re.push_back(num % 2);
num >>= 1;
}
reverse(re.begin(), re.end());
return re;
}
int main() {
int inp;
cin >> inp;
vector<int> bin(binary(inp));
int size = bin.size(), count = 0;
vector<i... | 5 |
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2E5;
long long arr[MAXN + 1];
long long sum[MAXN + 1];
long long bit[MAXN + 1];
int ans[MAXN + 1];
long long query(int x) {
long long ans = 0;
while (x > 0) {
ans += bit[x];
x -= x & -x;
}
return ans;
}
void increment(int x, int amt, in... | 11 |
#include <bits/stdc++.h>
using namespace std;
char symbol;
int a[50][50];
int n, m, answer;
bool Satisfy(int i1, int j1, int i2, int j2) {
int square;
square = a[i2][j2] - a[i1 - 1][j2] - a[i2][j1 - 1] + a[i1 - 1][j1 - 1];
return !square;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
... | 7 |
#include <bits/stdc++.h>
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(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a < b) {
a = a + b;
b = a - b;
a = a - b;
}
while (b != 0) {
long long int r = a % b;
a = b;
b = r;
}
return a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, c;
cin >> n >> k >> c;
vector<int> v(c);
for (int _n((c)-1), i(0); i <= _n; i++) cin >> v[i];
v.push_back(0);
v.push_back(n + 1);
sort((v).begin(), (v).end());
int res = (int)((v).end() - (v).begin()) - 2;
for (int _n(((int)((v).end(... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isSpecial[112345] = {false};
vector<int> adj[112345];
bool vis[112345];
long long int vCnt, eCnt, maxV = 0, spare = 0;
bool spcThr = false;
void dfs(int u) {
vis[u] = true;
if (isSpecial[u]) {
spcThr = true;
}
vCnt++;
for (int i = 0; i < adj[u].size(); ++... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, i, rez;
char S[105];
int main() {
ios::sync_with_stdio(false);
cin >> n;
cin >> (S + 1);
rez = n;
for (i = 1; i < n; i++) {
if (S[i] != S[i + 1] && S[i] != 'D') {
rez--;
S[i + 1] = 'D';
}
}
cout << rez << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long a[n];
long max = 0;
int count = 0;
int maxcount = 0;
for (int i = 0; i < n; i++) {
scanf("%ld", &a[i]);
if (a[i] > max) max = a[i];
}
for (int i = 0; i < n; i++) {
if (a[i] == max)
count++;
else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
void NO() {
cout << "-1\n";
exit(0);
}
const int N = 2000;
string s[N], t[N], m;
vector<PII> adj[2 * N + 1];
int val[2 * N + 1];
void add_edge(int u, int v, int w) {
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a[300011];
int main() {
long long n, i, sum = 0, j;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (i = 0; i < n / 2; i++) {
sum += (a[i] + a[n - 1 - i]) * (a[i] + a[n - 1 - i]);
}
cout << sum;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 7, M = (int)1e9 + 7;
long long a[N][N], b[N][N], c[N][N];
int S;
void mul(long long x[N][N], long long y[N][N]) {
for (int i = 0; i < S; ++i)
for (int j = 0; j < S; ++j) {
c[i][j] = 0ll;
for (int k = 0; k < S; ++k) (c[i][j] += x[i][k] * ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 300000;
unsigned long long arrA[SIZE];
unsigned long long arrB[SIZE];
int main() {
int n, m, i, j, a;
unsigned long long x, y;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a);
arrA[i] = a;
}
scanf("%d", &m);
for (j = 0; j < ... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
bool done[1200];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
int arr[n + 10];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
for (int i = 0; i < n - 1; ++i) {
int a = 0;
for ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int fact(int n) {
int res = 1;
for (int i = 2; i <= n; i++) res = res * i;
return res;
}
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
int cel(int a, int b) { return ((a - 1) / b + 1); }
int gcd(int a, int b) {
if (a < b) swap(a, b);
if (b ==... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const char dName[4] = {'U', 'R', 'D', 'L'};
int n, cnt, destX[MAXN][MAXN], destY[MAXN][MAXN], id[MAXN][MAXN];
char ans[MAXN][MAXN];
vector<pair<int, int>> start;
bool inBoard(int x, int... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long i, j, k;
long long co = 0;
scanf("%lld", &k);
for (i = 0; i < s.size(); i++) {
for (long long l = i; l < s.size(); l++) {
char ma = s[i];
long long ind = -1;
for (j = i + 1; co < k && j < s.size();... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, x, e = INT_MAX;
cin >> t;
while (t--) {
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int c = 0;
e = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
if (a[i] <= e) {
e = a[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n;
int p[MAXN];
int b = 0;
int ct = 0;
bool vis[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
p[i]--;
}
for (int i = 0; i < n; ++i) {
in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const double Pi = acos(-1);
int A[200005], Op[200005], Last[200005];
int main() {
int i, n, Q;
int Order, P, X;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &A[i]);
scanf("%d", &Q);
for (i = 1; i <= Q; i++) {
scanf("%d", ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mns = 0, z = 0;
scanf(" %d", &n);
int a[n + 5];
for (int i = 0; i < n; i++) {
scanf(" %d", &a[i]);
if (a[i] < 0) mns++;
if (a[i] <= 0) z++;
}
sort(a, a + n);
if (n == 1)
printf("%d", a[0]);
else if (mns % 2 == 0 && mns > 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MAXN = 100010;
class SegTree {
public:
SegTree(int _n) : n(_n) { x = vector<int>(_n * 4); }
void Insert(int t, int a, int l, int r, int p) {
if (l == r) {
x[t] = a;
return;
}
int mid = (l + r) >> 1;
if (p <= m... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int q;
cin >> q;
while (q--) {
string s, t;
cin >> s;
cin >> t;
bool ans = false;
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < t.length(); j++) {
if (s[i] == t[j]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int x;
bool flag = true;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (x & 1) flag = false;
}
if (flag)
puts("Second");
else
puts("First");
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
map<int, int> mp;
map<int, int>::iterator it;
cin >> n;
while (n--) {
scanf("%d %d", &a, &b);
mp[a]++;
mp[b + 1]--;
}
int temp = 0;
bool f = true;
int index;
for (it = mp.begin(); it != mp.end(); it++) {
it->seco... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[333][333], dp[4][333][333], tp, tu, td, t, mn = 2000000000, mx1,
mx2, my1, my2;
inline int cal(int x, int y) {
if (x == y)
return tp;
else
return x < y ? tu : td;
}
const int LEFT = 0, RIGHT = 1,... | 15 |
#include <bits/stdc++.h>
using namespace std;
string S;
int s;
int sa[200005], ra[200005], tsa[200005], tra[200005], freq[200005];
void cSort(int k) {
memset(freq, 0, sizeof(freq));
for (int i = (0); i <= (s - 1); i += (1)) freq[(i + k < s ? ra[i + k] : 0)]++;
for (int i = (1); i <= (max(s, 300)); i += (1)) freq[... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y, c;
inline long long calc(long long n, long long m, long long T) {
if (T <= 0) return 0;
if (n < m) swap(n, m);
if (T <= m) return T * 1LL * (T + 1) / 2;
if (T >= n + m - 1) return n * m;
long long xi = n - (T - m + 1);
if (m - xi <= 0) xi = m ... | 10 |
#include <bits/stdc++.h>
int a[3000000];
int main() {
int t, n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &t), ++a[t];
for (int i = 0; i <= 2000009; ++i) {
a[i + 1] += a[i] / 2;
a[i] %= 2;
}
int ans = 0;
for (int i = 0; i <= 2000010; ++i) {
ans += a[i];
}
printf("%d\n", ans... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int i, j, k;
int sum = 0;
string a;
cin >> a;
for (i = 0; i < a.size(); i++) {
int op = 0, mix = 0, cnt = 0;
for (j = i; j < a.size(); j++) {
if (a[j] == '(')
op++;
else if (a[j] == ')') ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[5005];
cin >> n;
cout << "? 2 3" << endl;
cin >> a[1];
for (int i = 2; i <= n; i++) {
cout << "? 1 " << i << endl;
cin >> a[i];
}
int sum = 0;
for (int i = 1; i <= 3; i++) sum += a[i];
sum /= 2;
a[1] = sum - a[1];
for (int... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long A[maxn], ta[maxn], tb[maxn];
long long n, k, a, b, q;
void insert(long long i, long long num, long long *t) {
for (; i < maxn; i += (i & (-i))) t[i] += num;
}
long long cal(long long i, long long *t) {
long long ans = 0;
for (; i >... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[300050];
int dp[300050];
int prv[300050];
map<int, int> mp[300050];
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
scanf("%d", &n);
long long res = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
prv[i] = -1;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, Q, ans;
struct Zt {
int l, r;
bool num;
bool operator<(const Zt &u) const {
if (l != u.l) return l < u.l;
return r < u.r;
}
};
set<Zt> second;
set<Zt>::iterator it;
vector<set<Zt>::iterator> cle;
inline void cut(int u) {
it = second.upper_bound((Zt)... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, r, z;
double s;
int main() {
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++) {
double val;
scanf("%lf", &val);
double x = floor(val);
if (val == x)
z++;
else
r++;
s += val - x;
}
double sol = 1e9;
for (int i = 0; i <= r... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n;
pair<int, int> a[n];
for (i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a, a + n);
for (j = 0; j < n - 1; j++) {
if (a[j].first < a[j + 1].first && a[j].second > a[j + 1].second) {
cout << "Happ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m;
cin >> n;
m = n;
int a[101] = {0};
while (m--) {
int r, x;
cin >> r;
for (i = 0; i < r; i++) {
cin >> x;
a[x]++;
}
}
for (i = 0; i < 101; i++) {
if (a[i] == n) cout << i << " ";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1];
a[1] = 0;
int p;
for (int i = 2; i <= n; ++i) {
cin >> a[i];
}
p = n;
vector<int> ans;
while (p) {
ans.push_back(p);
p = a[p];
}
for (int i = ans.size() - 1; i >= 0; --i) {
cout << ans[i] <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1e5 + 8;
int val[maxn];
int main() {
memset(val, 0, sizeof val);
int n, a, b, T;
char ph;
scanf("%d%d%d%d", &n, &a, &b, &T);
getchar();
for (int i = 0; i < n; i++) {
scanf("%c", &ph);
if (i == 0) {
if (ph == 'w')
val[0]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
c = min(a, min(b - 1, c - 2));
cout << 3 * c + 3;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005, E = 262144;
const int M = 998244353;
int n, i, m, x, y, k, sta[N], top;
struct str {
int x, y, f;
} a[N];
bool cmp(str a, str b) {
if (a.x == b.x && a.y == b.y) return a.f < b.f;
if (a.x == b.x) return a.y > b.y;
return a.x < b.x;
}
long long m... | 17 |
#include <bits/stdc++.h>
using namespace std;
namespace jumpmelon {
const int MAXN = 1000000;
int Q[MAXN + 1];
void work() {
int n;
long long k;
scanf("%d%lld", &n, &k);
for (int i = 1; i <= n; i++) k -= i;
for (int i = 1, p = n, j = n; i <= j; i++) {
while (i <= j && k + i < max(i, p)) Q[j--] = p--;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
using B=bool;
using C=char;
using D=double;
using I=int;
using L=long long;
using LD=long double;
using S=string;
using TIII=tuple<I,I,I>;
using SET=set<I>;
using USET=unordered_set<I>;
using MSET=multiset<I>;
using SETSET=set<SET>;
using MSI=map<S,I>;
using MII=map<I,I>;... | 0 |
#include <bits/stdc++.h>
using namespace std;
void PRT(long long a) {
if (a < 0) putchar(45), a = -a;
if (a >= 10) PRT(a / 10);
putchar(a % 10 + 48);
}
int a[123456];
int main() {
int n, r;
do {
char _c = getchar(), _v = 1;
for (n = 0; _c < 48 || _c > 57; _c = getchar())
if (_c == 45) _v = -1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
char ans[100005][7];
char shirts[6][7] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int GetId(char *s) {
if (s[0] == 'S') return 0;
if (s[0] == 'M') return 1;
if (s[0] == 'L') return 2;
if (s[1] == 'L') return 3;
if (s[2] == 'L') return 4;
if (s[3] == 'L') return 5;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long mod = 1e9 + 7;
long long n, a[N], pw[N], dp[N], cnt[N];
void input() {
scanf("%lld", &n);
memset(cnt, 0, sizeof(cnt));
pw[0] = 1;
for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (long long i = 1; i <= n; i+... | 12 |
#include <bits/stdc++.h>
const double eps = 1e-8;
template <typename T>
inline int cmpT(T x) {
return x < 0 ? -1 : x > 0;
}
template <typename T>
struct VecT {
T x = 0;
T y = 0;
static_assert(std::is_arithmetic<T>::value,
"T should be an arithmetic type.");
VecT() {}
VecT(T x, T y) : x(x), y... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
vector<vector<int>> graph(N);
vector<int> par(N, -1);
vector<int> done(N, 0);
set<pair<pair<int, int>, int>> e;
void dfs(int v, int d, int p) {
par[v] = p;
e.insert(make_pair(make_pair(-d, v), p));
for (auto &i : graph[v]) {
if (i != p... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int inf = (1 << 30);
const int MX = 1e5 + 9;
int a, b, ans, i = 1;
int main() {
cin >> a >> b;
if (a > b) swap(a, b);
while (a + 1 < b) {
a++;
b--;
ans += 2 * i;
i++;
}
if (a != b) ans += i;
cout << ans << end... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500010, M = 500010;
int n, m;
char p[N], s[M];
int ne[N];
int A[2], B[2], C[2];
int main() {
int len1, len2;
scanf("%s", s + 1);
len1 = strlen(s + 1);
for (int i = 1; i <= len1; i++) {
A[s[i] - '0']++;
}
scanf("%s", p + 1);
len2 = strlen(p + ... | 8 |
#include <bits/stdc++.h>
using namespace ::std;
const int N = 300000;
int n, m, k;
vector<int> ad[N + 5];
bool one_impo[N + 5];
bool finish[N + 5];
int cnt_edge[N + 5];
int cnt_true;
int next_node[N + 5];
int prev_node[N + 5];
void end_node(int now) {
finish[now] = true;
cnt_true++;
int pn = prev_node[now];
int... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x[7], sum, res = 0;
cin >> n;
for (int i = 0; i < 7; i++) cin >> x[i];
sum = 0;
while (1) {
for (int i = 0; i < 7; i++) {
sum += x[i];
if (sum >= n) {
res = i + 1;
break;
}
}
if (sum >= n) break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 121;
int arr[maxn][maxn];
int main() {
int n;
cin >> n;
int res = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> arr[i][j];
if (i + j == n + 1 || i == j || n - i == (n - 1) / 2 ||
n - j == (n - 1) /... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200200;
const int INF = 1e9;
int n;
int t[MAXN];
int a[MAXN];
int last[MAXN];
void solve() {
scanf("%d", &n);
fill(last, last + n + 1, -1);
last[0] = 0;
for (int i = 0; i < n; ++i) scanf("%d", &t[i]);
a[0] = 0;
int cnt = 1;
for (int i = 0; i <... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long calc(long long x, int t) {
long long ans = x * (x - 1) / 2;
long long tmp = x;
for (int i = 0; i < t; i++) {
ans += tmp;
tmp *= 2;
}
return ans;
}
long long a[1000];
int cnt;
long long solve(int t) {
long long l = 1, r = (n + 1) / ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const int N = 5e4 + 5;
int n, b[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vector<pair<int, int>> ve;
for (int i = (0); i < (n); i++) {
cin >> b[i];
}
fo... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans = 1;
vector<long long> cnt;
vector<long long> use;
vector<long long> use1;
void solve() {
cin >> n;
cnt.resize(n);
use.resize(n + 1, 0);
unordered_set<long long> check;
check.insert(0);
for (long long i = 0; i < n; ++i) cin >> cnt[i];
for (lon... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, n, m;
cin >> n >> m;
a = abs(n - m);
if (a % 2 == 0) {
d = a / 2;
cout << d * (d + 1);
} else {
d = a / 2;
d = d * (d + 1);
b = a / 2 + 1;
c = b * (b + 1);
cout << d / 2 + c / 2;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100010], c[100010];
int key[500], numKey = 0, sum[500][100010];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
c[i] = a[i];
}
sort(c, c + n);
c[n] = 0;
int counter = 1;
for (int i = 1; i < n + 1; i++) {
if (c[i] ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char A[510][510];
bool was[510][510];
void dfs(int a, int b) {
if (a < 0 || a >= n || b < 0 || b >= m || A[a][b] == '#' || was[a][b]) return;
was[a][b] = true;
const int da[] = {0, 0, -1, 1}, db[] = {-1, 1, 0, 0};
for (int i = 0; i < 4; i++) dfs(a + da[... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, t, s, c;
vector<int> a;
bool f(int t, int s, int c) {
for (int i = t; i < n; i++) {
if (a[i] <= s) {
s -= a[i];
} else {
if (c == 0 || k < a[i]) {
return 0;
} else {
s = k - a[i];
c--;
}
}
}
retu... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[105][1005];
int hash1[105][26] = {0};
int chars[105] = {0};
scanf("%d", &n);
int i, j, l;
for (i = 0; i < n; i++) {
scanf("%s", s[i]);
l = strlen(s[i]);
for (j = 0; j < l; j++) {
if (!hash1[i][s[i][j] - 'a']) chars[... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 mt(736);
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
int n;
cin >> n;
vector<pair<int, int>> arr(n);
for (auto &it : arr) cin >> it.first;
for (auto &it : arr) cin >> it.second;
sort(arr.begin(), arr.end());
l... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, n, sum = 0, i, j;
cin >> n >> a >> b >> c;
a = a / 2;
for (i = 0; i <= a; i++) {
for (j = 0; j <= c; j++) {
int s = n - i - j * 2;
if (s >= 0 && s <= b) {
sum++;
}
}
}
cout << sum << endl;
return 0;
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
string s;
int check(int x) {
cout << x << endl;
cin >> s;
return (s[0] == 'y');
}
int main() {
int x = 1;
int primes[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int p = 0;
for ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int zhdan = 0;
while (true) {
if ((zhdan + c) * b >= a * c) {
cout << zhdan << endl;
return 0;
}
zhdan++;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int T;
long long fmul(long long a, long long b, long long mod) {
long long ret = 0;
while (b) {
if (b & 1) ret = (0LL + ret + a) % mod;
a = (0LL + a + a) % mod;
b >>= 1;
}
return ret;
}
long long fpow(long long bas, long long tim, long long mod) {
long... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9;
long long get_r(long long l, long long r) {
if (l == r) return l;
long long m = (l + r) / 2;
cout << "> " << m << endl;
int ans;
cin >> ans;
if (ans == -1) exit(0);
if (ans)
return get_r(m + 1, r);
else
return get_r(l, m);
}
long... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x;
int y;
} sq[4], sp[4];
bool cmp(point a, point b) {
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
int t[220][220];
void tian(point a, point b) {
for (int i = a.x; i <= b.x; ++i) {
for (int j = a.y; j <= b.y; ++j) {
t[i][j] =... | 8 |
/**
* author: fractal
* timus: 288481RF
* created: 12/30/20 22:57:50
**/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define speed ios_base::sync_with_stdio(0),cin.tie... | 10 |
#include <bits/stdc++.h>
const int maxn = 3005;
const int maxm = 6005;
const int inf = 999999999;
struct edge {
int to, next;
};
int n;
edge e[maxm];
int head[maxn], tot;
int stn[maxn], stk[maxn], top = 1;
int cir[maxn], circ;
int cirr[maxn];
bool vis[maxn];
int dis[maxn][maxn];
bool vis2[maxn][maxn];
void dfs2(int u... | 22 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1000000007;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int h, w, n;
cin >> h >> w >> n;
set<int> X, Y;
multiset<int> CX, CY;
auto ins = [&](int b, set<int>& f, multiset<int>& ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int ara[100007];
int main() {
int a, b, c, ans = 0;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> ara[i];
}
int i, j, mx, mn;
for (i = 0; i < a; i++) {
mn = ara[i], mx = ara[i];
for (j = i + 1; j < a; j++) {
if (ara[j] < mn)
mn = ara[j... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
for (unsigned int i = 0; i < a.size()... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
string s;
cin >> s;
string a;
cin >> a;
string b;
cin >> b;
string rev_s = s;
reverse(rev_s.begin(), rev_s.end());
int pos1 = -1;
for (int i = 0; i < s.length() - a.len... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, k, ara[N], to[N];
vector<int> g[N];
int tree[4 * N], lazy[4 * N];
void upd(int node, int val) {
lazy[node] += val;
tree[node] += val;
}
void push(int node) {
if (lazy[node] != 0) {
upd(2 * node, lazy[node]);
upd(2 * node + 1, lazy... | 16 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
long long int cnt1 = 0, l = s.length(), i;
for (i = 0; i < l; i++)
if (s[i] == '1') cnt1++;
if (l == 1 && s[0] == '0') {
cout << 0;
return;
}
if (cnt1 == 1)
cout << (l) / 2;
else
cout << (l + 1) / 2;
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
int dp[N], cnt[N], first[N];
vector<int> res, a[N];
int n, x, y;
void dfsf(int v, int p = -1) {
cnt[v] = (first[v] == 0);
dp[v] = 1;
for (int i = 0; i < a[v].size(); i++) {
int to = a[v][i];
if (to == p) continue;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 1e5 + 5;
class node {
public:
int pre, suf, max, len;
};
class tree {
public:
node x;
tree *l, *r;
};
typedef tree* pTree;
int n, m, x, y, k;
pair<int, int> a[N];
pTree kd[N];
node merge(node l,... | 17 |
#include <bits/stdc++.h>
using namespace std;
int l, vaz[15];
char sir[15];
void ask() {
printf("next");
for (int i = 0; i < l; i++) printf(" %d", i);
printf("\n");
fflush(stdout);
int k;
scanf("%d", &k);
for (int i = 1; i <= k; i++) {
scanf(" %s", sir + 1);
int l1 = strlen(sir + 1);
for (int ... | 16 |
#include <bits/stdc++.h>
const static long long INF = 0x3f3f3f3f3f3f3f3f;
static inline void setio(void);
struct bg_point {
long long time, id;
bool close;
bool operator<(const bg_point& o) const {
return (time < o.time) || (time == o.time && close < o.close) ||
(time == o.time && close == o.close ... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define MAGIC 55
int n;
long long x, aa = -1, bb;
vector<long long> v, vv, fr, mm, ma;
vector<vector<long long>> ans;
map<long long, int> m;
long long po(long long b, int p) {
long long re = 1;
while (p) {
if (p % 2) re = re * b % MOD;
b = b ... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
long long n, m, k, i, ans = 0, x, mn = 10000000;
cin >> n >> m >> k;
for (i = 1; i <= n; i++) cin >> a[i];
if (n % 2 == 0) {
cout << 0;
return 0;
}
for (i = 1; i <= n; i++) {
if (i % 2 == 1) mn = min(mn, a[i]);
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int add(int x, int y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
int mul(int x, int y) {
long long z = 1LL * x * y;
return z - z / mod * mod;
}
int lowbit(int t) { return t & (-t); }
long long a[maxn], b[maxn],... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.