結果

問題 No.561 東京と京都
ユーザー magurogumamaguroguma
提出日時 2017-09-02 19:17:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-24 10:55:31
合計ジャッジ時間 1,418 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 26 ms
10,880 KB
testcase_03 AC 27 ms
10,752 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 26 ms
10,752 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 27 ms
10,880 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 27 ms
10,880 KB
testcase_11 AC 26 ms
10,752 KB
testcase_12 AC 27 ms
10,752 KB
testcase_13 AC 28 ms
10,752 KB
testcase_14 AC 27 ms
10,752 KB
testcase_15 AC 27 ms
10,752 KB
testcase_16 AC 28 ms
10,752 KB
testcase_17 AC 28 ms
10,752 KB
testcase_18 AC 29 ms
10,752 KB
testcase_19 AC 29 ms
10,752 KB
testcase_20 AC 27 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

N,D = map(int, input().split())
T = [-1]
K = [-1]
for i in range(N):
    t,k = map(int, input().split())
    T.append(t)
    K.append(k)

dp = [[-1,-1]]
for i in range(N):
    dp.append([-10000001,-10000001])

# nは何日目か,pはn日目の仕事前にどこにいるか(0:東京, 1:京都)
def solution(n, p):
    if dp[n][p] > -10000001:
        return dp[n][p]

    price = -1
    if n == N:
        if p==0:
            price = max(T[n], K[n]-D)
        else:
            price = max(T[n]-D, K[n])
    else:
        if p==0:
            price = max(T[n]+solution(n+1,0), K[n]-D+solution(n+1,1))
        else:
            price = max(T[n]-D+solution(n+1, 0), K[n]+solution(n+1, 1))
    
    dp[n][p] = price
    return dp[n][p]

print(solution(1, 0))
0