結果

問題 No.561 東京と京都
ユーザー sekiya9311sekiya9311
提出日時 2017-08-25 22:42:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 822 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 171,488 KB
実行使用メモリ 180,476 KB
最終ジャッジ日時 2024-04-23 15:38:26
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int MAX = 111;
int n, d;
long long t[MAX], k[MAX];
unordered_set<long long> dp[2];

int main() {
    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        cin >> t[i] >> k[i];
    }
    dp[0].insert(0);
    for (int i = 0; i < n; i++) {
        unordered_set<long long> ndp[2];
        for (long long e : dp[0]) {
            ndp[0].insert(e + t[i]);
            ndp[1].insert(e + k[i] - d);
        }
        for (long long e : dp[1]) {
            ndp[1].insert(e + k[i]);
            ndp[0].insert(e + t[i] - d);
        }
        for (int j = 0; j < 2; j++) {
            dp[j] = ndp[j];
        }
    }
    long long ans = 0;
    for (int i = 0; i < 2; i++) {
        for (long long e : dp[i]) ans = max(ans, e);
    }
    cout << ans << endl;
    return 0;
}
0