結果

問題 No.561 東京と京都
ユーザー Teruya-HimakiTeruya-Himaki
提出日時 2017-09-13 17:46:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 164,236 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 09:21:51
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

int n,d;
vector<int> t(100),k(100);

int memo[100][2]={};
bool done[100][2]={};

int Search(int day,bool tokyo){
    if(day==n){
        return 0;
    }
    if(done[day][tokyo==true?1:0]==true){
        return memo[day][tokyo==true?1:0];
    }
    done[day][tokyo==true?1:0]=true;
    if(tokyo==true){
        return memo[day][1]=max(Search(day+1,1)+t[day],Search(day+1,0)+k[day]-d);
    }else{
        return memo[day][0]=max(Search(day+1,0)+k[day],Search(day+1,1)+t[day]-d);
    }
}

int main(){
    cin>>n>>d;
    REP(i,n){
        cin>>t[i]>>k[i];
    }
    cout<<Search(0,true)<<endl;
    return 0;
}
0