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,98 @@
/* Problem URL: https://codeforces.com/contest/962/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;
cin >> n;
vi a(n);
cin >> a;
ll total = accumulate(all(a), 0LL);
ll now = 0;
int i = 0;
while (now < ((total + 1) >> 1)) {
now += a[i];
i++;
}
cout << i << '\n';
}

View File

@@ -0,0 +1,122 @@
/* Problem URL: https://codeforces.com/contest/962/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, a, b;
cin >> n >> a >> b;
string fds;
cin >> fds;
vi c = {a, b};
int s = c[0] > c[1] ? 0 : 1;
int prev = -1;
int ans = 0;
rep(i, n) {
if (fds[i] == '*') {
int now = s;
for (int j = prev + 1; j < i; j++) {
if (c[now]) {
ans++;
c[now]--;
}
now ^= 1;
}
s = c[0] > c[1] ? 0 : 1;
prev = i;
}
}
int now = s;
for (int j = prev + 1; j < n; j++) {
if (c[now]) {
ans++;
c[now]--;
}
now ^= 1;
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,118 @@
/* Problem URL: https://codeforces.com/contest/962/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);
string n;
cin >> n;
int ans = INT32_MAX >> 1;
nrep(i, 1, 1e5) {
string now = to_string((ll)i * i);
int j = 0;
int k = 0;
int tmp = 0;
while (j < n.size() && k < now.size()) {
if (n[j] == now[k]) {
k++;
} else {
tmp++;
}
j++;
}
if (k < now.size()) {
continue;
}
rmin(ans, tmp + (int)n.size() - j);
}
if (ans == INT32_MAX >> 1) {
cout << "-1\n";
return 0;
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,116 @@
/* Problem URL: https://codeforces.com/contest/962/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vl a(n);
cin >> a;
set<ll> act;
map<ll, int> pos;
rep(i, n) {
if (!act.count(a[i])) {
act.insert(a[i]);
pos[a[i]] = i;
continue;
}
act.erase(a[i]);
pos.erase(a[i]);
a[i] *= 2;
i--;
}
V<pair<int, ll>> ans;
repv(i, pos) {
ans.emplace_back(i.second, i.first);
}
sortv(ans);
cout << ans.size() << '\n';
repv(i, ans) {
cout << i.second << ' ';
}
cout << '\n';
}

View File

@@ -0,0 +1,227 @@
/* Problem URL: https://codeforces.com/contest/962/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;
vl r;
vl b;
vl p;
rep(i, n) {
ll x;
char o;
cin >> x >> o;
if (o == 'R') {
r.push_back(x);
continue;
}
if (o == 'B') {
b.push_back(x);
continue;
}
p.push_back(x);
}
sortv(r);
sortv(b);
sortv(p);
ll ans = 0;
nrep(i, 1, p.size()) {
ans += p[i] - p[i - 1];
}
V<pair<ll, int>> tmp;
repv(i, r) {
tmp.emplace_back(i, 0);
}
repv(i, p) {
tmp.emplace_back(i, 1);
}
sortv(tmp);
nrep(i, 1, tmp.size()) {
if (tmp[i].second == 0 || tmp[i - 1].second == 0) {
ans += tmp[i].first - tmp[i - 1].first;
}
}
tmp.clear();
repv(i, b) {
tmp.emplace_back(i, 0);
}
repv(i, p) {
tmp.emplace_back(i, 1);
}
sortv(tmp);
nrep(i, 1, tmp.size()) {
if (tmp[i].second == 0 || tmp[i - 1].second == 0) {
ans += tmp[i].first - tmp[i - 1].first;
}
}
repv(i, r) {
tmp.emplace_back(i, 2);
}
sortv(tmp);
int prev = -1;
bool ry = false;
bool by = false;
rep(i, tmp.size()) {
if (tmp[i].second == 1) {
if (prev == -1 || (!ry && !by)) {
prev = i;
ry = false;
by = false;
continue;
}
if (ry && by) {
int prevr = -1;
int prevb = -1;
ll maxr = 0;
ll maxb = 0;
nrep(j, prev + 1, i) {
if (tmp[j].second == 2) {
if (prevr == -1) {
rmax(maxr, tmp[j].first - tmp[prev].first);
} else {
rmax(maxr, tmp[j].first - tmp[prevr].first);
}
prevr = j;
continue;
}
if (prevb == -1) {
rmax(maxb, tmp[j].first - tmp[prev].first);
} else {
rmax(maxb, tmp[j].first - tmp[prevb].first);
}
prevb = j;
}
rmax(maxr, tmp[i].first - tmp[prevr].first);
rmax(maxb, tmp[i].first - tmp[prevb].first);
// cout << maxr << ' ' << maxb << ' ' << tmp[i].first - tmp[prev].first << '\n';
ans -= max(maxr + maxb, tmp[i].first - tmp[prev].first);
prev = i;
ry = false;
by = false;
continue;
}
ll maximal = 0;
nrep(j, prev + 1, i + 1) {
if (i > 0) {
rmax(maximal, tmp[j].first - tmp[j - 1].first);
}
}
ans -= maximal;
prev = i;
ry = false;
by = false;
continue;
}
if (tmp[i].second == 2) {
ry = true;
continue;
}
by = true;
}
cout << ans << '\n';
}