結果

問題 No.393 2本の竹
ユーザー lapilapi
提出日時 2019-08-18 14:53:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,540 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 111,616 KB
実行使用メモリ 30,432 KB
最終ジャッジ日時 2024-04-09 02:15:39
合計ジャッジ時間 2,795 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
28,268 KB
testcase_01 AC 6 ms
28,136 KB
testcase_02 AC 7 ms
28,256 KB
testcase_03 AC 7 ms
28,260 KB
testcase_04 AC 7 ms
28,012 KB
testcase_05 AC 7 ms
28,016 KB
testcase_06 AC 7 ms
28,144 KB
testcase_07 AC 7 ms
28,132 KB
testcase_08 AC 7 ms
28,000 KB
testcase_09 AC 66 ms
28,928 KB
testcase_10 AC 31 ms
30,372 KB
testcase_11 AC 33 ms
28,712 KB
testcase_12 AC 37 ms
28,924 KB
testcase_13 AC 22 ms
30,380 KB
testcase_14 AC 15 ms
28,340 KB
testcase_15 AC 11 ms
28,584 KB
testcase_16 WA -
testcase_17 AC 7 ms
27,996 KB
testcase_18 WA -
testcase_19 AC 7 ms
28,128 KB
testcase_20 AC 7 ms
28,144 KB
testcase_21 WA -
testcase_22 AC 46 ms
28,764 KB
testcase_23 WA -
testcase_24 AC 7 ms
28,152 KB
testcase_25 AC 7 ms
28,268 KB
testcase_26 AC 6 ms
28,140 KB
testcase_27 AC 57 ms
28,880 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;
		if (n2 >= A[0]) dp[0][0] = 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