結果

問題 No.561 東京と京都
ユーザー LuzhiledLuzhiled
提出日時 2017-08-25 22:40:55
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 472 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 158,044 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-04-23 15:37:51
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, d;
int a[101], b[101];
int dp[101][2];

int solver(int v = -1, bool f = false) {
  if (v == n) return 0;

  int &res = dp[v][f];

  res = max(solver(v + 1, false) + a[v + 1] - (f ? d : 0),
            solver(v + 1, true) + b[v + 1] - (f ? 0 : d));

  return res;
}

int main() {
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }

  memset(dp, -1, sizeof(dp));
  cout << solver() << endl;
}
0