結果

問題 No.1792 科学の甲子園
ユーザー startcppstartcpp
提出日時 2021-12-21 00:58:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 4,000 ms
コード長 1,742 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 80,536 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 18:41:26
合計ジャッジ時間 2,253 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int s[10000][6];

int calc(vector<int> gid) {
	typedef pair<int, int> P;
	vector<P> persons[4];
	for (int id = 0; id < 4; id++) { //科目集合{i | gid[i] == id}担当のスコアを計算
		for (int i = 0; i < n; i++) {
			int score = 1;
			for (int j = 0; j < 6; j++) {
				if (gid[j] == id) {
					score *= s[i][j];
				}
			}
			persons[id].push_back(P(score, i));
		}
		sort(persons[id].begin(), persons[id].end(), greater<P>());
	}
	
	int ret = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			if (persons[0][i].second == persons[1][j].second) continue;
			for (int k = 0; k < 4; k++) {
				if (persons[0][i].second == persons[2][k].second) continue;
				if (persons[1][j].second == persons[2][k].second) continue;
				for (int l = 0; l < 4; l++) {
					if (persons[0][i].second == persons[3][l].second) continue;
					if (persons[1][j].second == persons[3][l].second) continue;
					if (persons[2][k].second == persons[3][l].second) continue;
					int score = persons[0][i].first * persons[1][j].first * persons[2][k].first * persons[3][l].first;
					ret = max(ret, score);
				}
			}
		}
	}
	return ret;
}

int dfs(int dep, vector<int> &gid, int high) {
	if (dep == 6) {
		return calc(gid);
	}
	
	int ret = 0;
	for (int i = 0; i <= high; i++) {
		gid.push_back(i);
		int res = dfs(dep + 1, gid, max(i + 1, high));
		ret = max(ret, res);
		gid.pop_back();
	}
	return ret;
}

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) rep(j, 6) scanf("%lld", &s[i][j]);
	
	vector<int> gid;
	int ans = dfs(0, gid, 0);
	
	cout << ans << endl;
	return 0;
}
0