結果

問題 No.393 2本の竹
ユーザー kurenai3110kurenai3110
提出日時 2016-07-13 21:49:17
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,098 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 69,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-08 03:31:57
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 15 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0