diff --git a/CLAUDE.md b/CLAUDE.md index 82c5de4..9984074 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -28,6 +28,9 @@ am t .rs # Rust # 浮動小数点誤差を許容するテスト am tf .java +# タイムアウトを変更してテスト(デフォルト4秒) +OJ_TLE=2 am t .java # 制限時間を2秒に上書き + # コード提出 am s .java # 各言語の拡張子を指定 @@ -81,6 +84,7 @@ makefileで管理(`/root/lib/.support/makefile`へのシンボリックリン - C++ は `am t .cpp` で常に `/judge` ディレクトリ方式(Judge 環境と同じ)でコンパイル・実行されます。問題ディレクトリに `a.out` が生成されないため、クリーンな開発環境を維持できます。 - Elixir は `am t .ex` で常に Mix release(judge 環境と同じ方式)でビルドされます。ビルド時間が短いため、開発効率とjudge環境との完全一致を両立できます。 - JavaScript は `am t .js` で常に64MBスタックサイズ(judge 環境と同じ)で実行されます。デフォルトのNode.jsスタック(約1MB)と異なり、再帰処理でのスタックオーバーフローを防ぎます。 +- `am t` / `am tf` は `oj` の `--tle` により各テストケースを**デフォルト4秒**で打ち切ります(makefile の `OJ_TLE` 変数)。AtCoder の標準制限は2秒ですが、Dev Container は judge より遅い場合があるため誤TLEを避けて余裕を持たせています。無限ループや極端に遅いコードでもハングせず `TLE` と表示されます。問題ごとに変更する場合は `OJ_TLE=2 am t .java` のように環境変数で上書きできます(秒数は正の整数で指定)。 ### テンプレート設定 `atcoder-cli-nodejs/config.json`の`default-template`で指定: diff --git a/lib/.support/makefile b/lib/.support/makefile index c8c8ea2..94006a4 100644 --- a/lib/.support/makefile +++ b/lib/.support/makefile @@ -132,7 +132,26 @@ OJ_SFLAGS = -l 6077 endif OJ = oj -OJ_TFLAGS = -c '$(RUN_TEST)' --ignore-spaces-and-newline +# Per-case time limit, a positive integer number of seconds. AtCoder's +# standard limit is 2s, but the dev container can be slower than the judge, +# so allow extra headroom to avoid false TLE. Override per task with e.g. +# `OJ_TLE=2 am t .java`. +OJ_TLE ?= 4 +# Fail fast on a non-positive-integer OJ_TLE instead of handing a bad value to +# oj (e.g. OJ_TLE=0 would make every case TLE, OJ_TLE=abc errors deep in oj). +# Validate with Make built-ins only (no shell), so a value containing quotes or +# shell metacharacters cannot break or inject into a command. +# Strip every digit: a non-empty remainder means a non-digit char is present. +OJ_TLE_NONDIGIT := $(strip $(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(OJ_TLE)))))))))))) +# Strip zeros: an empty remainder means the value is empty or all-zero. +OJ_TLE_NONZERO := $(strip $(subst 0,,$(OJ_TLE))) +ifneq ($(OJ_TLE_NONDIGIT),) +$(error OJ_TLE must be a positive integer number of seconds, got: '$(OJ_TLE)') +endif +ifeq ($(OJ_TLE_NONZERO),) +$(error OJ_TLE must be a positive integer number of seconds, got: '$(OJ_TLE)') +endif +OJ_TFLAGS = -c '$(RUN_TEST)' --ignore-spaces-and-newline --tle $(OJ_TLE) OJ_TFLAGS_FLOAT = -e 1e-6 TASK:=$$(basename $(CURDIR))