Submission #581590

# Submission time Handle Problem Language Result Execution time Memory
581590 2022-06-22T19:34:20 Z Vanilla Pinball (JOI14_pinball) C++17
100 / 100
411 ms 26040 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 1e5 + 2;
int64 a[maxn], b[maxn], c[maxn], cost[maxn];
vector <int64> coord;
int64 sgt[2][12 * maxn]; // sgt[0] -> l, sgt[1] -> r;
int64 n,m;
 
int64 query (int x, int l, int r, int il, int ir, int idx) {
    if (il <= l && r <= ir) return sgt[idx][x];
    if (l > ir || r < il) return 1e15;
    int mid = (l + r) / 2;
    return min(query(x * 2, l, mid, il, ir, idx), query(x * 2 + 1, mid + 1, r, il, ir, idx));
} 

int64 update (int x, int l, int r, int pos, int64 nval, int idx) {
    if (l == pos && r == pos) return sgt[idx][x] = min(sgt[idx][x], nval);
    if (l > pos || r < pos) return sgt[idx][x];
    int mid = (l + r) / 2;
    return sgt[idx][x] = min(update(x * 2, l, mid, pos, nval, idx), update(x * 2 + 1, mid + 1, r, pos, nval, idx));
}
 

 
 
int main() {
    cin >> n >> m;
    bool f1 = 0, f2 = 0;
    for (int i = 0; i < 12 * maxn; i++){
        sgt[0][i] = sgt[1][i] = 1e15;
    }
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i] >> cost[i];
        if (a[i] == 1) f1 = 1;
        if (b[i] == m) f2 = 1;
        coord.push_back(a[i]);
        coord.push_back(b[i]);
        coord.push_back(c[i]);
    }
    if (!f1 || !f2){
        cout << -1;
        return 0;
    }
    sort(coord.begin(), coord.end());
    coord.erase(unique(coord.begin(), coord.end()), coord.end());
    m = 0;
    for (int i = 0; i < n; i++){
        a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin();
        b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin();
        c[i] = lower_bound(coord.begin(), coord.end(), c[i]) - coord.begin();
        m = max(m, b[i]);
    }
    int64 rs = 1e15;
    update(1, 0, n * 3, 0, 0, 0);
    update(1, 0, n * 3, m, 0, 1);
    for (int i = 0; i < n; i++){
        rs = min(rs, query(1, 0, n * 3, a[i], b[i], 0) + query(1, 0, n * 3, a[i], b[i], 1) + cost[i]);
        update(1, 0, n * 3, c[i], query(1, 0, n * 3, a[i], b[i], 0) + cost[i], 0);
        update(1, 0, n * 3, c[i], query(1, 0, n * 3, a[i], b[i], 1) + cost[i], 1);
    }
    cout << (rs >= 1e15 ? -1: rs);
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19092 KB Output is correct
3 Correct 8 ms 19016 KB Output is correct
4 Correct 9 ms 19048 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
8 Correct 9 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19092 KB Output is correct
3 Correct 8 ms 19016 KB Output is correct
4 Correct 9 ms 19048 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
8 Correct 9 ms 19028 KB Output is correct
9 Correct 11 ms 19028 KB Output is correct
10 Correct 9 ms 19028 KB Output is correct
11 Correct 10 ms 19028 KB Output is correct
12 Correct 10 ms 19028 KB Output is correct
13 Correct 9 ms 19028 KB Output is correct
14 Correct 10 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19092 KB Output is correct
3 Correct 8 ms 19016 KB Output is correct
4 Correct 9 ms 19048 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
8 Correct 9 ms 19028 KB Output is correct
9 Correct 11 ms 19028 KB Output is correct
10 Correct 9 ms 19028 KB Output is correct
11 Correct 10 ms 19028 KB Output is correct
12 Correct 10 ms 19028 KB Output is correct
13 Correct 9 ms 19028 KB Output is correct
14 Correct 10 ms 19028 KB Output is correct
15 Correct 8 ms 19028 KB Output is correct
16 Correct 12 ms 19028 KB Output is correct
17 Correct 12 ms 19196 KB Output is correct
18 Correct 12 ms 19136 KB Output is correct
19 Correct 11 ms 19124 KB Output is correct
20 Correct 14 ms 19156 KB Output is correct
21 Correct 11 ms 19076 KB Output is correct
22 Correct 11 ms 19196 KB Output is correct
23 Correct 11 ms 19132 KB Output is correct
24 Correct 11 ms 19156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19092 KB Output is correct
3 Correct 8 ms 19016 KB Output is correct
4 Correct 9 ms 19048 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 9 ms 19028 KB Output is correct
8 Correct 9 ms 19028 KB Output is correct
9 Correct 11 ms 19028 KB Output is correct
10 Correct 9 ms 19028 KB Output is correct
11 Correct 10 ms 19028 KB Output is correct
12 Correct 10 ms 19028 KB Output is correct
13 Correct 9 ms 19028 KB Output is correct
14 Correct 10 ms 19028 KB Output is correct
15 Correct 8 ms 19028 KB Output is correct
16 Correct 12 ms 19028 KB Output is correct
17 Correct 12 ms 19196 KB Output is correct
18 Correct 12 ms 19136 KB Output is correct
19 Correct 11 ms 19124 KB Output is correct
20 Correct 14 ms 19156 KB Output is correct
21 Correct 11 ms 19076 KB Output is correct
22 Correct 11 ms 19196 KB Output is correct
23 Correct 11 ms 19132 KB Output is correct
24 Correct 11 ms 19156 KB Output is correct
25 Correct 39 ms 19752 KB Output is correct
26 Correct 91 ms 20820 KB Output is correct
27 Correct 287 ms 22980 KB Output is correct
28 Correct 292 ms 25952 KB Output is correct
29 Correct 182 ms 22524 KB Output is correct
30 Correct 363 ms 26028 KB Output is correct
31 Correct 403 ms 25980 KB Output is correct
32 Correct 404 ms 26040 KB Output is correct
33 Correct 65 ms 20320 KB Output is correct
34 Correct 199 ms 22532 KB Output is correct
35 Correct 306 ms 26020 KB Output is correct
36 Correct 411 ms 25976 KB Output is correct
37 Correct 373 ms 26040 KB Output is correct
38 Correct 357 ms 26012 KB Output is correct