結果

問題 No.335 門松宝くじ
ユーザー lam6er
提出日時 2025-03-31 17:58:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,591 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 54,480 KB
最終ジャッジ日時 2025-03-31 17:59:06
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 1 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import combinations

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    M = int(input[ptr])
    ptr += 1
    tickets = []
    for _ in range(M):
        E = list(map(int, input[ptr:ptr+N]))
        ptr += N
        tickets.append(E)
    
    max_expected = -1
    best_ticket = 0

    for ticket_idx in range(M):
        E = tickets[ticket_idx]
        best_prize = [[0]*(N+2) for _ in range(N+2)]  # 1-based indexing

        for i, j, k in combinations(range(N), 3):
            a = E[i]
            b = E[j]
            c = E[k]
            if a == b or b == c or a == c:
                continue
            sorted_vals = sorted([a, b, c])
            med = sorted_vals[1]
            if med not in (a, c):
                continue
            max_val = max(a, b, c)
            pairs = [(a, b), (a, c), (b, c)]
            for pair in pairs:
                u, v = sorted(pair)
                if best_prize[u][v] < max_val:
                    best_prize[u][v] = max_val
        
        total = 0
        count = 0
        for u in range(1, N+1):
            for v in range(u+1, N+1):
                total += best_prize[u][v]
                count += 1
        
        if count == 0:
            expected = 0.0
        else:
            expected = total / count
        
        if expected > max_expected or (expected == max_expected and ticket_idx < best_ticket):
            max_expected = expected
            best_ticket = ticket_idx
    
    print(best_ticket)

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