結果

問題 No.335 門松宝くじ
ユーザー gew1fw
提出日時 2025-06-12 20:58:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,543 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 85,500 KB
最終ジャッジ日時 2025-06-12 21:01:53
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 3 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

n, m = map(int, input().split())

tickets = []
for _ in range(m):
    e = list(map(int, input().split()))
    tickets.append(e)

max_expected = -1
best_idx = 0

for idx, e in enumerate(tickets):
    sorted_after = []
    for j in range(n):
        sorted_after.append(sorted(e[j+1:]))
    
    total = 0
    for i in range(n):
        for j in range(i+1, n):
            x = e[i]
            y = e[j]
            if x == y:
                continue
            sa = sorted_after[j]
            if not sa:
                prize = 0
            else:
                if x < y:
                    if sa[0] < x:
                        prize = y
                    else:
                        left = bisect.bisect_right(sa, x)
                        right = bisect.bisect_left(sa, y)
                        if left < right:
                            prize = y
                        else:
                            prize = 0
                else:
                    if sa[-1] > x:
                        prize = x
                    else:
                        left = bisect.bisect_right(sa, y)
                        right = bisect.bisect_left(sa, x)
                        if left < right:
                            prize = x
                        else:
                            prize = 0
            total += prize
    expected = total / (n * (n - 1))
    if expected > max_expected or (expected == max_expected and idx < best_idx):
        max_expected = expected
        best_idx = idx

print(best_idx)
0