diff --git a/codeforces/1029/.clang-format b/codeforces/1029/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1029/.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/1029/.clangd b/codeforces/1029/.clangd new file mode 100644 index 0000000..d02250b --- /dev/null +++ b/codeforces/1029/.clangd @@ -0,0 +1,36 @@ +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 + -std=c++23 + -std=c++23 + -std=c++23 diff --git a/codeforces/1029/a.cc b/codeforces/1029/a.cc new file mode 100644 index 0000000..138ce1d --- /dev/null +++ b/codeforces/1029/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 n, x; + cin >> n >> x; + + bool ok = true; + + u32 door; + bool pushed = false; + u32 since = 0; + for (u32 i = 0; i < n; ++i) { + cin >> door; + if (door == 1) + pushed = true; + if (pushed) + ++since; + if (since > x && door == 1) + ok = false; +-std=c++23 + } + + if (ok) { + YES(); + } else { + NO(); + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1029/b.cc b/codeforces/1029/b.cc new file mode 100644 index 0000000..2f77d0c --- /dev/null +++ b/codeforces/1029/b.cc @@ -0,0 +1,92 @@ +#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); + u32 l = 0, r = n - 1; + for (u32 i = 1; i <= n; ++i) { + if (i & 1) { + a[l++] = i; + } else { + a[r--] = i; + } + } + + for (u32 i = 0; i < n; ++i) { + cout << a[i] << " \n"[i == n - 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/1029/c.cc b/codeforces/1029/c.cc new file mode 100644 index 0000000..a63df7e --- /dev/null +++ b/codeforces/1029/c.cc @@ -0,0 +1,96 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + vec a(n); + for (auto& e : a) + cin >> e; + + u32 ans = 1; + set seen{{a[0]}}; + auto next_seen = seen; + + for (u32 i = 1; i < n; ++i) { + seen.erase(a[i]); + next_seen.insert(a[i]); + if (seen.empty()) { + ++ans; + seen = next_seen; + } + } + + cout << ans << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1029/compile_flags.txt b/codeforces/1029/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/1029/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/1029/debug_flags.txt b/codeforces/1029/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/1029/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/1029/io/a.in b/codeforces/1029/io/a.in new file mode 100644 index 0000000..4535e90 --- /dev/null +++ b/codeforces/1029/io/a.in @@ -0,0 +1,15 @@ +7 +4 2 +0 1 1 0 +6 3 +1 0 1 1 0 0 +8 8 +1 1 1 0 0 1 1 1 +1 2 +1 +5 1 +1 0 1 0 1 +7 4 +0 0 0 1 1 0 1 +10 3 +0 1 0 0 1 0 0 1 0 0 diff --git a/codeforces/1029/io/a.out b/codeforces/1029/io/a.out new file mode 100644 index 0000000..7640a51 --- /dev/null +++ b/codeforces/1029/io/a.out @@ -0,0 +1,10 @@ +YES +NO +YES +YES +NO +YES +NO + +[code]: 0 +[time]: 2.98715 ms \ No newline at end of file diff --git a/codeforces/1029/io/b.in b/codeforces/1029/io/b.in new file mode 100644 index 0000000..a178d04 --- /dev/null +++ b/codeforces/1029/io/b.in @@ -0,0 +1,3 @@ +2 +3 +6 diff --git a/codeforces/1029/io/b.out b/codeforces/1029/io/b.out new file mode 100644 index 0000000..c5f999e --- /dev/null +++ b/codeforces/1029/io/b.out @@ -0,0 +1,5 @@ +1 3 2 +1 3 5 6 4 2 + +[code]: 0 +[time]: 2.70963 ms \ No newline at end of file diff --git a/codeforces/1029/io/c.in b/codeforces/1029/io/c.in new file mode 100644 index 0000000..b738bad --- /dev/null +++ b/codeforces/1029/io/c.in @@ -0,0 +1,17 @@ +8 +6 +1 2 2 3 1 5 +8 +1 2 1 3 2 1 3 2 +5 +5 4 3 2 1 +10 +5 8 7 5 8 5 7 8 10 9 +3 +1 2 2 +9 +3 3 1 4 3 2 4 1 2 +6 +4 5 4 5 6 4 +8 +1 2 1 2 1 2 1 2 diff --git a/codeforces/1029/io/c.out b/codeforces/1029/io/c.out new file mode 100644 index 0000000..8369757 --- /dev/null +++ b/codeforces/1029/io/c.out @@ -0,0 +1,11 @@ +2 +3 +1 +3 +1 +3 +3 +4 + +[code]: 0 +[time]: 2.87986 ms \ No newline at end of file diff --git a/codeforces/1029/makefile b/codeforces/1029/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/1029/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/1029/scripts/debug.sh b/codeforces/1029/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/1029/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/1029/scripts/run.sh b/codeforces/1029/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/1029/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/1029/scripts/utils.sh b/codeforces/1029/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/1029/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 +} diff --git a/codeforces/784/.clang-format b/codeforces/784/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/784/.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/784/.clangd b/codeforces/784/.clangd new file mode 100644 index 0000000..18faf04 --- /dev/null +++ b/codeforces/784/.clangd @@ -0,0 +1,47 @@ +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 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/784/a.cc b/codeforces/784/a.cc new file mode 100644 index 0000000..1f3cffc --- /dev/null +++ b/codeforces/784/a.cc @@ -0,0 +1,92 @@ +#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 rating; + cin >> rating; + + u32 division; + + if (rating <= 1399) { + division = 4; + } else if (rating <= 1599) { + division = 3; + } else if (rating <= 1899) { + division = 2; + } else { + division = 1; + } + + println("Division {}", division); +} + +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/784/b.cc b/codeforces/784/b.cc new file mode 100644 index 0000000..cb54bce --- /dev/null +++ b/codeforces/784/b.cc @@ -0,0 +1,92 @@ +#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), f(n + 1); + for (auto& e : a) + cin >> e; + for (auto e : a) + f[e]++; + + for (u32 i = 1; i <= n; ++i) { + if (f[i] >= 3) { + println("{}", i); + return; + } + } + println("-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/784/c.cc b/codeforces/784/c.cc new file mode 100644 index 0000000..68a89a9 --- /dev/null +++ b/codeforces/784/c.cc @@ -0,0 +1,96 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + + vec a(n); + for (auto& e : a) + cin >> e; + + for (u32 i = 1; i < n; i += 2) { + if ((a[i] & 1) != (a[1] & 1)) { + NO(); + return; + } + } + for (u32 i = 0; i < n; i += 2) { + if ((a[i] & 1) != (a[0] & 1)) { + NO(); + return; + } + } + YES(); +} + +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/784/compile_flags.txt b/codeforces/784/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/784/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/784/d.cc b/codeforces/784/d.cc new file mode 100644 index 0000000..7e3d65b --- /dev/null +++ b/codeforces/784/d.cc @@ -0,0 +1,103 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + string s; + cin >> s; + istringstream ss{s}; + + string word; + + while (getline(ss, word, 'W')) { + if (word.size() == 0) + continue; + + u32 R = 0, B = 0; + for (auto c : word) { + if (c == 'R') + ++R; + if (c == 'B') + ++B; + } + + if (!(R > 0 && B > 0)) { + NO(); + return; + } + } + + YES(); +} + +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/784/debug_flags.txt b/codeforces/784/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/784/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/784/e.cc b/codeforces/784/e.cc new file mode 100644 index 0000000..502d7b8 --- /dev/null +++ b/codeforces/784/e.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 n; + cin >> n; + + vec a(n); + for (auto& e : a) + cin >> e; + + u64 ans = 0; + + unordered_map> f; + + for (u32 i = 0; i < n; ++i) { + for (char c = 'a'; c <= 'k'; ++c) { + if (c != a[i][0]) + ans += f[c][a[i][1]]; + if (c != a[i][1]) { + ans += f[a[i][0]][c]; + } + } + + f[a[i][0]][a[i][1]]++; + } + + println("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/784/f.cc b/codeforces/784/f.cc new file mode 100644 index 0000000..a9ec89a --- /dev/null +++ b/codeforces/784/f.cc @@ -0,0 +1,101 @@ +#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; + cin >> n; + + vec a(n); + for (auto& e : a) + cin >> e; + + i32 ans = 0; + + u64 left = 0, right = 0; + i32 l = 0, r = n - 1; + + while (l <= r) { + if (left <= right) { + left += a[l++]; + } else { + right += a[r--]; + } + + if (left == right) { + ans = max(ans, l + n - r - 1); + } + } + + println("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/784/g.cc b/codeforces/784/g.cc new file mode 100644 index 0000000..e89595a --- /dev/null +++ b/codeforces/784/g.cc @@ -0,0 +1,107 @@ +#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); + for (auto& e : grid) + cin >> e; + + vec ans(n, string(m, '.')); + + for (u32 column = 0; column < m; ++column) { + i32 write = n - 1; + for (i32 row = n - 1; row >= 0; --row) { + if (grid[row][column] == '.') + continue; + + if (grid[row][column] == 'o') { + ans[row][column] = 'o'; + write = row - 1; + } + + if (grid[row][column] == '*') { + ans[write][column] = '*'; + --write; + } + } + } + + for (auto& e : ans) { + println("{}", e); + } + println(); +} + +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/784/h.cc b/codeforces/784/h.cc new file mode 100644 index 0000000..3eb66ed --- /dev/null +++ b/codeforces/784/h.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() { + i32 n; + cin >> n; + i64 k; + cin >> k; + + vec bit_count(31, 0); + vec a(n); + + for (auto& e : a) { + cin >> e; + for (u32 shift = 0; shift <= 30; ++shift) { + bit_count[shift] += bool(e & (1 << shift)); + } + } + + u32 ans = 0; + for (i32 shift = 30; shift >= 0; --shift) { + i32 cost = n - bit_count[shift]; + + if (cost <= k) { + k -= cost; + ans |= 1 << shift; + } + } + + 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/784/io/a.in b/codeforces/784/io/a.in new file mode 100644 index 0000000..c1a065c --- /dev/null +++ b/codeforces/784/io/a.in @@ -0,0 +1,8 @@ +7 +-789 +1299 +1300 +1399 +1400 +1679 +2300 diff --git a/codeforces/784/io/a.out b/codeforces/784/io/a.out new file mode 100644 index 0000000..e5a9e06 --- /dev/null +++ b/codeforces/784/io/a.out @@ -0,0 +1,10 @@ +Division 4 +Division 4 +Division 4 +Division 4 +Division 3 +Division 2 +Division 1 + +[code]: 0 +[time]: 5.79357 ms diff --git a/codeforces/784/io/b.in b/codeforces/784/io/b.in new file mode 100644 index 0000000..d026996 --- /dev/null +++ b/codeforces/784/io/b.in @@ -0,0 +1,15 @@ +7 +1 +1 +3 +2 2 2 +7 +2 2 3 3 4 2 2 +8 +1 4 3 4 3 2 4 1 +9 +1 1 1 2 2 2 3 3 3 +5 +1 5 2 4 3 +4 +4 4 4 4 diff --git a/codeforces/784/io/b.out b/codeforces/784/io/b.out new file mode 100644 index 0000000..132f522 --- /dev/null +++ b/codeforces/784/io/b.out @@ -0,0 +1,10 @@ +-1 +2 +2 +4 +1 +-1 +4 + +[code]: 0 +[time]: 2.40207 ms \ No newline at end of file diff --git a/codeforces/784/io/c.in b/codeforces/784/io/c.in new file mode 100644 index 0000000..389b5f9 --- /dev/null +++ b/codeforces/784/io/c.in @@ -0,0 +1,9 @@ +4 +3 +1 2 1 +4 +2 2 2 3 +4 +2 2 2 2 +5 +1000 1 1000 1 1000 diff --git a/codeforces/784/io/c.out b/codeforces/784/io/c.out new file mode 100644 index 0000000..12e859e --- /dev/null +++ b/codeforces/784/io/c.out @@ -0,0 +1,7 @@ +YES +NO +YES +YES + +[code]: 0 +[time]: 6.10971 ms \ No newline at end of file diff --git a/codeforces/784/io/d.in b/codeforces/784/io/d.in new file mode 100644 index 0000000..84c62c5 --- /dev/null +++ b/codeforces/784/io/d.in @@ -0,0 +1,25 @@ +12 +5 +BRBBW +1 +B +2 +WB +2 +RW +3 +BRB +3 +RBB +7 +WWWWWWW +9 +RBWBWRRBW +10 +BRBRBRBRRB +12 +BBBRWWRRRWBR +10 +BRBRBRBRBW +5 +RBWBW diff --git a/codeforces/784/io/d.out b/codeforces/784/io/d.out new file mode 100644 index 0000000..b16a2ce --- /dev/null +++ b/codeforces/784/io/d.out @@ -0,0 +1,15 @@ +YES +NO +NO +NO +YES +YES +YES +NO +YES +NO +YES +NO + +[code]: 0 +[time]: 2.47884 ms diff --git a/codeforces/784/io/e.in b/codeforces/784/io/e.in new file mode 100644 index 0000000..fc217b8 --- /dev/null +++ b/codeforces/784/io/e.in @@ -0,0 +1,27 @@ +4 +6 +ab +cb +db +aa +cc +ef +7 +aa +bb +cc +ac +ca +bb +aa +4 +kk +kk +ab +ab +5 +jf +jf +jk +jk +jk diff --git a/codeforces/784/io/e.out b/codeforces/784/io/e.out new file mode 100644 index 0000000..d6618b0 --- /dev/null +++ b/codeforces/784/io/e.out @@ -0,0 +1,8 @@ +5 +6 +0 +6 + +[code]: 0 +[time]: 4.33087 ms +[time]: 2.47264 ms \ No newline at end of file diff --git a/codeforces/784/io/f.in b/codeforces/784/io/f.in new file mode 100644 index 0000000..fbf1c63 --- /dev/null +++ b/codeforces/784/io/f.in @@ -0,0 +1,9 @@ +4 +3 +10 20 10 +6 +2 1 4 2 4 1 +5 +1 2 4 8 16 +9 +7 3 20 5 15 1 11 8 10 diff --git a/codeforces/784/io/f.out b/codeforces/784/io/f.out new file mode 100644 index 0000000..df1f2cc --- /dev/null +++ b/codeforces/784/io/f.out @@ -0,0 +1,7 @@ +2 +6 +0 +7 + +[code]: 0 +[time]: 2.23374 ms \ No newline at end of file diff --git a/codeforces/784/io/g.in b/codeforces/784/io/g.in new file mode 100644 index 0000000..2bb8b7e --- /dev/null +++ b/codeforces/784/io/g.in @@ -0,0 +1,17 @@ +3 +6 10 +.*.*....*. +.*.......* +...o....o. +.*.*....*. +.......... +.o......o* +2 9 +...***ooo +.*o.*o.*o +5 5 +***** +*.... +***** +....* +***** diff --git a/codeforces/784/io/g.out b/codeforces/784/io/g.out new file mode 100644 index 0000000..58ed6a3 --- /dev/null +++ b/codeforces/784/io/g.out @@ -0,0 +1,19 @@ +.......... +...*....*. +.*.o....o. +.*........ +.*......** +.o.*....o* + +....**ooo +.*o**o.*o + +..... +*...* +***** +***** +***** + + +[code]: 0 +[time]: 2.32959 ms \ No newline at end of file diff --git a/codeforces/784/io/h.in b/codeforces/784/io/h.in new file mode 100644 index 0000000..2fe8338 --- /dev/null +++ b/codeforces/784/io/h.in @@ -0,0 +1,9 @@ +4 +3 2 +2 1 1 +7 0 +4 6 6 28 6 6 12 +1 30 +0 +4 4 +3 1 3 1 diff --git a/codeforces/784/io/h.out b/codeforces/784/io/h.out new file mode 100644 index 0000000..c089f10 --- /dev/null +++ b/codeforces/784/io/h.out @@ -0,0 +1,7 @@ +2 +4 +2147483646 +1073741825 + +[code]: 0 +[time]: 3.09849 ms \ No newline at end of file diff --git a/codeforces/784/makefile b/codeforces/784/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/784/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/784/scripts/debug.sh b/codeforces/784/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/784/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/784/scripts/run.sh b/codeforces/784/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/784/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/784/scripts/utils.sh b/codeforces/784/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/784/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 +} diff --git a/codeforces/827/.clangd b/codeforces/827/.clangd index 298afc3..93653f7 100644 --- a/codeforces/827/.clangd +++ b/codeforces/827/.clangd @@ -43,3 +43,4 @@ CompileFlags: -std=c++23 -std=c++23 -std=c++23 + -std=c++23 diff --git a/codeforces/827/compile_flags.txt b/codeforces/827/compile_flags.txt index 5373b01..e88797b 100644 --- a/codeforces/827/compile_flags.txt +++ b/codeforces/827/compile_flags.txt @@ -27,4 +27,5 @@ -Wdouble-promotion -Wundef -DLOCAL +-godbolt-compiler=g143 -std=c++23 diff --git a/codeforces/827/d.cc b/codeforces/827/d.cc index ca9dcd7..3d78b52 100644 --- a/codeforces/827/d.cc +++ b/codeforces/827/d.cc @@ -57,6 +57,12 @@ using vec = std::vector; #endif // }}} +struct S{ + void method() { + + } +}; + void solve() { /* a[i] has factors S, |S| < = log2(MAX_A[i] = 1000) diff --git a/codeforces/827/io/a.out b/codeforces/827/io/a.out index be76365..753f07d 100644 --- a/codeforces/827/io/a.out +++ b/codeforces/827/io/a.out @@ -7,4 +7,4 @@ NO YES [code]: 0 -[time]: 11.7166 ms \ No newline at end of file +[time]: 11.7166 ms diff --git a/codeforces/835/.clangd b/codeforces/835/.clangd index 5b59a31..59d7ce0 100644 --- a/codeforces/835/.clangd +++ b/codeforces/835/.clangd @@ -32,3 +32,7 @@ CompileFlags: -DLOCAL -std=c++20 -Wno-unknown-pragmas + -std=c++23 + -std=c++23 + -std=c++23 + -std=c++23 diff --git a/codeforces/835/b.cc b/codeforces/835/b.cc index b029d7e..2c99e10 100644 --- a/codeforces/835/b.cc +++ b/codeforces/835/b.cc @@ -20,7 +20,7 @@ void solve() { cin >> _; string s; cin >> s; - i32 ans = 1; + i32 ans = 2; for (auto c : s) { ans = max(ans, c - 'a' + 1); } diff --git a/codeforces/835/compile_flags.txt b/codeforces/835/compile_flags.txt index af7fb72..e88797b 100644 --- a/codeforces/835/compile_flags.txt +++ b/codeforces/835/compile_flags.txt @@ -16,7 +16,6 @@ -Wunused -Woverloaded-virtual -Wconversion --Wsign-conversion -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches @@ -28,4 +27,5 @@ -Wdouble-promotion -Wundef -DLOCAL --std=c++20 +-godbolt-compiler=g143 +-std=c++23 diff --git a/codeforces/835/debug_flags.txt b/codeforces/835/debug_flags.txt index 03cba1b..62a0135 100644 --- a/codeforces/835/debug_flags.txt +++ b/codeforces/835/debug_flags.txt @@ -10,3 +10,5 @@ -ffunction-sections -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC +-DLOCAL +-std=c++23 diff --git a/codeforces/835/io/a.out b/codeforces/835/io/a.out index cc978f6..1abe0d8 100644 --- a/codeforces/835/io/a.out +++ b/codeforces/835/io/a.out @@ -9,4 +9,4 @@ 8 [code]: 0 -[time]: 4.3807 ms \ No newline at end of file +[time]: 4.3807 ms diff --git a/codeforces/835/makefile b/codeforces/835/makefile index 9c5450b..3c50267 100644 --- a/codeforces/835/makefile +++ b/codeforces/835/makefile @@ -1,5 +1,7 @@ .PHONY: run debug clean setup init +VERSION ?= 20 + SRC = $(word 2,$(MAKECMDGOALS)) .SILENT: @@ -17,9 +19,9 @@ setup: test -d build || mkdir -p build test -d io || mkdir -p io test -d scripts || mkdir -p scripts - test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . - test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . 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/888/.clangd b/codeforces/888/.clangd index 4f8ead9..36b2764 100644 --- a/codeforces/888/.clangd +++ b/codeforces/888/.clangd @@ -5,4 +5,5 @@ CompileFlags: - -Wpedantic - -Wshadow - -DLOCAL - - -Wno-unknown-pragmas \ No newline at end of file + - -Wno-unknown-pragmas -std=c++23 + -std=c++23 diff --git a/codeforces/888/compile_flags.txt b/codeforces/888/compile_flags.txt index 504aea8..5373b01 100644 --- a/codeforces/888/compile_flags.txt +++ b/codeforces/888/compile_flags.txt @@ -1,6 +1,30 @@ +-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/888/debug_flags.txt b/codeforces/888/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/888/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/888/io/a.in b/codeforces/888/io/a.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/888/io/a.out b/codeforces/888/io/a.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/888/io/b.in b/codeforces/888/io/b.in new file mode 100644 index 0000000..e8183f0 --- /dev/null +++ b/codeforces/888/io/b.in @@ -0,0 +1,3 @@ +1 +1 +1 diff --git a/codeforces/888/io/b.out b/codeforces/888/io/b.out new file mode 100644 index 0000000..79a7f6c --- /dev/null +++ b/codeforces/888/io/b.out @@ -0,0 +1,3 @@ +g++: error: unrecognized command-line option ‘-compiler=g143’ + +[code]: 1 \ No newline at end of file diff --git a/codeforces/888/makefile b/codeforces/888/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/888/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/888/scripts/debug.sh b/codeforces/888/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/888/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/888/scripts/run.sh b/codeforces/888/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/888/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/888/scripts/utils.sh b/codeforces/888/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/888/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 +} diff --git a/codeforces/993/h.cc b/codeforces/993/h.cc index b46c0bb..9c3326c 100644 --- a/codeforces/993/h.cc +++ b/codeforces/993/h.cc @@ -105,7 +105,7 @@ void solve() { u64 w = y2 - y1 + 1; - u64 ans = w * (sr - (u64)x1 * s) + (sc - (u64)y1 * s) + s; + u62 ans = w * (sr - (u64)x1 * s) + (sc - (u64)y1 * s) + s; cout << ans << " \n"[i == q - 1]; } diff --git a/codeforces/998/.clangd b/codeforces/998/.clangd index 61f8494..c2e9173 100644 --- a/codeforces/998/.clangd +++ b/codeforces/998/.clangd @@ -5,4 +5,5 @@ CompileFlags: - -Wextra - -Wpedantic - -Wshadow - - -Wno-unknown-pragmas \ No newline at end of file + - -Wno-unknown-pragmas -std=c++23 + -std=c++23 diff --git a/codeforces/998/compile_flags.txt b/codeforces/998/compile_flags.txt index b5d4b68..e88797b 100644 --- a/codeforces/998/compile_flags.txt +++ b/codeforces/998/compile_flags.txt @@ -1,5 +1,31 @@ --std=c++20 +-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 +-godbolt-compiler=g143 +-std=c++23 diff --git a/codeforces/998/debug_flags.txt b/codeforces/998/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/998/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/998/io/a.in b/codeforces/998/io/a.in new file mode 100644 index 0000000..63db1c6 --- /dev/null +++ b/codeforces/998/io/a.in @@ -0,0 +1,2 @@ +1 +1 2 3 4 diff --git a/codeforces/998/io/a.out b/codeforces/998/io/a.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/998/makefile b/codeforces/998/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/998/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/998/scripts/debug.sh b/codeforces/998/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/998/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/998/scripts/run.sh b/codeforces/998/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/998/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/998/scripts/utils.sh b/codeforces/998/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/998/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 +}