Add a bunch of other problems

This commit is contained in:
2025-10-01 10:35:36 -03:00
parent 489cb2ba51
commit e3421b4066
71 changed files with 9894 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
/* Problem URL: https://codeforces.com/contest/961/problem/A */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vi fds(n);
while (m--) {
int a;
cin >> a;
fds[a - 1]++;
}
cout << *min_element(all(fds)) << '\n';
}

View File

@@ -0,0 +1,110 @@
/* Problem URL: https://codeforces.com/contest/961/problem/B */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vl fds(n);
cin >> fds;
vl aw(n);
cin >> aw;
ll ans = 0;
vl pref(n + 1);
vl valpref(n + 1);
rep(i, n) {
pref[i + 1] = pref[i] + fds[i];
valpref[i + 1] += valpref[i];
if (aw[i]) {
ans += fds[i];
valpref[i + 1] += fds[i];
}
}
rep(i, n - k + 1) {
rmax(ans, valpref[i] + pref[i + k] - pref[i] + valpref[n] - valpref[i + k]);
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,131 @@
/* Problem URL: https://codeforces.com/contest/961/problem/C */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
V<V<string>> fds(4, V<string>(n));
repv(i, fds) {
cin >> i;
}
vi perm = {0, 1, 2, 3};
int ans = INT32_MAX >> 1;
do {
V<string> act(2 * n);
rep(i, n) {
act[i] = fds[perm[0]][i] + fds[perm[1]][i];
act[i + n] = fds[perm[2]][i] + fds[perm[3]][i];
}
int now = 0;
rep(i, 2 * n) {
rep(j, 2 * n) {
if ((i + j) & 1) {
now += act[i][j] == '0';
} else {
now += act[i][j] == '1';
}
}
}
rmin(ans, now);
now = 0;
rep(i, 2 * n) {
rep(j, 2 * n) {
if ((i + j) & 1) {
now += act[i][j] == '1';
} else {
now += act[i][j] == '0';
}
}
}
rmin(ans, now);
} while (next_permutation(all(perm)));
cout << ans << '\n';
}

View File

@@ -0,0 +1,206 @@
/* Problem URL: https://codeforces.com/contest/961/problem/D */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
// Geometria
typedef long long ld;
const ld DINF = 1e18;
const ld pi = acos(-1.0);
const ld eps = 1e-9;
#define sq(x) ((x)*(x))
bool eq(ld a, ld b) {
return abs(a - b) <= eps;
}
struct pt { // ponto
ld x, y;
pt(ld x_ = 0, ld y_ = 0) : x(x_), y(y_) {}
bool operator < (const pt p) const {
if (!eq(x, p.x)) return x < p.x;
if (!eq(y, p.y)) return y < p.y;
return 0;
}
bool operator == (const pt p) const {
return eq(x, p.x) and eq(y, p.y);
}
pt operator + (const pt p) const { return pt(x+p.x, y+p.y); }
pt operator - (const pt p) const { return pt(x-p.x, y-p.y); }
pt operator * (const ld c) const { return pt(x*c , y*c ); }
pt operator / (const ld c) const { return pt(x/c , y/c ); }
ld operator * (const pt p) const { return x*p.x + y*p.y; }
ld operator ^ (const pt p) const { return x*p.y - y*p.x; }
friend istream& operator >> (istream& in, pt& p) {
return in >> p.x >> p.y;
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
if (n <= 3) {
cout << "YES\n";
return 0;
}
V<pt> a(n);
cin >> a;
V<bool> group(n);
V<bool> invalid(n);
auto iscol = [&](pt a, pt b, pt c) {
return (b.y - a.y) * (c.x - b.x) == (c.y - b.y) * (b.x - a.x);
};
auto check = [&]() {
int first = 0;
while (group[first]) {
first++;
}
int second = first + 1;
while (group[second]) {
second++;
}
rep(i, n) {
if (group[i]) {
continue;
}
if (!iscol(a[first], a[second], a[i])) {
return false;
}
}
return true;
};
int c = 0;
rep(i, n) {
if (iscol(a[0], a[1], a[i])) {
group[i] = true;
} else {
c++;
}
}
if (c <= 2 || check()) {
cout << "YES\n";
return 0;
}
fill(all(group), false);
c = 0;
rep(i, n) {
if (iscol(a[0], a[2], a[i])) {
group[i] = true;
} else {
c++;
}
}
if (c <= 2 || check()) {
cout << "YES\n";
return 0;
}
fill(all(group), false);
c = 0;
rep(i, n) {
if (iscol(a[1], a[2], a[i])) {
group[i] = true;
} else {
c++;
}
}
if (c <= 2 || check()) {
cout << "YES\n";
return 0;
}
cout << "NO\n";
}

View File

@@ -0,0 +1,139 @@
/* Problem URL: https://codeforces.com/contest/961/problem/E */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi fds(n);
cin >> fds;
int size = n;
while (__builtin_popcount(size) != 1) {
size++;
fds.push_back(0);
}
vvl mergeseg(size * 2);
function<void(int, int, int)> build = [&](int i, int l, int r) {
if (l == r) {
mergeseg[i] = {fds[i - size]};
return;
}
int mid = (l + r) >> 1;
build(i * 2, l, mid);
build(i * 2 + 1, mid + 1, r);
merge(all(mergeseg[i * 2]), all(mergeseg[i * 2 + 1]), back_inserter(mergeseg[i]));
};
build(1, 0, size - 1);
function<ll(int, int, int, int, int, ll)> query = [&](int i, int l, int r, int tl, int tr, ll v) -> ll {
if (l > tr || r < tl) {
return 0LL;
}
if (l >= tl && r <= tr) {
auto lower = lower_bound(all(mergeseg[i]), v);
return mergeseg[i].end() - lower;
}
int mid = (l + r) >> 1;
return query(i * 2, l, mid, tl, tr, v) + query(i * 2 + 1, mid + 1, r, tl, tr, v);
};
ll ans = 0;
rep(i, n) {
rmin(fds[i], n);
if (fds[i] <= i + 1) {
continue;
}
ans += query(1, 0, size - 1, i + 1, fds[i] - 1, i + 1);
}
cout << ans << '\n';
}