結果

問題 No.1104 オンライン点呼
ユーザー maspy
提出日時 2020-07-03 23:12:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 570 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 25,428 KB
最終ジャッジ日時 2024-09-17 04:51:48
合計ジャッジ時間 6,467 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappush, heappop

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
A = [0] + list(map(int, readline().split()))
B = [0] + list(map(int, readline().split()))

if N == 1:
    print(0)
    exit()

q = [(0, 1)]
done = [0] * (N + 1)
done[1] = 0
ans = 0
while q:
    t, j = heappop(q)
    if done[j]:
        continue
    if j in (N - 1, N):
        ans = max(ans, t)
    done[j] = 1
    # j+1 への伝搬
    if j < N:
        t1, j1 = t + A[j] + B[j + 1], j + 1
        heappush(q, (t1, j1))
    # j+2 への伝搬
    if j < N - 1:
        t1, j1 = t + A[j] + B[j + 2] + K, j + 2
        heappush(q, (t1, j1))

print(ans)
0