結果
| 問題 |
No.335 門松宝くじ
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:13:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,797 bytes |
| コンパイル時間 | 193 ms |
| コンパイル使用メモリ | 82,944 KB |
| 実行使用メモリ | 90,680 KB |
| 最終ジャッジ日時 | 2025-06-12 16:14:03 |
| 合計ジャッジ時間 | 4,058 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 2 -- * 7 |
ソースコード
import sys
from itertools import combinations
def is_kadomatsu(A, B, C):
if A == B or B == C or A == C:
return False
max_val = max(A, B, C)
min_val = min(A, B, C)
if A != max_val and A != min_val:
second = A
elif B != max_val and B != min_val:
second = B
else:
second = C
return second == A or second == C
def main():
input = sys.stdin.read().split()
ptr = 0
N = int(input[ptr])
M = int(input[ptr+1])
ptr += 2
tickets = []
for _ in range(M):
E = list(map(int, input[ptr:ptr+N]))
ptr += N
tickets.append(E)
max_expected = -1
best_ticket = 0
for ticket_idx, E in enumerate(tickets):
N_current = len(E)
pair_max = [[0] * (N_current + 1) for _ in range(N_current + 1)]
for i, j, k in combinations(range(N_current), 3):
A = E[i]
B = E[j]
C = E[k]
if is_kadomatsu(A, B, C):
max_val = max(A, B, C)
if pair_max[A][B] < max_val:
pair_max[A][B] = max_val
if pair_max[A][C] < max_val:
pair_max[A][C] = max_val
if pair_max[B][C] < max_val:
pair_max[B][C] = max_val
sum_total = 0
for x in range(1, N_current + 1):
for y in range(1, N_current + 1):
if x != y:
sum_total += pair_max[x][y]
expected = sum_total / (N_current * (N_current - 1))
if expected > max_expected or (expected == max_expected and ticket_idx < best_ticket):
max_expected = expected
best_ticket = ticket_idx
print(best_ticket)
if __name__ == '__main__':
main()
gew1fw