답안 #441656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441656 2021-07-05T17:26:41 Z JovanB Pinball (JOI14_pinball) C++17
100 / 100
539 ms 31164 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

map <int, int> cval;

const int MAXN = 100000;

ll seg[12*MAXN+50];

const ll INF = 1000000000000000LL;

void init(int node, int l, int r){
    seg[node] = INF;
    if(l == r) return;
    int mid = (l+r)/2;
    init(node*2, l, mid);
    init(node*2+1, mid+1, r);
}

void upd(int node, int l, int r, int x, ll val){
    if(l == r){
        seg[node] = min(seg[node], val);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid) upd(node*2, l, mid, x, val);
    else upd(node*2+1, mid+1, r, x, val);
    seg[node] = min(seg[node*2], seg[node*2+1]);
}

ll query(int node, int l, int r, int tl, int tr){
    if(tl > r || l > tr) return INF;
    if(tl <= l && r <= tr) return seg[node];
    int mid = (l+r)/2;
    return min(query(node*2, l, mid, tl, tr), query(node*2+1, mid+1, r, tl, tr));
}

ll dp1[MAXN+5];
ll dpn[MAXN+5];
int a[MAXN+5];
int b[MAXN+5];
int c[MAXN+5];
ll cost[MAXN+5];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, m;
    cin >> n >> m;
    vector <int> cvec;
    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i] >> c[i] >> cost[i];
        cvec.push_back(a[i]);
        cvec.push_back(b[i]);
        cvec.push_back(c[i]);
    }
    cvec.push_back(1);
    cvec.push_back(m);
    sort(cvec.begin(), cvec.end());
    int maxv = 0;
    for(auto c : cvec) if(!cval[c]) cval[c] = ++maxv;
    init(1, 1, maxv);
    upd(1, 1, maxv, cval[1], 0);
    for(int i=1; i<=n; i++){
        a[i] = cval[a[i]];
        b[i] = cval[b[i]];
        c[i] = cval[c[i]];
    }
    for(int i=1; i<=n; i++){
        dp1[i] = query(1, 1, maxv, a[i], b[i]);
        upd(1, 1, maxv, c[i], dp1[i] + cost[i]);
    }
    init(1, 1, maxv);
    upd(1, 1, maxv, cval[m], 0);
    for(int i=1; i<=n; i++){
        dpn[i] = query(1, 1, maxv, a[i], b[i]);
        upd(1, 1, maxv, c[i], dpn[i] + cost[i]);
    }
    ll res = INF;
    for(int i=1; i<=n; i++){
        res = min(res, cost[i] + dp1[i] + dpn[i]);
    }
    cout << (res == INF ? -1 : res) << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 2 ms 324 KB Output is correct
19 Correct 3 ms 584 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 636 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 2 ms 324 KB Output is correct
19 Correct 3 ms 584 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 636 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 27 ms 2388 KB Output is correct
26 Correct 85 ms 5944 KB Output is correct
27 Correct 250 ms 12928 KB Output is correct
28 Correct 169 ms 8920 KB Output is correct
29 Correct 180 ms 10944 KB Output is correct
30 Correct 249 ms 10196 KB Output is correct
31 Correct 427 ms 20864 KB Output is correct
32 Correct 367 ms 16696 KB Output is correct
33 Correct 55 ms 5656 KB Output is correct
34 Correct 206 ms 15808 KB Output is correct
35 Correct 334 ms 31152 KB Output is correct
36 Correct 539 ms 31164 KB Output is correct
37 Correct 461 ms 31160 KB Output is correct
38 Correct 429 ms 31068 KB Output is correct