From 8a3884da873c9f18010bc2368d2c6a9d33bca9a4 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 22 Aug 2025 20:28:56 -0500 Subject: [PATCH] 1043 --- codeforces/1043/.clang-format | 9 +++ codeforces/1043/.clangd | 41 +++++++++++ codeforces/1043/a.cc | 96 ++++++++++++++++++++++++ codeforces/1043/b.cc | 99 +++++++++++++++++++++++++ codeforces/1043/c.cc | 104 ++++++++++++++++++++++++++ codeforces/1043/c2.cc | 115 +++++++++++++++++++++++++++++ codeforces/1043/compile_flags.txt | 31 ++++++++ codeforces/1043/d.cc | 116 +++++++++++++++++++++++++++++ codeforces/1043/debug_flags.txt | 14 ++++ codeforces/1043/e.cc | 118 ++++++++++++++++++++++++++++++ codeforces/1043/file | 15 ++++ codeforces/1043/io/a.in | 21 ++++++ codeforces/1043/io/a.out | 8 ++ codeforces/1043/io/b.in | 6 ++ codeforces/1043/io/b.out | 12 +++ codeforces/1043/io/c.in | 9 +++ codeforces/1043/io/c.out | 11 +++ codeforces/1043/io/c2.in | 10 +++ codeforces/1043/io/c2.out | 12 +++ codeforces/1043/io/d.in | 8 ++ codeforces/1043/io/d.out | 5 ++ codeforces/1043/io/e.in | 27 +++++++ codeforces/1043/io/e.out | 18 +++++ codeforces/1043/makefile | 30 ++++++++ codeforces/1043/scripts/debug.sh | 29 ++++++++ codeforces/1043/scripts/run.sh | 29 ++++++++ codeforces/1043/scripts/utils.sh | 61 +++++++++++++++ 27 files changed, 1054 insertions(+) create mode 100644 codeforces/1043/.clang-format create mode 100644 codeforces/1043/.clangd create mode 100644 codeforces/1043/a.cc create mode 100644 codeforces/1043/b.cc create mode 100644 codeforces/1043/c.cc create mode 100644 codeforces/1043/c2.cc create mode 100644 codeforces/1043/compile_flags.txt create mode 100644 codeforces/1043/d.cc create mode 100644 codeforces/1043/debug_flags.txt create mode 100644 codeforces/1043/e.cc create mode 100644 codeforces/1043/file create mode 100644 codeforces/1043/io/a.in create mode 100644 codeforces/1043/io/a.out create mode 100644 codeforces/1043/io/b.in create mode 100644 codeforces/1043/io/b.out create mode 100644 codeforces/1043/io/c.in create mode 100644 codeforces/1043/io/c.out create mode 100644 codeforces/1043/io/c2.in create mode 100644 codeforces/1043/io/c2.out create mode 100644 codeforces/1043/io/d.in create mode 100644 codeforces/1043/io/d.out create mode 100644 codeforces/1043/io/e.in create mode 100644 codeforces/1043/io/e.out create mode 100644 codeforces/1043/makefile create mode 100644 codeforces/1043/scripts/debug.sh create mode 100644 codeforces/1043/scripts/run.sh create mode 100644 codeforces/1043/scripts/utils.sh diff --git a/codeforces/1043/.clang-format b/codeforces/1043/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1043/.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/1043/.clangd b/codeforces/1043/.clangd new file mode 100644 index 0000000..316b539 --- /dev/null +++ b/codeforces/1043/.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/1043/a.cc b/codeforces/1043/a.cc new file mode 100644 index 0000000..f0b7858 --- /dev/null +++ b/codeforces/1043/a.cc @@ -0,0 +1,96 @@ +#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; + string a; + cin >> a; + cin >> n; + string b, c; + cin >> b >> c; + + string o; + for (u32 i = 0; i < b.size(); ++i) { + if (c[i] == 'D') { + a += b[i]; + } else { + o += b[i]; + } + } + + reverse(all(o)); + + println("{}", o + a); +} + +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/1043/b.cc b/codeforces/1043/b.cc new file mode 100644 index 0000000..6326282 --- /dev/null +++ b/codeforces/1043/b.cc @@ -0,0 +1,99 @@ +#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() { + u64 n; + cin >> n; + + vec ans; + + u64 ten_power = 1; + for (u32 a = 1; a <= 18; ++a) { + ten_power *= 10; + if (n % (ten_power + 1)) { + continue; + } else { + ans.push_back(n / (ten_power + 1)); + } + } + + // unecessary + sort(all(ans)); + + cout << ans.size() << '\n'; + + for (u32 i = 0; i < ans.size(); ++i) { + cout << ans[i] << " \n"[i == ans.size() - 1]; + } +} + +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/1043/c.cc b/codeforces/1043/c.cc new file mode 100644 index 0000000..1e40443 --- /dev/null +++ b/codeforces/1043/c.cc @@ -0,0 +1,104 @@ +#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() { + i64 n; + cin >> n; + + map w2c; + for (u32 x = 0; x <= 19; ++x) { + w2c[(i64)powl(3, x)] = (u64)powl(3, x + 1) + x * (u64)powl(3, x - 1); + } + + u64 ans = 0, deals = 0; + + // for (auto it = w2c.begin(); it != w2c.end(); ++it) { + // print("w: {} cost: {}; ", it->first, it->second); + // } + // println(); + + for (auto it = w2c.rbegin(); it != w2c.rend(); ++it) { + auto w = it->first; + auto c = it->second; + while (n >= w) { + // println("bought {} watermelons at cost {}", w, c); + ans += c; + n -= w; + ++deals; + } + } + + println("{}", ans); + // println("{} {}", ans, deals); +} + +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/1043/c2.cc b/codeforces/1043/c2.cc new file mode 100644 index 0000000..3ae364b --- /dev/null +++ b/codeforces/1043/c2.cc @@ -0,0 +1,115 @@ +#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() { + i64 n, k; + cin >> n >> k; + + vec costs(20); + for (u32 x = 0; x <= 19; ++x) { + costs[x] = (i64)powl(3, x + 1) + x * (i64)powl(3, x - 1); + } + + i64 cost = 0; + + vec deals(costs.size(), 0); + + for (i32 i = costs.size() - 1; i >= 0; --i) { + auto w = (u64)powl(3, i); + auto times = n / w; + n -= w * times; + cost += costs[i] * times; + deals[i] += times; + } + + i64 left = k - accumulate(all(deals), 0LL); + + if (left < 0) { + println("-1"); + return; + } + + for (i32 i = costs.size() - 1; left > 0 && i > 0; --i) { + i64 y = min(left / 2, deals[i]); + + left -= 2 * y; + cost -= y * costs[i]; + cost += 3 * y * costs[i - 1]; + + deals[i] -= y; + deals[i - 1] += 3 * y; + } + + println("{}", cost); +} + +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/1043/compile_flags.txt b/codeforces/1043/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/1043/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/1043/d.cc b/codeforces/1043/d.cc new file mode 100644 index 0000000..a2a21ed --- /dev/null +++ b/codeforces/1043/d.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 +// }}} + +const int MAXD = 18; +u64 POW10[MAXD], PREF[MAXD]; + +u64 digit_prefix_sum(u64 n) { + if (n < 10) + return n * (n + 1) / 2; + int d = 0; + while (POW10[d + 1] <= n) + ++d; + u64 p = POW10[d]; + u64 msd = n / p; + u64 rest = n % p; + return msd * PREF[d] + (msd * (msd - 1) / 2) * p + msd * (rest + 1) + + digit_prefix_sum(rest); +} + +void solve() { + u64 k; + cin >> k; + u64 K = k, D = 1; + for (u32 i = 0; i < 15; ++i) { + u64 base_count = (POW10[i + 1] - POW10[i]) * (i + 1); + if (base_count > K) { + D = i + 1; + break; + } + K -= base_count; + } + u64 ans = 0; + u64 x = POW10[D - 1] + K / D - 1; + if (K % D) { + u64 next = x + 1; + for (u32 i = 0; i < D - (K % D); ++i) + next /= 10; + while (next) { + ans += next % 10; + next /= 10; + } + } + ans += digit_prefix_sum(x); + cout << ans << "\n"; +} + +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/1043/debug_flags.txt b/codeforces/1043/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/1043/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/1043/e.cc b/codeforces/1043/e.cc new file mode 100644 index 0000000..629b9f7 --- /dev/null +++ b/codeforces/1043/e.cc @@ -0,0 +1,118 @@ +#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, q; + cin >> n >> m >> q; + + vec a(n), b(m); + for (auto& e : a) + cin >> e; + for (auto& e : b) + cin >> e; + sort(rall(a)); + sort(rall(b)); + + vec counts(n + m + 1, 0); + vec prefix_a(n + 1, 0), prefix_b(m + 1, 0); + for (u32 i = 1; i <= n; ++i) { + prefix_a[i] = prefix_a[i - 1] + a[i - 1]; + } + for (u32 i = 1; i <= m; ++i) { + prefix_b[i] = prefix_b[i - 1] + b[i - 1]; + } + + i32 i = 0, j = 0; + + for (u32 index = 1; index <= n + m; ++index) { + counts[index] = counts[index - 1]; + if (j >= m || a[i] >= b[j]) { + ++counts[index]; + ++i; + } else { + ++j; + } + } + + u32 x, y, z; + for (u32 i = 0; i < q; ++i) { + cin >> x >> y >> z; + u32 lo = (z > y) ? (z - y) : 0; + u32 hi = min(x, z); + u32 take_a = clamp(counts[z], lo, hi); + u32 take_b = z - take_a; + + println("{}", prefix_a[take_a] + prefix_b[take_b]); + } +} + +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/1043/file b/codeforces/1043/file new file mode 100644 index 0000000..e675a8e --- /dev/null +++ b/codeforces/1043/file @@ -0,0 +1,15 @@ +0 +70 +64 +39 +57 +2700000000 +4200000000 +420 +711 +711 +0 +997 +0 +1360 + diff --git a/codeforces/1043/io/a.in b/codeforces/1043/io/a.in new file mode 100644 index 0000000..a37cd0c --- /dev/null +++ b/codeforces/1043/io/a.in @@ -0,0 +1,21 @@ +4 +2 +ot +2 +ad +DV +3 +efo +7 +rdcoecs +DVDVDVD +3 +aca +4 +bbaa +DVDV +3 +biz +4 +abon +VVDD diff --git a/codeforces/1043/io/a.out b/codeforces/1043/io/a.out new file mode 100644 index 0000000..09e6bc6 --- /dev/null +++ b/codeforces/1043/io/a.out @@ -0,0 +1,8 @@ +dota +codeforces +abacaba +babizon + +[code]: 0 +[time]: 4.89187 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1043/io/b.in b/codeforces/1043/io/b.in new file mode 100644 index 0000000..36d75e9 --- /dev/null +++ b/codeforces/1043/io/b.in @@ -0,0 +1,6 @@ +5 +1111 +12 +55 +999999999999999999 +1000000000000000000 diff --git a/codeforces/1043/io/b.out b/codeforces/1043/io/b.out new file mode 100644 index 0000000..5e7cf74 --- /dev/null +++ b/codeforces/1043/io/b.out @@ -0,0 +1,12 @@ +2 +11 101 +0 +1 +5 +3 +999999999 999000999000999 90909090909090909 +0 + +[code]: 0 +[time]: 2.21372 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1043/io/c.in b/codeforces/1043/io/c.in new file mode 100644 index 0000000..3bf5445 --- /dev/null +++ b/codeforces/1043/io/c.in @@ -0,0 +1,9 @@ +7 +1 +3 +8 +2 +10 +20 +260010000 + diff --git a/codeforces/1043/io/c.out b/codeforces/1043/io/c.out new file mode 100644 index 0000000..2809e43 --- /dev/null +++ b/codeforces/1043/io/c.out @@ -0,0 +1,11 @@ +3 +10 +26 +6 +36 +72 +2250964728 + +[code]: 0 +[time]: 2.50387 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1043/io/c2.in b/codeforces/1043/io/c2.in new file mode 100644 index 0000000..238f856 --- /dev/null +++ b/codeforces/1043/io/c2.in @@ -0,0 +1,10 @@ +8 +1 1 +3 3 +8 3 +2 4 +10 10 +20 14 +3 2 +9 1 + diff --git a/codeforces/1043/io/c2.out b/codeforces/1043/io/c2.out new file mode 100644 index 0000000..96d16f8 --- /dev/null +++ b/codeforces/1043/io/c2.out @@ -0,0 +1,12 @@ +3 +9 +-1 +6 +30 +63 +10 +33 + +[code]: 0 +[time]: 2.52867 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1043/io/d.in b/codeforces/1043/io/d.in new file mode 100644 index 0000000..1b6825f --- /dev/null +++ b/codeforces/1043/io/d.in @@ -0,0 +1,8 @@ +7 +5 +10 +13 +29 +1000000000 +1000000000000000 +12 diff --git a/codeforces/1043/io/d.out b/codeforces/1043/io/d.out new file mode 100644 index 0000000..42275f9 --- /dev/null +++ b/codeforces/1043/io/d.out @@ -0,0 +1,5 @@ +timeout: the monitored command dumped core + +[code]: 136 (SIGFPE) +[time]: 81.4447 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1043/io/e.in b/codeforces/1043/io/e.in new file mode 100644 index 0000000..f00773b --- /dev/null +++ b/codeforces/1043/io/e.in @@ -0,0 +1,27 @@ +4 +3 4 5 +10 20 30 +1 2 3 4 +0 0 0 +3 4 7 +3 4 4 +1 4 4 +2 2 4 +5 5 2 +500000000 300000000 100000000 900000000 700000000 +800000000 400000000 1000000000 600000000 200000000 +1 4 3 +5 2 6 +4 4 1 +100 100 20 20 +100 100 20 20 +4 4 5 +3 3 6 +2 363 711 +286 121 102 +1 1 1 +3 1 1 +1 2 0 +1 3 2 +0 1 0 +3 3 3 diff --git a/codeforces/1043/io/e.out b/codeforces/1043/io/e.out new file mode 100644 index 0000000..e1e19d5 --- /dev/null +++ b/codeforces/1043/io/e.out @@ -0,0 +1,18 @@ +0 +70 +64 +39 +57 +2700000000 +4200000000 +420 +711 +711 +0 +997 +0 +1360 + +[code]: 0 +[time]: 3.03102 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1043/makefile b/codeforces/1043/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/1043/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/1043/scripts/debug.sh b/codeforces/1043/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/1043/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/1043/scripts/run.sh b/codeforces/1043/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/1043/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/1043/scripts/utils.sh b/codeforces/1043/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/1043/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 +}