結果

問題 No.783 門松計画
ユーザー addeight2addeight2
提出日時 2019-02-08 11:51:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 144,448 KB
実行使用メモリ 4,672 KB
最終ジャッジ日時 2023-09-30 18:43:27
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,396 KB
testcase_01 AC 2 ms
4,504 KB
testcase_02 AC 3 ms
4,456 KB
testcase_03 AC 3 ms
4,408 KB
testcase_04 AC 2 ms
4,412 KB
testcase_05 AC 2 ms
4,448 KB
testcase_06 AC 3 ms
4,432 KB
testcase_07 AC 3 ms
4,464 KB
testcase_08 AC 2 ms
4,608 KB
testcase_09 AC 2 ms
4,464 KB
testcase_10 AC 5 ms
4,440 KB
testcase_11 AC 27 ms
4,436 KB
testcase_12 AC 11 ms
4,672 KB
testcase_13 AC 4 ms
4,400 KB
testcase_14 AC 3 ms
4,444 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,392 KB
testcase_17 AC 2 ms
4,412 KB
testcase_18 AC 2 ms
4,436 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,576 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,556 KB
testcase_23 AC 2 ms
4,444 KB
testcase_24 AC 3 ms
4,436 KB
testcase_25 AC 2 ms
4,392 KB
testcase_26 AC 3 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const ll MAX_L=50,MAX_C=50,MAX_N=50;
ll N,C,L[MAX_N],W[MAX_N];
ll dp[MAX_L+1][MAX_L+1][MAX_C+1];
ll dfs(ll l,ll m,ll c){
	if(dp[l][m][c]!=-1){
		return dp[l][m][c];
	}
	ll ret=0;
	REP(i,N){
		if(W[i]>c)continue;
		if(L[i]==l || L[i]==m)continue;
		if(m<min(L[i],l) || m>max(L[i],l)){
			ret=max(ret,dfs(m,L[i],c-W[i])+L[i]);
		}
	}
	return dp[l][m][c]=ret;
}
int main(){
	cin>>N>>C;
	REP(i,N){
		cin>>L[i];
	}
	REP(i,N)cin>>W[i];
	ll ans=0;
	memset(dp,-1,sizeof(dp));
	REP(i,N){
		REP(j,N){
			if(L[i]==L[j]) continue;
			REP(k,N){
				if(L[k]==L[i] || L[k]==L[j])continue;
				if(W[i]+W[j]+W[k]>C)continue;
				if(L[j]<min(L[i],L[k]) || L[j]>max(L[i],L[k])){
					ans=max(ans,L[i]+L[j]+L[k]+dfs(L[j],L[k],C-W[i]-W[j]-W[k]));
				}
			}
		}
	}
	
	cout<<ans<<endl;
}
0