結果

問題 No.561 東京と京都
ユーザー kakira9618kakira9618
提出日時 2017-08-25 23:14:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 95,968 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 16:06:46
合計ジャッジ時間 1,329 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

map<pair<double,int>, double> dp;
double dfs(double M, int N) {
    if (dp.find(mp(M,N)) != dp.end()) {
        return dp[mp(M,N)];
    }
    if (N == 0) {
        return dp[mp(M,N)] = M;
    } else {
        return dp[mp(M,N)] = 1.0 / 3 * dfs(M * 2, N - 1) + 1.0 / 3 * dfs(M + 1, N - 1) + 1.0 / 3 * dfs(0, N - 1);
    }
}

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> dp(N + 1, vector<int>(2, -INF));

    dp[0][0] = 0;
    for(int i = 1; i <= N; i++) {
        int a, b;
        cin >> a >> b;

        dp[i][0] = max((dp[i - 1][0] + a), (dp[i - 1][1] + a - D));
        dp[i][1] = max((dp[i - 1][0] + b - D), (dp[i - 1][1] + b));
    }

    cout << max(dp[N][0], dp[N][1]) << endl;


    return 0;
}


0