結果

問題 No.458 異なる素数の和
ユーザー nebukuro09nebukuro09
提出日時 2016-12-09 10:02:54
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 97,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 23:26:14
合計ジャッジ時間 4,389 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,380 KB
testcase_01 AC 130 ms
4,376 KB
testcase_02 AC 149 ms
4,376 KB
testcase_03 AC 59 ms
4,376 KB
testcase_04 AC 67 ms
4,376 KB
testcase_05 AC 227 ms
4,376 KB
testcase_06 AC 145 ms
4,380 KB
testcase_07 AC 11 ms
4,384 KB
testcase_08 AC 228 ms
4,380 KB
testcase_09 AC 32 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 250 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 44 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 141 ms
4,376 KB
testcase_28 AC 247 ms
4,376 KB
testcase_29 AC 24 ms
4,376 KB
testcase_30 AC 110 ms
4,380 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);
  }
  dp[N].writeln;
}
0