結果
| 問題 |
No.335 門松宝くじ
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:59:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,988 bytes |
| コンパイル時間 | 181 ms |
| コンパイル使用メモリ | 82,408 KB |
| 実行使用メモリ | 84,644 KB |
| 最終ジャッジ日時 | 2025-06-12 16:00:04 |
| 合計ジャッジ時間 | 3,922 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 1 -- * 8 |
ソースコード
import sys
from itertools import permutations
def main():
import sys
N, M = map(int, sys.stdin.readline().split())
tickets = []
for _ in range(M):
e = list(map(int, sys.stdin.readline().split()))
tickets.append(e)
def is_mentsu(a, b, c):
sorted_vals = sorted([a, b, c])
min_val, med_val, max_val = sorted_vals
return med_val != b
def compute_expectation(ticket):
pos = {num: idx for idx, num in enumerate(ticket)}
total = 0.0
count = 0
for i in range(N):
for j in range(i+1, N):
a = ticket[i]
b = ticket[j]
max_k = 0
found = False
for k_val in range(N, 0, -1):
if k_val == a or k_val == b:
continue
for order in permutations([a, b, k_val]):
x, y, z = order
x_pos = pos[x]
y_pos = pos[y]
z_pos = pos[z]
if x_pos < y_pos < z_pos:
if is_mentsu(x, y, z):
current_max = max(x, y, z)
if current_max > max_k:
max_k = current_max
found = True
break
if found:
total += max_k
else:
total += 0
count += 1
if count == 0:
expectation = 0.0
else:
expectation = total / count
return expectation
expectations = []
for ticket in tickets:
exp = compute_expectation(ticket)
expectations.append(exp)
max_exp = max(expectations)
for i in range(M):
if expectations[i] == max_exp:
print(i)
break
if __name__ == "__main__":
main()
gew1fw