답안 #105501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105501 2019-04-13T00:42:06 Z onjo0127 Pinball (JOI14_pinball) C++11
100 / 100
323 ms 14260 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1LL * 1e18;

vector<int> S;
int A[100009], B[100009], C[100009], D[100009];
long long lm[100009], rm[100009];

struct segtree {
    vector<long long> T;
    segtree(int N) {
        T.resize(4*N, 0);
    }
    void upd(int idx, int s, int e, int x, long long y) {
        if(x < s || e < x) return;
        if(s == e) {
            T[idx] = y;
            return;
        }
        int m = s+e >> 1;
        upd(idx*2, s, m, x, y);
        upd(idx*2+1, m+1, e, x, y);
        T[idx] = min(T[idx*2], T[idx*2+1]);
    }
    long long mn(int idx, int s, int e, int l, int r) {
        if(r < s || e < l) return INF;
        if(l <= s && e <= r) return T[idx];
        int m = s+e >> 1;
        return min(mn(idx*2, s, m, l, r), mn(idx*2+1, m+1, e, l, r));
    }
};

int main() {
    int M, N; scanf("%d%d",&M,&N);
    for(int i=1; i<=M; i++) {
        scanf("%d%d%d%d",&A[i],&B[i],&C[i],&D[i]);
        S.push_back(C[i]);
    } S.push_back(1); S.push_back(N);
    sort(S.begin(), S.end());
    S.resize(unique(S.begin(), S.end()) - S.begin());

    long long ans = INF;
    int sz = S.size();
    segtree lseg(sz), rseg(sz);
    for(int i=1; i<sz; i++) {lseg.upd(1, 0, sz-1, i, INF); lm[i] = INF;}
    for(int i=0; i<sz-1; i++) {rseg.upd(1, 0, sz-1, i, INF); rm[i] = INF;}
    for(int i=1; i<=M; i++) {
        int l = lower_bound(S.begin(), S.end(), A[i]) - S.begin();
        int r = lower_bound(S.begin(), S.end(), B[i]+1) - S.begin() - 1;
        int x = lower_bound(S.begin(), S.end(), C[i]) - S.begin();
        long long lmn = lseg.mn(1, 0, sz-1, l, r);
        long long rmn = rseg.mn(1, 0, sz-1, l, r);
        ans = min(ans, lmn + rmn + D[i]);
        lm[x] = min(lm[x], lmn + D[i]);
        rm[x] = min(rm[x], rmn + D[i]);
        lseg.upd(1, 0, sz-1, x, lm[x]);
        rseg.upd(1, 0, sz-1, x, rm[x]);
    }
    if(ans == INF) puts("-1");
    else printf("%lld", ans);
    return 0;
}

Compilation message

pinball.cpp: In member function 'void segtree::upd(int, int, int, int, long long int)':
pinball.cpp:21:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = s+e >> 1;
                 ~^~
pinball.cpp: In member function 'long long int segtree::mn(int, int, int, int, int)':
pinball.cpp:29:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = s+e >> 1;
                 ~^~
pinball.cpp: In function 'int main()':
pinball.cpp:35:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int M, N; scanf("%d%d",&M,&N);
               ~~~~~^~~~~~~~~~~~~~
pinball.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d",&A[i],&B[i],&C[i],&D[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 372 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 372 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 372 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 26 ms 1408 KB Output is correct
26 Correct 64 ms 3448 KB Output is correct
27 Correct 199 ms 7920 KB Output is correct
28 Correct 133 ms 6256 KB Output is correct
29 Correct 113 ms 6260 KB Output is correct
30 Correct 184 ms 7024 KB Output is correct
31 Correct 251 ms 11760 KB Output is correct
32 Correct 269 ms 10732 KB Output is correct
33 Correct 37 ms 3072 KB Output is correct
34 Correct 126 ms 7412 KB Output is correct
35 Correct 181 ms 14132 KB Output is correct
36 Correct 323 ms 14192 KB Output is correct
37 Correct 303 ms 14260 KB Output is correct
38 Correct 276 ms 14064 KB Output is correct