結果

問題 No.561 東京と京都
ユーザー kyawashellkyawashell
提出日時 2018-03-28 13:19:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 198,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 19:23:57
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘ll solve(ll, ll)’ 内:
main.cpp:39:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   39 | }
      | ^

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,d;
ll t[200],k[200];
bool done[201][2];
ll memo[201][2];

ll solve(ll i,ll j) {
	if(done[i][j]) {
		return memo[i][j];
	}
	if(i >= n) {
		return 0;
	}

	if(j == 0) {
		memo[i][j] = max(t[i] + solve(i + 1,0),k[i] + solve(i + 1,1) - d);
		done[i][j] = true;
		return memo[i][j];
	}
	if(j == 1) {
		memo[i][j] = max(t[i] + solve(i + 1,0) - d,k[i] + solve(i + 1,1));
		done[i][j] = true;
		return memo[i][j];
	}
}

int main(){
	cin >> n;
	cin >> d;
	REP(i,n) {
		cin >> t[i] >> k[i];
	}

	cout << solve(0,0) << endl;
	return 0;
}
0