結果

問題 No.783 門松計画
ユーザー ats5515ats5515
提出日時 2019-01-11 22:56:21
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 583 ms
使用メモリ 54,276 KB
最終ジャッジ日時 2023-02-23 17:27:59
合計ジャッジ時間 2,256 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
7,724 KB
testcase_01 AC 1 ms
7,592 KB
testcase_02 AC 3 ms
13,736 KB
testcase_03 AC 1 ms
7,564 KB
testcase_04 AC 2 ms
7,656 KB
testcase_05 AC 2 ms
9,652 KB
testcase_06 AC 2 ms
7,612 KB
testcase_07 AC 2 ms
9,688 KB
testcase_08 AC 2 ms
7,672 KB
testcase_09 AC 2 ms
7,652 KB
testcase_10 AC 114 ms
23,872 KB
testcase_11 AC 158 ms
54,276 KB
testcase_12 AC 161 ms
38,364 KB
testcase_13 AC 15 ms
52,572 KB
testcase_14 AC 37 ms
32,164 KB
testcase_15 AC 6 ms
7,672 KB
testcase_16 AC 2 ms
7,608 KB
testcase_17 AC 6 ms
9,704 KB
testcase_18 AC 2 ms
7,588 KB
testcase_19 AC 20 ms
9,688 KB
testcase_20 AC 1 ms
9,668 KB
testcase_21 AC 1 ms
9,692 KB
testcase_22 AC 2 ms
7,656 KB
testcase_23 AC 1 ms
9,652 KB
testcase_24 AC 11 ms
15,748 KB
testcase_25 AC 4 ms
9,820 KB
testcase_26 AC 9 ms
11,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int dp[51][51][51][51];
void amax(int &res, int &a, const int &b) {
	a = max(a, b);
	res = max(res, b);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, C;
	cin >> N >> C;
	vector<pair<int, int> > A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first;
	}
	for (int i = 0; i < N; i++) {
		cin >> A[i].second;
	}
	sort(A.begin(), A.end());

	for (int j = 0; j < N; j++) {
		for (int k = 0; k < N; k++) {
			if (A[j].first != A[k].first && A[j].second + A[k].second <= C) {
				dp[2][j][k][A[j].second + A[k].second] = A[j].first + A[k].first;
			}
		}
	}
	int res = 0;

	for (int i = 2; i < C; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (A[j].first != A[k].first) {
					for (int x = 0; x < N; x++) {
						if ((j - k) * (k - x) < 0 && A[j].first != A[x].first && A[k].first != A[x].first) {
							for (int w = 0; w + A[x].second <= C; w++) {
								if (dp[i][j][k][w] != 0) {
									amax(res, dp[i + 1][k][x][w + A[x].second], dp[i][j][k][w] + A[x].first);
								}
							}
						}
					}
				}
			}
		}
	}
	/*cerr << dp[2][1][3][6] << endl;
	cerr << dp[3][3][0][9] << endl;
	cerr << dp[4][0][1][10] << endl;*/
	cout << res << endl;
}
0