Submission #113584

# Submission time Handle Problem Language Result Execution time Memory
113584 2019-05-26T13:17:36 Z MladenP Pinball (JOI14_pinball) C++17
51 / 100
699 ms 29156 KB
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%lld\n", x);
#define PRINT(x) fprintf(stderr, "%s = %lld\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
lld a[MAXN], b[MAXN], c[MAXN], d[MAXN], segL[12*MAXN], segR[12*MAXN];
lld dpl[MAXN], dpr[MAXN];
set<int> hshs;
map<int, int> hsh;
void update(lld seg[], int node, int l, int r, int idx, lld val) {
    if(l == r) {
        seg[node] = min(seg[node], val);
        return;
    }
    if(idx <= mid) update(seg, 2*node, l, mid, idx, val);
    else update(seg, 2*node+1, mid+1, r, idx, val);
    seg[node] = min(seg[2*node], seg[2*node+1]);
}
lld query(lld seg[], int node, int l, int r, int L, int R) {
    if(L <= l && r <= R) return seg[node];
    lld rez = LINF;
    if(L <= mid) rez = min(rez, query(seg, 2*node, l, mid, L, R));
    if(R > mid) rez = min(rez, query(seg, 2*node+1, mid+1, r, L, R));
    return rez;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    fill(segL, segL+4*MAXN, LINF);
    fill(segR, segR+4*MAXN, LINF);
    int m, n; cin >> m >> n;
    hshs.insert(1); hshs.insert(n);
    for(int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        hshs.insert(a[i]); hshs.insert(b[i]); hshs.insert(c[i]);
    }
    int N = 0;
    for(auto x : hshs) hsh[x] = ++N;
    update(segL, 1, 1, N, 1, 0);
    update(segR, 1, 1, N, N, 0);
    lld rez = LINF;
    for(int i = 1; i <= m; i++) {
        a[i] = hsh[a[i]]; b[i] = hsh[b[i]]; c[i] = hsh[c[i]];
        dpl[i] = query(segL, 1, 1, N, a[i], b[i]) + d[i];
        dpr[i] = query(segR, 1, 1, N, a[i], b[i]) + d[i];
        rez = min(rez, dpl[i]+dpr[i]-d[i]);

        update(segL, 1, 1, N, c[i], dpl[i]);
        update(segR, 1, 1, N, c[i], dpr[i]);
    }
    cout << (rez == LINF ? -1:rez);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6756 KB Output is correct
4 Correct 7 ms 6656 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 7 ms 6656 KB Output is correct
8 Correct 6 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6756 KB Output is correct
4 Correct 7 ms 6656 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 7 ms 6656 KB Output is correct
8 Correct 6 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 7 ms 6656 KB Output is correct
11 Correct 6 ms 6656 KB Output is correct
12 Correct 7 ms 6784 KB Output is correct
13 Correct 6 ms 6656 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6756 KB Output is correct
4 Correct 7 ms 6656 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 7 ms 6656 KB Output is correct
8 Correct 6 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 7 ms 6656 KB Output is correct
11 Correct 6 ms 6656 KB Output is correct
12 Correct 7 ms 6784 KB Output is correct
13 Correct 6 ms 6656 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 8 ms 6912 KB Output is correct
18 Correct 7 ms 6784 KB Output is correct
19 Correct 8 ms 6912 KB Output is correct
20 Correct 8 ms 6784 KB Output is correct
21 Correct 8 ms 6784 KB Output is correct
22 Correct 9 ms 7040 KB Output is correct
23 Correct 9 ms 7012 KB Output is correct
24 Correct 6 ms 7040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6756 KB Output is correct
4 Correct 7 ms 6656 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 7 ms 6656 KB Output is correct
8 Correct 6 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 7 ms 6656 KB Output is correct
11 Correct 6 ms 6656 KB Output is correct
12 Correct 7 ms 6784 KB Output is correct
13 Correct 6 ms 6656 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 8 ms 6912 KB Output is correct
18 Correct 7 ms 6784 KB Output is correct
19 Correct 8 ms 6912 KB Output is correct
20 Correct 8 ms 6784 KB Output is correct
21 Correct 8 ms 6784 KB Output is correct
22 Correct 9 ms 7040 KB Output is correct
23 Correct 9 ms 7012 KB Output is correct
24 Correct 6 ms 7040 KB Output is correct
25 Correct 31 ms 8704 KB Output is correct
26 Correct 140 ms 13064 KB Output is correct
27 Correct 578 ms 19532 KB Output is correct
28 Correct 152 ms 11512 KB Output is correct
29 Correct 271 ms 17660 KB Output is correct
30 Correct 264 ms 13048 KB Output is correct
31 Incorrect 699 ms 29156 KB Output isn't correct
32 Halted 0 ms 0 KB -