From 1b90a3d03903bae436b1c3fca5923200564d1726 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 23 Aug 2025 15:57:00 -0500 Subject: [PATCH] 790 --- codeforces/790/.clang-format | 9 +++ codeforces/790/.clangd | 41 +++++++++++ codeforces/790/a.cc | 90 +++++++++++++++++++++++ codeforces/790/b.cc | 89 +++++++++++++++++++++++ codeforces/790/c.cc | 98 +++++++++++++++++++++++++ codeforces/790/compile_flags.txt | 31 ++++++++ codeforces/790/d.cc | 103 ++++++++++++++++++++++++++ codeforces/790/debug_flags.txt | 14 ++++ codeforces/790/e.cc | 105 +++++++++++++++++++++++++++ codeforces/790/f.cc | 119 +++++++++++++++++++++++++++++++ codeforces/790/g.cc | 116 ++++++++++++++++++++++++++++++ codeforces/790/h.cc | 80 +++++++++++++++++++++ codeforces/790/io/a.in | 6 ++ codeforces/790/io/a.out | 14 ++++ codeforces/790/io/b.in | 12 ++++ codeforces/790/io/b.out | 9 +++ codeforces/790/io/c.in | 25 +++++++ codeforces/790/io/c.out | 10 +++ codeforces/790/io/d.in | 17 +++++ codeforces/790/io/d.out | 8 +++ codeforces/790/io/e.in | 17 +++++ codeforces/790/io/e.out | 14 ++++ codeforces/790/io/f.in | 9 +++ codeforces/790/io/f.out | 12 ++++ codeforces/790/io/g.in | 10 +++ codeforces/790/io/g.out | 7 ++ codeforces/790/io/h.in | 0 codeforces/790/io/h.out | 0 codeforces/790/makefile | 30 ++++++++ codeforces/790/scripts/debug.sh | 29 ++++++++ codeforces/790/scripts/run.sh | 29 ++++++++ codeforces/790/scripts/utils.sh | 61 ++++++++++++++++ 32 files changed, 1214 insertions(+) create mode 100644 codeforces/790/.clang-format create mode 100644 codeforces/790/.clangd create mode 100644 codeforces/790/a.cc create mode 100644 codeforces/790/b.cc create mode 100644 codeforces/790/c.cc create mode 100644 codeforces/790/compile_flags.txt create mode 100644 codeforces/790/d.cc create mode 100644 codeforces/790/debug_flags.txt create mode 100644 codeforces/790/e.cc create mode 100644 codeforces/790/f.cc create mode 100644 codeforces/790/g.cc create mode 100644 codeforces/790/h.cc create mode 100644 codeforces/790/io/a.in create mode 100644 codeforces/790/io/a.out create mode 100644 codeforces/790/io/b.in create mode 100644 codeforces/790/io/b.out create mode 100644 codeforces/790/io/c.in create mode 100644 codeforces/790/io/c.out create mode 100644 codeforces/790/io/d.in create mode 100644 codeforces/790/io/d.out create mode 100644 codeforces/790/io/e.in create mode 100644 codeforces/790/io/e.out create mode 100644 codeforces/790/io/f.in create mode 100644 codeforces/790/io/f.out create mode 100644 codeforces/790/io/g.in create mode 100644 codeforces/790/io/g.out create mode 100644 codeforces/790/io/h.in create mode 100644 codeforces/790/io/h.out create mode 100644 codeforces/790/makefile create mode 100644 codeforces/790/scripts/debug.sh create mode 100644 codeforces/790/scripts/run.sh create mode 100644 codeforces/790/scripts/utils.sh diff --git a/codeforces/790/.clang-format b/codeforces/790/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/790/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/790/.clangd b/codeforces/790/.clangd new file mode 100644 index 0000000..316b539 --- /dev/null +++ b/codeforces/790/.clangd @@ -0,0 +1,41 @@ +CompileFlags: + Add: + -O2 + -Wall + -Wextra + -Wpedantic + -Wshadow + -Wformat=2 + -Wfloat-equal + -Wlogical-op + -Wshift-overflow=2 + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-qual + -Wuseless-cast + -Wno-sign-promotion + -Wcast-align + -Wunused + -Woverloaded-virtual + -Wconversion + -Wsign-conversion + -Wmisleading-indentation + -Wduplicated-cond + -Wduplicated-branches + -Wlogical-op + -Wnull-dereference + -Wformat=2 + -Wformat-overflow + -Wformat-truncation + -Wdouble-promotion + -Wundef + -DLOCAL + -Wno-unknown-pragmas +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/790/a.cc b/codeforces/790/a.cc new file mode 100644 index 0000000..f7eb9e9 --- /dev/null +++ b/codeforces/790/a.cc @@ -0,0 +1,90 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#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 right = n % 1000; + u32 left = n / 1000; + + u32 left_sum = (left % 10) + (left / 10 % 10) + (left / 100 % 10); + u32 right_sum = (right % 10) + (right / 10 % 10) + (right / 100 % 10); + + if (left_sum == right_sum) { + YES(); + } else { + NO(); + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/b.cc b/codeforces/790/b.cc new file mode 100644 index 0000000..6b2f71b --- /dev/null +++ b/codeforces/790/b.cc @@ -0,0 +1,89 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#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; + vec a(n); + for (auto& e : a) + cin >> e; + + auto small = *min_element(all(a)); + u32 ans = 0; + for (auto e : a) { + ans += e - small; + } + + println("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/c.cc b/codeforces/790/c.cc new file mode 100644 index 0000000..80a2531 --- /dev/null +++ b/codeforces/790/c.cc @@ -0,0 +1,98 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#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; + cin >> n >> m; + + vec words(n); + for (auto& e : words) + cin >> e; + + u32 ans = 1e6; + + for (u32 i = 0; i < n; ++i) { + for (u32 j = i + 1; j < n; ++j) { + u32 diff = 0; + + for (u32 k = 0; k < m; ++k) { + diff += max(words[i][k], words[j][k]) - min(words[i][k], words[j][k]); + } + + ans = min(ans, diff); + } + } + + println("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/compile_flags.txt b/codeforces/790/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/790/compile_flags.txt @@ -0,0 +1,31 @@ +-O2 +-Wall +-Wextra +-Wpedantic +-Wshadow +-Wformat=2 +-Wfloat-equal +-Wlogical-op +-Wshift-overflow=2 +-Wnon-virtual-dtor +-Wold-style-cast +-Wcast-qual +-Wuseless-cast +-Wno-sign-promotion +-Wcast-align +-Wunused +-Woverloaded-virtual +-Wconversion +-Wmisleading-indentation +-Wduplicated-cond +-Wduplicated-branches +-Wlogical-op +-Wnull-dereference +-Wformat=2 +-Wformat-overflow +-Wformat-truncation +-Wdouble-promotion +-Wundef +-DLOCAL +-std=c++23 +-std=c++23 diff --git a/codeforces/790/d.cc b/codeforces/790/d.cc new file mode 100644 index 0000000..5bf0aeb --- /dev/null +++ b/codeforces/790/d.cc @@ -0,0 +1,103 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#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; + cin >> n >> m; + vec> grid(n, vec(m)); + for (auto& row : grid) + for (auto& cell : row) + cin >> cell; + + vec diag1(n + m - 1, 0); + vec diag2(n + m - 1, 0); + + for (u32 i = 0; i < n; ++i) { + for (u32 j = 0; j < m; ++j) { + diag1[i + j] += grid[i][j]; + diag2[i - j + m - 1] += grid[i][j]; + } + } + + u64 ans = 0; + + for (u32 i = 0; i < n; ++i) { + for (u32 j = 0; j < m; ++j) { + u64 score = diag1[i + j] + diag2[i - j + m - 1] - grid[i][j]; + ans = max(ans, score); + } + } + + println("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/debug_flags.txt b/codeforces/790/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/790/debug_flags.txt @@ -0,0 +1,14 @@ +-g3 +-fsanitize=address,undefined +-fsanitize=float-divide-by-zero +-fsanitize=float-cast-overflow +-fno-sanitize-recover=all +-fstack-protector-all +-fstack-usage +-fno-omit-frame-pointer +-fno-inline +-ffunction-sections +-D_GLIBCXX_DEBUG +-D_GLIBCXX_DEBUG_PEDANTIC +-DLOCAL +-std=c++23 diff --git a/codeforces/790/e.cc b/codeforces/790/e.cc new file mode 100644 index 0000000..67cddea --- /dev/null +++ b/codeforces/790/e.cc @@ -0,0 +1,105 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n, q; + cin >> n >> q; + + vec a(n); + for (auto& e : a) + cin >> e; + + sort(rall(a)); + + vec prefix(n + 1, 0); + for (u32 i = 1; i <= n; ++i) { + prefix[i] = prefix[i - 1] + a[i - 1]; + } + + u64 k; + for (u32 i = 0; i < q; ++i) { + cin >> k; + + auto it = lower_bound(all(prefix), k); + + i32 ans; + if (it == prefix.end()) { + ans = -1; + } else { + ans = distance(prefix.begin(), it); + } + + println("{}", ans); + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/f.cc b/codeforces/790/f.cc new file mode 100644 index 0000000..304c5d7 --- /dev/null +++ b/codeforces/790/f.cc @@ -0,0 +1,119 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n, k; + cin >> n >> k; + + vec a(n); + map f; + for (auto& e : a) { + cin >> e; + ++f[e]; + } + + vec candidates; + for (auto [number, frequency] : f) { + if (frequency >= k) { + candidates.push_back(number); + } + } + + sort(all(candidates)); + + u32 streak = 0; + u32 l, r, L, R; + u32 i = 0; + while (i < candidates.size()) { + l = i, r = i; + while (r + 1 < candidates.size() && + candidates[r] + 1 == candidates[r + 1]) { + ++r; + } + + if (r - l + 1 > streak) { + streak = r - l + 1; + L = candidates[l]; + R = candidates[r]; + } + + i = r + 1; + } + + if (streak == 0) { + println("-1"); + } else { + println("{} {}", L, R); + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/g.cc b/codeforces/790/g.cc new file mode 100644 index 0000000..2e6a7b9 --- /dev/null +++ b/codeforces/790/g.cc @@ -0,0 +1,116 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#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; + + vec> tree(n + 1); + u32 parent; + for (u32 i = 1; i <= n - 1; ++i) { + cin >> parent; + tree[parent].push_back(i + 1); + } + + string coloring; + cin >> coloring; + + u32 ans = 0; + + vec black(n + 1, 0), white(n + 1, 0); + + auto dfs = [&](auto&& self, u32 u, u32 par) -> void { + white[u] = coloring[u - 1] == 'W'; + black[u] = coloring[u - 1] == 'B'; + + for (auto v : tree[u]) { + if (v == par) + continue; + self(self, v, u); + + white[u] += white[v]; + black[u] += black[v]; + } + + if (white[u] == black[u]) { + ++ans; + } + + return; + }; + + dfs(dfs, 1, 1); + + println("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/h.cc b/codeforces/790/h.cc new file mode 100644 index 0000000..9e28a5d --- /dev/null +++ b/codeforces/790/h.cc @@ -0,0 +1,80 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#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(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#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; + vec a(n); + for (auto& e : a)cin >> e; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/790/io/a.in b/codeforces/790/io/a.in new file mode 100644 index 0000000..3f7d1b9 --- /dev/null +++ b/codeforces/790/io/a.in @@ -0,0 +1,6 @@ +5 +213132 +973894 +045207 +000000 +055776 diff --git a/codeforces/790/io/a.out b/codeforces/790/io/a.out new file mode 100644 index 0000000..fb54571 --- /dev/null +++ b/codeforces/790/io/a.out @@ -0,0 +1,14 @@ +YES +NO +YES +YES +NO + 213 132 + 973 894 + 45 207 + 0 0 + 55 776 + +[code]: 0 +[time]: 8.57687 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/b.in b/codeforces/790/io/b.in new file mode 100644 index 0000000..4b342f6 --- /dev/null +++ b/codeforces/790/io/b.in @@ -0,0 +1,12 @@ +5 +5 +1 2 3 4 5 +6 +1000 1000 5 1000 1000 1000 +10 +1 2 3 5 1 2 7 9 13 5 +3 +8 8 8 +1 +10000000 + diff --git a/codeforces/790/io/b.out b/codeforces/790/io/b.out new file mode 100644 index 0000000..2928183 --- /dev/null +++ b/codeforces/790/io/b.out @@ -0,0 +1,9 @@ +10 +4975 +38 +0 +0 + +[code]: 0 +[time]: 9.69386 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/c.in b/codeforces/790/io/c.in new file mode 100644 index 0000000..951de59 --- /dev/null +++ b/codeforces/790/io/c.in @@ -0,0 +1,25 @@ +6 +2 4 +best +cost +6 3 +abb +zba +bef +cdu +ooo +zzz +2 7 +aaabbbc +bbaezfe +3 2 +ab +ab +ab +2 8 +aaaaaaaa +zzzzzzzz +3 1 +a +u +y diff --git a/codeforces/790/io/c.out b/codeforces/790/io/c.out new file mode 100644 index 0000000..0cb8aa2 --- /dev/null +++ b/codeforces/790/io/c.out @@ -0,0 +1,10 @@ +11 +8 +35 +0 +200 +4 + +[code]: 0 +[time]: 6.47712 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/d.in b/codeforces/790/io/d.in new file mode 100644 index 0000000..9417451 --- /dev/null +++ b/codeforces/790/io/d.in @@ -0,0 +1,17 @@ +4 +4 4 +1 2 2 1 +2 4 2 4 +2 2 3 1 +2 4 2 4 +2 1 +1 +0 +3 3 +1 1 1 +1 1 1 +1 1 1 +3 3 +0 1 1 +1 0 1 +1 1 0 diff --git a/codeforces/790/io/d.out b/codeforces/790/io/d.out new file mode 100644 index 0000000..8796e98 --- /dev/null +++ b/codeforces/790/io/d.out @@ -0,0 +1,8 @@ +20 +1 +5 +3 + +[code]: 0 +[time]: 2.32363 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/e.in b/codeforces/790/io/e.in new file mode 100644 index 0000000..0d0b478 --- /dev/null +++ b/codeforces/790/io/e.in @@ -0,0 +1,17 @@ +3 +8 7 +4 3 3 1 1 4 5 9 +1 +10 +50 +14 +15 +22 +30 +4 1 +1 2 3 4 +3 +1 2 +5 +4 +6 diff --git a/codeforces/790/io/e.out b/codeforces/790/io/e.out new file mode 100644 index 0000000..2a2a2a5 --- /dev/null +++ b/codeforces/790/io/e.out @@ -0,0 +1,14 @@ +1 +2 +-1 +2 +3 +4 +8 +1 +1 +-1 + +[code]: 0 +[time]: 2.58231 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/f.in b/codeforces/790/io/f.in new file mode 100644 index 0000000..271bfe5 --- /dev/null +++ b/codeforces/790/io/f.in @@ -0,0 +1,9 @@ +4 +7 2 +11 11 12 13 13 14 14 +5 1 +6 3 5 2 1 +6 4 +4 3 4 3 3 4 +14 2 +1 1 2 2 2 3 3 3 3 4 4 4 4 4 diff --git a/codeforces/790/io/f.out b/codeforces/790/io/f.out new file mode 100644 index 0000000..ecc8cd2 --- /dev/null +++ b/codeforces/790/io/f.out @@ -0,0 +1,12 @@ +11 13 14 +13 14 +1 2 3 5 6 +1 3 + +-1 +1 2 3 4 +1 4 + +[code]: 0 +[time]: 2.43974 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/g.in b/codeforces/790/io/g.in new file mode 100644 index 0000000..248fbd4 --- /dev/null +++ b/codeforces/790/io/g.in @@ -0,0 +1,10 @@ +3 +7 +1 1 2 3 3 5 +WBBWWBW +2 +1 +BW +8 +1 2 3 4 5 6 7 +BWBWBWBW diff --git a/codeforces/790/io/g.out b/codeforces/790/io/g.out new file mode 100644 index 0000000..569ad04 --- /dev/null +++ b/codeforces/790/io/g.out @@ -0,0 +1,7 @@ +2 +1 +4 + +[code]: 0 +[time]: 2.36297 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/790/io/h.in b/codeforces/790/io/h.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/790/io/h.out b/codeforces/790/io/h.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/790/makefile b/codeforces/790/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/790/makefile @@ -0,0 +1,30 @@ +.PHONY: run debug clean setup init + +VERSION ?= 20 + +SRC = $(word 2,$(MAKECMDGOALS)) + +.SILENT: + +run: + sh scripts/run.sh $(SRC) + +debug: + sh scripts/debug.sh $(SRC) + +clean: + rm -rf build/* + +setup: + test -d build || mkdir -p build + test -d io || mkdir -p io + test -d scripts || mkdir -p scripts + test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format . + test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt + test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd + +init: + make setup + +%: + @: diff --git a/codeforces/790/scripts/debug.sh b/codeforces/790/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/790/scripts/debug.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. ./scripts/utils.sh + +SRC="$1" +BASE=$(basename "$SRC" .cc) +INPUT="${BASE}.in" +OUTPUT="${BASE}.out" +DBG_BIN="${BASE}.debug" + +test -d build || mkdir -p build +test -d io || mkdir -p io + +test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/" +test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/" + +test -f "io/$INPUT" || touch "io/$INPUT" +test -f "io/$OUTPUT" || touch "io/$OUTPUT" + +INPUT="io/$INPUT" +OUTPUT="io/$OUTPUT" +DBG_BIN="build/$DBG_BIN" + +compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt +CODE=$? +test $CODE -gt 0 && exit $CODE + +execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT" true +exit $? diff --git a/codeforces/790/scripts/run.sh b/codeforces/790/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/790/scripts/run.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. ./scripts/utils.sh + +SRC="$1" +BASE=$(basename "$SRC" .cc) +INPUT="${BASE}.in" +OUTPUT="${BASE}.out" +RUN_BIN="${BASE}.run" + +test -d build || mkdir -p build +test -d io || mkdir -p io + +test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/" +test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/" + +test -f "io/$INPUT" || touch "io/$INPUT" +test -f "io/$OUTPUT" || touch "io/$OUTPUT" + +INPUT="io/$INPUT" +OUTPUT="io/$OUTPUT" +RUN_BIN="build/$RUN_BIN" + +compile_source "$SRC" "$RUN_BIN" "$OUTPUT" "" +CODE=$? +test $CODE -gt 0 && exit $CODE + +execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT" +exit $? diff --git a/codeforces/790/scripts/utils.sh b/codeforces/790/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/790/scripts/utils.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +execute_binary() { + binary="$1" + input="$2" + output="$3" + is_debug="$4" + + start=$(date '+%s.%N') + if [ -n "$is_debug" ]; then + asan="$(ldconfig -p | grep libasan.so | head -n1 | awk '{print $4}')" + LD_PRELOAD="$asan" timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + else + timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + fi + CODE=$? + end=$(date '+%s.%N') + truncate -s "$(head -n 1000 "$output" | wc -c)" "$output" + + if [ $CODE -ge 124 ]; then + MSG='' + case $CODE in + 124) MSG='TIMEOUT' ;; + 128) MSG='SIGILL' ;; + 130) MSG='SIGABRT' ;; + 131) MSG='SIGBUS' ;; + 136) MSG='SIGFPE' ;; + 135) MSG='SIGSEGV' ;; + 137) MSG='SIGPIPE' ;; + 139) MSG='SIGTERM' ;; + esac + [ $CODE -ne 124 ] && sed -i '$d' "$output" + test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output" + else + printf '\n[code]: %s' "$CODE" >>"$output" + fi + + printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output + test -n "$is_debug" && is_debug_string=true || is_debug_string=false + printf '\n[debug]: %s' "$is_debug_string" >>$output + return $CODE +} + +compile_source() { + src="$1" + bin="$2" + output="$3" + flags="$4" + + test -f "$bin" && rm "$bin" || true + g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output" + CODE=$? + + if [ $CODE -gt 0 ]; then + printf '\n[code]: %s' "$CODE" >>"$output" + return $CODE + else + echo '' >"$output" + return 0 + fi +}