結果

問題 No.7 プライムナンバーゲーム
ユーザー rutilicusrutilicus
提出日時 2020-09-02 21:21:37
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 351 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 12,990 ms
コンパイル使用メモリ 433,996 KB
実行使用メモリ 57,232 KB
最終ジャッジ日時 2024-04-09 05:00:14
合計ジャッジ時間 19,675 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 290 ms
56,860 KB
testcase_01 AC 284 ms
56,796 KB
testcase_02 AC 346 ms
57,128 KB
testcase_03 AC 313 ms
56,952 KB
testcase_04 AC 296 ms
56,680 KB
testcase_05 AC 294 ms
56,780 KB
testcase_06 AC 332 ms
56,968 KB
testcase_07 AC 335 ms
57,232 KB
testcase_08 AC 319 ms
57,100 KB
testcase_09 AC 346 ms
57,044 KB
testcase_10 AC 290 ms
56,728 KB
testcase_11 AC 335 ms
57,192 KB
testcase_12 AC 351 ms
57,204 KB
testcase_13 AC 350 ms
57,108 KB
testcase_14 AC 344 ms
57,068 KB
testcase_15 AC 343 ms
57,092 KB
testcase_16 AC 344 ms
57,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:30:13: warning: 'appendln(String?): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(if (wins[n]) "Win" else "Lose")
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val isPrime = BooleanArray(n + 1) { true }
    val wins = BooleanArray(n + 1) { false }
    val primeSet = mutableSetOf<Int>()

    wins[0] = true
    wins[1] = true
    isPrime[0] = false
    isPrime[1] = false

    for (i in 2..n) {
        if (isPrime[i]) {
            primeSet.add(i)
            for (j in i * 2..n step i) {
                isPrime[j] = false
            }
        }
        for (p in primeSet) {
            if (!wins[i - p]) {
                wins[i] = true
                break
            }
        }
    }

    builder.appendln(if (wins[n]) "Win" else "Lose")

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0