feat: refactor
This commit is contained in:
parent
970b302ab8
commit
ae73b1baf1
23 changed files with 180 additions and 0 deletions
|
|
@ -1,6 +1,31 @@
|
||||||
|
-O2
|
||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
||||||
-Wpedantic
|
-Wpedantic
|
||||||
-Wshadow
|
-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
|
-DLOCAL
|
||||||
-std=c++23
|
-std=c++23
|
||||||
|
|
|
||||||
12
codeforces/886/debug_flags.txt
Normal file
12
codeforces/886/debug_flags.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
-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
|
||||||
0
codeforces/886/io/h.out
Normal file
0
codeforces/886/io/h.out
Normal file
28
codeforces/886/makefile
Normal file
28
codeforces/886/makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
.PHONY: run debug clean setup init
|
||||||
|
|
||||||
|
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 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 .
|
||||||
|
|
||||||
|
init:
|
||||||
|
make setup
|
||||||
|
|
||||||
|
%:
|
||||||
|
@:
|
||||||
29
codeforces/886/scripts/debug.sh
Normal file
29
codeforces/886/scripts/debug.sh
Normal file
|
|
@ -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 $?
|
||||||
29
codeforces/886/scripts/run.sh
Normal file
29
codeforces/886/scripts/run.sh
Normal file
|
|
@ -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 $?
|
||||||
53
codeforces/886/scripts/utils.sh
Normal file
53
codeforces/886/scripts/utils.sh
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -77,6 +77,10 @@ void solve() {
|
||||||
prices.erase(unique(all(prices)), prices.end());
|
prices.erase(unique(all(prices)), prices.end());
|
||||||
sort(all(a));
|
sort(all(a));
|
||||||
sort(all(b));
|
sort(all(b));
|
||||||
|
// fundamentally cooked - thought oculd binary search over the range (this is just not tree)
|
||||||
|
// "pass tc = right" mindset - braindead
|
||||||
|
// low patience -> lack of focus (phone?) gave up on e and f, espec. when
|
||||||
|
// f was doable
|
||||||
|
|
||||||
for (i64 price : prices) {
|
for (i64 price : prices) {
|
||||||
i64 A = n - distance(a.begin(), lower_bound(all(a), price));
|
i64 A = n - distance(a.begin(), lower_bound(all(a), price));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue