結果
問題 |
No.335 門松宝くじ
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:09:21 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,774 bytes |
コンパイル時間 | 414 ms |
コンパイル使用メモリ | 82,028 KB |
実行使用メモリ | 107,312 KB |
最終ジャッジ日時 | 2025-04-15 23:11:44 |
合計ジャッジ時間 | 4,141 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 TLE * 1 -- * 8 |
ソースコード
import sys from collections import defaultdict 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) best_idx = 0 max_expectation = -1 for idx, E in enumerate(tickets): max_prize = defaultdict(int) n = len(E) for i in range(n): for j in range(i+1, n): for k in range(j+1, n): 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]) if sorted_vals[1] not in {a, c}: continue current_max = max(a, b, c) pairs = [(a, b), (a, c), (b, c)] for x, y in pairs: if x == y: continue if x > y: x, y = y, x key = (x, y) if max_prize[key] < current_max: max_prize[key] = current_max total = 0 count = N * (N - 1) // 2 for x in range(1, N+1): for y in range(x+1, N+1): total += max_prize.get((x, y), 0) expectation = total / count if count != 0 else 0 if expectation > max_expectation or (expectation == max_expectation and idx < best_idx): max_expectation = expectation best_idx = idx print(best_idx) if __name__ == '__main__': main()