diff --git a/atcoder/042/.clang-format b/atcoder/042/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/atcoder/042/.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/atcoder/042/.clangd b/atcoder/042/.clangd new file mode 100644 index 0000000..8d85aa9 --- /dev/null +++ b/atcoder/042/.clangd @@ -0,0 +1,42 @@ +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 +-e -std=c++23 diff --git a/atcoder/042/a.cc b/atcoder/042/a.cc new file mode 100644 index 0000000..f9874b8 --- /dev/null +++ b/atcoder/042/a.cc @@ -0,0 +1,93 @@ +#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() { + vec a(3); + for (auto& e : a) + cin >> e; + + sort(all(a)); + + if (a == vec{5, 5, 7}) { + YES(); + } else { + 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); + + while (std::cin >> ws && !std::cin.eof()) { + solve(); + } +#else + std::cin.tie(nullptr)->sync_with_stdio(false); + + solve(); +#endif + + return 0; +} +// }}} diff --git a/atcoder/042/compile_flags.txt b/atcoder/042/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/atcoder/042/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/atcoder/042/debug_flags.txt b/atcoder/042/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/atcoder/042/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/atcoder/042/io/a.in b/atcoder/042/io/a.in new file mode 100644 index 0000000..1cddbca --- /dev/null +++ b/atcoder/042/io/a.in @@ -0,0 +1,3 @@ +5 5 7 +7 7 5 + diff --git a/atcoder/042/io/a.out b/atcoder/042/io/a.out new file mode 100644 index 0000000..dcb979c --- /dev/null +++ b/atcoder/042/io/a.out @@ -0,0 +1,6 @@ +YES +NO + +[code]: 0 +[time]: 5.74017 ms +[debug]: false \ No newline at end of file diff --git a/atcoder/042/makefile b/atcoder/042/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/atcoder/042/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/atcoder/042/scripts/debug.sh b/atcoder/042/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/atcoder/042/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/atcoder/042/scripts/run.sh b/atcoder/042/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/atcoder/042/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/atcoder/042/scripts/utils.sh b/atcoder/042/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/atcoder/042/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/806/.clang-format b/codeforces/806/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/806/.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/806/.clangd b/codeforces/806/.clangd new file mode 100644 index 0000000..316b539 --- /dev/null +++ b/codeforces/806/.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/806/a.cc b/codeforces/806/a.cc new file mode 100644 index 0000000..dbfe237 --- /dev/null +++ b/codeforces/806/a.cc @@ -0,0 +1,91 @@ +#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() { + string s; + cin >> s; + + if (tolower(s[0]) == 'y' && tolower(s[1]) == 'e' && tolower(s[2]) == 's') { + YES(); + } else { + 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/806/b.cc b/codeforces/806/b.cc new file mode 100644 index 0000000..00a344a --- /dev/null +++ b/codeforces/806/b.cc @@ -0,0 +1,94 @@ +#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 s; + cin >> s; + + set S; + for (auto e : s) { + S.insert(e); + } + + println("{}", n + S.size()); +} + +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/c.cc b/codeforces/806/c.cc new file mode 100644 index 0000000..08da34b --- /dev/null +++ b/codeforces/806/c.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; + cin >> n; + vec wheels(n); + for (auto& e : wheels) + cin >> e; + + u32 moves; + string pattern; + for (u32 i = 0; i < n; ++i) { + cin >> moves >> pattern; + + i32 delta = 0; + + for (auto letter : pattern) { + if (letter == 'U') + ++delta; + else + --delta; + } + + cout << (wheels[i] - delta + 10) % 10 << " \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; +} +// }}} diff --git a/codeforces/806/compile_flags.txt b/codeforces/806/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/806/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/806/d.cc b/codeforces/806/d.cc new file mode 100644 index 0000000..be54bf7 --- /dev/null +++ b/codeforces/806/d.cc @@ -0,0 +1,109 @@ +#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 strings(n); + for (auto& s : strings) + cin >> s; + + set S; + for (auto& s : strings) { + S.insert(s); + } + + for (auto& s : strings) { + bool ok = false; + + for (u32 i = 0; s.size() > 1 && i < s.size() - 1; ++i) { + if (S.contains(s.substr(0, i + 1)) && S.contains(s.substr(i + 1))) { + ok = true; + break; + } + } + + print("{}", ok ? '1' : '0'); + } + + 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/806/debug_flags.txt b/codeforces/806/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/806/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/806/e.cc b/codeforces/806/e.cc new file mode 100644 index 0000000..b45264c --- /dev/null +++ b/codeforces/806/e.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() { + u32 n; + cin >> n; + vec grid(n); + for (auto& row : grid) + cin >> row; + + u32 changes = 0; + + for (u32 i = 0; i < n / 2; ++i) { + for (u32 j = 0; j < n / 2; ++j) { + u32 ones = 0; + ones += grid[i][j] == '1'; + ones += grid[j][n - 1 - i] == '1'; + ones += grid[n - 1 - i][n - 1 - j] == '1'; + ones += grid[n - 1 - j][i] == '1'; + changes += min(ones, 4 - ones); + } + } + + if (n % 2 == 1) { + u32 mid = n / 2; + for (u32 i = 0; i < n / 2; ++i) { + u32 ones = 0; + ones += grid[i][mid] == '1'; + ones += grid[mid][n - 1 - i] == '1'; + ones += grid[n - 1 - i][mid] == '1'; + ones += grid[mid][i] == '1'; + changes += min(ones, 4 - ones); + } + } + + println("{}", changes); +} + +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/f.cc b/codeforces/806/f.cc new file mode 100644 index 0000000..456324d --- /dev/null +++ b/codeforces/806/f.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; + cin >> n; + + vec a(n); + for (auto& e : a) + cin >> e; + + vec pref(n + 1, 0); + for (u32 i = 1; i <= n; ++i) { + pref[i] = pref[i - 1] + (a[i - 1] < i ? 1 : 0); + } + + u64 ans = 0; + for (u32 j = 1; j <= n; ++j) { + if (a[j - 1] < j) { + u64 aj = a[j - 1]; + u32 limit = aj == 0 ? 0 : (aj - 1 > n ? n : aj - 1); + ans += pref[limit]; + } + } + + 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/806/g.cc b/codeforces/806/g.cc new file mode 100644 index 0000000..bc8870f --- /dev/null +++ b/codeforces/806/g.cc @@ -0,0 +1,112 @@ +#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; + i64 k; + cin >> n >> k; + vec a(n); + for (auto& e : a) + cin >> e; + + const u32 B = 31; + vec dp(B + 1, MIN), ndp(B + 1, MIN); + dp[0] = 0; + + for (u32 i = 0; i < n; ++i) { + fill(all(ndp), MIN); + u32 upto = min(B, i); + for (u32 b = 0; b <= upto; ++b) { + if (dp[b] == MIN) + continue; + + i64 gain_good = sc(a[i] >> b) - k; + ndp[b] = max(ndp[b], dp[b] + gain_good); + + u32 b2 = min(B, b + 1); + i64 gain_bad = sc(a[i] >> b2); + ndp[b2] = max(ndp[b2], dp[b] + gain_bad); + } + dp.swap(ndp); + } + + println("{}", *max_element(all(dp))); +} + +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/io/a.in b/codeforces/806/io/a.in new file mode 100644 index 0000000..b6e9152 --- /dev/null +++ b/codeforces/806/io/a.in @@ -0,0 +1,11 @@ +10 +YES +yES +yes +Yes +YeS +Noo +orZ +yEz +Yas +XES diff --git a/codeforces/806/io/a.out b/codeforces/806/io/a.out new file mode 100644 index 0000000..5e9d602 --- /dev/null +++ b/codeforces/806/io/a.out @@ -0,0 +1,14 @@ +YES +YES +YES +YES +YES +NO +NO +NO +NO +NO + +[code]: 0 +[time]: 5.40304 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/io/b.in b/codeforces/806/io/b.in new file mode 100644 index 0000000..c1839b2 --- /dev/null +++ b/codeforces/806/io/b.in @@ -0,0 +1,13 @@ +6 +3 +ABA +1 +A +3 +ORZ +5 +BAAAA +4 +BKPT +10 +CODEFORCES diff --git a/codeforces/806/io/b.out b/codeforces/806/io/b.out new file mode 100644 index 0000000..22854af --- /dev/null +++ b/codeforces/806/io/b.out @@ -0,0 +1,10 @@ +5 +2 +6 +7 +8 +17 + +[code]: 0 +[time]: 2.34175 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/io/c.in b/codeforces/806/io/c.in new file mode 100644 index 0000000..7c80a49 --- /dev/null +++ b/codeforces/806/io/c.in @@ -0,0 +1,17 @@ +3 +3 +9 3 1 +3 DDD +4 UDUU +2 DU +2 +0 9 +9 DDDDDDDDD +9 UUUUUUUUU +5 +0 5 9 8 3 +10 UUUUUUUUUU +3 UUD +8 UUDUUDDD +10 UUDUUDUDDU +4 UUUU diff --git a/codeforces/806/io/c.out b/codeforces/806/io/c.out new file mode 100644 index 0000000..38e6e90 --- /dev/null +++ b/codeforces/806/io/c.out @@ -0,0 +1,7 @@ +2 1 1 +9 0 +0 4 9 6 9 + +[code]: 0 +[time]: 2.40731 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/io/d.in b/codeforces/806/io/d.in new file mode 100644 index 0000000..d988bc1 --- /dev/null +++ b/codeforces/806/io/d.in @@ -0,0 +1,20 @@ +3 +5 +abab +ab +abc +abacb +c +3 +x +xx +xxx +8 +codeforc +es +codes +cod +forc +forces +e +code diff --git a/codeforces/806/io/d.out b/codeforces/806/io/d.out new file mode 100644 index 0000000..6dea1a7 --- /dev/null +++ b/codeforces/806/io/d.out @@ -0,0 +1,7 @@ +10100 +011 +10100101 + +[code]: 0 +[time]: 2.46286 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/io/e.in b/codeforces/806/io/e.in new file mode 100644 index 0000000..545459a --- /dev/null +++ b/codeforces/806/io/e.in @@ -0,0 +1,26 @@ +5 +3 +010 +110 +010 +1 +0 +5 +11100 +11011 +01011 +10011 +11000 +5 +01000 +10101 +01010 +00010 +01001 +5 +11001 +00000 +11111 +10110 +01111 + diff --git a/codeforces/806/io/e.out b/codeforces/806/io/e.out new file mode 100644 index 0000000..58bd8f3 --- /dev/null +++ b/codeforces/806/io/e.out @@ -0,0 +1,9 @@ +1 +0 +9 +7 +6 + +[code]: 0 +[time]: 2.52557 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/io/f.in b/codeforces/806/io/f.in new file mode 100644 index 0000000..bb1b141 --- /dev/null +++ b/codeforces/806/io/f.in @@ -0,0 +1,11 @@ +5 +8 +1 1 2 3 8 2 1 4 +2 +1 2 +10 +0 2 1 6 3 4 1 2 8 3 +2 +1 1000000000 +3 +0 1000000000 2 diff --git a/codeforces/806/io/f.out b/codeforces/806/io/f.out new file mode 100644 index 0000000..6cdcf61 --- /dev/null +++ b/codeforces/806/io/f.out @@ -0,0 +1,9 @@ +3 +0 +10 +0 +1 + +[code]: 0 +[time]: 2.49338 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/io/g.in b/codeforces/806/io/g.in new file mode 100644 index 0000000..3e4d69d --- /dev/null +++ b/codeforces/806/io/g.in @@ -0,0 +1,11 @@ +5 +4 5 +10 10 3 1 +1 2 +1 +3 12 +10 10 29 +12 51 +5 74 89 45 18 69 67 67 11 96 23 59 +2 57 +85 60 diff --git a/codeforces/806/io/g.out b/codeforces/806/io/g.out new file mode 100644 index 0000000..faaf60f --- /dev/null +++ b/codeforces/806/io/g.out @@ -0,0 +1,9 @@ +11 +0 +13 +60 +58 + +[code]: 0 +[time]: 2.5022 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/806/makefile b/codeforces/806/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/806/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/806/scripts/debug.sh b/codeforces/806/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/806/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/806/scripts/run.sh b/codeforces/806/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/806/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/806/scripts/utils.sh b/codeforces/806/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/806/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/918/.clang-format b/codeforces/918/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/918/.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/918/.clangd b/codeforces/918/.clangd new file mode 100644 index 0000000..8d85aa9 --- /dev/null +++ b/codeforces/918/.clangd @@ -0,0 +1,42 @@ +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 +-e -std=c++23 diff --git a/codeforces/918/a.cc b/codeforces/918/a.cc new file mode 100644 index 0000000..408b335 --- /dev/null +++ b/codeforces/918/a.cc @@ -0,0 +1,100 @@ +#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 a, b, c; + cin >> a >> b >> c; + + u32 ans; + // NOTE: ngl didn't even check if this was right lol + if (a == b) { + ans = c; + } + if (a == c) { + ans = b; + } + + if (b == c) { + ans = a; + } + + 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/b.cc b/codeforces/918/b.cc new file mode 100644 index 0000000..750e9c9 --- /dev/null +++ b/codeforces/918/b.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() { + vec grid(3); + for (auto& e : grid) + cin >> e; + + for (auto& row : grid) { + if (row.find('?') == string::npos) + continue; + + for (auto c : "ABC") { + if (row.find(c) == string::npos) { + println("{}", c); + 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/918/c.cc b/codeforces/918/c.cc new file mode 100644 index 0000000..de43a3e --- /dev/null +++ b/codeforces/918/c.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; + vec a(n); + for (auto& e : a) + cin >> e; + + u64 total = accumulate(all(a), 0LL); + + // NOTE: used auto and float, WA + u64 root = sqrtl(total); + while (root * root < total) { + ++root; + } + + if (root * root == total) { + YES(); + } else { + 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/918/compile_flags.txt b/codeforces/918/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/918/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/918/d.cc b/codeforces/918/d.cc new file mode 100644 index 0000000..7e33d79 --- /dev/null +++ b/codeforces/918/d.cc @@ -0,0 +1,108 @@ +#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 s; + cin >> s; + + // idea: can form valid word, greedy + // CV, CVC + // working backwards is easier + + string ans; + // NOTE: control flow took a second + for (i32 i = n - 1; i >= 0; --i) { + ans.push_back(s[i]); + ans.push_back(s[i - 1]); + if (!(s[i] == 'e' || s[i] == 'a')) { + ans.push_back(s[i - 2]); + --i; + } + --i; + if (i > 0) + ans.push_back('.'); + } + + reverse(all(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/918/debug_flags.txt b/codeforces/918/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/918/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/918/e.cc b/codeforces/918/e.cc new file mode 100644 index 0000000..2ebffa0 --- /dev/null +++ b/codeforces/918/e.cc @@ -0,0 +1,129 @@ +#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() { + /* + want sum(o[l:r])==sum(e[l:r]) + + for every r: + opref[r] - opref[l] == epref[r] - epref[l] + opref[r] - epref[r] == opref[l] - epref[l] + ^ known O(1) ^ insert in tree + */ + u32 n; + cin >> n; + + vec a(n); + for (auto& e : a) + cin >> e; + + if (n == 1) { + NO(); + return; + } + + // NOTE: missed initial array + // NOTE: had a major problem with your ideas + // "oh just change the sign, my logic is not right" + // TRUST YOUR LOGIC, BUT NOT THE IMPL - IMPL != IDEA + set pref{0}; + i64 acc = 0; + + for (u32 r = 1; r <= n; ++r) { + if (r & 1) { + acc += a[r - 1]; + } else { + acc -= a[r - 1]; + } + + // dbln("r={}, o={} e={}", r, o, e); + + // NOTE: had this backwards, and honestly idk even why + if (pref.find(acc) != pref.end()) { + YES(); + return; + } + + pref.insert(acc); + } + + 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/918/f.cc b/codeforces/918/f.cc new file mode 100644 index 0000000..d66776e --- /dev/null +++ b/codeforces/918/f.cc @@ -0,0 +1,114 @@ +#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 +// }}} + +i64 inv_merge(vector& a, vector& tmp) { + if (r - l <= 1) + return 0; + int m = (l + r) >> 1; + i64 ans = inv_merge(a, tmp, l, m) + inv_merge(a, tmp, m, r); + int i = l, j = m, k = l; + while (i < m || j < r) { + if (j == r || (i < m && a[i] <= a[j])) + tmp[k++] = a[i++]; + else { + tmp[k++] = a[j++]; + ans += (m - i); + } + } + return ans; +} + +void solve() { + // NOTE: erroneosouyl thought was interval overlaps (even that took too long + // to code) should've stayed at it and continued, but was tired/acted tired + // consider the problem statemnt & examples more slowly + // simplifcation: count the inversions + i32 n; + cin >> n; + vector> p(n); + for (i32 i = 0; i < n; ++i) + cin >> p[i].first >> p[i].second; + sort(all(p)); + vector b(n), tmp(n); + for (i32 i = 0; i < n; ++i) + b[i] = p[i].second; + println("{}", inv_merge(b, tmp, 0, n)); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/918/g.cc b/codeforces/918/g.cc new file mode 100644 index 0000000..76acd61 --- /dev/null +++ b/codeforces/918/g.cc @@ -0,0 +1,128 @@ +#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>> graph(n + 1); + for (u32 i = 0; i < m; ++i) { + u32 u, v, w; + cin >> u >> v >> w; + graph[u].push_back({v, w}); + graph[v].push_back({u, w}); + } + vec s(n + 1); + for (u32 i = 1; i <= n; ++i) + cin >> s[i]; + + const i64 INF = static_cast(4e18); + vec> dist(n + 1, vec(1001, INF)); + using T = tuple; + priority_queue, greater> pq; + + u32 b0 = s[1]; + dist[1][b0] = 0; + pq.emplace(0, 1, b0); + + while (!pq.empty()) { + auto [t, u, b] = pq.top(); + pq.pop(); + if (t != dist[u][b]) + continue; + u32 nb = min(b, s[u]); + if (nb < b && t < dist[u][nb]) { + dist[u][nb] = t; + pq.emplace(t, u, nb); + } + for (auto [v, w] : graph[u]) { + i64 nt = t + static_cast(w) * static_cast(b); + if (nt < dist[v][b]) { + dist[v][b] = nt; + pq.emplace(nt, v, b); + } + } + } + + i64 ans = INF; + for (u32 b = 1; b <= 1000; ++b) + ans = min(ans, dist[n][b]); + cout << ans << '\n'; +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/918/io/a.in b/codeforces/918/io/a.in new file mode 100644 index 0000000..bae24cd --- /dev/null +++ b/codeforces/918/io/a.in @@ -0,0 +1,11 @@ +10 +1 2 2 +4 3 4 +5 5 6 +7 8 8 +9 0 9 +3 6 3 +2 8 2 +5 7 7 +7 7 5 +5 7 5 diff --git a/codeforces/918/io/a.out b/codeforces/918/io/a.out new file mode 100644 index 0000000..1716ddd --- /dev/null +++ b/codeforces/918/io/a.out @@ -0,0 +1,14 @@ +1 +3 +6 +7 +0 +6 +8 +5 +5 +7 + +[code]: 0 +[time]: 2.48575 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/918/io/b.in b/codeforces/918/io/b.in new file mode 100644 index 0000000..a48f4da --- /dev/null +++ b/codeforces/918/io/b.in @@ -0,0 +1,10 @@ +3 +ABC +C?B +BCA +BCA +CA? +ABC +?AB +BCA +ABC diff --git a/codeforces/918/io/b.out b/codeforces/918/io/b.out new file mode 100644 index 0000000..d2d16f3 --- /dev/null +++ b/codeforces/918/io/b.out @@ -0,0 +1,7 @@ +A +B +C + +[code]: 0 +[time]: 5.89085 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/918/io/c.in b/codeforces/918/io/c.in new file mode 100644 index 0000000..9c017c3 --- /dev/null +++ b/codeforces/918/io/c.in @@ -0,0 +1,11 @@ +5 +1 +9 +2 +14 2 +7 +1 2 3 4 5 6 7 +6 +1 3 5 7 9 11 +4 +2 2 2 2 diff --git a/codeforces/918/io/c.out b/codeforces/918/io/c.out new file mode 100644 index 0000000..1f4c976 --- /dev/null +++ b/codeforces/918/io/c.out @@ -0,0 +1,9 @@ +NO +YES +NO +NO +YES + +[code]: 0 +[time]: 6.36053 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/918/io/d.in b/codeforces/918/io/d.in new file mode 100644 index 0000000..af9f2b0 --- /dev/null +++ b/codeforces/918/io/d.in @@ -0,0 +1,13 @@ +6 +8 +bacedbab +4 +baba +13 +daddecabeddad +3 +dac +6 +dacdac +22 +dababbabababbabbababba diff --git a/codeforces/918/io/d.out b/codeforces/918/io/d.out new file mode 100644 index 0000000..73c412c --- /dev/null +++ b/codeforces/918/io/d.out @@ -0,0 +1,10 @@ +ba.ced.bab +ba.ba +dad.de.ca.bed.dad +dac +dac.dac +da.bab.ba.ba.bab.bab.ba.bab.ba + +[code]: 0 +[time]: 2.4178 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/918/io/e.in b/codeforces/918/io/e.in new file mode 100644 index 0000000..472180e --- /dev/null +++ b/codeforces/918/io/e.in @@ -0,0 +1,13 @@ +6 +3 +1 3 2 +6 +1 1 1 1 1 1 +10 +1 6 9 8 55 3 14 2 7 2 +8 +1 2 11 4 1 5 1 2 +6 +2 6 1 5 7 8 +9 +2 5 10 4 4 9 6 7 8 diff --git a/codeforces/918/io/e.out b/codeforces/918/io/e.out new file mode 100644 index 0000000..6f3ad4b --- /dev/null +++ b/codeforces/918/io/e.out @@ -0,0 +1,10 @@ +YES +YES +NO +YES +NO +YES + +[code]: 0 +[time]: 9.7537 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/918/io/f.in b/codeforces/918/io/f.in new file mode 100644 index 0000000..7e8d0d8 --- /dev/null +++ b/codeforces/918/io/f.in @@ -0,0 +1,27 @@ +5 +2 +2 3 +1 4 +6 +2 6 +3 9 +4 5 +1 8 +7 10 +-2 100 +4 +-10 10 +-5 5 +-12 12 +-13 13 +5 +-4 9 +-2 5 +3 4 +6 7 +8 10 +4 +1 2 +3 4 +5 6 +7 8 diff --git a/codeforces/918/io/f.out b/codeforces/918/io/f.out new file mode 100644 index 0000000..d08e259 --- /dev/null +++ b/codeforces/918/io/f.out @@ -0,0 +1,30 @@ +f.cc: In function ‘i64 inv_merge(std::vector&, std::vector&)’: +f.cc:61:7: error: ‘r’ was not declared in this scope + 61 | if (r - l <= 1) + | ^ +f.cc:61:11: error: ‘l’ was not declared in this scope + 61 | if (r - l <= 1) + | ^ +f.cc:63:12: error: ‘l’ was not declared in this scope + 63 | int m = (l + r) >> 1; + | ^ +f.cc:63:16: error: ‘r’ was not declared in this scope + 63 | int m = (l + r) >> 1; + | ^ +f.cc: In function ‘void solve()’: +f.cc:91:26: error: too many arguments to function ‘i64 inv_merge(std::vector&, std::vector&)’ + 91 | println("{}", inv_merge(b, tmp, 0, n)); + | ~~~~~~~~~^~~~~~~~~~~~~~ +f.cc:60:5: note: declared here + 60 | i64 inv_merge(vector& a, vector& tmp) { + | ^~~~~~~~~ +f.cc: At global scope: +f.cc:39:13: warning: ‘void YES()’ defined but not used [-Wunused-function] + 39 | static void YES() { + | ^~~ +f.cc:35:13: warning: ‘void NO()’ defined but not used [-Wunused-function] + 35 | static void NO() { + | ^~ +cc1plus: note: unrecognized command-line option ‘-Wno-sign-promotion’ may have been intended to silence earlier diagnostics + +[code]: 1 \ No newline at end of file diff --git a/codeforces/918/io/g.in b/codeforces/918/io/g.in new file mode 100644 index 0000000..c955f15 --- /dev/null +++ b/codeforces/918/io/g.in @@ -0,0 +1,32 @@ +3 +5 5 +1 2 2 +3 2 1 +2 4 5 +2 5 7 +4 5 1 +5 2 1 3 3 +5 10 +1 2 5 +1 3 5 +1 4 4 +1 5 8 +2 3 6 +2 4 3 +2 5 2 +3 4 1 +3 5 8 +4 5 2 +7 2 8 4 1 +7 10 +3 2 8 +2 1 4 +2 5 7 +2 6 4 +7 1 2 +4 3 5 +6 4 2 +6 7 1 +6 7 4 +4 5 9 +7 6 5 4 3 2 1 diff --git a/codeforces/918/io/g.out b/codeforces/918/io/g.out new file mode 100644 index 0000000..42de110 --- /dev/null +++ b/codeforces/918/io/g.out @@ -0,0 +1,7 @@ +19 +36 +14 + +[code]: 0 +[time]: 2.39873 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/918/makefile b/codeforces/918/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/918/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/918/scripts/debug.sh b/codeforces/918/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/918/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/918/scripts/run.sh b/codeforces/918/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/918/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/918/scripts/utils.sh b/codeforces/918/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/918/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/928/.clangd b/codeforces/928/.clangd index bacf048..9767507 100644 --- a/codeforces/928/.clangd +++ b/codeforces/928/.clangd @@ -42,3 +42,4 @@ CompileFlags: -e -std=c++23 -e -std=c++23 -e -std=c++23 +-e -std=c++23 diff --git a/codeforces/928/f.cc b/codeforces/928/f.cc new file mode 100644 index 0000000..a715f14 --- /dev/null +++ b/codeforces/928/f.cc @@ -0,0 +1,87 @@ +#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; + dbln("before"); + std::cout << "rad\n"; + println("{}", n); +} + +int main() { // {{{ +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + cin.tie(nullptr)->sync_with_stdio(false); +#endif + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/928/io/f.in b/codeforces/928/io/f.in new file mode 100644 index 0000000..1191247 --- /dev/null +++ b/codeforces/928/io/f.in @@ -0,0 +1,2 @@ +1 +2 diff --git a/codeforces/928/io/f.out b/codeforces/928/io/f.out new file mode 100644 index 0000000..a296ec3 --- /dev/null +++ b/codeforces/928/io/f.out @@ -0,0 +1,7 @@ +before +rad +2 + +[code]: 0 +[time]: 23.0269 ms +[debug]: true \ No newline at end of file