結果

問題 No.7 プライムナンバーゲーム
ユーザー MiyamonYMiyamonY
提出日時 2019-09-04 11:30:08
言語 Scheme
(Gauche-0.9.13)
結果
AC  
実行時間 243 ms / 5,000 ms
コード長 593 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 5,392 KB
実行使用メモリ 26,888 KB
最終ジャッジ日時 2023-07-24 21:23:15
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
22,364 KB
testcase_01 AC 102 ms
22,352 KB
testcase_02 AC 239 ms
24,124 KB
testcase_03 AC 110 ms
22,388 KB
testcase_04 AC 103 ms
22,492 KB
testcase_05 AC 104 ms
22,408 KB
testcase_06 AC 147 ms
22,748 KB
testcase_07 AC 131 ms
22,408 KB
testcase_08 AC 115 ms
22,320 KB
testcase_09 AC 164 ms
22,828 KB
testcase_10 AC 100 ms
22,392 KB
testcase_11 AC 134 ms
22,616 KB
testcase_12 AC 204 ms
23,628 KB
testcase_13 AC 209 ms
26,888 KB
testcase_14 AC 243 ms
24,000 KB
testcase_15 AC 233 ms
23,860 KB
testcase_16 AC 225 ms
23,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(use math.prime)

(let ((n (read)))
  (define primes (filter small-prime? (iota (+ n 1))))

  (define result
    (let loop ((i 0)
	       (vec (make-vector (+ n 1) 0)))
      (cond ((= i (+ n 1))
	     (vector-ref vec n))
	    (else
	     (let1 winner
		   (if (<= i 3)
		       2
		       (let check-win ((ps primes))
			 (if (null? ps)
			     2
			     (let1 pred (- i (car ps))
				   (if (and (>= pred 2) (= (vector-ref vec pred) 2))
				       1
				       (check-win (cdr ps)))))))
		   (vector-set! vec i winner)
		   (loop (+ i 1) vec))))))

  (print (if (= result 1) "Win" "Lose")))
0