結果

問題 No.561 東京と京都
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2018-06-05 22:41:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 44,192 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-12 22:36:37
合計ジャッジ時間 1,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <limits>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100;
using ll = long long;
constexpr ll INF = std::numeric_limits<ll>::max()>>2;

ll N, D;
ll C[2][MAX_N];
ll dp[MAX_N+1][2];

void chmax( ll &a, ll b )
{ a = std::max( a, b ); }

int main()
{
  scanf( "%lld%lld", &N, &D );
  rep( i, N )
    scanf( "%lld%lld", C[0]+i, C[1]+i );

  dp[0][0] = 0;
  dp[0][1] = -INF;
  rep( i, N ) rep( j, 2 )
  {
    chmax( dp[i+1][j], dp[i][!j]-D+C[j][i] );
    chmax( dp[i+1][j], dp[i][j]+C[j][i] );
  }

  printf( "%lld\n", std::max( dp[N][0], dp[N][1] ) );

  return 0;
}
0