結果
問題 | No.335 門松宝くじ |
ユーザー |
![]() |
提出日時 | 2025-06-12 20:50:50 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,706 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 81,524 KB |
実行使用メモリ | 85,732 KB |
最終ジャッジ日時 | 2025-06-12 20:55:47 |
合計ジャッジ時間 | 4,097 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 TLE * 1 -- * 8 |
ソースコード
import sys 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): ticket = list(map(int, input[ptr:ptr+N])) ptr += N tickets.append(ticket) max_expectation = -1 best = 0 for idx, ticket in enumerate(tickets): pair_max = [[0] * (N + 1) for _ in range(N + 1)] # 1-based for i in range(N): a = ticket[i] for j in range(i + 1, N): b = ticket[j] for k in range(j + 1, N): c = ticket[k] sum_ = a + b + c max_val = max(a, b, c) min_val = min(a, b, c) middle = sum_ - max_val - min_val if middle == a or middle == c: # Update the three pairs for x, y in [(a, b), (a, c), (b, c)]: x_pair, y_pair = sorted((x, y)) if pair_max[x_pair][y_pair] < max_val: pair_max[x_pair][y_pair] = max_val total = 0 for x in range(1, N + 1): for y in range(x + 1, N + 1): total += pair_max[x][y] count = N * (N - 1) // 2 if count == 0: expectation = 0.0 else: expectation = total / count if expectation > max_expectation or (expectation == max_expectation and idx < best): max_expectation = expectation best = idx print(best) if __name__ == '__main__': main()