commit caf560fb60d1b05c58bc045a937ca42ccf1baa0b
parent c13f96b004972c363353842519edc642c00cdcbb
Author: Andrew Laack <andrew@laack.co>
Date: Fri, 13 Nov 2026 00:22:11 -0600
Moved container code, added example directory structure
Diffstat:
13 files changed, 85 insertions(+), 20 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,6 @@
+build-container:
+ podman build containers -t judge
+
+run-container:
+ cd example && \
+ timeout 5 podman run --rm -v ./code:/code:ro -v ./inputs:/inputs:ro -v ./outputs:/outputs:rw --network=none --memory=256MB --cpus 1 judge
diff --git a/ojudge/containers/Containerfile b/containers/Containerfile
diff --git a/containers/arch.txt b/containers/arch.txt
@@ -0,0 +1,22 @@
+architecture
+============
+
+each submission runs in its own container.
+
+bind mounted directories into the container should have least privileges.
+
+the follwing are bind mounted in:
+
+- /code:ro
+- /inputs:ro
+- /outputs:rw
+
+containers are responsible for:
+
+- building the program
+- executing the program
+- saving the outputs
+
+containers don't know the correct answers.
+
+containers have a timeout for total time to stop excessive build times and handle any other transient issues that may occur within the container.
diff --git a/containers/entrypoint.sh b/containers/entrypoint.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# copy out the main.ml file into the temp dir because otherwise
+# the build command will leave behind a few artifacts, but I'd rather
+# have the user code directory be read only.
+
+cp code/main.ml /tmp
+cd /tmp
+
+ocamlopt nums.cmxa str.cmxa -unsafe main.ml -o /tmp/submission.out
+chmod +x /tmp/submission.out
+
+# ./code:/code ./inputs:/inputs ./outputs:/outputs
+
+INPUTS=$(ls /inputs)
+
+for INPUT in $INPUTS; do
+ BASE=${INPUT%.*}
+ cat /inputs/$INPUT | /tmp/submission.out > /outputs/$BASE.out
+done
diff --git a/example/code/main.ml b/example/code/main.ml
@@ -0,0 +1,28 @@
+let readNext () = Scanf.scanf " %d" (fun x -> x) in
+let rec scanAll idx arr =
+ if idx >= Array.length arr then ()
+ else
+ let next = readNext () in
+ Array.set arr idx next;
+ scanAll (idx + 1) arr
+in
+let solve arr =
+ let soln = Array.make (Array.length arr) 0 in
+ let rec acc idx =
+ if idx = Array.length arr then 0
+ else
+ let best = acc (idx + 1) in
+ if idx < Array.length arr - 1 && arr.(idx) <= arr.(idx + 1) then
+ let () = soln.(idx) <- soln.(idx + 1) + 1 in
+ max soln.(idx) best
+ else
+ let () = soln.(idx) <- 1 in
+ max 1 best
+ in
+ acc 0
+in
+let numbers = readNext () in
+let arr = Array.make numbers 0 in
+let () = scanAll 0 arr in
+print_int (solve arr);
+print_newline ()
diff --git a/example/inputs/ex1.in b/example/inputs/ex1.in
@@ -0,0 +1,2 @@
+6
+2 2 1 3 4 1
diff --git a/example/inputs/ex2.in b/example/inputs/ex2.in
@@ -0,0 +1,2 @@
+3
+2 2 9
diff --git a/example/inputs/ex3.in b/example/inputs/ex3.in
@@ -0,0 +1,2 @@
+18
+1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
diff --git a/example/outputs/ex1.out b/example/outputs/ex1.out
@@ -0,0 +1 @@
+3
diff --git a/example/outputs/ex2.out b/example/outputs/ex2.out
@@ -0,0 +1 @@
+3
diff --git a/example/outputs/ex3.out b/example/outputs/ex3.out
@@ -0,0 +1 @@
+18
diff --git a/ojudge/Makefile b/ojudge/Makefile
@@ -1,8 +0,0 @@
-run-ocaml:
- dune exec ojudge
-
-build-container:
- podman build containers -t judge
-
-run-container:
- podman run --rm -it -v .:/code --network=none --memory=256MB --cpus 1 judge
diff --git a/ojudge/containers/entrypoint.sh b/ojudge/containers/entrypoint.sh
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-cd /code
-ocamlopt nums.cmxa str.cmxa -unsafe main.ml
-
-INPUTS=$(ls | grep \\.in$)
-
-for INPUT in $INPUTS; do
- BASE=${INPUT%.*}
- cat $INPUT | ./a.out > $BASE.sub.out
- diff $BASE.out $BASE.sub.out
-done