結果

問題 No.393 2本の竹
ユーザー IL_mstaIL_msta
提出日時 2017-07-23 11:42:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 255 ms / 1,000 ms
コード長 2,003 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 105,812 KB
実行使用メモリ 27,520 KB
最終ジャッジ日時 2024-04-17 16:49:26
合計ジャッジ時間 4,587 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
22,252 KB
testcase_01 AC 31 ms
7,904 KB
testcase_02 AC 92 ms
23,552 KB
testcase_03 AC 86 ms
14,824 KB
testcase_04 AC 44 ms
12,896 KB
testcase_05 AC 57 ms
11,404 KB
testcase_06 AC 39 ms
9,064 KB
testcase_07 AC 108 ms
15,980 KB
testcase_08 AC 180 ms
21,996 KB
testcase_09 AC 255 ms
27,376 KB
testcase_10 AC 69 ms
10,112 KB
testcase_11 AC 113 ms
15,340 KB
testcase_12 AC 120 ms
18,792 KB
testcase_13 AC 116 ms
17,636 KB
testcase_14 AC 100 ms
16,488 KB
testcase_15 AC 49 ms
27,520 KB
testcase_16 AC 82 ms
25,088 KB
testcase_17 AC 80 ms
18,284 KB
testcase_18 AC 45 ms
12,904 KB
testcase_19 AC 20 ms
8,164 KB
testcase_20 AC 38 ms
9,320 KB
testcase_21 AC 67 ms
19,948 KB
testcase_22 AC 110 ms
14,564 KB
testcase_23 AC 108 ms
13,696 KB
testcase_24 AC 67 ms
12,136 KB
testcase_25 AC 51 ms
8,960 KB
testcase_26 AC 28 ms
8,156 KB
testcase_27 AC 238 ms
27,372 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