結果

問題 No.3597 Queen Score Attack 2
コンテスト
ユーザー 👑 loop0919
提出日時 2026-07-24 21:25:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 508 ms / 2,000 ms
+ 301µs
コード長 750 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 96,236 KB
実行使用メモリ 85,376 KB
最終ジャッジ日時 2026-07-24 21:25:39
合計ジャッジ時間 10,177 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import product

INF = 10**18


def can_reach(src, dst):
    src_x, src_y = src
    dst_x, dst_y = dst

    for cx, cy in product((-1, 0, 1), repeat=2):
        if cx == cy == 0:
            continue
        if cx * src_x + cy * src_y == cx * dst_x + cy * dst_y:
            return True

    return False


H, W, sx, sy, N = [int(s) for s in input().split()]
curr_x, curr_y = sx, sy

dp = [-INF, 0]
for _ in range(N):
    x, y, c = [int(s) for s in input().split()]
    ndp = [-INF, -INF]

    if can_reach((curr_x, curr_y), (x, y)):
        ndp[0] = max(dp[0], dp[1])
        ndp[1] = max(dp[0], dp[1]) + c
    else:
        ndp[0] = max(dp[0], dp[1])
        ndp[1] = dp[0] + c

    curr_x, curr_y = x, y
    dp = ndp

print(max(dp))
0