結果

問題 No.335 門松宝くじ
ユーザー maspymaspy
提出日時 2020-03-22 12:56:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,427 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 18,316 KB
最終ジャッジ日時 2023-08-26 03:37:16
合計ジャッジ時間 11,064 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,280 KB
testcase_01 AC 18 ms
8,320 KB
testcase_02 AC 17 ms
8,276 KB
testcase_03 AC 17 ms
8,360 KB
testcase_04 AC 17 ms
8,340 KB
testcase_05 AC 925 ms
10,704 KB
testcase_06 AC 1,377 ms
10,560 KB
testcase_07 TLE -
testcase_08 AC 1,783 ms
13,764 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

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