結果
| 問題 | No.3597 Queen Score Attack 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-25 14:47:23 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 464 ms / 2,000 ms |
| + 141µs | |
| コード長 | 919 bytes |
| 記録 | |
| コンパイル時間 | 250 ms |
| コンパイル使用メモリ | 95,988 KB |
| 実行使用メモリ | 165,128 KB |
| 最終ジャッジ日時 | 2026-07-25 14:47:34 |
| 合計ジャッジ時間 | 9,563 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
# https://yukicoder.me/problems/no/3597
def same_line(h0, w0, h1, w1):
if h0 == h1 or w0 == w1:
return True
elif h0 - w0 == h1 - w1:
return True
elif h0 + w0 == h1 + w1:
return True
return False
def main():
H, W, sx, sy, N = map(int, input().split())
xyc = []
for _ in range(N):
x, y, c = map(int, input().split())
xyc.append((x, y, c))
dp = [-float("inf") for _ in range(2)]
dp[1] = 0
prev_x = sx
prev_y = sy
for x, y, c in xyc:
new_dp = [-float("inf") for _ in range(2)]
new_dp[0] = max(new_dp[0], dp[0])
new_dp[0] = max(new_dp[0], dp[1])
new_dp[1] = max(new_dp[1], dp[0] + c)
if same_line(prev_x, prev_y, x, y):
new_dp[1] = max(new_dp[1], dp[1] + c)
dp = new_dp
prev_x = x
prev_y = y
print(max(dp))
if __name__ == "__main__":
main()