結果

問題 No.783 門松計画
ユーザー leaf_1415leaf_1415
提出日時 2019-01-11 22:06:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 930 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 52,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 06:39:52
合計ジャッジ時間 2,794 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int n, c;
int l[55], w[55];
int memo[55][55][55];

int calc(int x, int pp, int p)
{
	if(memo[x][pp][p] != -1) return memo[x][pp][p];
	
	int ret = 0;
	for(int i = 1; i <= n; i++){
		if(pp < p && l[i] > p) continue;
		if(pp > p && l[i] < p) continue;
		if(l[i] == p || l[i] == pp) continue;
		if(x+w[i] > c) continue;
		ret = max(ret, calc(x+w[i], p, l[i]) + l[i]);
	}
	return memo[x][pp][p] = ret;
}

int main(void)
{
	cin >> n >> c;
	for(int i = 1; i <= n; i++) cin >> l[i];
	for(int i = 1; i <= n; i++) cin >> w[i];
	
	for(int i = 0; i < 55; i++){
		for(int j = 0; j < 55; j++){
			for(int k = 0; k < 55; k++){
				memo[i][j][k] = -1;
			}
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(l[i] == l[j]) continue;
			if(w[i]+w[j] > c) continue;
			ans = max(ans, calc(w[i]+w[j], l[i], l[j]) + l[i]+l[j]);
		}
	}
	cout << ans << endl;
	return 0;
}
0