結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | komkomh |
提出日時 | 2019-04-26 13:21:37 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,058 ms / 5,000 ms |
コード長 | 755 bytes |
コンパイル時間 | 12,889 ms |
コンパイル使用メモリ | 439,928 KB |
実行使用メモリ | 152,736 KB |
最終ジャッジ日時 | 2024-04-09 04:39:58 |
合計ジャッジ時間 | 25,913 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 312 ms
56,916 KB |
testcase_01 | AC | 310 ms
56,884 KB |
testcase_02 | AC | 1,058 ms
152,736 KB |
testcase_03 | AC | 635 ms
85,384 KB |
testcase_04 | AC | 513 ms
65,848 KB |
testcase_05 | AC | 497 ms
65,876 KB |
testcase_06 | AC | 630 ms
103,072 KB |
testcase_07 | AC | 562 ms
98,940 KB |
testcase_08 | AC | 638 ms
90,304 KB |
testcase_09 | AC | 709 ms
117,212 KB |
testcase_10 | AC | 313 ms
56,900 KB |
testcase_11 | AC | 565 ms
98,848 KB |
testcase_12 | AC | 884 ms
134,024 KB |
testcase_13 | AC | 916 ms
136,052 KB |
testcase_14 | AC | 1,042 ms
152,548 KB |
testcase_15 | AC | 1,034 ms
148,436 KB |
testcase_16 | AC | 974 ms
146,484 KB |
ソースコード
package yukicoder fun main() { val n = readLine()!!.toInt() val primeNumbers: List<Int> = (2..n).filter { isPrimeNumber(it) } val cache: MutableMap<Int, Boolean> = mutableMapOf() fun isWin(currentNumber: Int): Boolean { if (!cache.contains(currentNumber)) { val result = primeNumbers .filter { it < currentNumber } .map { currentNumber - it } .filter { it > 1 } .any { !isWin(it) } cache.put(currentNumber, result) } return cache.get(currentNumber)!! } when (isWin(n)) { true -> println("Win") false -> println("Lose") } } fun isPrimeNumber(n: Int): Boolean = !(2 until n).any { n % it == 0 }