From 60214bc8d0cfa68c1e3b74b62d9dcd1f548390eb Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Sun, 24 Sep 2023 21:04:29 +0300 Subject: Solved 5 problem in the last Div.4 --- contests/Round898/A/main.cpp | 143 ++++++++++++++++++++++++++++++ contests/Round898/A/main_input0.txt | 7 ++ contests/Round898/A/main_output0.txt | 6 ++ contests/Round898/B/main.cpp | 147 +++++++++++++++++++++++++++++++ contests/Round898/B/main_input0.txt | 9 ++ contests/Round898/B/main_output0.txt | 4 + contests/Round898/C/main.cpp | 163 ++++++++++++++++++++++++++++++++++ contests/Round898/C/main_input0.txt | 41 +++++++++ contests/Round898/C/main_output0.txt | 4 + contests/Round898/D/main.cpp | 146 +++++++++++++++++++++++++++++++ contests/Round898/D/main_input0.txt | 17 ++++ contests/Round898/D/main_output0.txt | 8 ++ contests/Round898/E/main.cpp | 157 +++++++++++++++++++++++++++++++++ contests/Round898/E/main_input0.txt | 11 +++ contests/Round898/E/main_output0.txt | 5 ++ contests/Round898/F/main.cpp | 165 +++++++++++++++++++++++++++++++++++ contests/Round898/F/main_input0.txt | 16 ++++ contests/Round898/F/main_output0.txt | 5 ++ contests/Round898/G/main.cpp | 161 ++++++++++++++++++++++++++++++++++ contests/Round898/G/main_input0.txt | 9 ++ contests/Round898/G/main_output0.txt | 8 ++ 21 files changed, 1232 insertions(+) create mode 100755 contests/Round898/A/main.cpp create mode 100644 contests/Round898/A/main_input0.txt create mode 100644 contests/Round898/A/main_output0.txt create mode 100755 contests/Round898/B/main.cpp create mode 100644 contests/Round898/B/main_input0.txt create mode 100644 contests/Round898/B/main_output0.txt create mode 100755 contests/Round898/C/main.cpp create mode 100644 contests/Round898/C/main_input0.txt create mode 100644 contests/Round898/C/main_output0.txt create mode 100755 contests/Round898/D/main.cpp create mode 100644 contests/Round898/D/main_input0.txt create mode 100644 contests/Round898/D/main_output0.txt create mode 100755 contests/Round898/E/main.cpp create mode 100644 contests/Round898/E/main_input0.txt create mode 100644 contests/Round898/E/main_output0.txt create mode 100755 contests/Round898/F/main.cpp create mode 100644 contests/Round898/F/main_input0.txt create mode 100644 contests/Round898/F/main_output0.txt create mode 100644 contests/Round898/G/main.cpp create mode 100644 contests/Round898/G/main_input0.txt create mode 100644 contests/Round898/G/main_output0.txt (limited to 'contests/Round898') diff --git a/contests/Round898/A/main.cpp b/contests/Round898/A/main.cpp new file mode 100755 index 0000000..a6c5585 --- /dev/null +++ b/contests/Round898/A/main.cpp @@ -0,0 +1,143 @@ +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +void solve() { + string s; + cin >> s; + string tmp1 = s; + string tmp2 = s; + string tmp3 = s; + swap(tmp1[0], tmp1[1]); + swap(tmp2[0], tmp2[2]); + swap(tmp3[1], tmp3[2]); + if (s == "abc" || tmp1 == "abc" || tmp2 == "abc" || tmp3 == "abc") { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/A/main_input0.txt b/contests/Round898/A/main_input0.txt new file mode 100644 index 0000000..67b9fb9 --- /dev/null +++ b/contests/Round898/A/main_input0.txt @@ -0,0 +1,7 @@ +6 +abc +acb +bac +bca +cab +cba diff --git a/contests/Round898/A/main_output0.txt b/contests/Round898/A/main_output0.txt new file mode 100644 index 0000000..d8b63f9 --- /dev/null +++ b/contests/Round898/A/main_output0.txt @@ -0,0 +1,6 @@ +YES +YES +YES +NO +NO +YES diff --git a/contests/Round898/B/main.cpp b/contests/Round898/B/main.cpp new file mode 100755 index 0000000..66112a9 --- /dev/null +++ b/contests/Round898/B/main.cpp @@ -0,0 +1,147 @@ +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +void solve() { + int n; + cin >> n; + vll v(n); + for (auto &x : v) { + cin >> x; + } + ll mx = 0; + for (int i = 0; i < n; i++) { + vll tmp = v; + tmp[i]++; + ll sum = 1; + for (int j = 0; j < n; j++) { + sum *= tmp[j]; + } + mx = max(mx, sum); + } + cout << mx << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/B/main_input0.txt b/contests/Round898/B/main_input0.txt new file mode 100644 index 0000000..246ddda --- /dev/null +++ b/contests/Round898/B/main_input0.txt @@ -0,0 +1,9 @@ +4 +4 +2 2 1 2 +3 +0 1 2 +5 +4 3 2 3 4 +9 +9 9 9 9 9 9 9 9 9 diff --git a/contests/Round898/B/main_output0.txt b/contests/Round898/B/main_output0.txt new file mode 100644 index 0000000..5ff12ca --- /dev/null +++ b/contests/Round898/B/main_output0.txt @@ -0,0 +1,4 @@ +16 +2 +432 +430467210 diff --git a/contests/Round898/C/main.cpp b/contests/Round898/C/main.cpp new file mode 100755 index 0000000..c27011c --- /dev/null +++ b/contests/Round898/C/main.cpp @@ -0,0 +1,163 @@ +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +bool is_ring(int i, int j, int ring) { + if (ring == 1) { + return i == 0 || i == 9 || j == 0 || j == 9; + } else if (ring == 2) { + return i == 1 || i == 8 || j == 1 || j == 8; + } else if (ring == 3) { + return i == 2 || i == 7 || j == 2 || j == 7; + } else if (ring == 4) { + return i == 3 || i == 6 || j == 3 || j == 6; + } else if (ring == 5) { + return i == 4 || i == 5 || j == 4 || j == 5; + } + return false; +} + +void solve() { + vector v(10); + for (auto &str : v) { + cin >> str; + } + int ans = 0; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + if (v[i][j] == 'X') { + for (int k = 1; k <= 5; k++) { + if (is_ring(i, j, k)) { + ans += k; + break; + } + } + } + } + } + cout << ans << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/C/main_input0.txt b/contests/Round898/C/main_input0.txt new file mode 100644 index 0000000..95a660f --- /dev/null +++ b/contests/Round898/C/main_input0.txt @@ -0,0 +1,41 @@ +4 +X......... +.......... +.......X.. +.....X.... +......X... +.......... +.........X +..X....... +.......... +.........X +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +.......... +....X..... +.......... +.......... +.......... +.......... +.......... +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX +XXXXXXXXXX diff --git a/contests/Round898/C/main_output0.txt b/contests/Round898/C/main_output0.txt new file mode 100644 index 0000000..4731b69 --- /dev/null +++ b/contests/Round898/C/main_output0.txt @@ -0,0 +1,4 @@ +17 +0 +5 +220 diff --git a/contests/Round898/D/main.cpp b/contests/Round898/D/main.cpp new file mode 100755 index 0000000..ffa3208 --- /dev/null +++ b/contests/Round898/D/main.cpp @@ -0,0 +1,146 @@ +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +void solve() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int last_black = find(all(s), 'B') - s.begin(); + int ans = 0; + int i = 0; + while (i < n) { + if (s[i] == 'B') { + ans++; + i += k; + } else { + i++; + } + } + cout << ans << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/D/main_input0.txt b/contests/Round898/D/main_input0.txt new file mode 100644 index 0000000..aa4b098 --- /dev/null +++ b/contests/Round898/D/main_input0.txt @@ -0,0 +1,17 @@ +8 +6 3 +WBWWWB +7 3 +WWBWBWW +5 4 +BWBWB +5 5 +BBBBB +8 2 +BWBWBBBB +10 2 +WBBWBBWBBW +4 1 +BBBB +3 2 +WWW diff --git a/contests/Round898/D/main_output0.txt b/contests/Round898/D/main_output0.txt new file mode 100644 index 0000000..ca0b797 --- /dev/null +++ b/contests/Round898/D/main_output0.txt @@ -0,0 +1,8 @@ +2 +1 +2 +1 +4 +3 +4 +0 diff --git a/contests/Round898/E/main.cpp b/contests/Round898/E/main.cpp new file mode 100755 index 0000000..ca3db87 --- /dev/null +++ b/contests/Round898/E/main.cpp @@ -0,0 +1,157 @@ +#include +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +bool is_more(vi &v, int h, int x) { + ll w = 0; + for (auto x : v) { + if (h > x) { + w += h - x; + } + } + return w > x; +} + +void solve() { + int n, x; + cin >> n >> x; + vi v(n); + for (auto &y : v) { + cin >> y; + } + ll l = 1, r = INT_MAX; + while (r - l > 1) { + ll mid = (r + l) / 2; + if (is_more(v, mid, x)) { + r = mid; + } else { + l = mid; + } + } + cout << l << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/E/main_input0.txt b/contests/Round898/E/main_input0.txt new file mode 100644 index 0000000..22ab867 --- /dev/null +++ b/contests/Round898/E/main_input0.txt @@ -0,0 +1,11 @@ +5 +7 9 +3 1 2 4 6 2 5 +3 10 +1 1 1 +4 1 +1 4 3 4 +6 1984 +2 6 5 9 1 8 +1 1000000000 +1 diff --git a/contests/Round898/E/main_output0.txt b/contests/Round898/E/main_output0.txt new file mode 100644 index 0000000..21620d0 --- /dev/null +++ b/contests/Round898/E/main_output0.txt @@ -0,0 +1,5 @@ +4 +4 +2 +335 +1000000001 diff --git a/contests/Round898/F/main.cpp b/contests/Round898/F/main.cpp new file mode 100755 index 0000000..87704f4 --- /dev/null +++ b/contests/Round898/F/main.cpp @@ -0,0 +1,165 @@ +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +// ABAB +void solve() { + int n, k; + cin >> n >> k; + vi v(n), h(n); + vll pfx(n + 1, 0); + for (auto &x : v) { + cin >> x; + } + for (auto &x : h) { + cin >> x; + } + for (int i = 0; i < n; i++) { + pfx[i + 1] = pfx[i] + v[i]; + } + int start = 0; + ll ans = 0; + for (int i = 0; i < n; i++) { + while (i < n - 1 && h[i] % h[i + 1] == 0) { + i++; + } + for (int j = start; j <= i; j++) { + ll lo = j - 1, hi = i + 1; + while (hi - lo > 1) { + ll mid = (hi + lo) / 2; + if (pfx[mid + 1] - pfx[j] > k) { + hi = mid; + } else { + lo = mid; + } + } + ans = max(ans, hi - j); + } + start = i + 1; + } + cout << ans << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/F/main_input0.txt b/contests/Round898/F/main_input0.txt new file mode 100644 index 0000000..07982e4 --- /dev/null +++ b/contests/Round898/F/main_input0.txt @@ -0,0 +1,16 @@ +5 +5 12 +3 2 4 1 8 +4 4 2 4 1 +4 8 +5 4 1 2 +6 2 3 1 +3 12 +7 9 10 +2 2 4 +1 10 +11 +1 +7 10 +2 6 3 1 5 10 6 +72 24 24 12 4 4 2 diff --git a/contests/Round898/F/main_output0.txt b/contests/Round898/F/main_output0.txt new file mode 100644 index 0000000..0e2f5c2 --- /dev/null +++ b/contests/Round898/F/main_output0.txt @@ -0,0 +1,5 @@ +3 +2 +1 +0 +3 diff --git a/contests/Round898/G/main.cpp b/contests/Round898/G/main.cpp new file mode 100644 index 0000000..677a4e0 --- /dev/null +++ b/contests/Round898/G/main.cpp @@ -0,0 +1,161 @@ +#include +using namespace std; + +using ll = long long; +using pii = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound +#define make_unique(x) \ + sort(all((x))); \ + (x).resize(unique(all((x))) - (x).begin()) +#define ceil(a, b) ((a) + (b)-1) / (b) + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +template +ostream &operator<<(ostream &os, const pair &p); +template ostream &operator<<(ostream &os, const vector &vec); +template +ostream &operator<<(ostream &os, const map &m); +template +ostream &operator<<(ostream &os, const unordered_map &m); +template ostream &operator<<(ostream &os, const set &s); +template +ostream &operator<<(ostream &os, const unordered_set &s); + +template +ostream &operator<<(ostream &os, const pair &p) { + os << "(" << p.first << ", " << p.second << ")"; + return os; +} + +template ostream &operator<<(ostream &os, const vector &vec) { + os << "{"; + for (size_t i = 0; i < vec.size(); ++i) { + if (i > 0) + os << ", "; + os << vec[i]; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_map &m) { + os << "{"; + for (const auto &p : m) { + os << p.first << ": " << p.second << ", "; + } + os << "}"; + return os; +} + +template ostream &operator<<(ostream &os, const set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +template +ostream &operator<<(ostream &os, const unordered_set &s) { + int i = 0; + os << "{"; + for (const auto &e : s) { + if (i > 0) + os << ", "; + os << e; + i++; + } + os << "}"; + return os; +} + +void dbg() { cerr << "\n"; } + +template void dbg(T val, TS... vals) { + cerr << val << " "; + dbg(vals...); +} + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +void solve() { + string s; + cin >> s; + int n = s.length(); + int ans1 = 0; + int ans2 = 0; + string tmp = s; + for (int i = 0; i < n - 1; i++) { + string sub = tmp.substr(i, 2); + if (sub == "AB") { + tmp[i] = 'B'; + tmp[i + 1] = 'C'; + ans1++; + } else if (sub == "BA") { + tmp[i] = 'C'; + tmp[i + 1] = 'B'; + ans1++; + } + } + for (int i = n - 2; i >= 0; i--) { + string sub = s.substr(i, 2); + if (sub == "AB") { + s[i] = 'B'; + s[i + 1] = 'C'; + ans2++; + } else if (sub == "BA") { + s[i] = 'C'; + s[i + 1] = 'B'; + ans2++; + } + } + cout << max(ans1, ans2) << '\n'; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + solve(); + } +} diff --git a/contests/Round898/G/main_input0.txt b/contests/Round898/G/main_input0.txt new file mode 100644 index 0000000..11a6a78 --- /dev/null +++ b/contests/Round898/G/main_input0.txt @@ -0,0 +1,9 @@ +8 +ABBA +ABA +BAABA +ABB +AAAAAAB +BABA +B +AAA diff --git a/contests/Round898/G/main_output0.txt b/contests/Round898/G/main_output0.txt new file mode 100644 index 0000000..4914abe --- /dev/null +++ b/contests/Round898/G/main_output0.txt @@ -0,0 +1,8 @@ +2 +1 +3 +1 +6 +2 +0 +0 -- cgit v1.2.3