結果

問題 No.393 2本の竹
ユーザー lapilapi
提出日時 2019-08-18 14:54:24
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 68 ms / 1,000 ms
コード長 1,582 bytes
コンパイル時間 981 ms
使用メモリ 28,792 KB
最終ジャッジ日時 2022-11-25 02:23:06
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,932 KB
testcase_01 AC 2 ms
3,908 KB
testcase_02 AC 2 ms
3,912 KB
testcase_03 AC 2 ms
3,908 KB
testcase_04 AC 2 ms
3,680 KB
testcase_05 AC 2 ms
3,876 KB
testcase_06 AC 2 ms
3,792 KB
testcase_07 AC 2 ms
3,976 KB
testcase_08 AC 2 ms
4,064 KB
testcase_09 AC 68 ms
28,792 KB
testcase_10 AC 27 ms
26,616 KB
testcase_11 AC 27 ms
20,116 KB
testcase_12 AC 34 ms
22,568 KB
testcase_13 AC 18 ms
12,980 KB
testcase_14 AC 13 ms
10,940 KB
testcase_15 AC 7 ms
10,808 KB
testcase_16 AC 22 ms
23,128 KB
testcase_17 AC 2 ms
3,880 KB
testcase_18 AC 1 ms
3,916 KB
testcase_19 AC 2 ms
3,876 KB
testcase_20 AC 2 ms
4,048 KB
testcase_21 AC 2 ms
4,004 KB
testcase_22 AC 42 ms
26,628 KB
testcase_23 AC 21 ms
20,516 KB
testcase_24 AC 2 ms
4,928 KB
testcase_25 AC 2 ms
4,152 KB
testcase_26 AC 2 ms
3,876 KB
testcase_27 AC 60 ms
28,756 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