結果

問題 No.7 プライムナンバーゲーム
ユーザー バカらっくバカらっく
提出日時 2019-08-29 23:27:17
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,046 ms / 5,000 ms
コード長 912 bytes
コンパイル時間 13,988 ms
コンパイル使用メモリ 445,692 KB
実行使用メモリ 102,776 KB
最終ジャッジ日時 2024-04-09 04:43:34
合計ジャッジ時間 24,829 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
56,820 KB
testcase_01 AC 292 ms
56,852 KB
testcase_02 AC 1,046 ms
102,772 KB
testcase_03 AC 480 ms
72,016 KB
testcase_04 AC 438 ms
61,404 KB
testcase_05 AC 435 ms
61,584 KB
testcase_06 AC 836 ms
90,320 KB
testcase_07 AC 723 ms
89,816 KB
testcase_08 AC 581 ms
75,200 KB
testcase_09 AC 699 ms
92,480 KB
testcase_10 AC 303 ms
56,816 KB
testcase_11 AC 728 ms
89,716 KB
testcase_12 AC 818 ms
98,468 KB
testcase_13 AC 861 ms
98,676 KB
testcase_14 AC 1,032 ms
102,676 KB
testcase_15 AC 1,005 ms
102,776 KB
testcase_16 AC 969 ms
102,756 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
         ^

ソースコード

diff #

fun main(args: Array<String>){
    val num = readLine()!!.toInt()
    primeList = getPrimeList(num)

    val ans = if(canWin(num)) "Win" else "Lose"
    println(ans)
}

var primeList = listOf<Int>()

val dic = mutableMapOf<Int, Boolean>()
fun canWin(num:Int): Boolean {
    if(num in (2..3)) {
        return false
    }
    dic[num]?.let { return it }

    var ret = false
    primeList.filter { it < num - 1 }.forEach{
        if(!canWin(num-it)) {
            ret = true
        }
    }
    dic[num] = ret
    return ret
}

fun getPrimeList(maxNum:Int):List<Int> {
    val flags = arrayOfNulls<Boolean>(maxNum+1)
    val list = mutableListOf<Int>()
    for (i in 2..maxNum) {
        if(flags[i] != null && flags[i]!!) {
            continue
        }
        val maxIndex = maxNum/i
        for(j in 1..maxIndex) {
            flags[i*j] = true
        }
        list.add(i)
    }
    return list.toList()
}
0