diff --git a/.gitignore b/.gitignore index 0296075..5ce1416 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build io .clangd +.clang-format diff --git a/README.md b/README.md new file mode 100644 index 0000000..cec2ad2 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# competitive programming + +a collection of my competitive programming solutions categorized as follows: + +- `/kattis`: a few ICPC problems from UVA's "practices" +- `/codeforces`: codeforces contests, including every division 4 round +- `/cses`: ~100 basic cses problems diff --git a/atcoder/042/.clang-format b/atcoder/042/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/atcoder/042/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1027/.clang-format b/codeforces/.clang-format similarity index 96% rename from codeforces/1027/.clang-format rename to codeforces/.clang-format index 99733d1..59cd6f1 100644 --- a/codeforces/1027/.clang-format +++ b/codeforces/.clang-format @@ -1,5 +1,5 @@ BasedOnStyle: LLVM -IndentWidth: 4 +IndentWidth: 2 UseTab: Never AllowShortIfStatementsOnASingleLine: Never diff --git a/codeforces/1003/.clang-format b/codeforces/1003/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1003/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1006/.clang-format b/codeforces/1006/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1006/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1009/.clang-format b/codeforces/1009/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1009/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1013/.clang-format b/codeforces/1013/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1013/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1016/.clang-format b/codeforces/1016/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1016/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1017/.clang-format b/codeforces/1017/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1017/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1020/.clang-format b/codeforces/1020/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1020/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1029/.clang-format b/codeforces/1029/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1029/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1032/.clang-format b/codeforces/1032/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1032/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1034/.clang-format b/codeforces/1034/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1034/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1037/.clang-format b/codeforces/1037/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1037/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1037/a.cc b/codeforces/1037/a.cc index 47ffe9d..bac1114 100644 --- a/codeforces/1037/a.cc +++ b/codeforces/1037/a.cc @@ -82,5 +82,4 @@ int main() { // {{{ } return 0; -} -// }}} +} // vim: set foldmethod=marker foldmarker={{{{{{,}}}}}} diff --git a/codeforces/1042/.clang-format b/codeforces/1042/.clang-format deleted file mode 100644 index d2c38f2..0000000 --- a/codeforces/1042/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 100 -BreakBeforeBraces: Allman -PointerAlignment: Left diff --git a/codeforces/1043/.clang-format b/codeforces/1043/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/1043/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1047/.clang-format b/codeforces/1047/.clang-format deleted file mode 100644 index d2c38f2..0000000 --- a/codeforces/1047/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 100 -BreakBeforeBraces: Allman -PointerAlignment: Left diff --git a/codeforces/1059/.clang-format b/codeforces/1059/.clang-format deleted file mode 100644 index d2c38f2..0000000 --- a/codeforces/1059/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 100 -BreakBeforeBraces: Allman -PointerAlignment: Left diff --git a/codeforces/1070/a.cc b/codeforces/1070/a.cc new file mode 100644 index 0000000..dc8702a --- /dev/null +++ b/codeforces/1070/a.cc @@ -0,0 +1,58 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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 >> t; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1071/a.cc b/codeforces/1071/a.cc new file mode 100644 index 0000000..93807a7 --- /dev/null +++ b/codeforces/1071/a.cc @@ -0,0 +1,62 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; +} + +// }}} + +// vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1073/a.cc b/codeforces/1073/a.cc new file mode 100644 index 0000000..805d4f6 --- /dev/null +++ b/codeforces/1073/a.cc @@ -0,0 +1,58 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1073/b1.cc b/codeforces/1073/b1.cc new file mode 100644 index 0000000..805d4f6 --- /dev/null +++ b/codeforces/1073/b1.cc @@ -0,0 +1,58 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1074/a.cc b/codeforces/1074/a.cc new file mode 100644 index 0000000..b2e4942 --- /dev/null +++ b/codeforces/1074/a.cc @@ -0,0 +1,62 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + for (u32 i = 1; i <= n; ++i) { + print("{}{}", i, " \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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1074/b.cc b/codeforces/1074/b.cc new file mode 100644 index 0000000..b3942f1 --- /dev/null +++ b/codeforces/1074/b.cc @@ -0,0 +1,66 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + u64 x = 0, a; + for (u32 i = 1; i <= n; ++i) { + cin >> a; + x = max(x, a); + } + + println("{}", x * 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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1074/c.cc b/codeforces/1074/c.cc new file mode 100644 index 0000000..ba0251d --- /dev/null +++ b/codeforces/1074/c.cc @@ -0,0 +1,78 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + vector a(n); + for (auto &e : a) + cin >> e; + + sort(begin(a), end(a)); + a.erase(unique(begin(a), end(a)), end(a)); + + u32 ans = 1, streak = 1; + + for (u32 i = 1; i < a.size(); ++i) { + if (i > 0 && a[i] - 1 == a[i - 1]) { + ++streak; + } else { + ans = max(ans, streak); + streak = 1; + } + } + + ans = max(ans, streak); + + println("{}", ans); +} + +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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1074/d.cc b/codeforces/1074/d.cc new file mode 100644 index 0000000..6a5d1a0 --- /dev/null +++ b/codeforces/1074/d.cc @@ -0,0 +1,83 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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 + 1> dirty; +void solve() { + dirty.reset(); + u32 n, m; + u64 h; + cin >> n >> m >> h; + vector> a(n); + for (u32 i = 0; i < n; ++i) { + cin >> a[i].first; + a[i].second = a[i].first; + } + + u64 b, c; + for (u32 i = 0; i < m; ++i) { + cin >> b >> c; + --b; + if (dirty[b]) { + dirty[b] = false; + a[b].second = a[b].first; + } + a[b].second += c; + if (a[b].second > h) { + dirty.set(); + } + } + + for (u32 i = 0; i < n; ++i) { + print("{}{}", dirty[i] ? a[i].first : a[i].second, " \n"[i == n - 1]); + } +} + +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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1074/e.cc b/codeforces/1074/e.cc new file mode 100644 index 0000000..42ab639 --- /dev/null +++ b/codeforces/1074/e.cc @@ -0,0 +1,71 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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, m, k; + string s; + + cin >> n >> m >> k; + + vector a(n), b(m); + + for (u32 i = 0; i < n; ++i) { + cin >> a[i]; + } + + for (u32 i = 0; i < m; ++i) { + cin >> b[i]; + } + + cin >> s; +} + +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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/1074/f.cc b/codeforces/1074/f.cc new file mode 100644 index 0000000..805d4f6 --- /dev/null +++ b/codeforces/1074/f.cc @@ -0,0 +1,58 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; +} // vim: set foldmethod=marker foldmarker={{{,}}} diff --git a/codeforces/17/.clang-format b/codeforces/17/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/17/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/19/.clang-format b/codeforces/19/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/19/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/431/.clang-format b/codeforces/431/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/431/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/479/.clang-format b/codeforces/479/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/479/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/498/.clang-format b/codeforces/498/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/498/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/506/.clang-format b/codeforces/506/.clang-format deleted file mode 100644 index b1ea9ab..0000000 --- a/codeforces/506/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/515/.clang-format b/codeforces/515/.clang-format deleted file mode 100644 index d2c38f2..0000000 --- a/codeforces/515/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 100 -BreakBeforeBraces: Allman -PointerAlignment: Left diff --git a/codeforces/544/.clang-format b/codeforces/544/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/544/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/547/.clang-format b/codeforces/547/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/547/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/550/.clang-format b/codeforces/550/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/550/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/552/.clang-format b/codeforces/552/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/552/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/555/.clang-format b/codeforces/555/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/555/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/560/.clang-format b/codeforces/560/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/560/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/565/.clang-format b/codeforces/565/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/565/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/570/.clang-format b/codeforces/570/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/570/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/575/.clang-format b/codeforces/575/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/575/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/611/.clang-format b/codeforces/611/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/611/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/640/.clang-format b/codeforces/640/.clang-format deleted file mode 100644 index 5625628..0000000 --- a/codeforces/640/.clang-format +++ /dev/null @@ -1,2 +0,0 @@ -BasedOnStyle: Google -AllowShortFunctionsOnASingleLine: Empty diff --git a/codeforces/702/a.cc b/codeforces/702/a.cc new file mode 100644 index 0000000..fb87a87 --- /dev/null +++ b/codeforces/702/a.cc @@ -0,0 +1,78 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + cin >> n; + vector a(n); + for(auto& e : a) cin >> e; + + u32 ans = 0; + + for (u32 i = 1; i < n; ++i) { + u32 A = max(a[i - 1], a[i]); + u32 B = min(a[i - 1], a[i]); + + while (B * 2 < A) { + ++ans; + B *= 2; + } + } + + println("{}", ans); +} + +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/710/a.cc b/codeforces/710/a.cc new file mode 100644 index 0000000..9f91d01 --- /dev/null +++ b/codeforces/710/a.cc @@ -0,0 +1,67 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + i64 n, m, x; + cin >> n >> m >> x; + + i64 row = x % n; + if (row == 0) + row = n; + i64 col = (x + n - 1) / n; + + println("{}", (row - 1) * m + col); +} + +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/713/a.cc b/codeforces/713/a.cc new file mode 100644 index 0000000..6674b36 --- /dev/null +++ b/codeforces/713/a.cc @@ -0,0 +1,73 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + vector a(n); + map f; + for (auto &e : a) { + cin >> e; + ++f[e]; + } + + for (u32 i = 0; i < n; ++i) { + if (f[a[i]] == 1) { + println("{}", i + 1); + return; + } + } +} + +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/719/a.cc b/codeforces/719/a.cc new file mode 100644 index 0000000..24663c4 --- /dev/null +++ b/codeforces/719/a.cc @@ -0,0 +1,81 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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<26> seen; + +void solve() { + seen.reset(); + u32 n; + string s; + cin >> n >> s; + + for (u32 i = 0; i < n; ++i) { + if (seen[s[i]]) { + println("NO"); + return; + } + + seen[s[i]] = true; + + while (i + 1 < n && s[i] == s[i + 1]) { + ++i; + } + } + + println("YES"); +} + +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/725/a.cc b/codeforces/725/a.cc new file mode 100644 index 0000000..4af7488 --- /dev/null +++ b/codeforces/725/a.cc @@ -0,0 +1,68 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + i32 n; + cin >> n; + vector a(n); + for (auto &e : a) + cin >> e; + + i32 i = distance(begin(a), max_element(begin(a), end(a))); + i32 j = distance(begin(a), min_element(begin(a), end(a))); + + println("{}", min({max(i, j) + 1, n - min(i, j), min(i, j) + 1 + n - max(i, j)})); +} + +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/731/a.cc b/codeforces/731/a.cc new file mode 100644 index 0000000..7eee3c5 --- /dev/null +++ b/codeforces/731/a.cc @@ -0,0 +1,69 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + i32 x1, y1, x2, y2, x3, y3; + cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; + + i32 ans = abs(y2 - y1) + abs(x2 - x1); + if (x1 == x2 && x2 == x3 && min(y1, y2) <= y3 && y3 <= max(y1, y2)) { + ans += 2; + } else if (y1 == y2 && y2 == y3 && min(x1, x2) <= x3 && x3 <= max(x1, x2)) { + ans += 2; + } + + println("{}", ans); +} + +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/734/a.cc b/codeforces/734/a.cc new file mode 100644 index 0000000..904c9f1 --- /dev/null +++ b/codeforces/734/a.cc @@ -0,0 +1,65 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + + array ans{0, n / 3, n / 3}; + ++ans[n % 3]; + + println("{} {}", ans[1], ans[2]); +} + +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/739/a.cc b/codeforces/739/a.cc new file mode 100644 index 0000000..43272b9 --- /dev/null +++ b/codeforces/739/a.cc @@ -0,0 +1,70 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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 k; + cin >> k; + + u32 ans = 1, i = 1; + while (i < k) { + ++ans; + if (!(ans % 3 == 0 || ans % 10 == 3)) { + ++i; + } + } + + println("{}", ans); +} + +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/744/a.cc b/codeforces/744/a.cc new file mode 100644 index 0000000..458dda6 --- /dev/null +++ b/codeforces/744/a.cc @@ -0,0 +1,70 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + string s; + cin >> s; + + u32 b = 0; + for (auto c : s) + b += c == 'B'; + + if (s.size() % 2 == 0 && b == s.size() / 2) { + println("YES"); + } else { + println("NO"); + } +} + +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/748/a.cc b/codeforces/748/a.cc new file mode 100644 index 0000000..03923a1 --- /dev/null +++ b/codeforces/748/a.cc @@ -0,0 +1,65 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + i32 a, b, c; + cin >> a >> b >> c; + + println("{} {} {}", + max({0, b - a + 1, c - a + 1}), + max({0, a - b + 1, c - b + 1}), + max({0, b - c + 1, a - c + 1})); +} + +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/753/a.cc b/codeforces/753/a.cc new file mode 100644 index 0000000..fe30e22 --- /dev/null +++ b/codeforces/753/a.cc @@ -0,0 +1,73 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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() { + string a, s; + cin >> a >> s; + map m; + for (u32 i = 0; i < a.size(); ++i) { + m[a[i]] = i; + } + + i32 ans = 0; + for (i32 i = 1; i < s.size(); ++i) { + ans += abs(m[s[i]] - m[s[i - 1]]); + } + + println("{}", ans); +} + +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/756/a.cc b/codeforces/756/a.cc new file mode 100644 index 0000000..b4c1e93 --- /dev/null +++ b/codeforces/756/a.cc @@ -0,0 +1,76 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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() { + string s; + cin >> s; + + if ((s.back() - '0') % 2 == 0) { + println("0"); + } else if ((s[0] - '0') % 2 == 0) { + println("1"); + } else { + for (auto c : s) { + if ((c - '0') % 2 == 0) { + println("2"); + return; + } + } + println("-1"); + } +} + +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/760/a.cc b/codeforces/760/a.cc new file mode 100644 index 0000000..df261aa --- /dev/null +++ b/codeforces/760/a.cc @@ -0,0 +1,65 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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() { + vector ss(7); + for (auto& e : ss) cin >> e; + sort(begin(ss), end(ss)); + + println("{} {} {}", ss[0], ss[1], ss.back() - (ss[0] + ss[1])); +} + +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/762/.clang-format b/codeforces/762/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/762/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/764/a.cc b/codeforces/764/a.cc new file mode 100644 index 0000000..443625f --- /dev/null +++ b/codeforces/764/a.cc @@ -0,0 +1,65 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + vector a(n); + for (auto &e : a) + cin >> e; + + println("{}", *max_element(begin(a), end(a)) - *min_element(begin(a), end(a))); +} + +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/776/a.cc b/codeforces/776/a.cc new file mode 100644 index 0000000..7bd90b5 --- /dev/null +++ b/codeforces/776/a.cc @@ -0,0 +1,72 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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() { + char c; + string s; + cin >> s >> c; + + for (u32 i = 0; i < s.size(); ++i) { + if (s[i] == c && i % 2 == 0 && (s.size() - i - 1) % 2 == 0) { + println("YES"); + return; + } + } + + println("NO"); +} + +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/780/a.cc b/codeforces/780/a.cc new file mode 100644 index 0000000..a88876e --- /dev/null +++ b/codeforces/780/a.cc @@ -0,0 +1,69 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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 a, b; + cin >> a >> b; + if (b == 0) { + println("{}", a + 1); + } else if (a == 0) { + println("{}", 1); + } else { + println("{}", 2 * b + a + 1); + } +} + +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/784/.clang-format b/codeforces/784/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/784/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/786/a.cc b/codeforces/786/a.cc new file mode 100644 index 0000000..caa37ca --- /dev/null +++ b/codeforces/786/a.cc @@ -0,0 +1,66 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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 x, y; + cin >> x >> y; + + if (y % x > 0) { + println("0 0"); + } else { + println("1 {}", y / x); + } +} + +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/787/a.cc b/codeforces/787/a.cc new file mode 100644 index 0000000..f94437f --- /dev/null +++ b/codeforces/787/a.cc @@ -0,0 +1,78 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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 a, b, c, y, x; + cin >> a >> b >> c >> x >> y; + + x -= min(x, a); + y -= min(y, b); + + if (x > 0) { + u32 diff = min(x, c); + x -= diff; + c -= diff; + } + + if (y > 0) { + u32 diff = min(y, c); + y -= diff; + } + + println("{}", (x == y && x == 0) ? "YES" : "NO"); +} + +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/790/.clang-format b/codeforces/790/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/790/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/797/a.cc b/codeforces/797/a.cc new file mode 100644 index 0000000..960e964 --- /dev/null +++ b/codeforces/797/a.cc @@ -0,0 +1,80 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + + u32 a = n / 3, b = n / 3, c = n / 3; + + switch (n % 3) { + case 0: + ++b; + --c; + break; + case 1: + b += 2; + --c; + break; + case 2: + ++a; + b += 2; + --c; + break; + } + + println("{} {} {}", a, b, c); +} + +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/799/.clang-format b/codeforces/799/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/799/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/805/a.cc b/codeforces/805/a.cc new file mode 100644 index 0000000..6eb8282 --- /dev/null +++ b/codeforces/805/a.cc @@ -0,0 +1,73 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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; + cin >> n; + u32 N = n; + u32 dcount = 0; + while (N > 0) { + ++dcount; + N /= 10; + } + + u32 base = 1; + for (u32 i = 0; i + 1 < dcount; ++i) { + base *= 10; + } + + println("{}", n - base); +} + +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/806/.clang-format b/codeforces/806/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/806/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/811/a.cc b/codeforces/811/a.cc new file mode 100644 index 0000000..44fd9d6 --- /dev/null +++ b/codeforces/811/a.cc @@ -0,0 +1,75 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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() { + i32 n, H, M, h, m; + cin >> n >> H >> M; + + i32 ans = 24 * 60; + + for (i32 i = 0; i < n; ++i) { + cin >> h >> m; + i32 diff = h * 60 + m - (H * 60 + M); + if (diff < 0) { + diff += 24 * 60; + } + ans = min(ans, diff); + } + + println("{} {}", ans / 60, ans % 60); +} + +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/817/.clang-format b/codeforces/817/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/817/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/820/a.cc b/codeforces/820/a.cc new file mode 100644 index 0000000..60d462d --- /dev/null +++ b/codeforces/820/a.cc @@ -0,0 +1,69 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + i32 a, b, c; + cin >> a >> b >> c; + + i32 A = a - 1; + i32 B = abs(c - b) + c - 1; + + if (A == B) { + println("3"); + } else { + println("{}", A < B ? 1 : 2); + } +} + +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/827/.clang-format b/codeforces/827/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/827/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/834/a.cc b/codeforces/834/a.cc new file mode 100644 index 0000000..c70dd81 --- /dev/null +++ b/codeforces/834/a.cc @@ -0,0 +1,74 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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 +// }}} + +string Yes = "Yes"; + +void solve() { + string s; + cin >> s; + + for (u32 i = 0; i < s.size(); ++i) { + auto c = s[i]; + if (Yes.find(c) == string::npos || + i + 1 < s.size() && !(c == 'Y' && s[i + 1] == 'e' || c == 'e' && s[i + 1] == 's' || + c == 's' && s[i + 1] == 'Y')) { + println("NO"); + return; + } + } + + println("YES"); +} + +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/835/.clang-format b/codeforces/835/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/835/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/839/a.cc b/codeforces/839/a.cc new file mode 100644 index 0000000..23f52a1 --- /dev/null +++ b/codeforces/839/a.cc @@ -0,0 +1,64 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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() { + string s; + cin >> s; + + println("{}", s[0] - '0' + s[2] - '0'); +} + +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/847/a.cc b/codeforces/847/a.cc new file mode 100644 index 0000000..833e241 --- /dev/null +++ b/codeforces/847/a.cc @@ -0,0 +1,71 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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 +// }}} + +string PI = "3141592653589793238462643383279"; + +void solve() { + string s; + cin >> s; + + u32 i = 0; + while (i < PI.size() && s[i] == PI[i]) { + ++i; + } + + println("{}", i); +} + +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/849/.clang-format b/codeforces/849/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/849/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/855/a.cc b/codeforces/855/a.cc new file mode 100644 index 0000000..f39bb2b --- /dev/null +++ b/codeforces/855/a.cc @@ -0,0 +1,81 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + string s; + cin >> n >> s; + + // NOTE: cannot due `for (auto c : "meow")` <- c-style string, includes null-terminator + string S{"meow"}; + + u32 i = 0; + for (auto c : S) { + u32 j = i; + while (j < n && tolower(s[j]) == c) { + ++j; + } + if (i == j) { + i = 0; + break; + } + i = j; + } + + println("{}", i == n ? "YES" : "NO"); +} + +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/859/.clang-format b/codeforces/859/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/859/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/863/a.cc b/codeforces/863/a.cc new file mode 100644 index 0000000..2966e2d --- /dev/null +++ b/codeforces/863/a.cc @@ -0,0 +1,73 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + char d; + string s; + cin >> n >> d >> s; + + for (u32 i = 0; i < n; ++i) { + if (d > s[i] || d == s[i] && i + 1 < n && d > s[i + 1]) { + println("{}{}{}", s.substr(0, i), d, s.substr(i)); + return; + } + } + + println("{}{}", s, d); +} + +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/867/a.cc b/codeforces/867/a.cc new file mode 100644 index 0000000..91553bd --- /dev/null +++ b/codeforces/867/a.cc @@ -0,0 +1,74 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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, t; + cin >> n >> t; + array ans{-1, -1}; + vector a(n), b(n); + for (u32 i = 0; i < n; ++i) { + cin >> a[i]; + } + for (u32 i = 0; i < n; ++i) { + cin >> b[i]; + } + for (u32 i = 1; i <= n; ++i) { + if (i - 1 + a[i - 1] <= t) { + ans = max(ans, {b[i - 1], i}); + } + } + println("{}", ans[1] == -1 ? -1 : ans[1]); +} + +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/871/.clang-format b/codeforces/871/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/871/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/874/.clang-format b/codeforces/874/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/874/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/878/a.cc b/codeforces/878/a.cc new file mode 100644 index 0000000..96696d4 --- /dev/null +++ b/codeforces/878/a.cc @@ -0,0 +1,75 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + string s; + cin >> n >> s; + + u32 i = 0; + string ans; + for (u32 j = 1; j < n; ++j) { + if (s[j] == s[i]) { + ans.push_back(s[i]); + i = j + 1; + ++j; + } + } + + println("{}", ans); +} + +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/881/a.cc b/codeforces/881/a.cc new file mode 100644 index 0000000..0bd367b --- /dev/null +++ b/codeforces/881/a.cc @@ -0,0 +1,74 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + cin >> n; + vector a(n); + for (auto& e : a) cin >> e; + + sort(begin(a), end(a)); + + u32 ans = 0; + + for (u32 i = 0; i < n / 2; ++i) { + ans += a[n - i - 1] - a[i]; + } + + println("{}", ans); +} + +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/886/.clang-format b/codeforces/886/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/886/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/888/.clang-format b/codeforces/888/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/888/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/891/.clang-format b/codeforces/891/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/891/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/894/.clang-format b/codeforces/894/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/894/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/895/.clang-format b/codeforces/895/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/895/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/898/.clang-format b/codeforces/898/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/898/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/900/.clang-format b/codeforces/900/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/900/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/903/.clang-format b/codeforces/903/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/903/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/905/a.cc b/codeforces/905/a.cc new file mode 100644 index 0000000..23f7ae5 --- /dev/null +++ b/codeforces/905/a.cc @@ -0,0 +1,78 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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 +// }}} + +string keys = "1234567890"; +vector m(10); + +void solve() { + string s; + cin >> s; + + u32 ans = 4; + + char last = '1'; + for (auto c : s) { + ans += abs(m[c - '0'] - m[last - '0']); + last = c; + } + + println("{}", ans); +} + +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 (i32 i = 0; i < keys.size(); ++i) { + m[keys[i] - '0'] = i; + } + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} +// }}} diff --git a/codeforces/909/a.cc b/codeforces/909/a.cc new file mode 100644 index 0000000..1a56db3 --- /dev/null +++ b/codeforces/909/a.cc @@ -0,0 +1,67 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + cin >> n; + if (n % 3 == 1 || n % 3 == 2) { + println("First"); + } else { + println("Second"); + } +} + +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/913/a.cc b/codeforces/913/a.cc new file mode 100644 index 0000000..3ac3a12 --- /dev/null +++ b/codeforces/913/a.cc @@ -0,0 +1,79 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 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() { + char C; + u32 x; + cin >> C >> x; + + for (u32 r = 1; r <= 8; ++r) { + if (r == x) { + continue; + } + + println("{}{}", C, r); + } + + for (char c = 'a'; c <= 'h'; ++c) { + if (c == C) { + continue; + } + + println("{}{}", c, x); + } + + println(); +} + +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/916/a.cc b/codeforces/916/a.cc new file mode 100644 index 0000000..78df74f --- /dev/null +++ b/codeforces/916/a.cc @@ -0,0 +1,79 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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 f('Z' - 'A' + 1); + +void solve() { + u32 n; + cin >> n; + string s; + cin >> s; + f.assign(f.size(), 0); + + for (auto& e : s) { + ++f[e - 'A']; + } + + u32 ans = 0; + + for (u32 i = 1; i <= f.size(); ++i) { + ans += f[i - 1] >= i; + } + + println("{}", ans); +} + +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/918/.clang-format b/codeforces/918/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/918/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/920/.clang-format b/codeforces/920/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/920/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/923/.clang-format b/codeforces/923/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/923/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/925/a.cc b/codeforces/925/a.cc new file mode 100644 index 0000000..c716e65 --- /dev/null +++ b/codeforces/925/a.cc @@ -0,0 +1,76 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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 +// }}} + +map m; + +void solve() { + u32 n; + cin >> n; + + string ans = "aaa"; + + u32 index = 2; + for (u32 i = 1; i <= n - 3; ++i) { + if (ans[index] == 'z') { + --index; + } + ++ans[index]; + } + + println("{}", ans); +} + +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/927/a.cc b/codeforces/927/a.cc new file mode 100644 index 0000000..5bfa67a --- /dev/null +++ b/codeforces/927/a.cc @@ -0,0 +1,78 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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; + cin >> n; + string s; + cin >> s; + + u32 ans = 0; + char last = '.'; + for (auto c : s) { + if (last == '*' && c == '*') { + break; + } + if (c == '@') { + ++ans; + } + last = c; + } + + println("{}", ans); +} + +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/928/.clang-format b/codeforces/928/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/928/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/929/.clang-format b/codeforces/929/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/929/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/933/a.cc b/codeforces/933/a.cc new file mode 100644 index 0000000..b160b8f --- /dev/null +++ b/codeforces/933/a.cc @@ -0,0 +1,77 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +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 +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, m, k; + cin >> n >> m >> k; + vector a(n), b(m); + for (auto& e : a) cin >> e; + for (auto& e : b) cin >> e; + + u32 ans = 0; + + for (u32 i = 1; i <= n; ++i) { + for (u32 j = 1; j <= m; ++j) { + if (a[i - 1] + b[j - 1] <= k) { + ++ans; + } + } + } + + println("{}", ans); +} + +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/935/.clang-format b/codeforces/935/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/935/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/937/.clang-format b/codeforces/937/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/937/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/938/.clang-format b/codeforces/938/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/938/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/943/.clang-format b/codeforces/943/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/943/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/944/.clang-format b/codeforces/944/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/944/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/946/.clang-format b/codeforces/946/.clang-format deleted file mode 100644 index cbec8b9..0000000 --- a/codeforces/946/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 100 -PointerAlignment: Left diff --git a/codeforces/950/.clang-format b/codeforces/950/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/950/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/952/.clang-format b/codeforces/952/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/952/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/954/.clang-format b/codeforces/954/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/954/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/954/a.cc b/codeforces/954/a.cc index 2c8526a..340661e 100644 --- a/codeforces/954/a.cc +++ b/codeforces/954/a.cc @@ -43,14 +43,7 @@ void solve() { for (auto& e : a) cin >> e; sort(begin(a), end(a)); - u32 ans = 1e9; - for (i32 c = 1; c <= 10; ++c) { - u32 diff = 0; - for (auto e : a) diff += abs(c - e); - ans = min(ans, diff); - } - - println("{}", ans); + println("{}", a[1] - a[0] + a[2] - a[1]); } int main() { // {{{ diff --git a/codeforces/957/.clang-format b/codeforces/957/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/957/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/962/.clang-format b/codeforces/962/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/962/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/964/.clang-format b/codeforces/964/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/964/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/966/.clang-format b/codeforces/966/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/966/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/970/.clang-format b/codeforces/970/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/970/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/971/.clang-format b/codeforces/971/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/971/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/974/.clang-format b/codeforces/974/.clang-format deleted file mode 100644 index 5625628..0000000 --- a/codeforces/974/.clang-format +++ /dev/null @@ -1,2 +0,0 @@ -BasedOnStyle: Google -AllowShortFunctionsOnASingleLine: Empty diff --git a/codeforces/981/.clang-format b/codeforces/981/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/981/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/988/.clang-format b/codeforces/988/.clang-format deleted file mode 100644 index 99733d1..0000000 --- a/codeforces/988/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false diff --git a/codeforces/993/.clang-format b/codeforces/993/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/993/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/995/.clang-format b/codeforces/995/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/995/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/996/.clang-format b/codeforces/996/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/996/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/codeforces/998/.clang-format b/codeforces/998/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/codeforces/998/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/cses/dynamic-programming/.clang-format b/cses/dynamic-programming/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/cses/dynamic-programming/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/cses/graph-algorithms/.clang-format b/cses/graph-algorithms/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/cses/graph-algorithms/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/cses/introductory-problems/.clang-format b/cses/introductory-problems/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/cses/introductory-problems/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/cses/range-queries/.clang-format b/cses/range-queries/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/cses/range-queries/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/cses/sorting-and-searching/.clang-format b/cses/sorting-and-searching/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/cses/sorting-and-searching/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/kattis/10-9-2024/1/input.txt b/kattis/10-9-2024/1/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/kattis/10-9-2024/1/script.py b/kattis/10-9-2024/1/script.py new file mode 100644 index 0000000..8d37a7d --- /dev/null +++ b/kattis/10-9-2024/1/script.py @@ -0,0 +1,15 @@ +n, a = list(map(int, input().split())) + +es = list(map(int, input().split())) + +es.sort() + +won = 0 + +for e in es: + if a <= e: + break + won += 1 + a -= (e + 1) + +print(won) diff --git a/kattis/10-9-2024/3/input.txt b/kattis/10-9-2024/3/input.txt new file mode 100644 index 0000000..c68b729 --- /dev/null +++ b/kattis/10-9-2024/3/input.txt @@ -0,0 +1,2 @@ +10 15 +10 11 12 13 14 15 diff --git a/kattis/10-9-2024/3/script.py b/kattis/10-9-2024/3/script.py new file mode 100644 index 0000000..af25fa5 --- /dev/null +++ b/kattis/10-9-2024/3/script.py @@ -0,0 +1,44 @@ +from math import gcd + +a, b = map(int, input().split()) +max_num = float('-inf') + +transcript = input().split() + +fizzs = [] +buzzs = [] + +for i, token in enumerate(transcript): + num = a + i + + max_num = max(max_num, num) + + if token.startswith("Fizz") or token.endswith("Fizz"): + fizzs.append(num) + if token.startswith("Buzz") or token.endswith("Buzz"): + buzzs.append(num) + + +def gcf(nums: list[int]) -> int: + if not nums: + return '' + if len(nums) == 1: + return nums[0] + + x, y = nums[0], nums[1] + ans = gcd(x, y) + + for i in range(2, len(nums)): + ans = gcd(ans, nums[i]) + + return ans + + +a, b = gcf(fizzs), gcf(buzzs) + +if a == '': + a = max_num + 1 +if b == '': + b = max_num + 1 + +print(a, b) diff --git a/kattis/10-9-2024/4/script.py b/kattis/10-9-2024/4/script.py new file mode 100644 index 0000000..5fee760 --- /dev/null +++ b/kattis/10-9-2024/4/script.py @@ -0,0 +1,54 @@ +N = int(input()) + +matrix: list[list[int]] = [] +for i in range(N): + matrix[i] = list(map(int, list(input()))) + +row_map = [0] * N +col_map = [0] * N + +ones_above = 0 +ones_above_row = [0] * N + +for i, row in enumerate(matrix): + ones_above_row[i] = ones_above + total = 0 + for cell in row: + total += cell + row_map[i] = total + ones_above += row_map[i] + +ones_left = 0 +ones_left_col = [0] * N + +for col in range(N): + total = 0 + for row in range(N): + total += matrix[row][col] + ones_left_col[col] = ones_left + col_map[col] = total + ones_left += col_map[col] + +found_valid_row = False +for i in range(N): + flips_remain = row_map[i] + total_ones = ones_above_row[-1] - row_map[i] + row_map[-1] + if total_ones <= flips_remain: + row_flag = True + break + +found_valid_col = False +for i in range(N): + flips_remain = col_map[i] + total_ones = ones_left_col[-1] - col_map[i] + col_map[-1] + if total_ones <= flips_remain: + found_valid_col = True + break + +if found_valid_row: + if found_valid_col: + print("+") + else: + print("-") +else: + print("-") diff --git a/kattis/10-9-2024/contest.md b/kattis/10-9-2024/contest.md new file mode 100644 index 0000000..9a0693a --- /dev/null +++ b/kattis/10-9-2024/contest.md @@ -0,0 +1,3 @@ +# contest 1 + +https://open.kattis.com/contests/asurii diff --git a/kattis/11-02-2025/.clang-format b/kattis/11-02-2025/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/kattis/11-02-2025/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/kattis/18-2-2025/.clang-format b/kattis/18-2-2025/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/kattis/18-2-2025/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/kattis/23-9-24/b/input.txt b/kattis/23-9-24/b/input.txt new file mode 100644 index 0000000..4165880 --- /dev/null +++ b/kattis/23-9-24/b/input.txt @@ -0,0 +1,23 @@ +2 + +.#.#.#.#.# +#.#.#.#.#. +.#.#.B.#.# +#.#.#.#.#. +.#.#.B.#.# +#.#.W.#.#. +.#.#.#.#.# +#.#.#.B.#. +.#.#.#.#.# +#.#.#.#.#. + +.#.#.#.#.# +#.#.#.#.#. +.#.#.B.#.# +#.B.#.B.#. +.#.#.B.#.# +#.B.W.#.#. +.#.B.B.#.# +#.#.#.#.#. +.#.B.B.#.# +#.#.#.#.#. diff --git a/kattis/23-9-24/b/solution.py b/kattis/23-9-24/b/solution.py new file mode 100644 index 0000000..e95ce65 --- /dev/null +++ b/kattis/23-9-24/b/solution.py @@ -0,0 +1,117 @@ +""" +Backtracking Framework +- Set of choices +- Limited by constraints +- To reach a goal + +1. Understand +- Board of W/B, can capture; looking for max consecutive sequence of captures using same piece +- Capture in any direction "skipping over"; land on open square + +Similar Problems: N Queens + +Set of candidates (W pieces) limited in moves (capturing B pieces) to reach max # captures (i.e. capturing moves) +2. Develop + +- Given board state, w/ W candidates +- Consider every candidate as the piece yielding correct answer +- For every candidate, consider every capturing move they can make + - For each move: + - Make the move, and recursively find max # captures using this piece after this capture + - update/restore state on failure + - Update max if new max found + +consider after: caching/optimization + +backtracking function: def max_captures(board, w) -> int: + + +3. Carry Out +4. Revise + +At any particular position, +""" + +BOARD_SIZE = 10 + + +def parse_board() -> tuple[list[list[str]], list[tuple[int, int]]]: + board = [] + candidates: list[tuple[int, int]] = [] + + input() + + for r in range(BOARD_SIZE): + board.append(list(input())) + + candidates.extend((r, c) for c, cell in enumerate(board[-1]) if cell == "W") + + return board, candidates + + +def valid(board, r, c): + return 0 <= r < len(board) and 0 <= c < len(board[0]) + + +# all capturing moves white piece can make +def capturing_moves(board, r, c) -> list[tuple[int, int]]: + if not valid(board, r, c): + return [] + + moves = [] + + for dr, dc in [(-1, -1), (1, 1), (-1, 1), (1, -1)]: + if ( + valid(board, r + 2 * dr, c + 2 * dc) + and board[r + dr][c + dc] == "B" + and board[r + 2 * dr][c + 2 * dc] not in "BW" + ): + moves.append((dr, dc)) + + return moves + + +def max_candidate_captures(board, r, c) -> int: + max_captures = 0 + + for dr, dc in capturing_moves(board, r, c): + # place + board[r][c] = "." + board[r + dr][c + dc] = "." + board[r + dr * 2][c + dc * 2] = "W" + + ans = max_candidate_captures(board, r + dr * 2, c + dc * 2) + max_captures = max(max_captures, 1 + ans) + + # unplace + board[r + dr * 2][c + dc * 2] = "." + board[r][c] = "W" + board[r + dr][c + dc] = "B" + + return max_captures + + +def max_captures(board, candidates: list[tuple[int, int]]) -> int: + max_captures = 0 + + for r, c in candidates: + max_captures = max(max_captures, max_candidate_captures(board, r, c)) + + return max_captures + + +def solve() -> None: + T = int(input()) + + while T: + board, candidates = parse_board() + print(max_captures(board, candidates)) + T -= 1 + + +def main() -> None: + solve() + + +if __name__ == "__main__": + main() diff --git a/kattis/23-9-24/contest.md b/kattis/23-9-24/contest.md new file mode 100644 index 0000000..065a704 --- /dev/null +++ b/kattis/23-9-24/contest.md @@ -0,0 +1,3 @@ +# contest 2 + +https://open.kattis.com/contests/wrrf23 diff --git a/kattis/23-9-24/d/input.txt b/kattis/23-9-24/d/input.txt new file mode 100644 index 0000000..b188259 --- /dev/null +++ b/kattis/23-9-24/d/input.txt @@ -0,0 +1 @@ +(2+(2*2)+2) diff --git a/kattis/23-9-24/d/solution.py b/kattis/23-9-24/d/solution.py new file mode 100644 index 0000000..68054c9 --- /dev/null +++ b/kattis/23-9-24/d/solution.py @@ -0,0 +1,46 @@ +def solve(equation: str) -> None: + stack = [] + paren_pairs = [] + + for i, token in enumerate(equation): + if token == "(": + stack.append([i, None]) + elif token == ")": + l, r = stack.pop() + r = i + paren_pairs.append((l, r)) + + P = [[]] + + for paren_pair in paren_pairs: + P.extend([[paren_pair] + p for p in P]) + + def format(permutation): + output = list(equation) + + for l, r in permutation: + output[l] = None + output[r] = None + + return "".join(filter(lambda token: token, output)) + + seen = set() + ans = [] + for permutation in P[1:]: + output = format(permutation) + if output not in seen: + seen.add(output) + ans.append(output) + + for x in sorted(ans): + print(x) + + +def main() -> None: + equation = input() + + solve(equation) + + +if __name__ == "__main__": + main() diff --git a/kattis/23-9-24/e/solution.py b/kattis/23-9-24/e/solution.py new file mode 100644 index 0000000..32811c7 --- /dev/null +++ b/kattis/23-9-24/e/solution.py @@ -0,0 +1,22 @@ +ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_." + +character_to_index = {c: i for i, c in enumerate(ALPHABET)} +index_to_character = {i: c for i, c in enumerate(ALPHABET)} + +while line := input(): + split = line.split() + + if len(split) == 1: + break + + k, string = int(split[0]), split[1] + + backwards = string[::-1] + + ans: list[str] = [] + + for letter in backwards: + index = character_to_index[letter] + ans.append(index_to_character[(index + k) % len(ALPHABET)]) + + print("".join(ans)) diff --git a/kattis/23-9-24/f/input.txt b/kattis/23-9-24/f/input.txt new file mode 100644 index 0000000..35b50fd --- /dev/null +++ b/kattis/23-9-24/f/input.txt @@ -0,0 +1,6 @@ +Will Smith +Agent Smith +Peter Pan +Micky Mouse +Minnie Mouse +Peter Gunn diff --git a/kattis/23-9-24/f/solution.py b/kattis/23-9-24/f/solution.py new file mode 100644 index 0000000..dbfae37 --- /dev/null +++ b/kattis/23-9-24/f/solution.py @@ -0,0 +1,32 @@ +import sys +from collections import Counter + + +def solve() -> None: + counter: Counter[str] = Counter() + + ans = [] + + lines = sys.stdin.readlines() + for line in lines: + first, last = line.split() + + counter[first] += 1 + + ans.append((last, first)) + + ans.sort() + + for last, first in ans: + if counter[first] > 1: + print(f"{first} {last}") + else: + print(first) + + +def main() -> None: + solve() + + +if __name__ == "__main__": + main() diff --git a/kattis/25-2-2025/.clang-format b/kattis/25-2-2025/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/kattis/25-2-2025/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false diff --git a/readme.md b/readme.md deleted file mode 100644 index 9f29833..0000000 --- a/readme.md +++ /dev/null @@ -1,5 +0,0 @@ -# competitive programming - -an archive of competitive programming code - -codeforces account: [frozenpipe](https://codeforces.com/profile/frozenpipe) diff --git a/usaco/bronze/simulation/.clang-format b/usaco/bronze/simulation/.clang-format deleted file mode 100644 index e7350c4..0000000 --- a/usaco/bronze/simulation/.clang-format +++ /dev/null @@ -1,9 +0,0 @@ -BasedOnStyle: Google -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLambdasOnASingleLine: false -AllowShortLoopsOnASingleLine: false