Separate lib, new problems and script for web
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
# usaco build <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
build_problem "$dir"
|
||||||
|
echo "Built $dir/main"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# usaco clean
|
||||||
|
for s in solving solved skipped; do
|
||||||
|
[[ -d "$ROOT/$s" ]] || continue
|
||||||
|
find "$ROOT/$s" -mindepth 2 -maxdepth 2 -type f \
|
||||||
|
\( -name main -o -name a.out -o -name '*.bak' \) -print -delete | sed "s|^$ROOT/|removed |"
|
||||||
|
done
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# usaco done <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
name="$1"
|
||||||
|
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; }
|
||||||
|
[[ -d "$ROOT/solved/$name" ]] && { echo "Error: solved/$name already exists" >&2; exit 1; }
|
||||||
|
mv "$ROOT/solving/$name" "$ROOT/solved/$name"
|
||||||
|
echo "Moved to solved/$name 🎉"
|
||||||
|
if git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
|
git -C "$ROOT" add -A "solved/$name" "solving/$name" 2>/dev/null || true
|
||||||
|
git -C "$ROOT" commit -m "Solve $name" >/dev/null && echo "Committed: Solve $name"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# usaco vim/edit/e <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
# run from inside the dir so :!./main etc. work and .in files are at hand
|
||||||
|
(cd "$dir" && exec ${EDITOR:-nvim} main.cpp)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# usaco io <name> [io-name]
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
old="$(detect_io "$dir" || true)"
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
stdio="$(grep -o 'STDIO("[^"]*")' "$dir/main.cpp" 2>/dev/null | sed 's/STDIO("\(.*\)")/\1/' | head -1 || true)"
|
||||||
|
echo "files: ${old:-none}"
|
||||||
|
echo "STDIO: ${stdio:-none}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
io="$2"
|
||||||
|
# rename data files
|
||||||
|
if [[ -n "$old" && "$old" != "$io" ]]; then
|
||||||
|
for ext in in out; do
|
||||||
|
[[ -e "$dir/$old.$ext" ]] && mv "$dir/$old.$ext" "$dir/$io.$ext" && echo "Renamed $old.$ext -> $io.$ext"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
[[ -e "$dir/$io.in" ]] || { touch "$dir/$io.in"; echo "Created $io.in"; }
|
||||||
|
# rewire STDIO in main.cpp
|
||||||
|
if grep -q 'STDIO("' "$dir/main.cpp" 2>/dev/null; then
|
||||||
|
sed -i "s/STDIO(\"[^\"]*\")/STDIO(\"$io\")/" "$dir/main.cpp"
|
||||||
|
echo "Updated STDIO(\"$io\") in main.cpp"
|
||||||
|
elif grep -q '^int main() {$' "$dir/main.cpp" 2>/dev/null; then
|
||||||
|
sed -i "s/^int main() {$/int main() {\n STDIO(\"$io\");/" "$dir/main.cpp"
|
||||||
|
echo "Inserted STDIO(\"$io\") in main.cpp"
|
||||||
|
else
|
||||||
|
echo "Warning: couldn't find STDIO(...) or 'int main() {' in main.cpp — wire it up manually" >&2
|
||||||
|
fi
|
||||||
|
echo "io name for $(basename "$dir") is now '$io'"
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# usaco list
|
||||||
|
list_by_mtime() { # list subdirs of $1 oldest-first by last modification
|
||||||
|
[[ -d "$1" ]] || return 0
|
||||||
|
for d in "$1"/*/; do
|
||||||
|
[[ -d "$d" ]] || continue
|
||||||
|
# newest mtime of any file in the problem dir
|
||||||
|
printf '%s\t%s\n' "$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1)" "$(basename "$d")"
|
||||||
|
done | sort -n | cut -f2 | sed 's/^/ /'
|
||||||
|
}
|
||||||
|
echo "== Solving =="
|
||||||
|
list_by_mtime "$ROOT/solving"
|
||||||
|
echo
|
||||||
|
echo "== Solved =="
|
||||||
|
list_by_mtime "$ROOT/solved"
|
||||||
|
if [[ -d "$ROOT/skipped" && -n "$(ls -A "$ROOT/skipped" 2>/dev/null)" ]]; then
|
||||||
|
echo
|
||||||
|
echo "== Skipped =="
|
||||||
|
list_by_mtime "$ROOT/skipped"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# usaco new <name> [io-name] [--url <link>]
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
name=""; io=""; url=""
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--url) url="${2:-}"; shift 2 ;;
|
||||||
|
*) if [[ -z "$name" ]]; then name="$1"; elif [[ -z "$io" ]]; then io="$1"; fi; shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[[ -n "$name" ]] || usage
|
||||||
|
io="${io:-$name}"
|
||||||
|
dir="$ROOT/solving/$name"
|
||||||
|
if [[ -d "$dir" || -d "$ROOT/solved/$name" || -d "$ROOT/skipped/$name" ]]; then
|
||||||
|
echo "Error: '$name' already exists" >&2; exit 1
|
||||||
|
fi
|
||||||
|
mkdir -p "$dir"
|
||||||
|
fresh_main "$dir" "$io"
|
||||||
|
touch "$dir/$io.in"
|
||||||
|
[[ -n "$url" ]] && echo "$url" > "$dir/.url"
|
||||||
|
echo "Created solving/$name (io: $io.in / $io.out)"
|
||||||
|
(cd "$dir" && exec ${EDITOR:-nvim} main.cpp)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# usaco open <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
[[ -f "$dir/.url" ]] || { echo "Error: no URL saved for '$1' (use --url with 'new', or write $dir/.url)" >&2; exit 1; }
|
||||||
|
xdg-open "$(cat "$dir/.url")" >/dev/null 2>&1 &
|
||||||
|
echo "Opening $(cat "$dir/.url")"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# usaco path <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
find_problem "$1"
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# usaco reset/rm/delete <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
name="$(basename "$dir")"
|
||||||
|
io="$(detect_io "$dir" || true)"
|
||||||
|
io="${io:-$name}"
|
||||||
|
echo "This resets ${dir#$ROOT/} to a fresh template:"
|
||||||
|
echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)"
|
||||||
|
echo " removes compiled binary and $io.out (tests/ and $io.in are kept)"
|
||||||
|
read -r -p "Reset '$name'? [y/N] " ans
|
||||||
|
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; }
|
||||||
|
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak"
|
||||||
|
fresh_main "$dir" "$io"
|
||||||
|
rm -f "$dir/main" "$dir/a.out" "$dir/$io.out"
|
||||||
|
echo "Reset $name (old solution in main.cpp.bak)"
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# usaco run <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
build_problem "$dir"
|
||||||
|
# run from inside the dir so freopen finds the .in file
|
||||||
|
(cd "$dir" && ./main)
|
||||||
|
# show the .out file if the program wrote one
|
||||||
|
out="$(ls "$dir"/*.out 2>/dev/null | grep -v '/a\.out$' | head -1 || true)"
|
||||||
|
if [[ -n "$out" ]]; then
|
||||||
|
echo "── $(basename "$out") ──"
|
||||||
|
cat "$out"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# usaco skip <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
name="$1"
|
||||||
|
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; }
|
||||||
|
[[ -d "$ROOT/skipped/$name" ]] && { echo "Error: skipped/$name already exists" >&2; exit 1; }
|
||||||
|
mkdir -p "$ROOT/skipped"
|
||||||
|
mv "$ROOT/solving/$name" "$ROOT/skipped/$name"
|
||||||
|
echo "Moved to skipped/$name (usaco undo $name to bring it back)"
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# usaco stats
|
||||||
|
count() { [[ -d "$1" ]] && find "$1" -mindepth 1 -maxdepth 1 -type d | wc -l || echo 0; }
|
||||||
|
solved=$(count "$ROOT/solved"); solving=$(count "$ROOT/solving"); skipped=$(count "$ROOT/skipped")
|
||||||
|
now=$(date +%s); week=0; month=0
|
||||||
|
if [[ -d "$ROOT/solved" ]]; then
|
||||||
|
for d in "$ROOT/solved"/*/; do
|
||||||
|
[[ -d "$d" ]] || continue
|
||||||
|
t="$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1)"
|
||||||
|
[[ -z "$t" ]] && continue
|
||||||
|
age=$(( now - t ))
|
||||||
|
(( age <= 7*86400 )) && week=$((week+1))
|
||||||
|
(( age <= 30*86400 )) && month=$((month+1))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
echo "Solved: $solved"
|
||||||
|
echo "Solving: $solving"
|
||||||
|
echo "Skipped: $skipped"
|
||||||
|
echo
|
||||||
|
echo "Solved in last 7 days: $week"
|
||||||
|
echo "Solved in last 30 days: $month"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# usaco template/tpl <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"
|
||||||
|
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak" && echo "Backed up old main.cpp -> main.cpp.bak"
|
||||||
|
cp "$ROOT/template.cpp" "$dir/main.cpp"
|
||||||
|
echo "Refreshed $dir/main.cpp from template"
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
# usaco test <name> [nums...] | usaco test create <name>
|
||||||
|
norm() { # trim trailing whitespace and trailing blank lines so diffs aren't pedantic
|
||||||
|
sed 's/[[:space:]]*$//' "$1" | awk 'NF{for(i=0;i<b;i++)print ""; b=0; print; next}{b++}'
|
||||||
|
}
|
||||||
|
|
||||||
|
test_create() { # $1 = problem dir, $2 = io basename
|
||||||
|
local dir="$1" io="$2" n
|
||||||
|
mkdir -p "$dir/tests"
|
||||||
|
n=1; while [[ -e "$dir/tests/$n.in" ]]; do n=$((n+1)); done
|
||||||
|
if [[ -s "$dir/$io.in" ]]; then
|
||||||
|
cp "$dir/$io.in" "$dir/tests/$n.in"
|
||||||
|
echo "Case $n input: took current $io.in ($(wc -l < "$dir/tests/$n.in") lines)"
|
||||||
|
else
|
||||||
|
echo "Case $n input: paste it, then Ctrl-D on an empty line"
|
||||||
|
cat > "$dir/tests/$n.in"
|
||||||
|
fi
|
||||||
|
echo "Case $n expected output: paste it, then Ctrl-D (just Ctrl-D to skip checking)"
|
||||||
|
cat > "$dir/tests/$n.out"
|
||||||
|
if [[ ! -s "$dir/tests/$n.out" ]]; then
|
||||||
|
rm "$dir/tests/$n.out"
|
||||||
|
echo "Saved tests/$n.in (no expected output — 'usaco t' will just show what it prints)"
|
||||||
|
else
|
||||||
|
echo "Saved tests/$n.in + tests/$n.out"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_case() { # $1 = dir, $2 = io, $3 = tests/N.in path; returns 0 pass, 1 fail, 2 unchecked
|
||||||
|
local dir="$1" io="$2" tin="$3" n ms start exp
|
||||||
|
n="$(basename "$tin" .in)"
|
||||||
|
cp "$tin" "$dir/$io.in"
|
||||||
|
rm -f "$dir/$io.out"
|
||||||
|
start=$(date +%s%N)
|
||||||
|
if ! (cd "$dir" && ./main); then
|
||||||
|
echo "${RED}✗ case $n CRASHED (nonzero exit)${RST}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
ms=$(( ($(date +%s%N) - start) / 1000000 ))
|
||||||
|
exp="$dir/tests/$n.out"
|
||||||
|
if [[ ! -e "$exp" ]]; then
|
||||||
|
echo "${YEL}• case $n${RST} ${DIM}(${ms}ms, no expected output)${RST} got:"
|
||||||
|
sed 's/^/ /' "$dir/$io.out" 2>/dev/null || echo " (no $io.out written)"
|
||||||
|
return 2
|
||||||
|
elif diff -q <(norm "$exp") <(norm "$dir/$io.out") >/dev/null 2>&1; then
|
||||||
|
echo "${GRN}✓ case $n${RST} ${DIM}(${ms}ms)${RST}"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "${RED}✗ case $n${RST} ${DIM}(${ms}ms)${RST}"
|
||||||
|
diff "$DIFF_COLOR" --label expected --label got -u \
|
||||||
|
<(norm "$exp") <(norm "$dir/$io.out") | sed 's/^/ /' | tail -n +3
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
sub=""
|
||||||
|
case "${1:-}" in create|add|new) sub=create; shift ;; esac
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
dir="$(find_problem "$1")"; shift || true
|
||||||
|
# io basename = the freopen filename ("<io>.in" in the problem dir)
|
||||||
|
io="$(detect_io "$dir" || true)"
|
||||||
|
[[ -n "$io" ]] || { echo "Error: no .in file in $dir — can't tell the io name" >&2; exit 1; }
|
||||||
|
|
||||||
|
if [[ "$sub" == create ]]; then
|
||||||
|
test_create "$dir" "$io"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# run mode: usaco t <name> [case-numbers...]
|
||||||
|
shopt -s nullglob
|
||||||
|
cases=("$dir"/tests/*.in)
|
||||||
|
shopt -u nullglob
|
||||||
|
if [[ ${#cases[@]} -eq 0 ]]; then
|
||||||
|
echo "No test cases yet. Create one with: usaco t create $(basename "$dir")" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ $# -gt 0 ]]; then # only the requested case numbers
|
||||||
|
picked=()
|
||||||
|
for want in "$@"; do
|
||||||
|
[[ -e "$dir/tests/$want.in" ]] || { echo "Error: tests/$want.in not found" >&2; exit 1; }
|
||||||
|
picked+=("$dir/tests/$want.in")
|
||||||
|
done
|
||||||
|
cases=("${picked[@]}")
|
||||||
|
fi
|
||||||
|
build_problem "$dir"
|
||||||
|
|
||||||
|
# keep whatever's in <io>.in/.out now, restore afterwards
|
||||||
|
tmp="$(mktemp -d)"
|
||||||
|
[[ -e "$dir/$io.in" ]] && cp "$dir/$io.in" "$tmp/in.orig"
|
||||||
|
[[ -e "$dir/$io.out" ]] && cp "$dir/$io.out" "$tmp/out.orig"
|
||||||
|
restore() {
|
||||||
|
[[ -e "$tmp/in.orig" ]] && cp "$tmp/in.orig" "$dir/$io.in"
|
||||||
|
[[ -e "$tmp/out.orig" ]] && cp "$tmp/out.orig" "$dir/$io.out"
|
||||||
|
rm -rf "$tmp"
|
||||||
|
}
|
||||||
|
trap restore EXIT
|
||||||
|
|
||||||
|
pass=0; fail=0
|
||||||
|
while IFS= read -r tin; do
|
||||||
|
rc=0; run_case "$dir" "$io" "$tin" || rc=$?
|
||||||
|
case $rc in 0) pass=$((pass+1)) ;; 1) fail=$((fail+1)) ;; esac
|
||||||
|
done < <(printf '%s\n' "${cases[@]}" | sort -V)
|
||||||
|
if [[ $fail -eq 0 ]]; then
|
||||||
|
echo "── ${GRN}$pass passed, $fail failed${RST} ──"
|
||||||
|
else
|
||||||
|
echo "── $pass passed, ${RED}$fail failed${RST} ──"
|
||||||
|
fi
|
||||||
|
[[ $fail -eq 0 ]]
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# usaco undo <name>
|
||||||
|
[[ $# -ge 1 ]] || usage
|
||||||
|
name="$1"; from=""
|
||||||
|
for s in solved skipped; do
|
||||||
|
[[ -d "$ROOT/$s/$name" ]] && from="$s" && break
|
||||||
|
done
|
||||||
|
[[ -n "$from" ]] || { echo "Error: '$name' not found in solved/ or skipped/" >&2; exit 1; }
|
||||||
|
[[ -d "$ROOT/solving/$name" ]] && { echo "Error: solving/$name already exists" >&2; exit 1; }
|
||||||
|
mv "$ROOT/$from/$name" "$ROOT/solving/$name"
|
||||||
|
echo "Moved back to solving/$name (was $from)"
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# common.sh - shared helpers for usaco commands (sourced, not executed)
|
||||||
|
# Expects ROOT to be set by the dispatcher.
|
||||||
|
|
||||||
|
CXXFLAGS=(-O2 -std=c++17 -Wall -Wextra)
|
||||||
|
|
||||||
|
find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; unique prefix ok
|
||||||
|
local name="$1" s d matches=()
|
||||||
|
for s in solving solved skipped; do
|
||||||
|
if [[ -d "$ROOT/$s/$name" ]]; then echo "$ROOT/$s/$name"; return 0; fi
|
||||||
|
done
|
||||||
|
for s in solving solved skipped; do
|
||||||
|
for d in "$ROOT/$s/$name"*/; do
|
||||||
|
[[ -d "$d" ]] && matches+=("${d%/}")
|
||||||
|
done
|
||||||
|
done
|
||||||
|
if [[ ${#matches[@]} -eq 1 ]]; then echo "${matches[0]}"; return 0; fi
|
||||||
|
if [[ ${#matches[@]} -gt 1 ]]; then
|
||||||
|
echo "Error: '$name' is ambiguous:" >&2
|
||||||
|
printf ' %s\n' "${matches[@]#$ROOT/}" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
echo "Error: problem '$name' not found in solving/, solved/, or skipped/" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
build_problem() { # $1 = problem dir
|
||||||
|
g++ "${CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
|
||||||
|
}
|
||||||
|
|
||||||
|
detect_io() { # echoes the io basename (first *.in in $1), or nothing
|
||||||
|
local f
|
||||||
|
for f in "$1"/*.in; do [[ -e "$f" ]] && basename "$f" .in && return 0; done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fresh_main() { # $1 = problem dir, $2 = io name: main.cpp from template with STDIO wired up
|
||||||
|
sed "s/^int main() {$/int main() {\n STDIO(\"$2\");/" "$ROOT/template.cpp" > "$1/main.cpp"
|
||||||
|
}
|
||||||
|
|
||||||
|
# colors (disabled when not a tty or NO_COLOR is set)
|
||||||
|
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
|
||||||
|
GRN=$'\e[32m' RED=$'\e[31m' YEL=$'\e[33m' DIM=$'\e[2m' RST=$'\e[0m'
|
||||||
|
DIFF_COLOR=--color=always
|
||||||
|
else
|
||||||
|
GRN='' RED='' YEL='' DIM='' RST=''
|
||||||
|
DIFF_COLOR=--color=never
|
||||||
|
fi
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
https://usaco.org/index.php?page=viewproblem2&cpid=644
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
4 3
|
||||||
|
|
||||||
|
1 2
|
||||||
|
2 3
|
||||||
|
3 4
|
||||||
|
|
||||||
|
3
|
||||||
|
4
|
||||||
|
1
|
||||||
|
2
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
typedef long long ll;
|
||||||
|
typedef pair<int,int> pii;
|
||||||
|
typedef vector<int> vi;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
|
||||||
|
// ----- FOR LOOPS -----
|
||||||
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||||
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||||
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||||
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||||
|
|
||||||
|
// ----- WEZ -----
|
||||||
|
#define takeI(n) int n; cin >> n
|
||||||
|
#define takeII(n,m) int n, m; cin >> n >> m
|
||||||
|
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||||
|
#define takeL(n) ll n; cin >> n
|
||||||
|
#define takeS(s) string s; cin >> s
|
||||||
|
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||||
|
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||||
|
#define whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,SZ(a)-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
|
bool is_connected(map<int,unordered_set<int>> edges) {
|
||||||
|
stack<int> stk;
|
||||||
|
unordered_set<int> seen;
|
||||||
|
|
||||||
|
stk.push(edges.begin()->first);
|
||||||
|
|
||||||
|
while (!stk.empty()) {
|
||||||
|
int node = stk.top(); stk.pop();
|
||||||
|
if (seen.count(node)) {continue;}
|
||||||
|
seen.insert(node);
|
||||||
|
for (auto nbor : edges[node]) {
|
||||||
|
stk.push(nbor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return seen.size() == edges.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_edges(map<int, unordered_set<int>> edges) {
|
||||||
|
for (auto [u, v] : edges) {
|
||||||
|
cerr << u << ": ";
|
||||||
|
for (int x : v) cerr << x << ' ';
|
||||||
|
cerr << NL;
|
||||||
|
}
|
||||||
|
cerr << NL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIO("closing");
|
||||||
|
|
||||||
|
takeII(n,m);
|
||||||
|
|
||||||
|
map<int,unordered_set<int>> edges;
|
||||||
|
F(i,0,m) {
|
||||||
|
takeII(u,v);
|
||||||
|
edges[u].insert(v);
|
||||||
|
edges[v].insert(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate so length of edges will be every node
|
||||||
|
F(i,1,n) edges[i];
|
||||||
|
|
||||||
|
|
||||||
|
FD(i,n,0) {
|
||||||
|
YESNO(is_connected(edges));
|
||||||
|
|
||||||
|
takeI(to_remove);
|
||||||
|
for (auto nbor : edges[to_remove]) {
|
||||||
|
edges[nbor].erase(to_remove);
|
||||||
|
}
|
||||||
|
edges.erase(to_remove);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
4 3
|
||||||
|
|
||||||
|
1 2
|
||||||
|
2 3
|
||||||
|
3 4
|
||||||
|
|
||||||
|
3
|
||||||
|
4
|
||||||
|
1
|
||||||
|
2
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
typedef long long ll;
|
||||||
|
typedef pair<int,int> pii;
|
||||||
|
typedef vector<int> vi;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
|
||||||
|
// ----- FOR LOOPS -----
|
||||||
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||||
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||||
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||||
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||||
|
|
||||||
|
// ----- WEZ -----
|
||||||
|
#define takeI(n) int n; cin >> n
|
||||||
|
#define takeII(n,m) int n, m; cin >> n >> m
|
||||||
|
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||||
|
#define takeL(n) ll n; cin >> n
|
||||||
|
#define takeS(s) string s; cin >> s
|
||||||
|
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||||
|
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||||
|
#define whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,SZ(a)-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
|
const int HEART_SIZE = 20;
|
||||||
|
const int HALF_SIZE = HEART_SIZE / 2;
|
||||||
|
|
||||||
|
bool is_in_love(int x, int y);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
string message = " SYSTEMATIC LOVE ";
|
||||||
|
int message_indent = (HALF_SIZE - (message.length() / 8)) - 1;
|
||||||
|
|
||||||
|
for (int y = 0; y < HEART_SIZE; ++y) {
|
||||||
|
for (int x = 0; x < HEART_SIZE; ++x) {
|
||||||
|
cout << ((is_in_love(x, y)) ? "vvvv" : " ");
|
||||||
|
|
||||||
|
if (y== HALF_SIZE-1) {
|
||||||
|
if (x == message_indent) {
|
||||||
|
cout << message.c_str();
|
||||||
|
x += (message.length()/4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_in_love(int x, int y) {
|
||||||
|
const float width = 2.2f;
|
||||||
|
const float height = 3.0f;
|
||||||
|
const float HEART_COEFFICIENT = 0.7f;
|
||||||
|
|
||||||
|
float check_x = ((static_cast<float>(x) / static_cast<float>(HEART_SIZE)) - 0.5f) * width;
|
||||||
|
float check_y = ((static_cast<float>(HEART_SIZE - y) / static_cast<float>(HEART_SIZE)) - 0.4f) * height;
|
||||||
|
|
||||||
|
float top_y = sqrt(1 - pow(check_x, 2)) + (HEART_COEFFICIENT * sqrt(abs(check_x)));
|
||||||
|
float bottom_y = -sqrt(1 - pow(check_x, 2)) + (HEART_COEFFICIENT* sqrt(abs(check_x)));
|
||||||
|
|
||||||
|
if ((bottom_y <= check_y) && (check_y <= top_y)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
https://judge.yosupo.jp/problem/zalgorithm
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
typedef long long ll;
|
||||||
|
typedef pair<int,int> pii;
|
||||||
|
typedef vector<int> vi;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
#define SP " "
|
||||||
|
|
||||||
|
// ----- FOR LOOPS -----
|
||||||
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||||
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||||
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||||
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||||
|
|
||||||
|
// ----- WEZ -----
|
||||||
|
#define takeI(n) int n; cin >> n
|
||||||
|
#define takeII(n,m) int n, m; cin >> n >> m
|
||||||
|
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||||
|
#define takeL(n) ll n; cin >> n
|
||||||
|
#define takeS(s) string s; cin >> s
|
||||||
|
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||||
|
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||||
|
#define whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,SZ(a)-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FASTIO;
|
||||||
|
takeS(s);
|
||||||
|
int n = s.size();
|
||||||
|
|
||||||
|
F(i,0,n) {
|
||||||
|
int val = 0;
|
||||||
|
F(j,0,s.size()-i) {
|
||||||
|
if (s[j] != s[j+i]) break;
|
||||||
|
++val;
|
||||||
|
}
|
||||||
|
cout << val << SP;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
abcbcba
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
mississippi
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ababacaca
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
aaaaa
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
https://usaco.org/index.php?page=viewproblem2&cpid=1276
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
typedef long long ll;
|
||||||
|
typedef pair<int,int> pii;
|
||||||
|
typedef vector<int> vi;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
|
||||||
|
// ----- FOR LOOPS -----
|
||||||
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||||
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||||
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||||
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||||
|
|
||||||
|
// ----- WEZ -----
|
||||||
|
#define takeI(n) int n; cin >> n
|
||||||
|
#define takeII(n,m) int n, m; cin >> n >> m
|
||||||
|
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||||
|
#define takeL(n) ll n; cin >> n
|
||||||
|
#define takeS(s) string s; cin >> s
|
||||||
|
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||||
|
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||||
|
#define whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,SZ(a)-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FASTIO;
|
||||||
|
|
||||||
|
takeII(n,m);
|
||||||
|
vector<tuple<int,int,int>> cows(n);
|
||||||
|
F(i,0,n) {
|
||||||
|
int s,t,c;
|
||||||
|
cin >> s >> t >> c;
|
||||||
|
cows[i] = {s,t,c};
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<tuple<int,int,int,int>> conditioners(m);
|
||||||
|
F(i,0,m) {
|
||||||
|
int a,b,p,m;
|
||||||
|
cin >> a >> b >> p >> m;
|
||||||
|
conditioners[i] = {a,b,p,m};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
https://usaco.org/index.php?page=viewproblem2&cpid=668
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
typedef long long ll;
|
||||||
|
typedef pair<int,int> pii;
|
||||||
|
typedef vector<int> vi;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
|
||||||
|
// ----- FOR LOOPS -----
|
||||||
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||||
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||||
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||||
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||||
|
|
||||||
|
// ----- WEZ -----
|
||||||
|
#define takeI(n) int n; cin >> n
|
||||||
|
#define takeII(n,m) int n, m; cin >> n >> m
|
||||||
|
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||||
|
#define takeL(n) ll n; cin >> n
|
||||||
|
#define takeS(s) string s; cin >> s
|
||||||
|
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||||
|
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||||
|
#define whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,SZ(a)-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
|
int squared_dist(int x, int y, int xx, int yy) {
|
||||||
|
int xDiff = abs(xx-x);
|
||||||
|
int yDiff = abs(yy-y);
|
||||||
|
return (xDiff * xDiff + yDiff * yDiff);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<bool> seen;
|
||||||
|
int dfs(const vector<vector<int>>& edges, int node) {
|
||||||
|
seen[node] = true;
|
||||||
|
int res = 1;
|
||||||
|
for (auto nbor : edges[node]) {
|
||||||
|
if (!seen[nbor]) res += dfs(edges, nbor);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIO("moocast");
|
||||||
|
|
||||||
|
takeI(n);
|
||||||
|
vi x(n), y(n), p(n);
|
||||||
|
F(i,0,n) {
|
||||||
|
int z;
|
||||||
|
cin >> x[i] >> y[i] >> z;
|
||||||
|
p[i] = z*z;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to graph
|
||||||
|
vector<vector<int>> edges(n);
|
||||||
|
F(i,0,n-1) {
|
||||||
|
F(j,i+1, n) {
|
||||||
|
int sq = squared_dist(x[i], y[i], x[j], y[j]);
|
||||||
|
if (sq <= p[i] || sq <= p[j]) {
|
||||||
|
edges[i].push_back(j);
|
||||||
|
edges[j].push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
seen = vector<bool>(n, false);
|
||||||
|
int ans = 0;
|
||||||
|
F(i,0,n) {
|
||||||
|
if (seen[i]) continue;
|
||||||
|
REMAX(ans, dfs(edges,i));
|
||||||
|
}
|
||||||
|
cout << ans;
|
||||||
|
|
||||||
|
// Find size of largest connected components
|
||||||
|
// Components connected if dist(X, Y) < p_x
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
4
|
||||||
|
1 3 5
|
||||||
|
5 4 3
|
||||||
|
7 2 1
|
||||||
|
6 1 1
|
||||||
|
|
||||||
@@ -1,53 +1,98 @@
|
|||||||
// #include "../../debugging.h"
|
#include <climits>
|
||||||
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void preprocessPrices(vector<long long> &prices) {
|
// ----- TYPES -----
|
||||||
for (int i = 1; i < prices.size(); i++) {
|
typedef long long ll;
|
||||||
prices[i] = min(2 * prices[i - 1], prices[i]);
|
typedef pair<int,int> pii;
|
||||||
}
|
typedef vector<int> vi;
|
||||||
}
|
|
||||||
|
|
||||||
int cheapest(const vector<long long> &prices, long long query) {
|
// ----- FILE IO -----
|
||||||
long long sum = 0;
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
|
||||||
for (int j = 0; j < prices.size(); j++) {
|
// ----- FOR LOOPS -----
|
||||||
if (query % 2 == 1) {
|
#define F(i,L,R) for (int i = L; i < R; i++)
|
||||||
sum += prices[j];
|
#define FE(i,L,R) for (int i = L; i <= R; i++)
|
||||||
}
|
#define FD(i,L,R) for (int i = L; i > R; i--)
|
||||||
query /= 2;
|
#define FDE(i,L,R) for (int i = L; i >= R; i--)
|
||||||
}
|
|
||||||
|
|
||||||
int over = 2;
|
// ----- WEZ -----
|
||||||
while (query > 0) {
|
#define takeI(n) int n; cin >> n
|
||||||
if (query % 2 == 1) {
|
#define takeII(n,m) int n, m; cin >> n >> m
|
||||||
sum += over * prices.back();
|
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k
|
||||||
}
|
#define takeL(n) ll n; cin >> n
|
||||||
over *= 2;
|
#define takeS(s) string s; cin >> s
|
||||||
query /= 2;
|
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x
|
||||||
}
|
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x
|
||||||
return sum;
|
#define whileZ takeI(T); while(T--)
|
||||||
}
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,SZ(a)-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int N, Q;
|
STDIO("pails");
|
||||||
cin >> N >> Q;
|
takeII(n,q);
|
||||||
|
|
||||||
vector<long long> prices(N);
|
|
||||||
for (int i = 0; i < N; i++) {
|
vi a(n);
|
||||||
cin >> prices[i];
|
for (auto &x : a) cin >> x;
|
||||||
|
|
||||||
|
vi querys(q);
|
||||||
|
int mx = 0;
|
||||||
|
for (auto &query : querys) {
|
||||||
|
takeI(z);
|
||||||
|
REMAX(mx,z);
|
||||||
|
query = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
preprocessPrices(prices);
|
F(i,1,n) {
|
||||||
|
a[i] = 2*a[i-1] < a[i] ? 2*a[i-1] : a[i];
|
||||||
|
}
|
||||||
|
F(i,n,log2(mx)) a.push_back(2*a[i-1]);
|
||||||
|
|
||||||
vector<long long> queries(Q);
|
while(q--) {
|
||||||
for (int i = 0; i < Q; i++) {
|
int cost = INT_MAX;
|
||||||
cin >> queries[i];
|
int running_cost = 0;
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < Q; i++) {
|
takeI(remaining);
|
||||||
cout << cheapest(prices, queries[i]) << '\n';
|
|
||||||
|
while(remaining > 0) {
|
||||||
|
int low = log2(remaining);
|
||||||
|
int high = low + 1;
|
||||||
|
REMIN(cost, running_cost + a[high]);
|
||||||
|
remaining -= pow(2,low);
|
||||||
|
running_cost += a[low];
|
||||||
|
}
|
||||||
|
REMIN(cost, running_cost);
|
||||||
|
cout << cost << NL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
2 4
|
||||||
|
10 15
|
||||||
|
1
|
||||||
|
2
|
||||||
|
6
|
||||||
|
7
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
4 10
|
||||||
|
10 25 30 70
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
15
|
||||||
|
101
|
||||||
|
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
# usaco done <name> Move solving/<name> -> solved/<name> and git commit
|
# usaco done <name> Move solving/<name> -> solved/<name> and git commit
|
||||||
# usaco undo <name> Move solved/ or skipped/<name> -> solving/<name>
|
# usaco undo <name> Move solved/ or skipped/<name> -> solving/<name>
|
||||||
# usaco skip <name> Move solving/<name> -> skipped/<name>
|
# usaco skip <name> Move solving/<name> -> skipped/<name>
|
||||||
|
# usaco io <name> [io-name] Show the problem's io name, or set it: renames <old>.in/.out
|
||||||
|
# and rewires STDIO("...") in main.cpp (adds it if missing)
|
||||||
# usaco vim <name> Open the problem's main.cpp in $EDITOR (aliases: edit, e)
|
# usaco vim <name> Open the problem's main.cpp in $EDITOR (aliases: edit, e)
|
||||||
# usaco open <name> Open the problem's saved URL in a browser
|
# usaco open <name> Open the problem's saved URL in a browser
|
||||||
# usaco list List problems by status
|
# usaco list List problems by status
|
||||||
@@ -16,186 +18,45 @@
|
|||||||
# usaco path <name> Print the problem's directory (used by the ucd shell helper)
|
# usaco path <name> Print the problem's directory (used by the ucd shell helper)
|
||||||
# usaco clean Delete compiled binaries and backups from all problem dirs
|
# usaco clean Delete compiled binaries and backups from all problem dirs
|
||||||
# usaco template <name> Re-copy template.cpp into the problem as main.cpp (backs up old one)
|
# usaco template <name> Re-copy template.cpp into the problem as main.cpp (backs up old one)
|
||||||
|
# usaco reset <name> Reset the solution: fresh main.cpp from template (STDIO wired up),
|
||||||
|
# delete binary + .out; keeps tests/ and .in (aliases: rm, delete)
|
||||||
|
# usaco test create <name> Save a test case: uses the current .in (or lets you paste one),
|
||||||
|
# then asks for the expected output. Stored in tests/N.in + N.out
|
||||||
|
# usaco test <name> [nums...] Build and run every saved test case (or just the given ones),
|
||||||
|
# diff against expected output, show pass/fail
|
||||||
|
#
|
||||||
|
# Short aliases: n=new r=run b=build t=test d=done u=undo sk=skip o=open
|
||||||
|
# l/ls=list st=stats p=path tpl=template e=edit=vim
|
||||||
#
|
#
|
||||||
# Names may be unique prefixes: 'usaco e diam' finds diamond-collector.
|
# Names may be unique prefixes: 'usaco e diam' finds diamond-collector.
|
||||||
|
#
|
||||||
|
# Implementation: each command lives in lib/cmd/<name>.sh; shared helpers in lib/common.sh.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
CXXFLAGS=(-O2 -std=c++17 -Wall -Wextra)
|
|
||||||
|
|
||||||
usage() { sed -n '2,21p' "$0" | sed 's/^# \{0,1\}//'; exit 1; }
|
usage() { awk 'NR>1 { if (!/^#/) exit; sub(/^# ?/,""); print }' "$0"; exit 1; }
|
||||||
|
|
||||||
find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; unique prefix ok
|
|
||||||
local name="$1" s d matches=()
|
|
||||||
for s in solving solved skipped; do
|
|
||||||
if [[ -d "$ROOT/$s/$name" ]]; then echo "$ROOT/$s/$name"; return 0; fi
|
|
||||||
done
|
|
||||||
for s in solving solved skipped; do
|
|
||||||
for d in "$ROOT/$s/$name"*/; do
|
|
||||||
[[ -d "$d" ]] && matches+=("${d%/}")
|
|
||||||
done
|
|
||||||
done
|
|
||||||
if [[ ${#matches[@]} -eq 1 ]]; then echo "${matches[0]}"; return 0; fi
|
|
||||||
if [[ ${#matches[@]} -gt 1 ]]; then
|
|
||||||
echo "Error: '$name' is ambiguous:" >&2
|
|
||||||
printf ' %s\n' "${matches[@]#$ROOT/}" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
echo "Error: problem '$name' not found in solving/, solved/, or skipped/" >&2
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
build_problem() { # $1 = problem dir
|
|
||||||
g++ "${CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd="${1:-}"; shift || true
|
cmd="${1:-}"; shift || true
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
new)
|
new|n) cmd=new ;;
|
||||||
[[ $# -ge 1 ]] || usage
|
run|r) cmd=run ;;
|
||||||
name=""; io=""; url=""
|
build|b) cmd=build ;;
|
||||||
while [[ $# -gt 0 ]]; do
|
test|t) cmd=test ;;
|
||||||
case "$1" in
|
done|d) cmd=done ;;
|
||||||
--url) url="${2:-}"; shift 2 ;;
|
undo|u) cmd=undo ;;
|
||||||
*) if [[ -z "$name" ]]; then name="$1"; elif [[ -z "$io" ]]; then io="$1"; fi; shift ;;
|
skip|sk) cmd=skip ;;
|
||||||
esac
|
io) cmd=io ;;
|
||||||
done
|
vim|edit|e) cmd=edit ;;
|
||||||
[[ -n "$name" ]] || usage
|
open|o) cmd=open ;;
|
||||||
io="${io:-$name}"
|
list|l|ls) cmd=list ;;
|
||||||
dir="$ROOT/solving/$name"
|
stats|st) cmd=stats ;;
|
||||||
if [[ -d "$dir" || -d "$ROOT/solved/$name" || -d "$ROOT/skipped/$name" ]]; then
|
path|p) cmd=path ;;
|
||||||
echo "Error: '$name' already exists" >&2; exit 1
|
clean) cmd=clean ;;
|
||||||
fi
|
template|tpl) cmd=template ;;
|
||||||
mkdir -p "$dir"
|
reset|rm|delete) cmd=reset ;;
|
||||||
# insert STDIO("<io>"); at the top of main() so file IO is wired up
|
|
||||||
sed "s/^int main() {$/int main() {\n STDIO(\"$io\");/" "$ROOT/template.cpp" > "$dir/main.cpp"
|
|
||||||
touch "$dir/$io.in"
|
|
||||||
[[ -n "$url" ]] && echo "$url" > "$dir/.url"
|
|
||||||
echo "Created solving/$name (io: $io.in / $io.out)"
|
|
||||||
(cd "$dir" && exec ${EDITOR:-nvim} main.cpp)
|
|
||||||
;;
|
|
||||||
path)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
find_problem "$1"
|
|
||||||
;;
|
|
||||||
clean)
|
|
||||||
for s in solving solved skipped; do
|
|
||||||
[[ -d "$ROOT/$s" ]] || continue
|
|
||||||
find "$ROOT/$s" -mindepth 2 -maxdepth 2 -type f \
|
|
||||||
\( -name main -o -name a.out -o -name '*.bak' \) -print -delete | sed "s|^$ROOT/|removed |"
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
build)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
dir="$(find_problem "$1")"
|
|
||||||
build_problem "$dir"
|
|
||||||
echo "Built $dir/main"
|
|
||||||
;;
|
|
||||||
run)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
dir="$(find_problem "$1")"
|
|
||||||
build_problem "$dir"
|
|
||||||
# run from inside the dir so freopen finds the .in file
|
|
||||||
(cd "$dir" && ./main)
|
|
||||||
# show the .out file if the program wrote one
|
|
||||||
out="$(ls "$dir"/*.out 2>/dev/null | grep -v '/a\.out$' | head -1 || true)"
|
|
||||||
if [[ -n "$out" ]]; then
|
|
||||||
echo "── $(basename "$out") ──"
|
|
||||||
cat "$out"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
done)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
name="$1"
|
|
||||||
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; }
|
|
||||||
[[ -d "$ROOT/solved/$name" ]] && { echo "Error: solved/$name already exists" >&2; exit 1; }
|
|
||||||
mv "$ROOT/solving/$name" "$ROOT/solved/$name"
|
|
||||||
echo "Moved to solved/$name 🎉"
|
|
||||||
if git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
||||||
git -C "$ROOT" add -A "solved/$name" "solving/$name" 2>/dev/null || true
|
|
||||||
git -C "$ROOT" commit -m "Solve $name" >/dev/null && echo "Committed: Solve $name"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
undo)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
name="$1"; from=""
|
|
||||||
for s in solved skipped; do
|
|
||||||
[[ -d "$ROOT/$s/$name" ]] && from="$s" && break
|
|
||||||
done
|
|
||||||
[[ -n "$from" ]] || { echo "Error: '$name' not found in solved/ or skipped/" >&2; exit 1; }
|
|
||||||
[[ -d "$ROOT/solving/$name" ]] && { echo "Error: solving/$name already exists" >&2; exit 1; }
|
|
||||||
mv "$ROOT/$from/$name" "$ROOT/solving/$name"
|
|
||||||
echo "Moved back to solving/$name (was $from)"
|
|
||||||
;;
|
|
||||||
skip)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
name="$1"
|
|
||||||
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; }
|
|
||||||
[[ -d "$ROOT/skipped/$name" ]] && { echo "Error: skipped/$name already exists" >&2; exit 1; }
|
|
||||||
mkdir -p "$ROOT/skipped"
|
|
||||||
mv "$ROOT/solving/$name" "$ROOT/skipped/$name"
|
|
||||||
echo "Moved to skipped/$name (usaco undo $name to bring it back)"
|
|
||||||
;;
|
|
||||||
vim|edit|e)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
dir="$(find_problem "$1")"
|
|
||||||
# run from inside the dir so :!./main etc. work and .in files are at hand
|
|
||||||
(cd "$dir" && exec ${EDITOR:-nvim} main.cpp)
|
|
||||||
;;
|
|
||||||
open)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
dir="$(find_problem "$1")"
|
|
||||||
[[ -f "$dir/.url" ]] || { echo "Error: no URL saved for '$1' (use --url with 'new', or write $dir/.url)" >&2; exit 1; }
|
|
||||||
xdg-open "$(cat "$dir/.url")" >/dev/null 2>&1 &
|
|
||||||
echo "Opening $(cat "$dir/.url")"
|
|
||||||
;;
|
|
||||||
list)
|
|
||||||
list_by_mtime() { # list subdirs of $1 oldest-first by last modification
|
|
||||||
[[ -d "$1" ]] || return 0
|
|
||||||
for d in "$1"/*/; do
|
|
||||||
[[ -d "$d" ]] || continue
|
|
||||||
# newest mtime of any file in the problem dir
|
|
||||||
printf '%s\t%s\n' "$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1)" "$(basename "$d")"
|
|
||||||
done | sort -n | cut -f2 | sed 's/^/ /'
|
|
||||||
}
|
|
||||||
echo "== Solving =="
|
|
||||||
list_by_mtime "$ROOT/solving"
|
|
||||||
echo
|
|
||||||
echo "== Solved =="
|
|
||||||
list_by_mtime "$ROOT/solved"
|
|
||||||
if [[ -d "$ROOT/skipped" && -n "$(ls -A "$ROOT/skipped" 2>/dev/null)" ]]; then
|
|
||||||
echo
|
|
||||||
echo "== Skipped =="
|
|
||||||
list_by_mtime "$ROOT/skipped"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
stats)
|
|
||||||
count() { [[ -d "$1" ]] && find "$1" -mindepth 1 -maxdepth 1 -type d | wc -l || echo 0; }
|
|
||||||
solved=$(count "$ROOT/solved"); solving=$(count "$ROOT/solving"); skipped=$(count "$ROOT/skipped")
|
|
||||||
now=$(date +%s); week=0; month=0
|
|
||||||
if [[ -d "$ROOT/solved" ]]; then
|
|
||||||
for d in "$ROOT/solved"/*/; do
|
|
||||||
[[ -d "$d" ]] || continue
|
|
||||||
t="$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1)"
|
|
||||||
[[ -z "$t" ]] && continue
|
|
||||||
age=$(( now - t ))
|
|
||||||
(( age <= 7*86400 )) && week=$((week+1))
|
|
||||||
(( age <= 30*86400 )) && month=$((month+1))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
echo "Solved: $solved"
|
|
||||||
echo "Solving: $solving"
|
|
||||||
echo "Skipped: $skipped"
|
|
||||||
echo
|
|
||||||
echo "Solved in last 7 days: $week"
|
|
||||||
echo "Solved in last 30 days: $month"
|
|
||||||
;;
|
|
||||||
template)
|
|
||||||
[[ $# -ge 1 ]] || usage
|
|
||||||
dir="$(find_problem "$1")"
|
|
||||||
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak" && echo "Backed up old main.cpp -> main.cpp.bak"
|
|
||||||
cp "$ROOT/template.cpp" "$dir/main.cpp"
|
|
||||||
echo "Refreshed $dir/main.cpp from template"
|
|
||||||
;;
|
|
||||||
*) usage ;;
|
*) usage ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
source "$ROOT/lib/common.sh"
|
||||||
|
source "$ROOT/lib/cmd/$cmd.sh"
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name USACO Auto-Login
|
||||||
|
// @namespace usaco-autologin
|
||||||
|
// @version 1.0
|
||||||
|
// @description Automatically signs in to usaco.org when logged out
|
||||||
|
// @match http://usaco.org/*
|
||||||
|
// @match https://usaco.org/*
|
||||||
|
// @match http://www.usaco.org/*
|
||||||
|
// @match https://www.usaco.org/*
|
||||||
|
// @grant none
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// ---- Fill these in ----
|
||||||
|
const USERNAME = "YOUR_USERNAME";
|
||||||
|
const PASSWORD = "YOUR_PASSWORD";
|
||||||
|
// -----------------------
|
||||||
|
|
||||||
|
// If a logout link exists, we're already signed in.
|
||||||
|
if (document.querySelector('a[href*="logout"]')) return;
|
||||||
|
|
||||||
|
const uname = document.querySelector('input[name="uname"]');
|
||||||
|
const pword = document.querySelector(
|
||||||
|
'input[name="password"], input[name="pword"]',
|
||||||
|
);
|
||||||
|
if (!uname || !pword) return;
|
||||||
|
|
||||||
|
// Avoid an infinite reload loop if credentials are wrong:
|
||||||
|
// only auto-submit once per minute.
|
||||||
|
const last = sessionStorage.getItem("usacoAutoLoginAt");
|
||||||
|
if (last && Date.now() - Number(last) < 60000) return;
|
||||||
|
sessionStorage.setItem("usacoAutoLoginAt", String(Date.now()));
|
||||||
|
|
||||||
|
uname.value = USERNAME;
|
||||||
|
pword.value = PASSWORD;
|
||||||
|
|
||||||
|
const form = uname.closest("form");
|
||||||
|
if (form) {
|
||||||
|
// Prefer clicking the submit button so any onclick handlers run.
|
||||||
|
const btn = form.querySelector(
|
||||||
|
'input[type="submit"], button[type="submit"], button',
|
||||||
|
);
|
||||||
|
if (btn) btn.click();
|
||||||
|
else form.submit();
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -25,28 +25,53 @@ _usaco() {
|
|||||||
local -a cmds
|
local -a cmds
|
||||||
cmds=(
|
cmds=(
|
||||||
'new:create a problem from template'
|
'new:create a problem from template'
|
||||||
|
'n:create a problem from template'
|
||||||
'run:build and run main.cpp'
|
'run:build and run main.cpp'
|
||||||
|
'r:build and run main.cpp'
|
||||||
'build:build main.cpp'
|
'build:build main.cpp'
|
||||||
|
'b:build main.cpp'
|
||||||
'vim:open main.cpp in $EDITOR'
|
'vim:open main.cpp in $EDITOR'
|
||||||
'edit:open main.cpp in $EDITOR'
|
'edit:open main.cpp in $EDITOR'
|
||||||
'e:open main.cpp in $EDITOR'
|
'e:open main.cpp in $EDITOR'
|
||||||
|
'test:run saved test cases (test create <name> to add one)'
|
||||||
|
't:run saved test cases'
|
||||||
'done:mark solved (auto-commits)'
|
'done:mark solved (auto-commits)'
|
||||||
|
'd:mark solved (auto-commits)'
|
||||||
'undo:move back to solving'
|
'undo:move back to solving'
|
||||||
|
'u:move back to solving'
|
||||||
'skip:set aside for later'
|
'skip:set aside for later'
|
||||||
|
'sk:set aside for later'
|
||||||
|
'io:show or set the freopen io name'
|
||||||
'open:open the saved problem URL'
|
'open:open the saved problem URL'
|
||||||
|
'o:open the saved problem URL'
|
||||||
'list:list problems by status'
|
'list:list problems by status'
|
||||||
|
'l:list problems by status'
|
||||||
|
'ls:list problems by status'
|
||||||
'stats:show solve counts'
|
'stats:show solve counts'
|
||||||
|
'st:show solve counts'
|
||||||
'path:print problem directory'
|
'path:print problem directory'
|
||||||
|
'p:print problem directory'
|
||||||
'clean:delete binaries and backups'
|
'clean:delete binaries and backups'
|
||||||
'template:reset main.cpp from template'
|
'template:re-copy template.cpp as main.cpp (backs up old)'
|
||||||
|
'tpl:re-copy template.cpp as main.cpp (backs up old)'
|
||||||
|
'reset:fresh main.cpp from template, delete binary/.out'
|
||||||
|
'rm:fresh main.cpp from template, delete binary/.out'
|
||||||
|
'delete:fresh main.cpp from template, delete binary/.out'
|
||||||
)
|
)
|
||||||
if (( CURRENT == 2 )); then
|
if (( CURRENT == 2 )); then
|
||||||
_describe 'command' cmds
|
_describe 'command' cmds
|
||||||
elif (( CURRENT == 3 )); then
|
elif (( CURRENT == 3 )); then
|
||||||
case "$words[2]" in
|
case "$words[2]" in
|
||||||
new|list|stats|clean) ;;
|
new|n|list|l|ls|stats|st|clean) ;; # no problem-name argument
|
||||||
|
test|t)
|
||||||
|
local -a subs
|
||||||
|
subs=('create:save a new test case' 'add:save a new test case' 'new:save a new test case')
|
||||||
|
_describe 'subcommand' subs
|
||||||
|
_usaco_problems ;;
|
||||||
*) _usaco_problems ;;
|
*) _usaco_problems ;;
|
||||||
esac
|
esac
|
||||||
|
elif (( CURRENT == 4 )) && [[ "$words[2]" == (test|t) && "$words[3]" == (create|add|new) ]]; then
|
||||||
|
_usaco_problems
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
if (( $+functions[compdef] )); then
|
if (( $+functions[compdef] )); then
|
||||||
|
|||||||
Reference in New Issue
Block a user