結果

問題 No.1792 科学の甲子園
ユーザー startcppstartcpp
提出日時 2021-12-21 00:50:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,769 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 80,576 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 19:43:23
合計ジャッジ時間 2,093 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 15 ms
4,352 KB
testcase_12 AC 10 ms
4,352 KB
testcase_13 AC 14 ms
4,348 KB
testcase_14 AC 20 ms
4,352 KB
testcase_15 AC 11 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 11 ms
4,352 KB
testcase_20 AC 20 ms
4,348 KB
testcase_21 AC 9 ms
4,348 KB
testcase_22 AC 14 ms
4,352 KB
testcase_23 AC 11 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 6 ms
4,352 KB
testcase_28 AC 20 ms
4,348 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) {
		if (high != 4) return 0;
		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