답안 #113582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113582 2019-05-26T13:13:23 Z MladenP Pinball (JOI14_pinball) C++17
51 / 100
790 ms 31068 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 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
lld a[MAXN], b[MAXN], c[MAXN], d[MAXN], segL[4*MAXN], segR[4*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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6656 KB Output is correct
3 Correct 7 ms 6656 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
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6656 KB Output is correct
3 Correct 7 ms 6656 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 8 ms 6656 KB Output is correct
12 Correct 7 ms 6656 KB Output is correct
13 Correct 7 ms 6656 KB Output is correct
14 Correct 7 ms 6784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6656 KB Output is correct
3 Correct 7 ms 6656 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 8 ms 6656 KB Output is correct
12 Correct 7 ms 6656 KB Output is correct
13 Correct 7 ms 6656 KB Output is correct
14 Correct 7 ms 6784 KB Output is correct
15 Correct 7 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 9 ms 6912 KB Output is correct
18 Correct 8 ms 6784 KB Output is correct
19 Correct 10 ms 7040 KB Output is correct
20 Correct 9 ms 6784 KB Output is correct
21 Correct 8 ms 6784 KB Output is correct
22 Correct 10 ms 7040 KB Output is correct
23 Correct 9 ms 7040 KB Output is correct
24 Correct 9 ms 7040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6656 KB Output is correct
3 Correct 7 ms 6656 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 8 ms 6656 KB Output is correct
12 Correct 7 ms 6656 KB Output is correct
13 Correct 7 ms 6656 KB Output is correct
14 Correct 7 ms 6784 KB Output is correct
15 Correct 7 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 9 ms 6912 KB Output is correct
18 Correct 8 ms 6784 KB Output is correct
19 Correct 10 ms 7040 KB Output is correct
20 Correct 9 ms 6784 KB Output is correct
21 Correct 8 ms 6784 KB Output is correct
22 Correct 10 ms 7040 KB Output is correct
23 Correct 9 ms 7040 KB Output is correct
24 Correct 9 ms 7040 KB Output is correct
25 Correct 38 ms 9072 KB Output is correct
26 Correct 137 ms 14040 KB Output is correct
27 Correct 413 ms 21876 KB Output is correct
28 Correct 154 ms 15184 KB Output is correct
29 Correct 313 ms 19536 KB Output is correct
30 Correct 302 ms 16872 KB Output is correct
31 Incorrect 790 ms 31068 KB Output isn't correct
32 Halted 0 ms 0 KB -