diff --git a/codeforces/855/1800d.cc b/codeforces/1054/d.cc similarity index 67% rename from codeforces/855/1800d.cc rename to codeforces/1054/d.cc index 3968628..861bf8e 100644 --- a/codeforces/855/1800d.cc +++ b/codeforces/1054/d.cc @@ -39,14 +39,34 @@ template constexpr T MAX = std::numeric_limits::max(); // }}} void solve() { - int n; - cin >> n; + u32 n; string s; - cin >> s; - int ans = n - 1; - for (int i = 0; i < n - 2; ++i) { - ans -= s[i] == s[i + 2]; - } + cin >> n >> s; + + u64 ans = MAX; + + auto f = [&](string &t) { + vector pos; + for (u64 i = 0; i < n; i++) + if (t[i] == 'a') + pos.push_back(i); + u64 m = pos.size(); + + vector pref(m + 1), suff(m + 1); + for (u64 i = 0; i < m; i++) + pref[i + 1] = pref[i] + pos[i] - i; + for (u64 i = m; i--;) + suff[i] = suff[i + 1] + (n - (m - i)) - pos[i]; + + for (u64 i = 0; i <= m; i++) + ans = min(ans, pref[i] + suff[i]); + }; + + f(s); + transform(s.begin(), s.end(), s.begin(), + [](char c) { return c ^ 'a' ^ 'b'; }); + f(s); + cout << ans << '\n'; } diff --git a/codeforces/1054/io/2149a.cpin b/codeforces/1054/io/2149a.cpin new file mode 100644 index 0000000..8332666 --- /dev/null +++ b/codeforces/1054/io/2149a.cpin @@ -0,0 +1,11 @@ +5 +4 +abab +6 +bababa +7 +abababa +2 +ab +1 +b diff --git a/codeforces/1054/io/d.1.cpin b/codeforces/1054/io/d.1.cpin new file mode 100644 index 0000000..8332666 --- /dev/null +++ b/codeforces/1054/io/d.1.cpin @@ -0,0 +1,11 @@ +5 +4 +abab +6 +bababa +7 +abababa +2 +ab +1 +b diff --git a/codeforces/855/1800a.cc b/codeforces/855/1800a.cc deleted file mode 100644 index ac88e9c..0000000 --- a/codeforces/855/1800a.cc +++ /dev/null @@ -1,86 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 constexpr T MIN = std::numeric_limits::min(); - -template constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -constexpr string meow{"meow"}; - -void solve() { - u32 n; - cin >> n; - string s; - cin >> s; - - u32 i = 0, j = 0; - - while (j < meow.size() && i < n && tolower(s[i]) == meow[j]) { - while (i < n && tolower(s[i]) == meow[j]) - ++i; - ++j; - } - - if (i == n && j == meow.size()) { - cout << "YES"; - } else { - cout << "NO"; - } - - 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; -} -// }}} diff --git a/codeforces/855/1800b.cc b/codeforces/855/1800b.cc deleted file mode 100644 index c51eb50..0000000 --- a/codeforces/855/1800b.cc +++ /dev/null @@ -1,89 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 constexpr T MIN = std::numeric_limits::min(); - -template constexpr T MAX = std::numeric_limits::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, k; - cin >> n >> k; - string s; - cin >> s; - vector f(26, 0); - - u32 ans = 0; - for (auto letter : s) { - if (isupper(letter)) { - if (f[letter - 'a']++ < 0) { - ++ans; - } - } else { - if (f[letter]-- > 0) { - ++ans; - } - } - } - - u32 matches = 0; - // for (auto freq : f) { - // matches += freq / 2; - // } - - cout << ans + min(k, matches) << '\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; -} -// }}} diff --git a/codeforces/855/1800c1.cc b/codeforces/855/1800c1.cc deleted file mode 100644 index ec154da..0000000 --- a/codeforces/855/1800c1.cc +++ /dev/null @@ -1,66 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 -constexpr T MIN = std::numeric_limits::min(); - -template -constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -void solve() { -} - -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; -} -// }}} diff --git a/codeforces/855/1800c2.cc b/codeforces/855/1800c2.cc deleted file mode 100644 index a59d150..0000000 --- a/codeforces/855/1800c2.cc +++ /dev/null @@ -1,67 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 -constexpr T MIN = std::numeric_limits::min(); - -template -constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -void solve() { - -} - -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; -} -// }}} diff --git a/codeforces/855/1800e1.cc b/codeforces/855/1800e1.cc deleted file mode 100644 index a59d150..0000000 --- a/codeforces/855/1800e1.cc +++ /dev/null @@ -1,67 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 -constexpr T MIN = std::numeric_limits::min(); - -template -constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -void solve() { - -} - -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; -} -// }}} diff --git a/codeforces/855/1800e2.cc b/codeforces/855/1800e2.cc deleted file mode 100644 index 117401d..0000000 --- a/codeforces/855/1800e2.cc +++ /dev/null @@ -1,95 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 constexpr T MIN = std::numeric_limits::min(); - -template constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -bitset<2 * 100000> seen; -void solve() { - seen.reset(); - u32 n, k; - cin >> n >> k; - string s, t; - cin >> s >> t; - - u32 ans = 0; - vector f(26, 0); - - auto dfs = [&](auto &&self, i32 i) -> void { - if (i < 0 || i >= n || seen[i]) - return; - seen[i] = true; - ++f[s[i] - 'a']; - --f[t[i] - 'a']; - for (auto d : {i - k, i - k - 1, i + k, i + k + 1}) { - self(self, d); - } - }; - - bool ok = true; - for (i32 i = 0; i < n && ok; ++i) { - if (!seen[i]) { - dfs(dfs, i); - ok &= count(f.begin(), f.end(), 0) == 26; - f.assign(26, 0); - } - } - - cout << (ok ? "YES" : "NO") << '\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; -} -// }}} diff --git a/codeforces/855/1800f.cc b/codeforces/855/1800f.cc deleted file mode 100644 index 3ce0dca..0000000 --- a/codeforces/855/1800f.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 constexpr T MIN = std::numeric_limits::min(); - -template constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -vector parities(200000, 0); -vector> present(200000); - -void solve() { - u32 n; - cin >> n; - - string s; - for (u32 i = 0; i < n; ++i) { - cin >> s; - for (auto c : s) { - parities[i] ^= 1 << (c - 'a'); - present[i].set(c - 'a'); - } - } - - u64 ans = 0; - unordered_map f; - - for (u32 c = 0; c < 26; ++c) { - u32 mask = ((1 << 26) - 1) ^ (1 << c); - for (u32 i = 0; i < n; i++) { - if (present[i].test(c)) - continue; - ans += f[parities[i] ^ mask]; - ++f[parities[i]]; - } - f.clear(); - } - - 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; -} -// }}} diff --git a/codeforces/855/1800g.cc b/codeforces/855/1800g.cc deleted file mode 100644 index a59d150..0000000 --- a/codeforces/855/1800g.cc +++ /dev/null @@ -1,67 +0,0 @@ -#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -// https://codeforces.com/blog/entry/96344 - -#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 -constexpr T MIN = std::numeric_limits::min(); - -template -constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -void solve() { - -} - -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; -} -// }}} diff --git a/codeforces/855/io/1800a.1.cpin b/codeforces/855/io/1800a.1.cpin deleted file mode 100644 index 3a194d3..0000000 --- a/codeforces/855/io/1800a.1.cpin +++ /dev/null @@ -1,15 +0,0 @@ -7 -4 -meOw -14 -mMmeoOoWWWwwwW -3 -mew -7 -MmeEeUw -4 -MEOW -6 -MmyaVW -5 -meowA diff --git a/codeforces/855/io/1800a.1.cpout b/codeforces/855/io/1800a.1.cpout deleted file mode 100644 index 222b3f9..0000000 --- a/codeforces/855/io/1800a.1.cpout +++ /dev/null @@ -1,7 +0,0 @@ -YES -YES -NO -NO -YES -NO -NO diff --git a/codeforces/855/io/1800b.1.cpin b/codeforces/855/io/1800b.1.cpin deleted file mode 100644 index 5edeb84..0000000 --- a/codeforces/855/io/1800b.1.cpin +++ /dev/null @@ -1,11 +0,0 @@ -5 -11 2 -aAaaBACacbE -2 2 -ab -4 1 -aaBB -6 0 -abBAcC -5 3 -cbccb diff --git a/codeforces/855/io/1800b.1.cpout b/codeforces/855/io/1800b.1.cpout deleted file mode 100644 index bf5057a..0000000 --- a/codeforces/855/io/1800b.1.cpout +++ /dev/null @@ -1,5 +0,0 @@ -5 -0 -1 -3 -2 diff --git a/codeforces/855/io/1800c1.1.cpin b/codeforces/855/io/1800c1.1.cpin deleted file mode 100644 index d850bc4..0000000 --- a/codeforces/855/io/1800c1.1.cpin +++ /dev/null @@ -1,11 +0,0 @@ -5 -5 -3 3 3 0 0 -6 -0 3 3 0 0 3 -7 -1 2 3 0 4 5 0 -7 -1 2 5 0 4 3 0 -5 -3 1 0 0 4 diff --git a/codeforces/855/io/1800c1.1.cpout b/codeforces/855/io/1800c1.1.cpout deleted file mode 100644 index 26aa2ea..0000000 --- a/codeforces/855/io/1800c1.1.cpout +++ /dev/null @@ -1,5 +0,0 @@ -6 -6 -8 -9 -4 diff --git a/codeforces/855/io/1800c2.1.cpin b/codeforces/855/io/1800c2.1.cpin deleted file mode 100644 index d850bc4..0000000 --- a/codeforces/855/io/1800c2.1.cpin +++ /dev/null @@ -1,11 +0,0 @@ -5 -5 -3 3 3 0 0 -6 -0 3 3 0 0 3 -7 -1 2 3 0 4 5 0 -7 -1 2 5 0 4 3 0 -5 -3 1 0 0 4 diff --git a/codeforces/855/io/1800c2.1.cpout b/codeforces/855/io/1800c2.1.cpout deleted file mode 100644 index 26aa2ea..0000000 --- a/codeforces/855/io/1800c2.1.cpout +++ /dev/null @@ -1,5 +0,0 @@ -6 -6 -8 -9 -4 diff --git a/codeforces/855/io/1800d.1.cpin b/codeforces/855/io/1800d.1.cpin deleted file mode 100644 index cd6670e..0000000 --- a/codeforces/855/io/1800d.1.cpin +++ /dev/null @@ -1,15 +0,0 @@ -7 -6 -aaabcc -10 -aaaaaaaaaa -6 -abcdef -7 -abacaba -6 -cccfff -4 -abba -5 -ababa diff --git a/codeforces/855/io/1800d.1.cpout b/codeforces/855/io/1800d.1.cpout deleted file mode 100644 index 78452a0..0000000 --- a/codeforces/855/io/1800d.1.cpout +++ /dev/null @@ -1,7 +0,0 @@ -4 -1 -5 -3 -3 -3 -1 diff --git a/codeforces/855/io/1800e1.1.cpin b/codeforces/855/io/1800e1.1.cpin deleted file mode 100644 index 50c15a4..0000000 --- a/codeforces/855/io/1800e1.1.cpin +++ /dev/null @@ -1,22 +0,0 @@ -7 -6 3 -talant -atltna -7 3 -abacaba -aaaabbc -12 3 -abracadabraa -avadakedavra -5 3 -accio -cicao -5 3 -lumos -molus -4 3 -uwjt -twju -4 3 -kvpx -vxpk diff --git a/codeforces/855/io/1800e1.1.cpout b/codeforces/855/io/1800e1.1.cpout deleted file mode 100644 index 5b1cfa6..0000000 --- a/codeforces/855/io/1800e1.1.cpout +++ /dev/null @@ -1,7 +0,0 @@ -YES -YES -NO -YES -NO -YES -NO diff --git a/codeforces/855/io/1800e2.1.cpin b/codeforces/855/io/1800e2.1.cpin deleted file mode 100644 index 0d27b05..0000000 --- a/codeforces/855/io/1800e2.1.cpin +++ /dev/null @@ -1,22 +0,0 @@ -7 -6 3 -talant -atltna -7 1 -abacaba -aaaabbc -12 6 -abracadabraa -avadakedavra -5 3 -accio -cicao -5 4 -lumos -molus -4 3 -uwjt -twju -4 3 -kvpx -vxpk diff --git a/codeforces/855/io/1800e2.1.cpout b/codeforces/855/io/1800e2.1.cpout deleted file mode 100644 index 5b1cfa6..0000000 --- a/codeforces/855/io/1800e2.1.cpout +++ /dev/null @@ -1,7 +0,0 @@ -YES -YES -NO -YES -NO -YES -NO diff --git a/codeforces/855/io/1800f.1.cpin b/codeforces/855/io/1800f.1.cpin deleted file mode 100644 index 79618aa..0000000 --- a/codeforces/855/io/1800f.1.cpin +++ /dev/null @@ -1,11 +0,0 @@ -10 -ftl -abcdefghijklmnopqrstuvwxy -abcdeffghijkllmnopqrsttuvwxy -ffftl -aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy -thedevid -bcdefghhiiiijklmnopqrsuwxyz -gorillasilverback -abcdefg -ijklmnopqrstuvwxyz diff --git a/codeforces/855/io/1800f.1.cpout b/codeforces/855/io/1800f.1.cpout deleted file mode 100644 index 7ed6ff8..0000000 --- a/codeforces/855/io/1800f.1.cpout +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/codeforces/855/io/1800g.1.cpin b/codeforces/855/io/1800g.1.cpin deleted file mode 100644 index 32df116..0000000 --- a/codeforces/855/io/1800g.1.cpin +++ /dev/null @@ -1,44 +0,0 @@ -6 -6 -1 5 -1 6 -1 2 -2 3 -2 4 -7 -1 5 -1 3 -3 6 -1 4 -4 7 -4 2 -9 -1 2 -2 4 -2 3 -3 5 -1 7 -7 6 -7 8 -8 9 -10 -2 9 -9 10 -2 3 -6 7 -4 3 -1 2 -3 8 -2 5 -6 5 -10 -3 2 -8 10 -9 7 -4 2 -8 2 -2 1 -4 5 -6 5 -5 7 -1 diff --git a/codeforces/855/io/1800g.1.cpout b/codeforces/855/io/1800g.1.cpout deleted file mode 100644 index 3569a3e..0000000 --- a/codeforces/855/io/1800g.1.cpout +++ /dev/null @@ -1,6 +0,0 @@ -YES -NO -YES -NO -NO -YES diff --git a/leetcode/.clang-format b/leetcode/.clang-format deleted file mode 100644 index 5625628..0000000 --- a/leetcode/.clang-format +++ /dev/null @@ -1,2 +0,0 @@ -BasedOnStyle: Google -AllowShortFunctionsOnASingleLine: Empty diff --git a/leetcode/a.cc b/leetcode/a.cc deleted file mode 100644 index b1ed3ac..0000000 --- a/leetcode/a.cc +++ /dev/null @@ -1,268 +0,0 @@ -#include - -// https://codeforces.com/blog/entry/96344 - -#pragma GCC optimize("O2,unroll-loops") -#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") - -using namespace std; - -template -void print(std::string const &str, Args &&...args) { - std::cout << std::vformat( - str, - // make_format_args binds arguments to const - std::make_format_args(static_cast(args)...)); -} - -template -void print(T const &t) { - std::cout << t; -} - -template -void print(T const &t) { - if constexpr (std::is_convertible_v) { - std::cout << t; - } else { - for (auto const &e : t) { - std::cout << e << ' '; - } - } -} - -template -void println(std::string const &str, Args &&...args) { - print(str, std::forward(args)...); - cout << '\n'; -} - -void println() { - std::cout << '\n'; -} - -template -void println(T const &t) { - print(t); - println(); -} - -template -void println(T const &t) { - print(t); - println(); -} - -template -T MAX() { - return std::numeric_limits::max(); -} - -template -T MIN() { - return std::numeric_limits::min(); -} - -#define ff first -#define ss second -#define eb emplace_back -#define ll long long -#define ld long double -#define vec vector - -#define all(x) (x).begin(), (x).end() -#define rall(x) (r).rbegin(), (x).rend() -#define sz(x) static_cast((x).size()) -#define FOR(a, b, c) for (int a = b; a < c; ++a) - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -#define randint(a, b) uniform_int_distribution(a, b)(rng) - -void YES() { - cout << "YES\n"; -} -void NO() { - cout << "NO\n"; -} - -#ifdef LOCAL -#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; -#else -#define dbg(x) -#endif - -static constexpr int MOD = 1e9 + 7; - -#include -#include - -using namespace __gnu_pbds; - -// https://mirror.codeforces.com/blog/entry/124683 - -namespace hashing { -using i64 = std::int64_t; -using u64 = std::uint64_t; -static const u64 FIXED_RANDOM = - std::chrono::steady_clock::now().time_since_epoch().count(); - -#if USE_AES -std::mt19937 rd(FIXED_RANDOM); -const __m128i KEY1{(i64)rd(), (i64)rd()}; -const __m128i KEY2{(i64)rd(), (i64)rd()}; -#endif - -template -struct custom_hash {}; - -template -inline void hash_combine(u64 &seed, T const &v) { - custom_hash hasher; - seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); -}; - -template -struct custom_hash::value>::type> { - u64 operator()(T _x) const { - u64 x = _x; -#if USE_AES - __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; - __m128i y = _mm_aesenc_si128(m, KEY1); - __m128i z = _mm_aesenc_si128(y, KEY2); - return z[0]; -#else - x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; - x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; - x = (x ^ (x >> 27)) * 0x94d049bb133111eb; - return x ^ (x >> 31); -#endif - } -}; - -template -struct custom_hash()))>> { - u64 operator()(T const &a) const { - u64 value = FIXED_RANDOM; - for (auto &x : a) hash_combine(value, x); - return value; - } -}; - -template -struct custom_hash> { - u64 operator()(const std::tuple &a) const { - u64 value = FIXED_RANDOM; - std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, - a); - return value; - } -}; - -template -struct custom_hash> { - u64 operator()(std::pair const &a) const { - u64 value = FIXED_RANDOM; - hash_combine(value, a.first); - hash_combine(value, a.second); - return value; - } -}; -}; // namespace hashing - -#ifdef PB_DS_ASSOC_CNTNR_HPP -template -using hashmap = gp_hash_table< - Key, Value, hashing::custom_hash, std::equal_to, - direct_mask_range_hashing<>, linear_probe_fn<>, - hash_standard_resize_policy, - hash_load_check_resize_trigger<>, true>>; -template -using hashset = gp_hash_table< - Key, null_type, hashing::custom_hash, std::equal_to, - direct_mask_range_hashing<>, linear_probe_fn<>, - hash_standard_resize_policy, - hash_load_check_resize_trigger<>, true>>; - -#endif -#ifdef PB_DS_TREE_POLICY_HPP -template -using multiset = tree, rb_tree_tag, - tree_order_statistics_node_update>; -template -using rbtree = tree, rb_tree_tag, - tree_order_statistics_node_update>; -#endif - -const vec> dirs = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; - -constexpr int RIGHT = 1, LEFT = 2, DOWN = 3, UP = 4; - -void solve() { - int m, n; - cin >> m >> n; - - vec> grid(m, vec(n, 0)); - - for (auto &row : grid) { - for (auto &cell : row) { - cin >> cell; - } - } - - deque> q{{0, 0, 0}}; - - hashset> seen; - - while (!q.empty()) { - auto [r, c, w] = q.front(); - q.pop_front(); - - println("at r={}, c={}, w={}", r, c, w); - - if (min(r, c) < 0 || r == m || c == n) continue; - - if (r == m - 1 && c == n - 1) { - println(w); - return; - } - - if (seen.find({r, c}) != seen.end()) continue; - - seen.insert({r, c}); - - switch (grid[r][c]) { - case UP: - q.emplace_front(r - 1, c, w); - break; - case LEFT: - q.emplace_front(r, c - 1, w); - break; - case DOWN: - q.emplace_front(r + 1, c, w); - break; - case RIGHT: - q.emplace_front(r, c + 1, w); - break; - } - - for (auto &[dr, dc] : dirs) { - int nr = r + dr, nc = c + dc; - - q.emplace_back(nr, nc, w + 1); - } - } -} - -int main() { - cin.tie(nullptr)->sync_with_stdio(false); - - int t = 1; - cin >> t; - - while (t--) { - solve(); - } - - return 0; -} diff --git a/leetcode/a.in b/leetcode/a.in deleted file mode 100644 index aca90a1..0000000 --- a/leetcode/a.in +++ /dev/null @@ -1,7 +0,0 @@ -3 -4 4 -1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 -3 3 -1 1 3 3 2 2 1 1 4 -2 2 -1 2 4 3 diff --git a/leetcode/b.cc b/leetcode/b.cc deleted file mode 100644 index 7aa6310..0000000 --- a/leetcode/b.cc +++ /dev/null @@ -1,110 +0,0 @@ -#include - -// https://codeforces.com/blog/entry/96344 - -#pragma GCC optimize("O2,unroll-loops") -#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") - -using namespace std; - -template -void print(std::string const &str, Args &&...args) { - std::cout << std::vformat( - str, - // make_format_args binds arguments to const - str, std::make_format_args(static_cast(args)...)); -} - -template -void print(T const &t) { - std::cout << t; -} - -template -void print(T const &t) { - if constexpr (std::is_convertible_v) { - std::cout << t << '\n'; - } else { - for (auto const &e : t) { - std::cout << e << ' '; - } - std::cout << '\n'; - } -} - -template -void println(std::string const &str, Args &&...args) { - print(str, std::forward(args)...); - cout << '\n'; -} - -template -void println(T const &t) { - print("{}\n", t); -} - -template -void println(T const &t) { - cout << t << '\n'; -} - -void println() { - std::cout << '\n'; -} - -template -T MAX() { - return std::numeric_limits::max(); -} - -template -T MIN() { - return std::numeric_limits::min(); -} - -#define ff first -#define ss second -#define eb emplace_back -#define ll long long -#define ld long double -#define vec vector - -#define all(x) (x).begin(), (x).end() -#define rall(x) (r).rbegin(), (x).rend() -#define sz(x) static_cast((x).size()) -#define FOR(a, b, c) for (int a = b; a < c; ++a) - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -#define randint(a, b) uniform_int_distribution(a, b)(rng) - -void YES() { - cout << "YES\n"; -} -void NO() { - cout << "NO\n"; -} - -#ifdef LOCAL -#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; -#else -#define dbg(x) -#endif - -static constexpr int MOD = 1e9 + 7; - -void solve() { - -} - -int main() { - cin.tie(nullptr)->sync_with_stdio(false); - - int t = 1; - cin >> t; - - while (t--) { - solve(); - } - - return 0; -} diff --git a/leetcode/b.in b/leetcode/b.in deleted file mode 100644 index e69de29..0000000 diff --git a/leetcode/b.out b/leetcode/b.out deleted file mode 100644 index e69de29..0000000 diff --git a/leetcode/compile_flags.txt b/leetcode/compile_flags.txt deleted file mode 100644 index ebd5be8..0000000 --- a/leetcode/compile_flags.txt +++ /dev/null @@ -1,5 +0,0 @@ --std=c++20 --Wall --Wextra --Wshadow --DLOCAL