From 3e46a241a1b4d862bf7ab8c94949536c2a7c3674 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 24 Aug 2025 14:47:38 -0500 Subject: [PATCH] feat: 928 --- codeforces/898/.clangd | 3 +- codeforces/898/compile_flags.txt | 25 +++++++ codeforces/898/debug_flags.txt | 14 ++++ codeforces/898/io/a.in | 0 codeforces/898/io/a.out | 0 codeforces/898/makefile | 30 +++++++++ codeforces/898/scripts/debug.sh | 29 ++++++++ codeforces/898/scripts/run.sh | 29 ++++++++ codeforces/898/scripts/utils.sh | 61 +++++++++++++++++ codeforces/928/.clang-format | 9 +++ codeforces/928/.clangd | 43 ++++++++++++ codeforces/928/a.cc | 91 ++++++++++++++++++++++++++ codeforces/928/b.cc | 104 +++++++++++++++++++++++++++++ codeforces/928/c.cc | 94 ++++++++++++++++++++++++++ codeforces/928/compile_flags.txt | 31 +++++++++ codeforces/928/d.cc | 95 +++++++++++++++++++++++++++ codeforces/928/debug_flags.txt | 14 ++++ codeforces/928/e.cc | 109 +++++++++++++++++++++++++++++++ codeforces/928/g.cc | 105 +++++++++++++++++++++++++++++ codeforces/928/io/a.in | 9 +++ codeforces/928/io/a.out | 12 ++++ codeforces/928/io/b.in | 34 ++++++++++ codeforces/928/io/b.out | 10 +++ codeforces/928/io/c.in | 8 +++ codeforces/928/io/c.out | 11 ++++ codeforces/928/io/d.in | 19 ++++++ codeforces/928/io/d.out | 13 ++++ codeforces/928/io/e.in | 12 ++++ codeforces/928/io/e.out | 15 +++++ codeforces/928/io/g.in | 10 +++ codeforces/928/io/g.out | 7 ++ codeforces/928/makefile | 30 +++++++++ codeforces/928/scripts/debug.sh | 29 ++++++++ codeforces/928/scripts/run.sh | 29 ++++++++ codeforces/928/scripts/utils.sh | 61 +++++++++++++++++ 35 files changed, 1194 insertions(+), 1 deletion(-) create mode 100644 codeforces/898/debug_flags.txt create mode 100644 codeforces/898/io/a.in create mode 100644 codeforces/898/io/a.out create mode 100644 codeforces/898/makefile create mode 100644 codeforces/898/scripts/debug.sh create mode 100644 codeforces/898/scripts/run.sh create mode 100644 codeforces/898/scripts/utils.sh create mode 100644 codeforces/928/.clang-format create mode 100644 codeforces/928/.clangd create mode 100644 codeforces/928/a.cc create mode 100644 codeforces/928/b.cc create mode 100644 codeforces/928/c.cc create mode 100644 codeforces/928/compile_flags.txt create mode 100644 codeforces/928/d.cc create mode 100644 codeforces/928/debug_flags.txt create mode 100644 codeforces/928/e.cc create mode 100644 codeforces/928/g.cc create mode 100644 codeforces/928/io/a.in create mode 100644 codeforces/928/io/a.out create mode 100644 codeforces/928/io/b.in create mode 100644 codeforces/928/io/b.out create mode 100644 codeforces/928/io/c.in create mode 100644 codeforces/928/io/c.out create mode 100644 codeforces/928/io/d.in create mode 100644 codeforces/928/io/d.out create mode 100644 codeforces/928/io/e.in create mode 100644 codeforces/928/io/e.out create mode 100644 codeforces/928/io/g.in create mode 100644 codeforces/928/io/g.out create mode 100644 codeforces/928/makefile create mode 100644 codeforces/928/scripts/debug.sh create mode 100644 codeforces/928/scripts/run.sh create mode 100644 codeforces/928/scripts/utils.sh diff --git a/codeforces/898/.clangd b/codeforces/898/.clangd index 4f8ead9..0fd8fc8 100644 --- a/codeforces/898/.clangd +++ b/codeforces/898/.clangd @@ -5,4 +5,5 @@ CompileFlags: - -Wpedantic - -Wshadow - -DLOCAL - - -Wno-unknown-pragmas \ No newline at end of file + - -Wno-unknown-pragmas-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/898/compile_flags.txt b/codeforces/898/compile_flags.txt index 504aea8..04a3a2a 100644 --- a/codeforces/898/compile_flags.txt +++ b/codeforces/898/compile_flags.txt @@ -1,6 +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/898/debug_flags.txt b/codeforces/898/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/898/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/898/io/a.in b/codeforces/898/io/a.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/898/io/a.out b/codeforces/898/io/a.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/898/makefile b/codeforces/898/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/898/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/898/scripts/debug.sh b/codeforces/898/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/898/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/898/scripts/run.sh b/codeforces/898/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/898/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/898/scripts/utils.sh b/codeforces/898/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/898/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/.clang-format b/codeforces/928/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/928/.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/928/.clangd b/codeforces/928/.clangd new file mode 100644 index 0000000..c9330f1 --- /dev/null +++ b/codeforces/928/.clangd @@ -0,0 +1,43 @@ +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 +-e -std=c++23 diff --git a/codeforces/928/a.cc b/codeforces/928/a.cc new file mode 100644 index 0000000..0ea364d --- /dev/null +++ b/codeforces/928/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; + + u32 as = 0; + for (auto e : s) { + as += e == 'A'; + } + + if (as >= 3) { + cout << 'A'; + } else { + cout << 'B'; + } + + cout << '\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/928/b.cc b/codeforces/928/b.cc new file mode 100644 index 0000000..04f778c --- /dev/null +++ b/codeforces/928/b.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() { + u32 n; + cin >> n; + vec grid(n); + for (auto& e : grid) + cin >> e; + + for (u32 r = 0; r < n; ++r) { + u32 count = 0; + for (auto c : grid[r]) { + if (c == '1') { + ++count; + } + } + + if (count > 0) { + u32 count2 = 0; + for (auto c : grid[r + 1]) { + count2 += c == '1'; + } + if (count != count2) { + cout << "TRIANGLE\n"; + } else { + cout << "SQUARE\n"; + } + + return; + } + } +} + +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/928/c.cc b/codeforces/928/c.cc new file mode 100644 index 0000000..08e683e --- /dev/null +++ b/codeforces/928/c.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 +// }}} + +vec cache(2 * 100000 + 1, 0); + +void solve() { + u32 n; + cin >> n; + + println("{}", cache[n]); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + for (u32 i = 1; i <= 200000; ++i) { + u32 val = 0; + + auto I = i; + while (I) { + val += I % 10; + I /= 10; + } + + cache[i] = val + cache[i - 1]; + } + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/928/compile_flags.txt b/codeforces/928/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/928/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/928/d.cc b/codeforces/928/d.cc new file mode 100644 index 0000000..6c2fcf9 --- /dev/null +++ b/codeforces/928/d.cc @@ -0,0 +1,95 @@ +#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; + + multiset seen; + u32 ans = 0; + for (auto e : a) { + auto complement = ((1LL << 31) - 1) ^ e; + if (seen.empty() || !seen.contains(complement)) { + seen.insert(e); + } else { + seen.erase(seen.find(complement)); + ++ans; + } + } + + println("{}", ans + seen.size()); +} + +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/928/debug_flags.txt b/codeforces/928/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/928/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/928/e.cc b/codeforces/928/e.cc new file mode 100644 index 0000000..72f7f9e --- /dev/null +++ b/codeforces/928/e.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() { + u64 n, k; + cin >> n >> k; + + /* + initially lays down ceil(n / 2.0) cards + + if found, its just 2 * k + + n - ceil(n / 2.0) left + + lays down 2 * odds + +note: only odd # turns matter + + n = 24 + 1 3 5 7 9 11 13 15 17 19 21 23 -> 2 4 6 8 10 12 ... left + 2 6 10 14 + div. both sides by 2: + 1 2 3 4 5 6 <- n - ceil(n / 2.0) left + continue, log(n) itme + 3 9 ... <- don't matter + + div by 2 + */ + + u64 multiplier = 1; + while (k > (u64)ceil(n / 2.0)) { + k -= (u64)ceil(n / 2.0); + n -= (u64)ceil(n / 2.0); + multiplier *= 2; + } + + println("{}", multiplier * (1 + 2 * (k - 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/928/g.cc b/codeforces/928/g.cc new file mode 100644 index 0000000..0cd64c4 --- /dev/null +++ b/codeforces/928/g.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> tree(n + 1); + for (u32 i = 2; i <= n; ++i) { + u32 a; + cin >> a; + tree[i].push_back(a); + tree[a].push_back(i); + } + string s; + cin >> s; + s = ' ' + s; + + auto dfs = [&](auto&& self, u32 u, u32 p) -> vec { + vec dp(2); + dp[0] = (s[u] == 'P') ? 1 << 30 : 0; + dp[1] = (s[u] == 'S') ? 1 << 30 : 0; + for (u32 v : tree[u]) { + if (v == p) + continue; + auto prev = self(self, v, u); + dp[0] += min(prev[0], prev[1] + 1); + dp[1] += min(prev[1], prev[0] + 1); + } + return dp; + }; + + auto ans = dfs(dfs, 1, 0); + cout << *min_element(all(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/928/io/a.in b/codeforces/928/io/a.in new file mode 100644 index 0000000..1d481a4 --- /dev/null +++ b/codeforces/928/io/a.in @@ -0,0 +1,9 @@ +8 +ABABB +ABABA +BBBAB +AAAAA +BBBBB +BABAA +AAAAB +BAAAA diff --git a/codeforces/928/io/a.out b/codeforces/928/io/a.out new file mode 100644 index 0000000..cceb9e0 --- /dev/null +++ b/codeforces/928/io/a.out @@ -0,0 +1,12 @@ +B +A +B +A +B +A +A +A + +[code]: 0 +[time]: 2.9614 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/928/io/b.in b/codeforces/928/io/b.in new file mode 100644 index 0000000..170d89d --- /dev/null +++ b/codeforces/928/io/b.in @@ -0,0 +1,34 @@ +6 +3 +000 +011 +011 +4 +0000 +0000 +0100 +1110 +2 +11 +11 +5 +00111 +00010 +00000 +00000 +00000 +10 +0000000000 +0000000000 +0000000000 +0000000000 +0000000000 +1111111110 +0111111100 +0011111000 +0001110000 +0000100000 +3 +111 +111 +111 diff --git a/codeforces/928/io/b.out b/codeforces/928/io/b.out new file mode 100644 index 0000000..b0a5615 --- /dev/null +++ b/codeforces/928/io/b.out @@ -0,0 +1,10 @@ +SQUARE +TRIANGLE +SQUARE +TRIANGLE +TRIANGLE +SQUARE + +[code]: 0 +[time]: 5.67222 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/928/io/c.in b/codeforces/928/io/c.in new file mode 100644 index 0000000..41f9257 --- /dev/null +++ b/codeforces/928/io/c.in @@ -0,0 +1,8 @@ +7 +12 +1 +2 +3 +1434 +2024 +200000 diff --git a/codeforces/928/io/c.out b/codeforces/928/io/c.out new file mode 100644 index 0000000..c140d02 --- /dev/null +++ b/codeforces/928/io/c.out @@ -0,0 +1,11 @@ +51 +1 +3 +6 +18465 +28170 +4600002 + +[code]: 0 +[time]: 7.12848 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/928/io/d.in b/codeforces/928/io/d.in new file mode 100644 index 0000000..b9e8c65 --- /dev/null +++ b/codeforces/928/io/d.in @@ -0,0 +1,19 @@ +9 +4 +1 4 3 4 +2 +0 2147483647 +5 +476319172 261956880 2136179468 1671164475 1885526767 +3 +1335890506 811593141 1128223362 +4 +688873446 627404104 1520079543 1458610201 +4 +61545621 2085938026 1269342732 1430258575 +4 +0 0 2147483647 2147483647 +3 +0 0 2147483647 +8 +1858058912 289424735 1858058912 2024818580 1858058912 289424735 122665067 289424735 diff --git a/codeforces/928/io/d.out b/codeforces/928/io/d.out new file mode 100644 index 0000000..f0a29dc --- /dev/null +++ b/codeforces/928/io/d.out @@ -0,0 +1,13 @@ +4 +1 +3 +2 +2 +3 +2 +2 +4 + +[code]: 0 +[time]: 2.39205 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/928/io/e.in b/codeforces/928/io/e.in new file mode 100644 index 0000000..d051ae4 --- /dev/null +++ b/codeforces/928/io/e.in @@ -0,0 +1,12 @@ +11 +7 1 +7 2 +7 3 +7 4 +7 5 +7 6 +7 7 +1 1 +34 14 +84 19 +1000000000 1000000000 diff --git a/codeforces/928/io/e.out b/codeforces/928/io/e.out new file mode 100644 index 0000000..c024463 --- /dev/null +++ b/codeforces/928/io/e.out @@ -0,0 +1,15 @@ +1 +3 +5 +7 +2 +6 +4 +1 +27 +37 +536870912 + +[code]: 0 +[time]: 2.3458 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/928/io/g.in b/codeforces/928/io/g.in new file mode 100644 index 0000000..7743707 --- /dev/null +++ b/codeforces/928/io/g.in @@ -0,0 +1,10 @@ +3 +3 +1 1 +CSP +4 +1 2 2 +PCSS +4 +1 2 2 +PPSS diff --git a/codeforces/928/io/g.out b/codeforces/928/io/g.out new file mode 100644 index 0000000..7bba283 --- /dev/null +++ b/codeforces/928/io/g.out @@ -0,0 +1,7 @@ +1 +1 +2 + +[code]: 0 +[time]: 2.3241 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/928/makefile b/codeforces/928/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/928/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/928/scripts/debug.sh b/codeforces/928/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/928/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/928/scripts/run.sh b/codeforces/928/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/928/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/928/scripts/utils.sh b/codeforces/928/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/928/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 +}