結果

問題 No.458 異なる素数の和
ユーザー nebukuro09nebukuro09
提出日時 2016-12-09 10:04:06
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 95,880 KB
実行使用メモリ 4,844 KB
最終ジャッジ日時 2023-09-02 23:26:48
合計ジャッジ時間 4,224 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 121 ms
4,380 KB
testcase_02 AC 143 ms
4,844 KB
testcase_03 AC 59 ms
4,380 KB
testcase_04 AC 67 ms
4,380 KB
testcase_05 AC 216 ms
4,376 KB
testcase_06 AC 137 ms
4,380 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 212 ms
4,376 KB
testcase_09 AC 30 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 240 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 41 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,844 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 131 ms
4,376 KB
testcase_28 AC 235 ms
4,376 KB
testcase_29 AC 22 ms
4,380 KB
testcase_30 AC 105 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import core.bitop;


void main() {
  auto N = readln.chomp.to!int;
  
  int M = 40000;
  auto pt = new bool[](M);
  foreach (i; 2..M)
    pt[i] = true;
  foreach (i; 2..M)
    if (pt[i])
      foreach (j; iota(i+i, M, i))
        pt[j] = false;

  int[] P;
  foreach (i; 2..M)
    if (pt[i])
      P ~= i;

  auto dp = new int[](100000);
  foreach (p; P) {
    foreach (i; iota(N, -1, -1))
      if (dp[i] > 0) {
        dp[p+i] = max(dp[p+i], dp[i]+1);
      }
    dp[p] = max(dp[p], 1);
  }
  writeln(dp[N] == 0 ? -1 : dp[N]);
}
0