結果

問題 No.458 異なる素数の和
ユーザー htkbhtkb
提出日時 2018-06-04 22:13:08
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 764 bytes
コンパイル時間 10,650 ms
コンパイル使用メモリ 437,544 KB
実行使用メモリ 58,024 KB
最終ジャッジ日時 2024-04-30 18:34:31
合計ジャッジ時間 23,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
57,692 KB
testcase_01 AC 392 ms
57,804 KB
testcase_02 AC 473 ms
57,804 KB
testcase_03 AC 353 ms
57,940 KB
testcase_04 AC 363 ms
57,864 KB
testcase_05 AC 491 ms
57,984 KB
testcase_06 AC 399 ms
57,808 KB
testcase_07 AC 314 ms
57,788 KB
testcase_08 AC 495 ms
57,880 KB
testcase_09 AC 354 ms
57,780 KB
testcase_10 AC 304 ms
55,220 KB
testcase_11 AC 527 ms
57,912 KB
testcase_12 AC 318 ms
57,696 KB
testcase_13 WA -
testcase_14 AC 300 ms
57,784 KB
testcase_15 AC 310 ms
57,820 KB
testcase_16 AC 356 ms
57,936 KB
testcase_17 AC 303 ms
57,780 KB
testcase_18 AC 308 ms
57,784 KB
testcase_19 AC 306 ms
57,684 KB
testcase_20 AC 310 ms
57,772 KB
testcase_21 AC 309 ms
57,688 KB
testcase_22 AC 317 ms
57,928 KB
testcase_23 AC 304 ms
57,688 KB
testcase_24 AC 316 ms
57,828 KB
testcase_25 AC 311 ms
57,688 KB
testcase_26 AC 316 ms
57,684 KB
testcase_27 AC 394 ms
57,916 KB
testcase_28 AC 519 ms
57,892 KB
testcase_29 AC 351 ms
58,024 KB
testcase_30 AC 373 ms
57,792 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    if (N <= 3) { println(-1); return; }
    val primes = mutableListOf<Int>(2, 3)
    for (i in 5 until N step 6) primes.add(i)
    for (i in 7 until N step 6) primes.add(i)
    for (i in 5 until N step 6) {
        if (primes.contains(i)) {
            for (j in i*3 until N step i*2) primes.remove(j)
        }
        if (primes.contains(i+2)) {
            for (j in i*3+6 until N step i*2+4) primes.remove(j)
        }
    }

    val dp = Array(N+1, {0})
    for (n in primes) {
        for (i in N-n downTo 0) if (dp[i] > 0) dp[i+n] = Math.max(dp[i+n], dp[i]+1)
        dp[n] = Math.max(dp[n], 1)
    }
    println(if (dp[N] > 0) dp[N] else -1)
}
0