Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed May 16, 2018
0 parents commit 1aa58a1
Show file tree
Hide file tree
Showing 61 changed files with 358 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Hello.
This is a bundle of scripts used to prepare competitive programming problems
The files here have the following structure:
* README.md
* problemname
* timelimit
* lib.sh
* build\_test.sh
* run.sh
* ingen
* makefile
* ingen.bin
* incf
* okgen
* makefile
* okgen.bin
* eval
* makefile
* eval.bin
* tests
* ...
* src
* ...
* stage

File descriptions:

README.md | This readme
--------- | -----------
problemname | A file that should contain exactly the problem name
timelimit | A file that should contain the time limit, in seconds
lib.sh | A bash library, used for the scripts in this bundle
build\_test.sh | ./build\_test.sh *xxx* will build *problemname*-*xxx*.in with ingen/ingen.bin with configuration incf/*xxx*
run.sh | ./run.sh *xxx* will run src/*xxx* on all the tests
ingen | Contains files related to input generation
ingen/makefile | A file that needs to make the input generator, ingen/ingen.bin
ingen/ingen.bin | The input generator. When run, a configuration file *problemname*.cf might be made available to it (depending on whether an appropriate file exists in incf). The input should be written to a file *problemname*.in.
incf | Holds various configuration files
okgen | Contains files related to ok generation
okgen/makefile | A file that needs to make the ok generator, okgen/okgen.bin
okgen/okgen.bin | A file that needs to make ok's. It will read the input from *problemname*.in and write the ok to *problemname*.ok
eval | Contains files related to evaluation
eval/makefile | A file that needs to make the evaluator, eval/eval.bin
eval/eval.bin | A file that evaluates. It will read the input file from *problemname*.in, the output file from *problemname*.out, the ok file from *problemname*.ok. It will write the score to *stdout* and the evaluation message to *stderr*.
tests | Holds tests
stage | Where evaluation happens
47 changes: 47 additions & 0 deletions build_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
#
# This builds test $problemname.$1 using ingen, incf/$1 and okgen
# Tamio-Vesa Nakajima

# include the library
source lib.sh

# Get problem name
problemname=`cat problemname`

#################
# Build input:
#################

# Build input generator
try "cd ingen && make -s && cd .." "input generator build fail"

# Copy ingen/ingen.bin and incf/$1 into stage, building an empty cf if none exists
cp ingen/ingen.bin stage/$problemname.bin
maybecp incf/$1 stage/$problemname.cf

# Build input
try "cd stage && ./$problemname.bin > ../tests/$problemname-$1.in && cd .." "input generation fail"

# Clean stage
rm stage/*

###################
# Build ok
###################

# Build ok generator
try "cd okgen && make -s && cd .." "ok generator build fil"

# Copy ok generator and input into stage
cp okgen/okgen.bin stage/$problemname.bin
cp tests/$problemname-$1.in stage/$problemname.in

# Build ok
try "cd stage && ./$problemname.bin && cd .." "ok generation fail"

# Copy ok from stage into tests
cp stage/$problemname.out tests/$problemname-$1.ok

# Clean stage
rm stage/*
Binary file added eval/eval.bin
Binary file not shown.
22 changes: 22 additions & 0 deletions eval/eval.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

int main(){
ifstream fout("aplusb.out");
ifstream fok("aplusb.ok");

int points = 0;
fok >> points;

string s1, s2;
while(fok >> s1){
if(!bool(fout >> s2) || s1 != s2){
cerr << "WA" << endl;
cout << 0 << endl;
return 0; } }

cerr << "OK" << endl;
cout << points << endl;
return 0; }
2 changes: 2 additions & 0 deletions eval/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../eval/eval.bin:
g++ eval.cpp -std=c++11 -o ../eval/eval.bin
1 change: 1 addition & 0 deletions incf/00
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions incf/01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions incf/02
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
Binary file added ingen/ingen.bin
Binary file not shown.
14 changes: 14 additions & 0 deletions ingen/ingen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <fstream>
using namespace std;

int main(){
ifstream f("aplusb.cf");
if(!f){
srand(time(nullptr));
cout << rand() << ' ' << rand() << endl; }
else {
int x;
f >> x;
cout << x << ' ' << x << endl; }
return 0; }
2 changes: 2 additions & 0 deletions ingen/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../ingen/ingen.bin:
g++ ingen.cpp -std=c++11 -o ../ingen/ingen.bin
24 changes: 24 additions & 0 deletions lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# Bash library for this project
# Tamio-Vesa Nakajima

# Tries to execute $1 ; if this succeeds, do nothing
# otherwise, output $2
try () {
if eval $1 ; then
:
else
echo $2
exit 1
fi
}

# Tries to copy $1 to $2 ; if $1 doesn't exist, creates an empty $2
maybecp () {
if [ -f $1 ] ; then
cp $1 $2
else
touch $2
fi
}
2 changes: 2 additions & 0 deletions okgen/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../okgen/okgen.bin:
g++ okgen.cpp -std=c++11 -o ../okgen/okgen.bin
Binary file added okgen/okgen.bin
Binary file not shown.
11 changes: 11 additions & 0 deletions okgen/okgen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <fstream>
using namespace std;

int main(){
ifstream f("aplusb.in");
ofstream g("aplusb.out");
long long x, y;
f >> x >> y;
g << 5 << endl;
g << x+y << endl;
return 0; }
1 change: 1 addition & 0 deletions problemname
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aplusb
107 changes: 107 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash
#
# Runs $1.cpp on all tests
# Tamio-Vesa Nakajima

# include the library
source lib.sh

# Get an appropriate timeout command
timeoutCommand=timeout

if [[ "$OSTYPE" == "darwin"* ]] ; then
timeoutCommand=gtimeout
fi

# Check if timoutCommand is valid
#try "hash $timeoutCommand$" "timeout fail"

# Get the problem name and the time limit
try "problemname=`cat problemname`" "no problemname file"
try "timelimit=`cat timelimit`" "no timelimit file"

# Make the evaluator
try "cd eval && make -s && cd .." "evaluator build fail"

# Copy the evaluator into the stage
cp eval/eval.bin stage/eval.bin

# Copy the source into the stage
try "cp src/$1 stage/$problemname.cpp" "source file missing"

# Create a temporary file to hold the problem binary
binary=`mktemp`

# Build the source
try "g++ stage/$problemname.cpp -std=c++11 -o $binary -O2" "Compile error"

# Make a temporary file to hold the table:
table=`mktemp`

# $table holds the score table
echo Test Message Time Points > $table

# Find names of all inputs
tests=`ls -1 tests | grep .in | awk -F '.' '{print $1}'`

# For all tests
for testname in $tests ; do
# Output an appropriate messgae
echo -en "Doing $testname\r"

# Clean the stage
rm stage/*

# Copy the executable into the stage
cp $binary stage/$problemname.bin

# Copy the input into the stage
cp tests/$testname.in stage/$problemname.in

# This string runs the competitor's executable
runExec="./$problemname.bin > /dev/null 2> /dev/null"

# This string runs the competitors executable with an appropriate timeout
runExecWithTimeout="$timeoutCommand $timelimit $runExec"

# Run the competitors executable with a timeout, and store the time used in timeUsed
timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \
| head -2 \
| awk -F ' ' '{print $2}' \
| awk -F 'm' '{print $2}' \
| awk -F 's' '{print $1}' && cd ..)

if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then
# Print that this testcase resulted in a TLE
echo $testname TLE $timeUsed 0 >> $table
else
# Copy the evaluator into the stage
cp eval/eval.bin stage/eval.bin

# Copy the ok file into the stage
cp tests/$testname.ok stage/$problemname.ok

# Create temporary files to hold the points and the eval message
points=`mktemp`
message=`mktemp`

# Enter the stage and evaluate, storing the results in $points and $message
try "cd stage && ./eval.bin > $points 2> $message && cd .." "eval error"

# Add the relevant information into the table
echo $testname `cat $message` $timeUsed `cat $points` >> $table
fi
done

# Output the table
column -t $table

# Calculate the score
echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table`

# Clear the temporary files
rm $table
rm $binary

# And the stage
rm stage/*
10 changes: 10 additions & 0 deletions src/ok.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <fstream>
using namespace std;

int main(){
ifstream f("aplusb.in");
ofstream g("aplusb.out");
long long x, y;
f >> x >> y;
g << x+y << endl;
return 0; }
2 changes: 2 additions & 0 deletions src/tle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
int main(){
while(true){} }
4 changes: 4 additions & 0 deletions src/wa.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <iostream>
using namespace std;

int main(){}
1 change: 1 addition & 0 deletions tests/aplusb-00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-00.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1
2 changes: 2 additions & 0 deletions tests/aplusb-01.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
2
1 change: 1 addition & 0 deletions tests/aplusb-02.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 2
2 changes: 2 additions & 0 deletions tests/aplusb-02.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
4
1 change: 1 addition & 0 deletions tests/aplusb-03.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-03.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-04.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-04.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-05.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-05.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-06.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-06.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-07.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-07.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-08.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-08.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-09.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-09.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-10.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-10.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-11.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-11.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-12.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-12.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-13.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-13.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-14.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-14.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-15.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-15.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
1 change: 1 addition & 0 deletions tests/aplusb-16.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
2 changes: 2 additions & 0 deletions tests/aplusb-16.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
Loading

0 comments on commit 1aa58a1

Please sign in to comment.