結果

問題 No.393 2本の竹
ユーザー IL_mstaIL_msta
提出日時 2017-07-23 11:42:52
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 202 ms / 1,000 ms
コード長 2,003 bytes
コンパイル時間 821 ms
使用メモリ 27,372 KB
最終ジャッジ日時 2022-12-02 07:39:23
合計ジャッジ時間 5,209 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 75 ms
22,172 KB
testcase_01 AC 26 ms
7,644 KB
testcase_02 AC 72 ms
23,304 KB
testcase_03 AC 69 ms
14,920 KB
testcase_04 AC 36 ms
13,000 KB
testcase_05 AC 47 ms
11,456 KB
testcase_06 AC 31 ms
9,080 KB
testcase_07 AC 89 ms
15,832 KB
testcase_08 AC 145 ms
22,052 KB
testcase_09 AC 202 ms
27,288 KB
testcase_10 AC 56 ms
10,256 KB
testcase_11 AC 91 ms
15,112 KB
testcase_12 AC 99 ms
18,736 KB
testcase_13 AC 95 ms
17,420 KB
testcase_14 AC 79 ms
16,360 KB
testcase_15 AC 38 ms
27,372 KB
testcase_16 AC 64 ms
25,012 KB
testcase_17 AC 64 ms
18,280 KB
testcase_18 AC 36 ms
13,032 KB
testcase_19 AC 16 ms
8,256 KB
testcase_20 AC 31 ms
9,336 KB
testcase_21 AC 55 ms
19,836 KB
testcase_22 AC 90 ms
14,344 KB
testcase_23 AC 88 ms
13,648 KB
testcase_24 AC 55 ms
12,212 KB
testcase_25 AC 43 ms
9,032 KB
testcase_26 AC 24 ms
8,180 KB
testcase_27 AC 182 ms
27,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

/*
thx
http://hamayanhamayan.hatenablog.jp/entry/2016/07/13/160541
*/
void solve(){
	int D;
	cin >> D;
while(D--){
	int N1,N2;
	cin >> N1 >> N2;
	int M;
	cin >> M;
	vector<int> A(M);
	vector<int> sum(M,0);
	for(int i=0;i<M;++i){
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	for(int i=0;i<M;++i){
		if( i ) sum[i] += sum[i-1];
		sum[i] += A[i];
	}
	const int MAX = 100000;
	vector< vector<int> > dp(M+1,vector<int>(MAX+1,0));
	dp[0][0] = 1;
	int ans = 1;
	for(int i=0;i<M;++i){
		for(int j=0;j<=MAX;++j){//N1に使っている長さ
			if( dp[i][j] ){
				int Len1 = N1-j;
				int Len2 = N2-(sum[i]-A[i]-j);
				if( A[i] <= Len1 ){
					dp[i+1][j+A[i]] = max(dp[i+1][j+A[i]],dp[i][j]+1);
					ans = max(ans,dp[i+1][j+A[i]]);
				}
				if( A[i] <= Len2 ){
					dp[i+1][j] = max(dp[i+1][j],dp[i][j]+1);
					ans = max(ans,dp[i+1][j]);
				}
			}
		}
	}
	cout << ans-1 << endl;
}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()
0