結果

問題 No.783 門松計画
ユーザー ats5515ats5515
提出日時 2019-01-11 22:56:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 83,620 KB
実行使用メモリ 53,404 KB
最終ジャッジ日時 2023-09-30 18:40:00
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,500 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
5,576 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
5,476 KB
testcase_05 AC 2 ms
5,444 KB
testcase_06 AC 2 ms
5,408 KB
testcase_07 AC 2 ms
5,420 KB
testcase_08 AC 2 ms
5,404 KB
testcase_09 AC 2 ms
5,440 KB
testcase_10 AC 134 ms
9,444 KB
testcase_11 AC 213 ms
53,404 KB
testcase_12 AC 191 ms
22,452 KB
testcase_13 AC 14 ms
11,412 KB
testcase_14 AC 42 ms
10,480 KB
testcase_15 AC 7 ms
5,516 KB
testcase_16 AC 2 ms
5,484 KB
testcase_17 AC 6 ms
5,564 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 22 ms
6,004 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
5,412 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 11 ms
6,712 KB
testcase_25 AC 4 ms
5,560 KB
testcase_26 AC 11 ms
6,136 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