結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー pekempeypekempey
提出日時 2016-11-18 23:28:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,460 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 168,788 KB
実行使用メモリ 10,984 KB
最終ジャッジ日時 2023-09-02 12:51:08
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,892 KB
testcase_01 AC 4 ms
7,812 KB
testcase_02 AC 4 ms
7,804 KB
testcase_03 AC 4 ms
7,996 KB
testcase_04 AC 4 ms
7,812 KB
testcase_05 AC 4 ms
7,880 KB
testcase_06 AC 4 ms
7,904 KB
testcase_07 AC 4 ms
7,896 KB
testcase_08 AC 4 ms
8,036 KB
testcase_09 AC 4 ms
7,940 KB
testcase_10 AC 4 ms
7,824 KB
testcase_11 AC 4 ms
7,824 KB
testcase_12 AC 4 ms
7,816 KB
testcase_13 AC 15 ms
8,028 KB
testcase_14 AC 16 ms
8,312 KB
testcase_15 AC 37 ms
8,840 KB
testcase_16 AC 58 ms
9,704 KB
testcase_17 AC 59 ms
9,644 KB
testcase_18 AC 13 ms
8,052 KB
testcase_19 AC 80 ms
10,472 KB
testcase_20 AC 30 ms
8,588 KB
testcase_21 AC 79 ms
10,544 KB
testcase_22 AC 31 ms
8,700 KB
testcase_23 AC 81 ms
10,476 KB
testcase_24 AC 22 ms
8,116 KB
testcase_25 AC 79 ms
10,428 KB
testcase_26 AC 12 ms
8,164 KB
testcase_27 AC 61 ms
9,684 KB
testcase_28 AC 56 ms
9,388 KB
testcase_29 AC 33 ms
8,648 KB
testcase_30 AC 83 ms
10,576 KB
testcase_31 AC 15 ms
8,100 KB
testcase_32 AC 16 ms
8,060 KB
testcase_33 AC 89 ms
10,628 KB
testcase_34 AC 85 ms
10,752 KB
testcase_35 AC 88 ms
10,696 KB
testcase_36 AC 80 ms
10,984 KB
testcase_37 AC 88 ms
10,984 KB
testcase_38 AC 86 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5;

template<class T1, class T2>
void chmin(T1 &a, T2 b) {
    if (b < a) a = b;
}

const int M = 1 << 18;
int seg[M * 2];

int maximum(int l, int r) {
    int res = -2e9;
    for (l += M, r += M; l < r; l >>= 1, r >>= 1) {
        if (l & 1) res = max(res, seg[l++]);
        if (r & 1) res = max(res, seg[--r]);
    }
    return res;
}

int main() {
    int n, K;
    cin >> n >> K;

    vector<int> T(n), D(n);
    for (int i = 0; i < n; i++) scanf("%d %d", &T[i], &D[i]);

    static int dp[N + 1];
    fill_n(dp, N + 1, INT_MAX);
    fill_n(seg, M * 2, -2e9);
    dp[0] = 0;

    for (int i = 0; i < n; i++) seg[i + M] = D[i];
    for (int i = M - 1; i >= 1; i--) seg[i] = max(seg[i * 2], seg[i * 2 + 1]);

    for (int i = 0; i < n; i++) {
        int j = lower_bound(T.begin(), T.end(), T[i] + K) - T.begin();
        chmin(dp[j], max(dp[i], maximum(i + 1, j)));
        chmin(dp[i + 1], max(dp[i], D[i]));
    }

    vector<int64_t> sum(n + 1);
    for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + (D[i] <= dp[n] ? D[i] : 2e9);

    static int64_t dp2[N + 1];
    fill_n(dp2, N + 1, 1e18);
    dp2[0] = 0;
    for (int i = 0; i < n; i++) {
        int j = lower_bound(T.begin(), T.end(), T[i] + K) - T.begin();
        chmin(dp2[j], dp2[i] + sum[j] - sum[i + 1]);
        if (D[i] <= dp[n]) chmin(dp2[i + 1], dp2[i] + D[i]);
    }

    cout << dp[n] << endl;
    cout << dp2[n] << endl;
}
0