結果

問題 No.7 プライムナンバーゲーム
ユーザー MiyamonYMiyamonY
提出日時 2019-09-04 11:30:08
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 251 ms / 5,000 ms
コード長 593 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 6,820 KB
実行使用メモリ 29,696 KB
最終ジャッジ日時 2024-04-09 04:42:25
合計ジャッジ時間 4,949 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
29,352 KB
testcase_01 AC 113 ms
29,440 KB
testcase_02 AC 249 ms
29,696 KB
testcase_03 AC 124 ms
29,516 KB
testcase_04 AC 118 ms
29,440 KB
testcase_05 AC 116 ms
29,440 KB
testcase_06 AC 157 ms
29,328 KB
testcase_07 AC 144 ms
29,184 KB
testcase_08 AC 126 ms
29,312 KB
testcase_09 AC 177 ms
29,312 KB
testcase_10 AC 117 ms
29,552 KB
testcase_11 AC 145 ms
29,312 KB
testcase_12 AC 211 ms
29,400 KB
testcase_13 AC 217 ms
29,272 KB
testcase_14 AC 251 ms
29,696 KB
testcase_15 AC 245 ms
29,440 KB
testcase_16 AC 234 ms
29,440 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