結果
問題 | No.393 2本の竹 |
ユーザー |
![]() |
提出日時 | 2016-07-13 21:04:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,092 bytes |
コンパイル時間 | 690 ms |
コンパイル使用メモリ | 66,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 01:08:54 |
合計ジャッジ時間 | 1,757 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 23 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>using namespace std;int n1, n2;vector<int> a;vector<int> DP;int n0,sa,n_max;bool solve(int cnt, int sum,int first);int main(){int d,m;cin >> d;for (int i = 0; i < d; i++) {cin >> n1 >> n2;cin >> m;a.resize(m);for (int j = 0; j < m; j++) {cin >> a[j];}sort(a.begin(), a.end());n0 = n1 + n2;n_max = max(n1, n2);int a_sum=0, ans=0;for (int j = 0; j < a.size(); j++) {if (a_sum + a[j] <= n0) {a_sum += a[j];ans = j + 1;}else {a.erase(a.begin() + j);j--;}}sa = n0 - a_sum;reverse(a.begin(), a.end());DP.assign(100010, 100);cout << ans - !solve(0, 0,0) << endl;}return 0;}bool solve(int cnt,int sum,int first) {for (int i = first; i < a.size(); i++) {int tmp;tmp = sum + a[i];if ((tmp >= n1 - sa&&tmp <= n1) || (tmp >= n2 - sa&&tmp <= n2)) return true;else if (tmp > n_max) continue;if (DP[tmp] < cnt) continue;else {DP[tmp] = cnt;if (solve(cnt+1, tmp,cnt+1+i)) return true;}}return false;}