From eda108e6b945d4fb886b692823e6d69102f1c5ef Mon Sep 17 00:00:00 2001 From: Segcolt Date: Mon, 23 Mar 2026 17:02:28 -0300 Subject: [PATCH] Add more stuff --- .../D. Drunken Maze.cpp | 174 +++++++++++++++++ .../A. Unit Array.cpp | 127 +++++++++++++ .../B. Maximum Strength.cpp | 128 +++++++++++++ .../C. Game with Reversing.cpp | 133 +++++++++++++ .../D. Survey in Class.cpp | 164 ++++++++++++++++ .../C. The Trail.cpp | 156 +++++++++++++++ .../D. Triangle Coloring.cpp | 156 +++++++++++++++ .../A. Passing the Ball.cpp | 121 ++++++++++++ .../B. Right Maximum.cpp | 129 +++++++++++++ .../C. Spring.cpp | 118 ++++++++++++ .../D. Alternating Path.cpp | 179 ++++++++++++++++++ TODO.md | 4 + 12 files changed, 1589 insertions(+) create mode 100644 2024 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/D. Drunken Maze.cpp create mode 100644 Codeforces Round 879 (Div. 2)/A. Unit Array.cpp create mode 100644 Codeforces Round 879 (Div. 2)/B. Maximum Strength.cpp create mode 100644 Codeforces Round 879 (Div. 2)/C. Game with Reversing.cpp create mode 100644 Codeforces Round 879 (Div. 2)/D. Survey in Class.cpp create mode 100644 Codeforces Round 996 (Div. 2)/C. The Trail.cpp create mode 100644 Educational Codeforces Round 143 (Rated for Div. 2)/D. Triangle Coloring.cpp create mode 100644 Educational Codeforces Round 188 (Rated for Div. 2)/A. Passing the Ball.cpp create mode 100644 Educational Codeforces Round 188 (Rated for Div. 2)/B. Right Maximum.cpp create mode 100644 Educational Codeforces Round 188 (Rated for Div. 2)/C. Spring.cpp create mode 100644 Educational Codeforces Round 188 (Rated for Div. 2)/D. Alternating Path.cpp diff --git a/2024 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/D. Drunken Maze.cpp b/2024 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/D. Drunken Maze.cpp new file mode 100644 index 0000000..9a226cd --- /dev/null +++ b/2024 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/D. Drunken Maze.cpp @@ -0,0 +1,174 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2041/D */ + +#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 0 + +void solve() +{ + int n, m; + cin >> n >> m; + + V a(n); + cin >> a; + + vvvvi dis(n, vvvi(m, vvi(4, vi(4, oo)))); + auto find_s = [&]() -> pair, pair> { + int si; + int sj; + int ei; + int ej; + rep(i, n) { + rep(j, m) { + if (a[i][j] == 'S') { + si = i; + sj = j; + continue; + } + + if (a[i][j] == 'T') { + ei = i; + ej = j; + } + } + } + + return {{si, sj}, {ei, ej}}; + }; + + auto [s, t] = find_s(); + auto [si, sj] = s; + auto [ei, ej] = t; + + queue> q; + dis[si][sj][0][0] = 0; + dis[si][sj][1][0] = 0; + dis[si][sj][2][0] = 0; + dis[si][sj][3][0] = 0; + q.emplace(si, sj, 0, 0); + q.emplace(si, sj, 1, 0); + q.emplace(si, sj, 2, 0); + q.emplace(si, sj, 3, 0); + int ans = oo; + while (!q.empty()) { + auto [i, j, d, t] = q.front(); + q.pop(); + + if (i == ei && j == ej) { + rmin(ans, dis[i][j][d][t]); + } + + int add[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; + rep(k, 4) { + int id = i + add[k][0]; + int jd = j + add[k][1]; + + int td = k == d ? t + 1 : 1; + + if (a[id][jd] == '#' || td > 3 || dis[id][jd][k][td] <= dis[i][j][d][t] + 1) { + continue; + } + + dis[id][jd][k][td] = dis[i][j][d][t] + 1; + q.emplace(id, jd, k, td); + } + } + + cout << (ans == oo ? -1 : 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/Codeforces Round 879 (Div. 2)/A. Unit Array.cpp b/Codeforces Round 879 (Div. 2)/A. Unit Array.cpp new file mode 100644 index 0000000..0ed06c7 --- /dev/null +++ b/Codeforces Round 879 (Div. 2)/A. Unit Array.cpp @@ -0,0 +1,127 @@ +/* Problem URL: https://codeforces.com/contest/1834/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; + cin >> n; + + array c = {0, 0}; + rep(i, n) { + int r; + cin >> r; + c[r > 0]++; + } + + int ans = 0; + if (c[1] < c[0]) { + int diff = (c[0] - c[1] + 1) >> 1; + ans += diff; + c[0] -= diff; + } + + if (c[0] & 1) { + ans++; + } + + 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/Codeforces Round 879 (Div. 2)/B. Maximum Strength.cpp b/Codeforces Round 879 (Div. 2)/B. Maximum Strength.cpp new file mode 100644 index 0000000..5013f7c --- /dev/null +++ b/Codeforces Round 879 (Div. 2)/B. Maximum Strength.cpp @@ -0,0 +1,128 @@ +/* Problem URL: https://codeforces.com/contest/1834/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() +{ + string l, r; + cin >> l >> r; + + int pad = r.size() - l.size(); + string p(pad, '0'); + p += l; + l = p; + + int i = 0; + ll ans = 0; + while (i < r.size() && r[i] == l[i]) { + i++; + } + + if (i == r.size()) { + cout << "0\n"; + return; + } + + ans += r[i] - l[i]; + ans += (r.size() - i - 1) * 9; + + 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/Codeforces Round 879 (Div. 2)/C. Game with Reversing.cpp b/Codeforces Round 879 (Div. 2)/C. Game with Reversing.cpp new file mode 100644 index 0000000..2ff15ff --- /dev/null +++ b/Codeforces Round 879 (Div. 2)/C. Game with Reversing.cpp @@ -0,0 +1,133 @@ +/* Problem URL: https://codeforces.com/contest/1834/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() +{ + int n; + cin >> n; + string a, b; + cin >> a >> b; + + int c1 = 0; + int c2 = 0; + rep(i, n) { + c1 += a[i] != b[i]; + c2 += a[i] != b[n - i - 1]; + } + + if (c1 == 0) { + cout << "0\n"; + return; + } + + if (c1 == 1) { + cout << "1\n"; + return; + } + + if (c2 == 0) { + cout << "2\n"; + return; + } + + cout << min(c1 * 2 - 1 + (~c1 & 1), c2 * 2 - 1 + (c2 & 1)) << '\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 879 (Div. 2)/D. Survey in Class.cpp b/Codeforces Round 879 (Div. 2)/D. Survey in Class.cpp new file mode 100644 index 0000000..ecc515c --- /dev/null +++ b/Codeforces Round 879 (Div. 2)/D. Survey in Class.cpp @@ -0,0 +1,164 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1834/D */ + +#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; + cin >> n >> m; + + V> a(n); + + pair a1 = {oo, oo}; + pair a2 = {0, 0}; + pair a3 = {0, oo}; + + auto sz = [&](pair a) { + return a.second - a.first + 1; + }; + + repv(i, a) { + cin >> i.first >> i.second; + if (a1.second > i.second || (a1.second == i.second && a1.first > i.first)) { + a1 = i; + } + + if (a2.first < i.first || (a2.first == i.first && a2.second < i.second)) { + a2 = i; + } + + if (sz(i) <= sz(a3)) { + a3 = i; + } + } + + auto calc = [&](pair a, pair b) { + if (a.first > b.first) { + swap(a, b); + } + + auto [al, ar] = a; + auto [bl, br] = b; + + if (al <= bl && ar >= br) { + return sz(a) - sz(b); + } + + if (al <= br && bl <= ar) { + return max(sz({al, bl}), sz({ar, br})) - 1; + } + + return max(sz(a), sz(b)); + }; + + ll ans = 0; + repv(i, a) { + rmax(ans, calc(a1, i) * 2); + } + repv(i, a) { + rmax(ans, calc(a2, i) * 2); + } + repv(i, a) { + rmax(ans, calc(a3, i) * 2); + } + + 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/Codeforces Round 996 (Div. 2)/C. The Trail.cpp b/Codeforces Round 996 (Div. 2)/C. The Trail.cpp new file mode 100644 index 0000000..f3a1e53 --- /dev/null +++ b/Codeforces Round 996 (Div. 2)/C. The Trail.cpp @@ -0,0 +1,156 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2055/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, m; + cin >> n >> m; + + string s; + cin >> s; + + vvl a(n, vl(m)); + cin >> a; + + vvl ss(2); + ss[0].resize(n); + ss[1].resize(m); + + rep(i, n) { + rep(j, m) { + ss[0][i] += a[i][j]; + ss[1][j] += a[i][j]; + } + } + + int i = s[0] == 'D'; + int j = s[0] == 'R'; + a[0][0] = s[0] == 'D' ? -ss[0][0] : -ss[1][0]; + ss[0][0] += a[0][0]; + ss[1][0] += a[0][0]; + ll ch = 0; + while (i < n - 1 || j < m - 1) { + // int pi = i - (s[i + j - 1] == 'D'); + // int pj = j - (s[i + j - 1] == 'R'); + + // int ch = s[pi + pj] == 'R'; + if (s[i + j] == 'R') { + ll s = ss[1][j]; + a[i][j] = -s; + ss[0][i] -= s; + ss[1][j] -= s; + j++; + continue; + } + + ll s = ss[0][i]; + a[i][j] = -s; + ss[0][i] -= s; + ss[1][j] -= s; + i++; + } + + ll diff = ss[0][n - 1]; + a[n - 1][m - 1] = -diff; + + cout << a; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Educational Codeforces Round 143 (Rated for Div. 2)/D. Triangle Coloring.cpp b/Educational Codeforces Round 143 (Rated for Div. 2)/D. Triangle Coloring.cpp new file mode 100644 index 0000000..9d7e8cf --- /dev/null +++ b/Educational Codeforces Round 143 (Rated for Div. 2)/D. Triangle Coloring.cpp @@ -0,0 +1,156 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1795/D */ + +#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 0 + +void solve() +{ + int n; + cin >> n; + vl a(n); + cin >> a; + + const ll mod = 998244353; + ll mul = 1; + for (int i = 0; i < n; i += 3) { + ll ma = *max_element(a.begin() + i, a.begin() + i + 3); + ll mi = *min_element(a.begin() + i, a.begin() + i + 3); + + int ca = count(a.begin() + i, a.begin() + i + 3, ma); + int ci = count(a.begin() + i, a.begin() + i + 3, mi); + + if (ca == 3) { + (mul *= 3) %= mod; + continue; + } + + if (ca == 2) { + continue; + } + + if (ci == 2) { + (mul *= 2) %= mod; + } + } + + auto fpow = [&](ll a, ll p) { + ll ans = 1; + + rep(i, 61) { + if ((p >> i) & 1) { + (ans *= a) %= mod; + } + (a *= a) %= mod; + } + + return ans; + }; + + vl fact(n + 1); + + fact[0] = 1; + nrep(i, 1, n + 1) { + fact[i] = fact[i - 1] * i % mod; + } + + n /= 3; + ll comb = fact[n] * fpow(fact[n / 2], mod - 2) % mod * fpow(fact[n / 2], mod - 2) % mod; + cout << mul * comb % mod << '\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/Educational Codeforces Round 188 (Rated for Div. 2)/A. Passing the Ball.cpp b/Educational Codeforces Round 188 (Rated for Div. 2)/A. Passing the Ball.cpp new file mode 100644 index 0000000..3a69b3b --- /dev/null +++ b/Educational Codeforces Round 188 (Rated for Div. 2)/A. Passing the Ball.cpp @@ -0,0 +1,121 @@ +/* Problem URL: https://codeforces.com/contest/2204/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; + cin >> n; + + string s; + cin >> s; + + int now = 0; + vi a(n); + a[0] = 1; + + rep(i, n) { + now += (s[now] == 'R') - (s[now] == 'L'); + a[now] = 1; + } + + cout << accumulate(all(a), 0) << '\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/Educational Codeforces Round 188 (Rated for Div. 2)/B. Right Maximum.cpp b/Educational Codeforces Round 188 (Rated for Div. 2)/B. Right Maximum.cpp new file mode 100644 index 0000000..51b4a64 --- /dev/null +++ b/Educational Codeforces Round 188 (Rated for Div. 2)/B. Right Maximum.cpp @@ -0,0 +1,129 @@ +/* Problem URL: https://codeforces.com/contest/2204/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; + cin >> n; + + vi a(n); + cin >> a; + + vvi pos(n); + rep(i, n) { + pos[a[i] - 1].push_back(i); + } + + int ans = 0; + int cur = n; + + for (int i = n - 1; i >= 0; i--) { + for (int j = pos[i].size() - 1; j >= 0; j--) { + if (pos[i][j] < cur ) { + cur = pos[i][j]; + ans++; + } + } + } + + 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/Educational Codeforces Round 188 (Rated for Div. 2)/C. Spring.cpp b/Educational Codeforces Round 188 (Rated for Div. 2)/C. Spring.cpp new file mode 100644 index 0000000..5439893 --- /dev/null +++ b/Educational Codeforces Round 188 (Rated for Div. 2)/C. Spring.cpp @@ -0,0 +1,118 @@ +/* Problem URL: https://codeforces.com/contest/2204/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 a, b , c, d; + cin >> a >> b >> c >> d; + + ll ab = lcm(a, b); + ll ac = lcm(a, c); + ll bc = lcm(c, b); + ll abc = lcm(ab, ac); + + vl ans(3); + ans[0] = d / abc * 2 + (d / ab + d / ac - d / abc * 2) * 3 + (d / a - d / ab - d / ac + d / abc) * 6; + ans[1] = d / abc * 2 + (d / ab + d / bc - d / abc * 2) * 3 + (d / b - d / ab - d / bc + d / abc) * 6; + ans[2] = d / abc * 2 + (d / bc + d / ac - d / abc * 2) * 3 + (d / c - d / bc - d / ac + d / abc) * 6; + cout << ans; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Educational Codeforces Round 188 (Rated for Div. 2)/D. Alternating Path.cpp b/Educational Codeforces Round 188 (Rated for Div. 2)/D. Alternating Path.cpp new file mode 100644 index 0000000..29bfa15 --- /dev/null +++ b/Educational Codeforces Round 188 (Rated for Div. 2)/D. Alternating Path.cpp @@ -0,0 +1,179 @@ +/* Problem URL: https://codeforces.com/contest/2204/problem/D */ + +#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; + cin >> n >> m; + + vvi graph(n); + while (m--) { + int a, b; + cin >> a >> b; + a--, b--; + graph[a].push_back(b); + graph[b].push_back(a); + } + + vi dis(n, oo); + function(int)> bfs = [&](int i) -> pair { + dis[i] = 0; + queue q; + q.push(i); + bool pos = true; + int sz = 1; + + while (!q.empty()) { + auto i = q.front(); + q.pop(); + + repv(j, graph[i]) { + if (dis[j] > dis[i] + 1) { + dis[j] = dis[i] + 1; + q.push(j); + sz++; + continue; + } + + if ((dis[j] & 1) == (dis[i] & 1)) { + pos = false; + } + } + } + + return {sz, pos}; + }; + + V vis(n); + + int ans = 0; + rep(i, n) { + if (dis[i] != oo) { + continue; + } + + auto [c, p] = bfs(i); + + if (!p) { + continue; + } + + array co = {0, 0}; + function dfs = [&](int i, int g) { + co[g]++; + vis[i] = true; + + repv(j, graph[i]) { + if (vis[j]) { + continue; + } + + dfs(j, g^1); + } + }; + + dfs(i, 0); + ans += max(co[0], co[1]); + } + + 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/TODO.md b/TODO.md index 0970e3e..d804fb9 100644 --- a/TODO.md +++ b/TODO.md @@ -133,6 +133,10 @@ Official divs from codeforces I got everything I need to do it, but I still need to find the equation to solve every single case... + + - [X] [D. Survey in Class](https://codeforces.com/problemset/problem/1834/D) + + Almost did it, I think I got what it needs to do it, but ran out of time. - Div 3