diff --git a/codeforces/1032/.clang-format b/codeforces/1032/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1032/.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/1032/.clangd b/codeforces/1032/.clangd new file mode 100644 index 0000000..7b2523e --- /dev/null +++ b/codeforces/1032/.clangd @@ -0,0 +1,39 @@ +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 diff --git a/codeforces/1032/a.cc b/codeforces/1032/a.cc new file mode 100644 index 0000000..1d72314 --- /dev/null +++ b/codeforces/1032/a.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() { + i32 n, s; + cin >> n >> s; + + vec a(n); + for (auto& e : a) + cin >> e; + + i32 ans = a[n - 1] - a[0]; + + // NOTE: forgot abs + ans += min(abs(s - a[0]), abs(a[n - 1] - s)); + + 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/1032/b.cc b/codeforces/1032/b.cc new file mode 100644 index 0000000..0e829fb --- /dev/null +++ b/codeforces/1032/b.cc @@ -0,0 +1,102 @@ +#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; + + unordered_set seen{{a[0]}}; + + for (u32 i = 1; i < n - 1; ++i) { + if (seen.contains(a[i])) { + YES(); + return; + } + seen.insert(a[i]); + } + + seen = {{a[n - 1]}}; + + for (i32 i = n - 2; i > 0; --i) { + if (seen.contains(a[i])) { + YES(); + return; + } + seen.insert(a[i]); + } + + 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/1032/c.cc b/codeforces/1032/c.cc new file mode 100644 index 0000000..d4dd6e9 --- /dev/null +++ b/codeforces/1032/c.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, m; + cin >> n >> m; + + vec> grid(n, vec(m)); + for (auto& row : grid) + for (auto& cell : row) + cin >> cell; + + u32 M = 0; + for (auto& row : grid) + for (auto cell : row) + M = max(M, cell); + + unordered_map M_col, M_row; + + u32 total_M = 0; + + for (u32 i = 0; i < n; ++i) { + for (u32 j = 0; j < m; ++j) { + M_row[i] += grid[i][j] == M; + // NOTE: had typo here, `=` instead of `==` + total_M += grid[i][j] == M; + } + } + + for (u32 j = 0; j < m; ++j) { + for (u32 i = 0; i < n; ++i) { + M_col[j] += grid[i][j] == M; + } + } + + for (u32 i = 0; i < n; ++i) { + for (u32 j = 0; j < m; ++j) { + u32 M_count = M_row[i] + M_col[j] - (grid[i][j] == M); + + if (M_count == total_M) { + println("{}", M - 1); + return; + } + } + } + + println("{}", M); +} + +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/1032/compile_flags.txt b/codeforces/1032/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/1032/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/1032/d.cc b/codeforces/1032/d.cc new file mode 100644 index 0000000..dd58f70 --- /dev/null +++ b/codeforces/1032/d.cc @@ -0,0 +1,111 @@ +#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; + vector a(n), b(n); + for (auto &e : a) + cin >> e; + for (auto &e : b) + cin >> e; + struct Op { + int t, i; + }; + vector ops; + for (u32 i = 0; i < n; i++) + for (u32 j = 0; j + 1 < n - i; j++) + if (a[j] > a[j + 1]) { + swap(a[j], a[j + 1]); + ops.push_back({1, (int)j + 1}); + } + for (u32 i = 0; i < n; i++) + for (u32 j = 0; j + 1 < n - i; j++) + if (b[j] > b[j + 1]) { + swap(b[j], b[j + 1]); + ops.push_back({2, (int)j + 1}); + } + for (u32 i = 0; i < n; ++i) { + if (a[i] > b[i]) { + ops.push_back({3, (int)i + 1}); + } + } + + // NOTE: did not consider/investigate correctness of bubble sort + naive swap + + println("{}", ops.size()); + for (auto &op : ops) { + println("{} {}", op.t, op.i); + } +} + +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/1032/debug_flags.txt b/codeforces/1032/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/1032/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/1032/io/a.in b/codeforces/1032/io/a.in new file mode 100644 index 0000000..478afc4 --- /dev/null +++ b/codeforces/1032/io/a.in @@ -0,0 +1,25 @@ +12 +1 1 +1 +1 2 +1 +1 1 +2 +2 1 +2 3 +2 2 +1 3 +2 3 +1 2 +3 1 +1 2 3 +3 2 +1 3 4 +3 3 +1 2 3 +4 3 +1 2 3 10 +5 5 +1 2 3 6 7 +6 6 +1 2 3 9 10 11 diff --git a/codeforces/1032/io/a.out b/codeforces/1032/io/a.out new file mode 100644 index 0000000..a2526ff --- /dev/null +++ b/codeforces/1032/io/a.out @@ -0,0 +1,16 @@ +0 +1 +1 +2 +3 +2 +2 +4 +2 +11 +8 +15 + +[code]: 0 +[time]: 2.58851 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1032/io/b.in b/codeforces/1032/io/b.in new file mode 100644 index 0000000..d39898d --- /dev/null +++ b/codeforces/1032/io/b.in @@ -0,0 +1,25 @@ +12 +3 +aaa +3 +aba +3 +aab +4 +abca +4 +abba +4 +aabb +5 +abaca +5 +abcda +5 +abcba +6 +abcbbf +6 +abcdaa +3 +abb diff --git a/codeforces/1032/io/b.out b/codeforces/1032/io/b.out new file mode 100644 index 0000000..408355a --- /dev/null +++ b/codeforces/1032/io/b.out @@ -0,0 +1,16 @@ +YES +NO +YES +NO +YES +YES +YES +NO +YES +YES +YES +YES + +[code]: 0 +[time]: 2.75302 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1032/io/c.in b/codeforces/1032/io/c.in new file mode 100644 index 0000000..4705876 --- /dev/null +++ b/codeforces/1032/io/c.in @@ -0,0 +1,36 @@ +10 +1 1 +1 +1 2 +1 2 +2 1 +2 +1 +2 2 +4 2 +3 4 +3 4 +1 2 3 2 +3 2 1 3 +2 1 3 2 +4 3 +1 5 1 +3 1 3 +5 5 5 +3 5 1 +4 4 +1 3 3 2 +2 3 2 2 +1 2 2 1 +3 3 2 3 +2 2 +2 2 +1 2 +3 2 +1 2 +2 1 +1 2 +3 3 +2 1 1 +1 2 1 +1 1 2 diff --git a/codeforces/1032/io/c.out b/codeforces/1032/io/c.out new file mode 100644 index 0000000..5db893b --- /dev/null +++ b/codeforces/1032/io/c.out @@ -0,0 +1,14 @@ +0 +1 +1 +3 +2 +4 +3 +1 +1 +2 + +[code]: 0 +[time]: 2.58493 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1032/io/d.in b/codeforces/1032/io/d.in new file mode 100644 index 0000000..e85480d --- /dev/null +++ b/codeforces/1032/io/d.in @@ -0,0 +1,19 @@ +6 +1 +1 +2 +1 +2 +1 +2 +1 3 +4 2 +2 +1 4 +3 2 +3 +6 5 4 +3 2 1 +3 +5 3 4 +2 6 1 diff --git a/codeforces/1032/io/d.out b/codeforces/1032/io/d.out new file mode 100644 index 0000000..df07ccc --- /dev/null +++ b/codeforces/1032/io/d.out @@ -0,0 +1,29 @@ +0 +1 +3 1 +1 +2 1 +2 +2 1 +3 2 +9 +1 1 +1 2 +1 1 +2 1 +2 2 +2 1 +3 1 +3 2 +3 3 +6 +1 1 +1 2 +2 2 +2 1 +3 1 +3 2 + +[code]: 0 +[time]: 2.55299 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1032/io/e.in b/codeforces/1032/io/e.in new file mode 100644 index 0000000..66bbdb6 --- /dev/null +++ b/codeforces/1032/io/e.in @@ -0,0 +1,15 @@ +14 +1 1 +2 3 +4 6 +15 16 +17 19 +199 201 +899 999 +1990 2001 +6309 6409 +12345 12501 +19987 20093 +746814 747932 +900990999 900991010 +999999999 999999999 diff --git a/codeforces/1032/io/e.out b/codeforces/1032/io/e.out new file mode 100644 index 0000000..faa29df --- /dev/null +++ b/codeforces/1032/io/e.out @@ -0,0 +1,18 @@ +1 2 +2 1 +5 0 +15 3 +18 2 +199 3 +899 5 +1990 4 +6309 7 +12445 6 +19987 5 +746824 7 +900990999 14 +999999999 18 + +[code]: 0 +[time]: 2.56085 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1032/makefile b/codeforces/1032/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/1032/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/1032/scripts/debug.sh b/codeforces/1032/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/1032/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/1032/scripts/run.sh b/codeforces/1032/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/1032/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/1032/scripts/utils.sh b/codeforces/1032/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/1032/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 +} diff --git a/codeforces/784/.clangd b/codeforces/784/.clangd index 18faf04..1981abb 100644 --- a/codeforces/784/.clangd +++ b/codeforces/784/.clangd @@ -45,3 +45,12 @@ CompileFlags: -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 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/784/io/a.out b/codeforces/784/io/a.out index e5a9e06..4a6a83d 100644 --- a/codeforces/784/io/a.out +++ b/codeforces/784/io/a.out @@ -7,4 +7,5 @@ Division 2 Division 1 [code]: 0 -[time]: 5.79357 ms +[time]: 20.0531 ms +[debug]: true \ No newline at end of file diff --git a/codeforces/784/io/b.out b/codeforces/784/io/b.out index 132f522..ecd0be1 100644 --- a/codeforces/784/io/b.out +++ b/codeforces/784/io/b.out @@ -7,4 +7,4 @@ 4 [code]: 0 -[time]: 2.40207 ms \ No newline at end of file +[time]: 2.40207 ms diff --git a/codeforces/784/io/c.out b/codeforces/784/io/c.out index 12e859e..21efbe5 100644 --- a/codeforces/784/io/c.out +++ b/codeforces/784/io/c.out @@ -4,4 +4,4 @@ YES YES [code]: 0 -[time]: 6.10971 ms \ No newline at end of file +[time]: 6.10971 ms diff --git a/codeforces/784/io/e.out b/codeforces/784/io/e.out index d6618b0..3c56cde 100644 --- a/codeforces/784/io/e.out +++ b/codeforces/784/io/e.out @@ -5,4 +5,4 @@ [code]: 0 [time]: 4.33087 ms -[time]: 2.47264 ms \ No newline at end of file +[time]: 2.47264 ms diff --git a/codeforces/784/io/f.out b/codeforces/784/io/f.out index df1f2cc..77a92a5 100644 --- a/codeforces/784/io/f.out +++ b/codeforces/784/io/f.out @@ -4,4 +4,4 @@ 7 [code]: 0 -[time]: 2.23374 ms \ No newline at end of file +[time]: 2.23374 ms diff --git a/codeforces/784/io/g.out b/codeforces/784/io/g.out index 58ed6a3..c7f7aad 100644 --- a/codeforces/784/io/g.out +++ b/codeforces/784/io/g.out @@ -16,4 +16,4 @@ [code]: 0 -[time]: 2.32959 ms \ No newline at end of file +[time]: 2.32959 ms diff --git a/codeforces/784/io/h.out b/codeforces/784/io/h.out index c089f10..c033b59 100644 --- a/codeforces/784/io/h.out +++ b/codeforces/784/io/h.out @@ -1,7 +1,4 @@ -2 -4 -2147483646 -1073741825 +==1344370==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD. -[code]: 0 -[time]: 3.09849 ms \ No newline at end of file +[code]: 1 +[time]: 3.08728 ms \ No newline at end of file diff --git a/codeforces/784/scripts/debug.sh b/codeforces/784/scripts/debug.sh index 2979422..1e63f37 100644 --- a/codeforces/784/scripts/debug.sh +++ b/codeforces/784/scripts/debug.sh @@ -25,5 +25,5 @@ compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt CODE=$? test $CODE -gt 0 && exit $CODE -execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT" +execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT" true exit $? diff --git a/codeforces/784/scripts/utils.sh b/codeforces/784/scripts/utils.sh index e99b25b..e4cf8f8 100644 --- a/codeforces/784/scripts/utils.sh +++ b/codeforces/784/scripts/utils.sh @@ -4,9 +4,15 @@ execute_binary() { binary="$1" input="$2" output="$3" + is_debug="$4" start=$(date '+%s.%N') - timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + 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" @@ -30,6 +36,8 @@ execute_binary() { 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 } diff --git a/codeforces/874/.clangd b/codeforces/874/.clangd index c903361..ec96ea2 100644 --- a/codeforces/874/.clangd +++ b/codeforces/874/.clangd @@ -21,4 +21,4 @@ CompileFlags: - -Wdouble-promotion - -Wundef - -DLOCAL - - -Wno-unknown-pragmas \ No newline at end of file + - -Wno-unknown-pragmas-e -std=c++23 diff --git a/codeforces/874/compile_flags.txt b/codeforces/874/compile_flags.txt index 559f9a4..04a3a2a 100644 --- a/codeforces/874/compile_flags.txt +++ b/codeforces/874/compile_flags.txt @@ -1,21 +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 --Wpedantic +-Wconversion -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wnull-dereference --Wuseless-cast -Wformat=2 -Wformat-overflow -Wformat-truncation -Wdouble-promotion +-Wundef -DLOCAL -std=c++23 +-std=c++23 diff --git a/codeforces/874/debug_flags.txt b/codeforces/874/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/874/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/874/io/a.in b/codeforces/874/io/a.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/874/io/a.out b/codeforces/874/io/a.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/874/makefile b/codeforces/874/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/874/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/874/scripts/debug.sh b/codeforces/874/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/874/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" +exit $? diff --git a/codeforces/874/scripts/run.sh b/codeforces/874/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/874/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/874/scripts/utils.sh b/codeforces/874/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/874/scripts/utils.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +execute_binary() { + binary="$1" + input="$2" + output="$3" + + start=$(date '+%s.%N') + timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + 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 + 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 +}