結果
問題 |
No.393 2本の竹
|
ユーザー |
|
提出日時 | 2016-10-21 15:39:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 1,000 ms |
コード長 | 1,152 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 77,000 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-23 16:46:48 |
合計ジャッジ時間 | 1,774 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i)) #define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x) using namespace std; int main() { int dataset; cin >> dataset; while (dataset --) { // input int n1, n2, m; cin >> n1 >> n2 >> m; vector<int> a(m); repeat (i,m) cin >> a[i]; // roughly estimate whole(sort, a); int acc = 0; int cnt = 0; while (cnt < m and acc + a[cnt] <= n1 + n2) { acc += a[cnt]; ++ cnt; } // check the boundary vector<bool> dp(n1+1); dp[0] = true; repeat (j, cnt) { repeat_reverse (i, n1) if (dp[i]) { if (i + a[j] < n1+1) { dp[i + a[j]] = true; } } } int last = n1; while (not dp[last]) -- last; bool found = (acc - last <= n2); // output cout << (cnt - not found) << endl; } return 0; }