結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2016-02-18 09:16:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 799 bytes |
コンパイル時間 | 1,353 ms |
コンパイル使用メモリ | 82,792 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 11:54:38 |
合計ジャッジ時間 | 17,202 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 32 |
ソースコード
#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; }