結果

問題 No.335 門松宝くじ
ユーザー maspy
提出日時 2020-03-22 12:56:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,427 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,928 KB
最終ジャッジ日時 2024-12-24 17:15:28
合計ジャッジ時間 24,643 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 3 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

N, M = map(int, readline().split())
cards = [tuple(map(int, readline().split())) for _ in range(M)]


def is_kadomatsu(a, b, c):
    return (a < b > c) or (a > b < c)


def solve(card):
    range_max = [None, card]  # n_elem, left_end -> max
    range_min = [None, card]  # n_elem, left_end -> min
    for n in range(2, N + 1):
        r = range_max[-1]
        range_max.append(tuple(max(x, y) for x, y in zip(r, r[1:])))
        r = range_min[-1]
        range_min.append(tuple(min(x, y) for x, y in zip(r, r[1:])))

    def gen_cand(i, j):
        x = card[i]
        y = card[j]
        if i:
            for z in (range_max[i][0], range_min[i][0]):
                if is_kadomatsu(z, x, y):
                    yield max(x, y, z)
        if j - i - 1:
            for z in (range_max[j - i - 1][i + 1], range_min[j - i - 1][i + 1]):
                if is_kadomatsu(x, z, y):
                    yield max(x, y, z)
        if N - 1 - j:
            for z in (range_max[N - 1 - j][j + 1], range_min[N - 1 - j][j + 1]):
                if is_kadomatsu(x, y, z):
                    yield max(x, y, z)
    return sum(max(gen_cand(i, j), default=0) for i, j in itertools.combinations(range(N), 2))


score = [solve(card) for card in cards]
print(score.index(max(score)))
0