結果

問題 No.393 2本の竹
ユーザー lapilapi
提出日時 2019-08-18 14:54:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 1,000 ms
コード長 1,582 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 111,288 KB
実行使用メモリ 29,996 KB
最終ジャッジ日時 2023-07-24 18:50:29
合計ジャッジ時間 2,547 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
28,100 KB
testcase_01 AC 7 ms
28,100 KB
testcase_02 AC 6 ms
27,920 KB
testcase_03 AC 7 ms
27,948 KB
testcase_04 AC 7 ms
27,964 KB
testcase_05 AC 6 ms
27,992 KB
testcase_06 AC 7 ms
27,960 KB
testcase_07 AC 7 ms
28,008 KB
testcase_08 AC 7 ms
27,968 KB
testcase_09 AC 60 ms
29,892 KB
testcase_10 AC 27 ms
29,732 KB
testcase_11 AC 28 ms
29,400 KB
testcase_12 AC 33 ms
29,508 KB
testcase_13 AC 20 ms
28,736 KB
testcase_14 AC 15 ms
28,668 KB
testcase_15 AC 11 ms
28,612 KB
testcase_16 AC 21 ms
29,452 KB
testcase_17 AC 7 ms
28,012 KB
testcase_18 AC 6 ms
28,004 KB
testcase_19 AC 7 ms
28,052 KB
testcase_20 AC 7 ms
28,004 KB
testcase_21 AC 7 ms
27,968 KB
testcase_22 AC 41 ms
29,872 KB
testcase_23 AC 22 ms
29,264 KB
testcase_24 AC 8 ms
28,092 KB
testcase_25 AC 7 ms
27,980 KB
testcase_26 AC 7 ms
28,096 KB
testcase_27 AC 54 ms
29,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int dp[69][100009]; // dp[i][j] : 小さい順に竹をi個使い、そのうち長さjをm1から取るときの最大個数

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int d; cin >> d;
	vector<int> ans;
	for (int q = 0; q < d; q++) {
		int n1, n2, m; cin >> n1 >> n2 >> m;
		int A[100];
		for (int i = 0; i < m; i++) cin >> A[i];
		sort(A, A + m);
		int sum[100];
		sum[0] = A[0];
		for (int i = 1; i < m; i++) sum[i] = sum[i - 1] + A[i];

		for (int i = 0; i < 65; i++) {
			for (int j = 0; j <= n1; j++) dp[i][j] = -1;
		}
		int res = 0;
		if (n1 >= A[0]) {
			dp[0][A[0]] = 1;
			res = 1;
		}
		if (n2 >= A[0]) {
			dp[0][0] = 1;
			res = 1;
		}
		for (int i = 0; i < m-1; i++) {
			for (int j = 0; j <= n1; j++) {
				if (dp[i][j] != -1) {
					if (n1 - j - A[i + 1] >= 0) {
						dp[i + 1][j + A[i + 1]] = max(dp[i + 1][j + A[i + 1]], dp[i][j] + 1);
						res = max(res, dp[i + 1][j + A[i + 1]]);
					}
					if (n2 - (sum[i] - j) - A[i + 1] >= 0) {
						dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1);
						res = max(res, dp[i + 1][j]);
					}
				}
			}
		}

		ans.push_back(res);
	}

	for (int k = 0; k < d; k++)cout << ans[k] << endl;


	return 0;
}
0