結果
問題 |
No.50 おもちゃ箱
|
ユーザー |
|
提出日時 | 2025-06-27 06:19:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 5,000 ms |
コード長 | 675 bytes |
コンパイル時間 | 1,803 ms |
コンパイル使用メモリ | 198,720 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-27 06:19:33 |
合計ジャッジ時間 | 3,723 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> A(N); for(auto &a : A) cin >> a; int M; cin >> M; vector<int> B(M); for(auto &b : B) cin >> b; int n2 = 1<<N; vector<int> S(n2); for(int i=0; i<n2; i++) for(int k=0; k<N; k++) if(i&(1<<k)) S.at(i) += A.at(k); vector<int> dp(n2,1001001001); dp.at(0) = 0; for(auto b : B) for(int i=n2-1; i>=0; i--) for(int k=0; k<n2; k++) if((i&k) == 0) if(S.at(k) <= b) dp.at(i+k) = min(dp.at(i+k),dp.at(i)+1); if(dp.back() == 1001001001) dp.back() = -1; cout << dp.back() << endl; }