結果

問題 No.393 2本の竹
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-14 19:17:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 112 ms / 1,000 ms
コード長 1,219 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 65,888 KB
実行使用メモリ 27,572 KB
最終ジャッジ日時 2024-04-25 21:27:35
合計ジャッジ時間 3,488 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
27,292 KB
testcase_01 AC 74 ms
27,516 KB
testcase_02 AC 72 ms
27,408 KB
testcase_03 AC 70 ms
27,516 KB
testcase_04 AC 70 ms
27,380 KB
testcase_05 AC 68 ms
27,260 KB
testcase_06 AC 62 ms
27,484 KB
testcase_07 AC 71 ms
27,384 KB
testcase_08 AC 65 ms
27,292 KB
testcase_09 AC 112 ms
27,452 KB
testcase_10 AC 79 ms
27,320 KB
testcase_11 AC 84 ms
27,280 KB
testcase_12 AC 89 ms
27,468 KB
testcase_13 AC 84 ms
27,504 KB
testcase_14 AC 72 ms
27,240 KB
testcase_15 AC 23 ms
27,572 KB
testcase_16 AC 60 ms
27,384 KB
testcase_17 AC 73 ms
27,472 KB
testcase_18 AC 71 ms
27,384 KB
testcase_19 AC 49 ms
27,408 KB
testcase_20 AC 71 ms
27,408 KB
testcase_21 AC 69 ms
27,448 KB
testcase_22 AC 88 ms
27,196 KB
testcase_23 AC 82 ms
27,284 KB
testcase_24 AC 72 ms
27,468 KB
testcase_25 AC 68 ms
27,448 KB
testcase_26 AC 55 ms
27,492 KB
testcase_27 AC 101 ms
27,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int dp[61][100001];

int main(void){
	int d; cin >> d;
	while(d){
		int n1, n2; cin >> n1 >> n2;
		int sum = n1 + n2; 
		int max_n = max(n1, n2);
		int m; cin >> m;

		vector<int> a(m + 1);
		a[0] = 0;
		rep(i, m) cin >> a[i + 1];
		sort(a.begin(), a.end());

		vector<int> s(m + 1);
		s[0] = 0;
		rep(i, m) s[i + 1] += s[i] + a[i + 1];

		//rep(i, m + 1) printf("%d %d\n", a[i], s[i]);

		//初期化
		//memset(dp, -1, sizeof(dp));
		rep(i, 61)rep(j, 100001) dp[i][j] = -1;
		dp[0][n1] = 0;

		for (int i = 0; i < m; ++i){
			for (int j = 0; j <= n1 ; ++j){
				//n1から切り出す
				if(j - a[i + 1] >= 0 && dp[i][j] != -1){
					dp[i + 1][j - a[i + 1]] = dp[i][j] + 1;
					//printf("dp[%d][%d] = %d\n", i + 1, j - a[i + 1], dp[i + 1][j - a[i + 1]]);

				}
				//n2から切り出す
				if(sum - j - s[i] >= a[i + 1] && dp[i][j] != -1){
					dp[i + 1][j] = dp[i][j] + 1;
					//printf("dp[%d][%d] = %d\n", i + 1, j, dp[i + 1][j]);
				}
			}
		}
		int ans = -2;
		rep(i, 61) rep(j, 100001) ans = max(ans, dp[i][j]);
		printf("%d\n", ans);
		d--;
	}

}
0