feat(codeforces): 799

This commit is contained in:
Barrett Ruth 2025-04-10 11:56:50 -04:00
parent 1a5e885c8f
commit 375a673932
52 changed files with 3233 additions and 0 deletions

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

23
codeforces/799/.clangd Normal file
View file

@ -0,0 +1,23 @@
CompileFlags:
Add:
- -Wall
- -Wextra
- -Wshadow
- -Wnon-virtual-dtor
- -Wold-style-cast
- -Wcast-align
- -Wunused
- -Woverloaded-virtual
- -Wpedantic
- -Wmisleading-indentation
- -Wduplicated-cond
- -Wduplicated-branches
- -Wlogical-op
- -Wnull-dereference
- -Wuseless-cast
- -Wformat=2
- -Wformat-overflow
- -Wformat-truncation
- -Wdouble-promotion
- -DLOCAL
- -Wno-unknown-pragmas

41
codeforces/799/a.cc Normal file
View file

@ -0,0 +1,41 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << (b > a) + (c > a) + (d > a) << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

6
codeforces/799/a.in Normal file
View file

@ -0,0 +1,6 @@
4
2 3 4 1
10000 0 1 2
500 600 400 300
0 9999 10000 9998

54
codeforces/799/b.cc Normal file
View file

@ -0,0 +1,54 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
bitset<10000 + 1> seen;
void solve() {
seen.reset();
int n;
cin >> n;
int a, dups = 0;
for (int i = 0; i < n; ++i) {
cin >> a;
if (seen[a]) {
++dups;
} else {
seen[a] = true;
}
}
int unique = n - dups;
cout << (dups & 1 ? unique - 1 : unique) << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

9
codeforces/799/b.in Normal file
View file

@ -0,0 +1,9 @@
4
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000

52
codeforces/799/c.cc Normal file
View file

@ -0,0 +1,52 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
void solve() {
vector<string> board(8);
for (auto& s : board)
cin >> s;
for (int r = 1; r <= 6; ++r) {
for (int c = 1; c <= 6; ++c) {
if (board[r][c] == '#' && board[r - 1][c - 1] == '#' &&
board[r + 1][c + 1] == '#' && board[r - 1][c + 1] == '#' &&
board[r + 1][c - 1] == '#') {
cout << r + 1 << ' ' << c + 1 << '\n';
return;
}
}
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

31
codeforces/799/c.in Normal file
View file

@ -0,0 +1,31 @@
3
.....#..
#...#...
.#.#....
..#.....
.#.#....
#...#...
.....#..
......#.
#.#.....
.#......
#.#.....
...#....
....#...
.....#..
......#.
.......#
.#.....#
..#...#.
...#.#..
....#...
...#.#..
..#...#.
.#.....#
#.......

View file

@ -0,0 +1,21 @@
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wpedantic
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wuseless-cast
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-DLOCAL
-std=c++23

74
codeforces/799/d.cc Normal file
View file

@ -0,0 +1,74 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
bitset<1441> seen;
void solve() {
string s;
int x;
cin >> s >> x;
int start = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3, 2));
seen.reset();
int ans = 0;
auto is_palindrome = [&](string const& S) {
int l = 0, r = S.size() - 1;
while (l < r) {
if (S[l++] != S[r--])
return false;
}
return true;
};
auto mutate = [&](int time) {
int hour = time / 60;
string hour_part = to_string(hour);
if (hour_part.size() == 1)
hour_part = "0" + hour_part;
int minute = time % 60;
string minute_part = to_string(minute);
if (minute_part.size() == 1)
minute_part = "0" + minute_part;
return hour_part + ":" + minute_part;
};
while (!seen[start]) {
if (is_palindrome(s))
++ans;
seen[start] = true;
start = (start + x) % 1440;
s = mutate(start);
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

7
codeforces/799/d.in Normal file
View file

@ -0,0 +1,7 @@
6
03:12 360
00:00 1
13:22 2
15:15 10
11:11 1440
22:30 27

72
codeforces/799/e.cc Normal file
View file

@ -0,0 +1,72 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
void solve() {
int n, s;
cin >> n >> s;
vector<int> a(n);
int total = 0;
for (auto& e : a) {
cin >> e;
total += e;
}
if (total < s) {
cout << -1 << '\n';
return;
}
int r = n - 1;
int cur = 0;
while (cur != total - s) {
cur += a[r] == 1;
--r;
}
++r;
int ans = n - r;
for (int l = 0; l < n; ++l) {
if (a[l] == 0) {
continue;
}
// NOTE: while loop instead of maintaing invariant
++r;
while (r < n && a[r] == 0) {
++r;
}
ans = min(ans, l + 1 + n - r);
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

15
codeforces/799/e.in Normal file
View file

@ -0,0 +1,15 @@
7
3 1
1 0 0
3 1
1 1 0
9 3
0 1 0 1 1 1 0 0 1
6 4
1 1 1 1 1 1
5 1
0 0 1 1 0
16 2
1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1
6 3
1 0 1 0 0 0

70
codeforces/799/f.cc Normal file
View file

@ -0,0 +1,70 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
void solve() {
int n;
cin >> n;
vector<int> a(n);
vector<int> f(10, 0);
for (auto& e : a)
cin >> e;
for (int i = 0; i < n; ++i) {
++f[a[i] % 10];
}
// NOTE: missed n - 2, did just < n
// NOTE: also, removed f[digit] after, causing a[i] % 10 to be
// included in f erroneously
for (int i = 0; i < n - 2; ++i) {
int digit = a[i] % 10;
--f[digit];
for (int l = 0; l <= 9; ++l) {
for (int r = 0; r <= 9; ++r) {
if ((l + r + digit) % 10 == 3) {
// NOTE: forgot l != r condition
// simplify conditions
if ((l == r && f[l] >= 2) || (l != r && f[l] >= 1 && f[r] >= 1)) {
cout << "YES\n";
return;
}
}
}
}
}
cout << "NO\n";
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

13
codeforces/799/f.in Normal file
View file

@ -0,0 +1,13 @@
6
4
20 22 19 84
4
1 11 1 2022
4
1100 1100 1100 1111
5
12 34 56 78 90
4
1 9 8 4
6
16 38 94 25 18 99

73
codeforces/799/g.cc Normal file
View file

@ -0,0 +1,73 @@
#include <bits/stdc++.h> // {{{
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#else
#define dbgln(...)
#define dbg(...)
#endif
// }}}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto& e : a) {
cin >> e;
}
vector<int> can(n, 0);
for (int i = 0; i < n - 1; ++i) {
can[i] = a[i] / 2.0 < a[i + 1];
}
int ans = 0, window = 0;
// had <= , not < k - 1, then had it wrong AGAIN
// NOTE: sliding window impl bad - just decide on one approach and go with it
for (int i = 0; i < n - 1; ++i) {
window += can[i];
if (i >= k - 1) {
if (window == k) {
++ans;
}
window -= can[i - k + 1];
}
}
// for (int i = 0; i < n - 1; ++i) {
// can[i] = (i ? can[i - 1] : 0) + (a[i] / 2.0 < a[i + 1]);
// }
// int ans = 0;
// for (int i = k - 1; i < n - 1; ++i) {
// // cout << "i: " << i << endl;
// // NOTE: i - k - 1 before (wrong)
// if (can[i] - (i - k >= 0 ? can[i - k] : 0) == k) {
// // cout << "yes\n";
// ++ans;
// }
// }
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

13
codeforces/799/g.in Normal file
View file

@ -0,0 +1,13 @@
6
4 2
20 22 19 84
5 1
9 5 3 2 1
5 2
9 5 3 2 1
7 2
22 12 16 4 3 22 12
7 3
22 12 16 4 3 22 12
9 3
3 9 12 3 9 12 3 9 12