結果

問題 No.561 東京と京都
ユーザー Kiona1018Kiona1018
提出日時 2019-09-24 23:01:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 171,792 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:39:53
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define chmax(a, b) a = max((a), (b))
using namespace std;
using ll = long long;
const int INF = 1000000000;


int main()
{
    int n, d;
    cin >> n >> d;
    vector<int> tokyo(n), kyoto(n);
    rep(i, 0, n) cin >> tokyo[i] >> kyoto[i];

    vector<vector<int>> dp(n+1, vector<int>(2, -INF));
    dp[0][0] = 0;
    // 0 -> tokyo , 1 -> kyoto
    rep(i, 0, n)
    {
        // from tokyo 
        chmax(dp[i+1][0], dp[i][0]+tokyo[i]);
        chmax(dp[i+1][1], dp[i][0]+kyoto[i]-d);
        // from kyoto
        chmax(dp[i+1][0], dp[i][1]+tokyo[i]-d);
        chmax(dp[i+1][1], dp[i][1]+kyoto[i]);
    }
    cout << max(dp[n][0], dp[n][1]) << endl;
    return 0;
}
0