結果
問題 | No.458 異なる素数の和 |
ユーザー | Eliza_0x |
提出日時 | 2018-05-04 08:09:14 |
言語 | Scala(Beta) (3.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 842 bytes |
コンパイル時間 | 9,237 ms |
コンパイル使用メモリ | 272,708 KB |
実行使用メモリ | 134,640 KB |
最終ジャッジ日時 | 2023-09-12 18:55:39 |
合計ジャッジ時間 | 16,171 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
ソースコード
object Main extends App { val n = (new java.util.Scanner(System.in)).next().toInt val numbers = Array.fill(20000)(true) for ( i <- 2 until numbers.length/2 ) numbers(2*i) = false for ( i <- 3 until numbers.length ) for ( l <- 3 until numbers.length by 2; if i*l < numbers.length ) numbers(i*l) = false val primes = (0 to numbers.length).zip(numbers).filter(_._2).map(_._1).drop(2).toList var memo = Array.fill(1+primes.length, 20000)(-1) memo(0)(0) = 0 for ( (i, n) <- (1 to primes.length).zip(primes) ) { for ( l <- 0 until 20000 ) { memo(i)(l) = math.max(memo(i-1)(l), memo(i)(l)) if (memo(i-1)(l) != -1 && l+n < 20000) { memo(i)(l+n) = math.max(memo(i-1)(l)+1, memo(i)(l+n)) if (l+n==4) println("prime: " ++ n.toString) } } } println(memo(primes.length)(n)) }