結果

問題 No.783 門松計画
ユーザー addeight2addeight2
提出日時 2019-02-08 11:44:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 769 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 146,040 KB
実行使用メモリ 4,592 KB
最終ジャッジ日時 2023-09-09 23:30:09
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,432 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,412 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,592 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,436 KB
testcase_10 AC 5 ms
4,444 KB
testcase_11 AC 26 ms
4,488 KB
testcase_12 AC 10 ms
4,428 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,408 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,412 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,428 KB
testcase_21 AC 2 ms
4,448 KB
testcase_22 WA -
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,384 KB
testcase_25 AC 2 ms
4,444 KB
testcase_26 AC 3 ms
4,564 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;
			if(W[i]+W[j]>C) continue;
			ans=max(ans,L[i]+L[j]+dfs(L[i],L[j],C-W[i]-W[j]));
		}
	}
	cout<<ans<<endl;
}
0