Skip to main content

__debug's Home Keep it simple, stupid

OI in Linux

Update log

UPD 2016.04.26: 更新了编译函数

UPD 2016.05.22: 去掉 global-linum-mode, 因为在大文件中打开 linum-mode 会让 M-> 等命令变得很慢, 故仅在 c++-mode 中开启 linum-mode

UPD 2016.07.10: 编译选项加入了 -Wshadow

UPD 2016.08.11: 更新了各种小地方… jury.sh 变强大了很多

比赛时的 Emacs 配置

追求在最少的行数中实现必要的功能.

(set-background-color "#1B1D1E")
(set-foreground-color "white")

(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(winner-mode t)
(show-paren-mode t)

(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "C-h") 'backward-delete-char)
(global-set-key (kbd "M-h") 'backward-kill-word)

(defun myc++()
  (setq c-basic-offset 4)
  (linum-mode t)
  (c-toggle-hungry-state t)
  (defun compile-and-run ()
    (interactive)
    (setq file-name (file-name-nondirectory buffer-file-name))
    (compile
     (format "g++ %s -o %s -g -O2 -Wall -Wextra -Wshadow && time ./%s "
	     file-name
	     (file-name-sans-extension file-name)
	     (file-name-sans-extension file-name))))
  (local-set-key (kbd "C-c C-c") 'compile-and-run)
  (local-set-key (kbd "C-c C-k") 'kill-compilation))
(add-hook 'c++-mode-hook 'myc++)

对拍

while true; do
    python gen.py || break
    ./a || break
    ./a_bf || break
    diff a.out a_bf.out || break
    echo -n "."
done

评测脚本

简单版: (感谢 PPFish 的帮助)

proname=helloworld
totscore=0
totcase=0

cd ../data/$proname
rm -f "$proname.in"
for inputfile in *.in
do
    outputfile="${inputfile/%.in/.out}"
    cp -f $inputfile "$proname.in"
    time "../../modified/$proname/$proname"
    if diff -Bbq $outputfile "$proname.out"; then
	echo \"$inputfile\" accept
	((++totscore))
    else
	echo \"$inputfile\" wrong anwser
    fi
    ((++totcase))
done

echo $totscore / $totcase

复杂版:

red='\033[0;31m'
green='\033[0;32m'
cyan='\033[0;36m'
gray='\033[0;37m'
reset='\033[0m'

proname=$1
totscore=0
totcase=0

ulimit -s 1048576

cd ../../data/$proname || exit 1
rm -f $proname.in

for inputfile in *.in
do
    echo -e "${gray}Testing \"$inputfile\"...${reset}"

    if [ -f "${inputfile/%.in/.out}" ];
    then
	outputfile="${inputfile/%.in/.out}"
    elif [ -f "${inputfile/%.in/.ans}" ];
    then
	outputfile="${inputfile/%.in/.ans}"
    else
	echo -e "${red}ERR ${reset}the corresponding answer file of \"$inputfile\" does not exist"
	continue
    fi

    cp -f $inputfile $proname.in

    start=$(date +%s.%N)
    if ! { ../../modified/$proname/$proname; } &> /dev/null;
    then
	echo -e "${cyan}Status:       ${red}Runtime Error${reset}"
    else
	end=$(date +%s.%N)
	echo -ne "${cyan}Time elapsed: ${reset}"
	echo "$end $start" | awk '{printf "%.3f s\n", $1 - $2}'

	if diff -Bbq $outputfile $proname.out &> /dev/null;
	then
	    echo -e "${cyan}Status:       ${green}Accept${reset}"
	    ((++totscore))
	else
	    echo -e "${cyan}Status:       ${red}Wrong Answer${reset}"
	fi
    fi
    ((++totcase))
done

echo
echo -e "${cyan}Total score: ${reset}$totscore / $totcase"
if [ $totcase == 0 ];
then
    echo -e "${red}===== NO TEST DATA =====${reset}"
elif [ $totscore == $totcase ];
then
    echo -e "${green}====== ACCEPTED ======${reset}"
else
    echo -e "${red}====== NOT ACCEPTED ======${reset}"
fi

Comments

Comments powered by Disqus