feat: 826

This commit is contained in:
Barrett Ruth 2025-10-12 16:14:51 -04:00
parent 02eaf3965e
commit 6a188c7cff
104 changed files with 840 additions and 0 deletions

93
codeforces/826/1741a.cc Normal file
View file

@ -0,0 +1,93 @@
#include <bits/stdc++.h> // {{{
#include <version>
#ifdef __cpp_lib_ranges_enumerate
#include <ranges>
namespace rv = std::views;
namespace rs = std::ranges;
#endif
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
template <typename T> constexpr T MIN = std::numeric_limits<T>::min();
template <typename T> constexpr T MAX = std::numeric_limits<T>::max();
#endif
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
string a, b;
cin >> a >> b;
u32 i = 0, j = 0;
while (i < a.size() && j < b.size()) {
u32 a_xs = 0, b_xs = 0;
while (a[i] == 'X') {
++a_xs;
++i;
}
while (b[j] == 'X') {
++b_xs;
++j;
}
if (a[i] == b[j]) {
if (a_xs != b_xs) {
cout << ((a[i] == 'S' && a_xs < b_xs || a[i] == 'L' && a_xs > b_xs)
? '>'
: '<')
<< '\n';
return;
}
} else {
cout << ((a[i] == 'S' || a[i] == 'M' && b[j] == 'L') ? '<' : '>') << '\n';
return;
}
++i;
++j;
}
cout << "=\n";
}
int main() { // {{{
std::cin.exceptions(std::cin.failbit);
#ifdef LOCAL
std::cerr.rdbuf(std::cout.rdbuf());
std::cout.setf(std::ios::unitbuf);
std::cerr.setf(std::ios::unitbuf);
#else
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
u32 tc = 1;
std::cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

75
codeforces/826/1741b.cc Normal file
View file

@ -0,0 +1,75 @@
#include <bits/stdc++.h> // {{{
#include <version>
#ifdef __cpp_lib_ranges_enumerate
#include <ranges>
namespace rv = std::views;
namespace rs = std::ranges;
#endif
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
template <typename T> constexpr T MIN = std::numeric_limits<T>::min();
template <typename T> constexpr T MAX = std::numeric_limits<T>::max();
#endif
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
if (n == 1 || n == 3) {
cout << "-1\n";
return;
}
u32 x = n, i = 1;
for (; i <= n / 2; ++i, --x) {
cout << x << ' ';
}
x = 1;
for (; i <= n; ++i, ++x) {
cout << x << " \n"
[i == n];
}
}
int main() { // {{{
std::cin.exceptions(std::cin.failbit);
#ifdef LOCAL
std::cerr.rdbuf(std::cout.rdbuf());
std::cout.setf(std::ios::unitbuf);
std::cerr.setf(std::ios::unitbuf);
#else
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
u32 tc = 1;
std::cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

90
codeforces/826/1741c.cc Normal file
View file

@ -0,0 +1,90 @@
#include <bits/stdc++.h> // {{{
#include <version>
#ifdef __cpp_lib_ranges_enumerate
#include <ranges>
namespace rv = std::views;
namespace rs = std::ranges;
#endif
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
template <typename T> constexpr T MIN = std::numeric_limits<T>::min();
template <typename T> constexpr T MAX = std::numeric_limits<T>::max();
#endif
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<u32> a(n);
for (u32 i = 0; i < n; ++i) {
cin >> a[i];
}
u32 ans = n;
u64 target = 0;
for (u32 i = 1; i <= n; ++i) {
target += a[i - 1];
u32 big_block = i;
u32 curlen = 0;
u64 total = 0;
for (u32 j = i + 1; j <= n; ++j) {
total += a[j - 1];
++curlen;
if (total == target) {
big_block = max(big_block, curlen);
total = 0;
curlen = 0;
} else if (total > target) {
break;
}
}
if (total == 0)
ans = min(ans, big_block);
}
cout << ans << '\n';
}
int main() { // {{{
std::cin.exceptions(std::cin.failbit);
#ifdef LOCAL
std::cerr.rdbuf(std::cout.rdbuf());
std::cout.setf(std::ios::unitbuf);
std::cerr.setf(std::ios::unitbuf);
#else
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
u32 tc = 1;
std::cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

104
codeforces/826/1741d.cc Normal file
View file

@ -0,0 +1,104 @@
#include <bits/stdc++.h> // {{{
#include <version>
#ifdef __cpp_lib_ranges_enumerate
#include <ranges>
namespace rv = std::views;
namespace rs = std::ranges;
#endif
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
template <typename T> constexpr T MIN = std::numeric_limits<T>::min();
template <typename T> constexpr T MAX = std::numeric_limits<T>::max();
#endif
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<u32> a(n);
for (auto &e : a)
cin >> e;
auto f = [&](auto &&self, i32 l, i32 r) -> i64 {
if (l + 1 == r) {
return 0;
}
i32 m = l + (r - l) / 2;
i64 left = self(self, l, m);
i64 right = self(self, m, r);
if (left == -1 || right == -1) {
return -1;
}
bool oknoswap = true;
for (i32 i = l; i < r - 1; ++i) {
oknoswap = oknoswap && (a[i] < a[i + 1]);
}
if (oknoswap) {
return left + right;
}
bool okswap = true;
for (i32 i = m, cnt = 0; cnt < r - l - 1; ++cnt) {
i32 nxt = i == r - 1 ? l : i + 1;
okswap = okswap && (a[i] < a[nxt]);
i = nxt;
}
if (okswap) {
for (i32 i = 0; i < m - l; ++i) {
swap(a[l + i], a[m + i]);
}
return left + right + 1;
}
return -1;
};
cout << f(f, 0, n) << '\n';
}
int main() { // {{{
std::cin.exceptions(std::cin.failbit);
#ifdef LOCAL
std::cerr.rdbuf(std::cout.rdbuf());
std::cout.setf(std::ios::unitbuf);
std::cerr.setf(std::ios::unitbuf);
#else
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
u32 tc = 1;
std::cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,16 @@
5
3
1 0 1
0 0 1
4
1 1 0 0
0 1 1 1
2
1 1
1 1
4
1 0 0 1
0 1 1 0
1
0
1

View file

@ -0,0 +1,5 @@
1
2
0
1
1

View file

@ -0,0 +1,9 @@
4
1
343
2
4 2
3
4 2 4
4
1 1 1 1

View file

@ -0,0 +1,4 @@
YES
YES
NO
YES

View file

@ -0,0 +1,7 @@
3
3
1 2 3
3
1 1 1
4
2 1 4 3

View file

@ -0,0 +1,3 @@
6
3
7

View file

@ -0,0 +1,6 @@
4
2 4 1 4
3
2 4
3 3
2 1

View file

@ -0,0 +1,3 @@
6
10
5

View file

@ -0,0 +1,6 @@
5
1 1 3 2 1
3
1 3
2 5
4 5

View file

@ -0,0 +1,3 @@
7
9
8

View file

@ -0,0 +1,9 @@
4
2
1010
3
100010
2
1111
2
1110

View file

@ -0,0 +1,7 @@
0
1 2
2 3 5
1 2 5
3 2 3 4
1 4
-1

View file

@ -0,0 +1,2 @@
2
3 1

View file

@ -0,0 +1 @@
6

View file

@ -0,0 +1,2 @@
5
7 3 9 6 12

View file

@ -0,0 +1 @@
52

View file

@ -0,0 +1,7 @@
6
XXXS XS
XXXL XL
XL M
XXL XXL
XXXXXS M
L M

View file

@ -0,0 +1,6 @@
<
>
>
=
<
>

View file

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

View file

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

View file

@ -0,0 +1,9 @@
4
6
55 45 30 30 40 100
4
10 23 7 13
5
10 55 35 30 65
6
4 1 1 1 1 4

View file

@ -0,0 +1,4 @@
3
4
2
3

View file

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

View file

@ -0,0 +1,4 @@
4
-1
0
-1

View file

@ -0,0 +1,15 @@
7
9
1 1 2 3 1 3 2 2 3
5
12 1 2 7 5
6
5 7 8 9 10 3
4
4 8 6 2
2
3 1
10
4 6 2 1 9 4 9 3 4 2
1
1

View file

@ -0,0 +1,7 @@
YES
YES
YES
NO
YES
YES
NO

View file

@ -0,0 +1,41 @@
9
3
1 2 1
3 4 1
5 6 2
2
100000000 200000000 1
900000000 1000000000 2
5
1 2 1
2 3 2
3 4 3
4 5 4
5 6 5
5
1 5 1
4 9 2
1 2 1
8 9 2
5 7 3
2
1 100 2
10 90 1
3
1 1 1
10 10 2
1000000000 1000000000 3
3
3 4 1
2 5 1
1 6 2
6
5 6 2
11 12 3
7 8 2
3 4 2
1 2 1
9 10 2
2
1 3 1
2 3 2

View file

@ -0,0 +1,9 @@
3 1 1
700000000 700000000
0 0 0 0 0
0 0 2 1 0
0 0
9 9 999999990
0 0 0
3 1 3 1 1 1
0 0

View file

@ -0,0 +1,40 @@
4
8
11 16 7
12 15 7
2 5 8
17 22 5
1 8 8
19 23 8
16 16 6
6 7 5
9
1 4 3
5 11 1
8 11 3
1 10 1
2 11 1
1 10 4
3 11 1
5 7 1
1 11 1
9
25 25 1
26 26 1
24 24 2
13 14 2
12 16 2
17 18 1
19 19 1
24 27 2
24 27 1
9
15 18 1
20 22 2
13 22 2
13 22 2
3 13 2
6 10 2
3 6 2
19 24 2
22 24 2

View file

@ -0,0 +1,4 @@
0 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 3 1 1 3 0 0
0 2 0 0 2 5 9 1 4

View file

@ -0,0 +1,34 @@
3
6 7
1 2
2 3
2 4
3 5
4 5
3 6
6 5
5
2 3 4 5 6
4
1 2 3 5
6 7
1 2
2 3
2 4
3 5
4 5
3 6
6 5
6
2 3 4 5 6 5
4
1 2 3 5
4 4
1 2
1 3
2 3
3 4
3
3 4 2
2
1 3

View file

@ -0,0 +1,3 @@
2
1
1

View file

@ -0,0 +1,24 @@
3
2 1
1 2
3
2 2 2
3
1 2 3
3 3
1 2
1 3
2 3
4
2 2 2 3
3
1 2 4
4 4
3 1
3 2
1 4
2 4
5
3 2 2 4 2
3
1 3 4

View file

@ -0,0 +1,3 @@
3
1
0

View file

@ -0,0 +1 @@
5 5 7

View file

@ -0,0 +1 @@
YES

View file

@ -0,0 +1 @@
7 7 5

View file

@ -0,0 +1 @@
NO

View file

@ -0,0 +1,4 @@
3 3
dxx
axx
cxx

View file

@ -0,0 +1 @@
axxcxxdxx

View file

@ -0,0 +1,2 @@
1000 8
1 3 4 5 6 7 8 9

View file

@ -0,0 +1 @@
2000

View file

@ -0,0 +1,2 @@
9999 1
0

View file

@ -0,0 +1 @@
9999

View file

@ -0,0 +1 @@
2 3 1 1

View file

@ -0,0 +1 @@
2

View file

@ -0,0 +1 @@
10 7 3 4

View file

@ -0,0 +1 @@
3570

View file

@ -0,0 +1 @@
100000 100000 99999 99999

View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1 @@
100000 100000 44444 55555

View file

@ -0,0 +1 @@
738162020

View file

@ -0,0 +1 @@
3

View file

@ -0,0 +1 @@
3 10 5 16 8 4 2 1

View file

@ -0,0 +1 @@
ATTCGGGA

View file

@ -0,0 +1 @@
3

View file

@ -0,0 +1 @@
5

View file

@ -0,0 +1 @@
4 2 5 3 1

View file

@ -0,0 +1,4 @@
3
2 3
1 1
4 2

View file

@ -0,0 +1,3 @@
8
1
15

View file

@ -0,0 +1 @@
8

View file

@ -0,0 +1,8 @@
0
6
28
96
252
550
1056
1848

View file

@ -0,0 +1,2 @@
5
2 3 1 5

View file

@ -0,0 +1 @@
4

View file

@ -0,0 +1 @@
7

View file

@ -0,0 +1,5 @@
YES
4
1 2 4 7
3
3 5 6

View file

@ -0,0 +1,2 @@
5
3 2 5 1 7

View file

@ -0,0 +1 @@
5

View file

@ -0,0 +1 @@
3

View file

@ -0,0 +1 @@
8

View file

@ -0,0 +1 @@
20

View file

@ -0,0 +1 @@
4

View file

@ -0,0 +1 @@
aabac

View file

@ -0,0 +1,21 @@
20
aaabc
aaacb
aabac
aabca
aacab
aacba
abaac
abaca
abcaa
acaab
acaba
acbaa
baaac
baaca
bacaa
bcaaa
caaab
caaba
cabaa
cbaaa

View file

@ -0,0 +1,2 @@
5
3 2 7 4 1

View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1,8 @@
........
........
..*.....
........
........
.....**.
...*....
........

View file

@ -0,0 +1 @@
65

View file

@ -0,0 +1 @@
??????R??????U??????????????????????????LD????D?

View file

@ -0,0 +1 @@
201

View file

@ -0,0 +1 @@
HATTIVATTI

View file

@ -0,0 +1 @@
AHATITITVT

View file

@ -0,0 +1,4 @@
3
2 1
2 2
3 3

View file

@ -0,0 +1,3 @@
YES
NO
YES

View file

@ -0,0 +1 @@
AAAACACBA

View file

@ -0,0 +1 @@
AACABACAA

View file

@ -0,0 +1 @@
2

View file

@ -0,0 +1,4 @@
3
1 2
1 3
2 3

View file

@ -0,0 +1 @@
2

View file

@ -0,0 +1,4 @@
00
01
11
10

View file

@ -0,0 +1,4 @@
3
7
19
12

View file

@ -0,0 +1,3 @@
7
4
1

View file

@ -0,0 +1 @@
8

View file

@ -0,0 +1,8 @@
0 3 2 3 2 3 4 5
3 4 1 2 3 4 3 4
2 1 4 3 2 3 4 5
3 2 3 2 3 4 3 4
2 3 2 3 4 3 4 5
3 4 3 4 3 4 5 4
4 3 4 3 4 5 4 5
5 4 5 4 5 4 5 6

View file

@ -0,0 +1,4 @@
3 4
AAAA
BBBB
CCDD

View file

@ -0,0 +1,3 @@
CDCD
DCDC
ABAB

Some files were not shown because too many files have changed in this diff Show more