結果

問題 No.561 東京と京都
ユーザー sekiya9311sekiya9311
提出日時 2017-08-25 22:45:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 173,924 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 19:24:38
合計ジャッジ時間 2,699 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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].clear();
            dp[j].insert(*max_element(ndp[j].begin(), ndp[j].end()));
        }
    }
    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