結果

問題 No.1792 科学の甲子園
ユーザー gew1fw
提出日時 2025-06-12 13:37:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,728 KB
実行使用メモリ 77,608 KB
最終ジャッジ日時 2025-06-12 13:43:05
合計ジャッジ時間 3,370 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    N = int(data[0])
    students = []
    index = 0
    for i in range(N):
        row = list(map(int, data[1 + i*6 : 1 + i*6 + 6]))
        row.append(i)  # add index to the tuple
        students.append(tuple(row))
    
    # Collect top 4 students for each subject
    candidates = set()
    for subject in range(6):
        # Sort by descending subject score, then by index
        sorted_subj = sorted(students, key=lambda x: (-x[subject], x[6]))
        top4 = sorted_subj[:4]
        for s in top4:
            candidates.add(s)
    
    candidate_list = list(candidates)
    if len(candidate_list) < 4:
        print(0)
        return
    
    max_product = 0
    for comb in itertools.combinations(candidate_list, 4):
        m = max(s[0] for s in comb)
        i = max(s[1] for s in comb)
        p = max(s[2] for s in comb)
        c = max(s[3] for s in comb)
        b = max(s[4] for s in comb)
        e = max(s[5] for s in comb)
        product = m * i * p * c * b * e
        if product > max_product:
            max_product = product
    
    print(max_product)

if __name__ == "__main__":
    main()
0