結果

問題 No.247 線形計画問題もどき
ユーザー te-sh
提出日時 2017-05-25 16:35:08
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 108,108 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 19:25:10
合計ジャッジ時間 2,187 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const inf = 10 ^^ 9;

void main()
{
  auto c = readln.chomp.to!int;
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.to!(int[]);

  ai = ai.sort().uniq.array;
  n = ai.length;

  auto dp = new int[](c+1);
  dp[] = inf;
  dp[0] = 0;

  foreach (i; 1..c+1)
    foreach (a; ai)
      if (i >= a)
        dp[i] = min(dp[i], dp[i-a] + 1);

  auto r = dp[$-1];
  writeln(r == inf ? -1 : r);
}
0