結果

問題 No.5 数字のブロック
コンテスト
ユーザー H.Yamada
提出日時 2016-02-18 09:16:49
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 799 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 486 ms
コンパイル使用メモリ 105,276 KB
実行使用メモリ 9,800 KB
最終ジャッジ日時 2026-09-02 10:48:56
合計ジャッジ時間 6,923 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <limits>

inline int get_how_many(const std::vector<int>& W,std::unordered_map<int,int>& how_many,int L){

  if(how_many.end() == how_many.find(L)){
    how_many[L] = std::numeric_limits<int>::max();
    for(auto w : W){
      if(L - w >= 0){
	how_many[L] = std::min(how_many[L],get_how_many(W,how_many,L-w)+1);
      }
    }
  }
  
  return how_many[L];
}

int main(){
  int L,N;
  std::vector<int> W{};
  std::unordered_map<int,int> how_many{};
  
  std::cin >> L >> N;
  how_many.reserve(L+1);
  W.reserve(N);

  std::copy_n(std::istream_iterator<int>(std::cin),N,std::back_inserter(W));
  
  how_many[0] = 0;
  std::cout << get_how_many(W,how_many,L) << std::endl;
  
  return 0;
}
0