結果

問題 No.393 2本の竹
ユーザー E31415926E31415926
提出日時 2017-02-21 20:41:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 1,000 ms
コード長 941 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 168,436 KB
実行使用メモリ 55,296 KB
最終ジャッジ日時 2023-08-28 23:37:48
合計ジャッジ時間 5,777 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
54,952 KB
testcase_01 AC 85 ms
55,096 KB
testcase_02 AC 113 ms
54,960 KB
testcase_03 AC 87 ms
54,972 KB
testcase_04 AC 85 ms
54,960 KB
testcase_05 AC 86 ms
54,964 KB
testcase_06 AC 89 ms
54,964 KB
testcase_07 AC 91 ms
54,964 KB
testcase_08 AC 107 ms
54,992 KB
testcase_09 AC 166 ms
55,128 KB
testcase_10 AC 106 ms
54,968 KB
testcase_11 AC 115 ms
54,952 KB
testcase_12 AC 110 ms
54,960 KB
testcase_13 AC 108 ms
55,000 KB
testcase_14 AC 102 ms
55,296 KB
testcase_15 AC 66 ms
54,976 KB
testcase_16 AC 106 ms
54,952 KB
testcase_17 AC 86 ms
54,980 KB
testcase_18 AC 83 ms
55,012 KB
testcase_19 AC 62 ms
54,960 KB
testcase_20 AC 88 ms
55,012 KB
testcase_21 AC 83 ms
54,948 KB
testcase_22 AC 101 ms
54,972 KB
testcase_23 AC 111 ms
55,024 KB
testcase_24 AC 91 ms
54,952 KB
testcase_25 AC 83 ms
54,964 KB
testcase_26 AC 71 ms
55,016 KB
testcase_27 AC 136 ms
55,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
#define FI first
#define SE second
#define all(s) s.begin(),s.end()
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)

int N1, N2;
int M;
int A[66];
int dp[66][100100];

int solve() {
	cin >> N1 >> N2;
	cin >> M;
	rep(i,M)
	{
		cin >> A[i];
	}
	sort(A, A + M);
	int sum = 0;
	int ans = 0;
	rep(i,M)
	{
		rep(j,N1+1)
		{
			ans = max(ans, dp[i][j]);
			int jj = sum - j;
			if (jj < 0)
				break;
			if (j + A[i] <= N1) {
				dp[i + 1][j + A[i]] = max(dp[i + 1][j + A[i]], dp[i][j] + 1);
			}
			if (jj + A[i] <= N2) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1);
			}
		}
		sum += A[i];
	}
	rep(i,N1+1)
		ans = max(ans, dp[M][i]);
	return ans;
}

signed main() {
	int d;
	cin >> d;
	rep(i,d)
	{
		cout << solve() << endl;
		memset(A, 0, sizeof(A));
		memset(dp, 0, sizeof(dp));
	}
}
0