Submission #391554

# Submission time Handle Problem Language Result Execution time Memory
391554 2021-04-19T10:30:55 Z KoD Pinball (JOI14_pinball) C++17
100 / 100
325 ms 16324 KB
#include <bits/stdc++.h>

template <class T>
using Vec = std::vector<T>;

using ll = long long;

constexpr ll INF = std::numeric_limits<ll>::max() / 3;

struct Segtree {
    int size;
    Vec<ll> min;
    Segtree(const int n): size(n), min(2 * n, INF) { }

    void setmin(int i, const ll x) {
        i += size;
        while (i > 0) {
            min[i] = std::min(min[i], x);
            i >>= 1;
        }
    }

    ll fold(int l, int r) const {
        ll ret = INF;
        l += size;
        r += size;
        while (l < r) {
            if (l & 1) ret = std::min(ret, min[l++]);
            if (r & 1) ret = std::min(ret, min[--r]);
            l >>= 1;
            r >>= 1;
        }
        return ret;
    }
};

int main() {
    int H, W;
    std::cin >> H >> W;
    Vec<int> A(H), B(H), C(H), D(H);
    Vec<int> cmp;
    cmp.reserve(3 * H + 2);
    cmp.push_back(1);
    cmp.push_back(W);
    for (int i = 0; i < H; ++i) {
        std::cin >> A[i] >> B[i] >> C[i] >> D[i];
        cmp.push_back(A[i]);
        cmp.push_back(B[i]);
        cmp.push_back(C[i]);
    }
    std::sort(cmp.begin(), cmp.end());
    cmp.erase(std::unique(cmp.begin(), cmp.end()), cmp.end());
    for (auto& x: A) {
        x = std::lower_bound(cmp.begin(), cmp.end(), x) - cmp.begin();
    }
    for (auto& x: B) {
        x = std::lower_bound(cmp.begin(), cmp.end(), x) - cmp.begin();
    }
    for (auto& x: C) {
        x = std::lower_bound(cmp.begin(), cmp.end(), x) - cmp.begin();
    }
    W = (int) cmp.size();
    Segtree left(W), right(W);
    left.setmin(0, 0);
    right.setmin(W - 1, 0);
    ll ans = INF;
    for (int i = 0; i < H; ++i) {
        left.setmin(C[i], left.fold(A[i], C[i]) + D[i]);
        right.setmin(C[i], right.fold(C[i] + 1, B[i] + 1) + D[i]);
        ans = std::min(ans, left.fold(A[i], W) + right.fold(0, B[i] + 1) + D[i]);
    }
    if (ans == INF) {
        std::cout << -1 << '\n';
    }
    else {
        std::cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 304 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 304 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 444 KB Output is correct
25 Correct 26 ms 1356 KB Output is correct
26 Correct 77 ms 3504 KB Output is correct
27 Correct 199 ms 7804 KB Output is correct
28 Correct 233 ms 6848 KB Output is correct
29 Correct 147 ms 6396 KB Output is correct
30 Correct 266 ms 7472 KB Output is correct
31 Correct 325 ms 12168 KB Output is correct
32 Correct 296 ms 10692 KB Output is correct
33 Correct 46 ms 3268 KB Output is correct
34 Correct 143 ms 8260 KB Output is correct
35 Correct 246 ms 16252 KB Output is correct
36 Correct 315 ms 16264 KB Output is correct
37 Correct 312 ms 16324 KB Output is correct
38 Correct 297 ms 16196 KB Output is correct