結果
問題 |
No.335 門松宝くじ
|
ユーザー |
![]() |
提出日時 | 2025-04-16 16:00:07 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,246 bytes |
コンパイル時間 | 253 ms |
コンパイル使用メモリ | 82,528 KB |
実行使用メモリ | 80,488 KB |
最終ジャッジ日時 | 2025-04-16 16:04:09 |
合計ジャッジ時間 | 4,298 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | WA * 1 TLE * 2 -- * 7 |
ソースコード
import sys def is_kadomatsu(a, b, c): return (b < a < c) or (c < a < b) or (a < c < b) or (b < c < a) def main(): input = sys.stdin.read().split() ptr = 0 N, M = int(input[ptr]), int(input[ptr+1]) ptr += 2 tickets = [] for _ in range(M): ticket = list(map(int, input[ptr:ptr+N])) ptr += N tickets.append(ticket) best_idx = 0 best_expectation = -1 for idx, ticket in enumerate(tickets): N_ticket = len(ticket) max_prize = [[0]*(N_ticket + 1) for _ in range(N_ticket + 1)] # Find z_max and its position z_max = max(ticket) pos_z_max = ticket.index(z_max) # Process pairs (i, j) where i < j < pos_z_max for i in range(pos_z_max): for j in range(i + 1, pos_z_max): a = ticket[i] b = ticket[j] if b < a < z_max: if max_prize[a][b] < z_max: max_prize[a][b] = z_max # Process other triplets for i in range(N_ticket): for j in range(i + 1, N_ticket): for k in range(j + 1, N_ticket): if k == pos_z_max: continue a = ticket[i] b = ticket[j] c = ticket[k] if is_kadomatsu(a, b, c): max_val = max(a, b, c) pairs = [(a, b), (a, c), (b, c)] for x, y in pairs: if max_prize[x][y] < max_val: max_prize[x][y] = max_val # Compute expected value total = 0 count = N_ticket * (N_ticket - 1) for x in range(1, N_ticket + 1): for y in range(1, N_ticket + 1): if x != y: total += max_prize[x][y] expectation = total / count if count != 0 else 0 # Update best if expectation > best_expectation or (expectation == best_expectation and idx < best_idx): best_expectation = expectation best_idx = idx print(best_idx) if __name__ == '__main__': main()