結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2016-07-13 21:49:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,098 bytes |
| コンパイル時間 | 651 ms |
| コンパイル使用メモリ | 66,984 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 09:24:56 |
| 合計ジャッジ時間 | 1,763 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 WA * 1 |
ソースコード
#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,i+1)) return true;
}
}
return false;
}
kurenai3110