From 25fe530b274d03f85907493134db38e92870e848 Mon Sep 17 00:00:00 2001 From: Segcolt Date: Tue, 14 Apr 2026 20:25:40 -0300 Subject: [PATCH] More problems --- .../A. The Equalizer.cpp | 121 +++++++++++ .../B. Flip the Bit (Easy Version).cpp | 126 ++++++++++++ .../C. Grid Covering.cpp | 114 +++++++++++ .../F. Rudolf and Imbalance.cpp | 193 ++++++++++++++++++ Hello 2024/C. Grouping Increases.cpp | 134 ++++++++++++ .../C. Remove the Bracket.cpp | 139 +++++++++++++ 6 files changed, 827 insertions(+) create mode 100644 Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp create mode 100644 Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp create mode 100644 Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp create mode 100644 Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp create mode 100644 Hello 2024/C. Grouping Increases.cpp create mode 100644 TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp diff --git a/Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp new file mode 100644 index 0000000..c0aae04 --- /dev/null +++ b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp @@ -0,0 +1,121 @@ +/* Problem URL: https://codeforces.com/contest/2217/problem/A */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n, k; + cin >> n >> k; + + vi a(n); + cin >> a; + int c = 0; + rep(i, n) { + c += a[i] & 1; + } + + if ((c & 1) || (~k & 1) || ((k & 1) && (~n & 1))) { + cout << "YES\n"; + return; + } + + cout << "NO\n"; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp new file mode 100644 index 0000000..100a209 --- /dev/null +++ b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp @@ -0,0 +1,126 @@ +/* Problem URL: https://codeforces.com/contest/2217/problem/B */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n, k; + cin >> n >> k; + + vi a(n); + cin >> a; + + int p; + cin >> p; + p--; + + int a1 = 0; + for (int i = p - 1; i >= 0; i--) { + a1 += a[i] != a[i + 1]; + } + + int a2 = 0; + for (int i = p + 1; i < n; i++) { + a2 += a[i] != a[i - 1]; + } + + cout << max(a1 + (a[0] != a[p]), a2 + (a[n - 1] != a[p])) << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp new file mode 100644 index 0000000..0a4846d --- /dev/null +++ b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp @@ -0,0 +1,114 @@ +/* Problem URL: https://codeforces.com/contest/2217/problem/C */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + ll n, m, a, b; + cin >> n >> m >> a >> b; + + if (gcd(n, a) != 1 || gcd(m, b) != 1 || gcd(n, m) > 2) { + cout << "NO\n"; + return; + } + + cout << "YES\n"; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp b/Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp new file mode 100644 index 0000000..7a998a7 --- /dev/null +++ b/Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp @@ -0,0 +1,193 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1941/F */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n, m, k; + cin >> n >> m >> k; + + vl a(n); + vl d(m); + vl f(k); + cin >> a >> d >> f; + + map> c; + rep(i, n - 1) { + c[a[i + 1] - a[i]]++; + } + + if (c.begin()->second > 1 || c.begin()->first == 1) { + cout << c.begin()->first << '\n'; + return; + } + + sortv(d); + sortv(f); + + ll lim = c.begin()->first; + + int choice = 0; + rep(i, n - 1) { + if (a[i + 1] - a[i] == lim) { + choice = i; + break; + } + } + + auto getlesseq = [&](ll mid) { + ll ans = -1; + rep(i, m) { + auto itr = upper_bound(all(f), mid - d[i]) - f.begin(); + if (itr == 0) { + continue; + } + + rmax(ans, d[i] + f[itr - 1]); + } + + return ans; + }; + + auto getgreatereq = [&](ll mid) { + ll ans = OO; + rep(i, m) { + auto itr = lower_bound(all(f), mid - d[i]) - f.begin(); + if (itr == k) { + continue; + } + + rmin(ans, d[i] + f[itr]); + } + + return ans; + }; + + ll ch = a[choice]; + ll bt = max(ch - a[choice], a[choice + 1] - ch); + + auto getans = [&](ll m) { + if (m < a[choice] || m > a[choice + 1]) { + return; + } + ll tbt = max(m - a[choice], a[choice + 1] - m); + + if (tbt < bt) { + bt = tbt; + ch = m; + } + }; + + ll mid = (a[choice] + a[choice + 1]) >> 1; + + getans(getlesseq(mid)); + getans(getgreatereq(mid)); + + a.push_back(ch); + sortv(a); + + ll ans = 0; + rep(i, n) { + rmax(ans, a[i + 1] - a[i]); + } + + cout << ans << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Hello 2024/C. Grouping Increases.cpp b/Hello 2024/C. Grouping Increases.cpp new file mode 100644 index 0000000..6caa52e --- /dev/null +++ b/Hello 2024/C. Grouping Increases.cpp @@ -0,0 +1,134 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1919/C */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n; + cin >> n; + vi a(n); + cin >> a; + + int x = oo; + int y = oo; + int ans = 0; + + rep(i, n) { + if (x > y) { + swap(x, y); + } + + if (a[i] <= x) { + x = a[i]; + continue; + } + + if (a[i] > y) { + x = a[i]; + ans++; + continue; + } + + y = a[i]; + } + + cout << ans << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp b/TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp new file mode 100644 index 0000000..3be2c3c --- /dev/null +++ b/TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp @@ -0,0 +1,139 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1787/C */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n; + ll s; + cin >> n >> s; + vl a(n); + cin >> a; + + V> act(n); + rep(i, n) { + if (a[i] >= s * 2) { + act[i] = {s, a[i] - s}; + continue; + } + + if (a[i] >= s) { + ll diff = a[i] - s; + act[i] = {diff, a[i] - diff}; + continue; + } + + act[i] = {0, a[i]}; + } + + vvl dp(n, vl(2, OO)); + dp[1][0] = a[0] * act[1].first; + dp[1][1] = a[0] * act[1].second; + + nrep(i, 2, n - 1) { + auto [x, y] = act[i]; + auto [xb, yb] = act[i - 1]; + dp[i][0] = min(dp[i - 1][0] + (a[i - 1] - xb) * x, dp[i - 1][1] + (a[i - 1] - yb) * x); + dp[i][1] = min(dp[i - 1][0] + (a[i - 1] - xb) * y, dp[i - 1][1] + (a[i - 1] - yb) * y); + } + + cout << min(dp[n - 2][0] + (a[n - 2] - act[n - 2].first) * a[n - 1], dp[n - 2][1] + (a[n - 2] - act[n - 2].second) * a[n - 1]) << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +}