Submission #52572

# Submission time Handle Problem Language Result Execution time Memory
52572 2018-06-26T07:30:55 Z tlwpdus Pinball (JOI14_pinball) C++11
100 / 100
265 ms 15932 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const ll INF = 1LL<<55;

struct segtree {
    int key = 524288;
    ll tree[1050000];
    void init() {
        int i;
        for (i=0;i<2*key;i++) tree[i] = INF;
    }
    void upd(int idx, ll v) {
        idx += key;
        while(idx) {
            tree[idx] = min(tree[idx],v);
            idx/=2;
        }
    }
    ll getv(int s, int e) {
        s += key; e += key;
        ll val = INF;
        while(s<=e) {
            if (s&1) val = min(val,tree[s++]);
            if (~e&1) val = min(val,tree[e--]);
            s/=2; e/=2;
        }
        return val;
    }
} st;

int m, n;
ll A[100100], B[100100], C[100100], D[100100], L[100100], R[100100];
vector<ll> comp;

int main() {
    int i;

    scanf("%d%d",&m,&n);
    for (i=0;i<m;i++) scanf("%lld%lld%lld%lld",&A[i],&B[i],&C[i],&D[i]);
    for (i=0;i<m;i++) {
        comp.push_back(A[i]);
        comp.push_back(B[i]);
        comp.push_back(C[i]);
    }
    comp.push_back(1); comp.push_back(n);
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());
    for (i=0;i<m;i++) {
        A[i] = lower_bound(comp.begin(),comp.end(),A[i])-comp.begin();
        B[i] = lower_bound(comp.begin(),comp.end(),B[i])-comp.begin();
        C[i] = lower_bound(comp.begin(),comp.end(),C[i])-comp.begin();
    }
    st.init();
    st.upd(0,0);
    for (i=0;i<m;i++) st.upd(C[i],L[i] = st.getv(A[i],B[i])+D[i]);
    st.init();
    st.upd((int)comp.size()-1,0);
    for (i=0;i<m;i++) st.upd(C[i],R[i] = st.getv(A[i],B[i])+D[i]);
    ll res = INF;
    for (i=0;i<m;i++) res = min(res,L[i]+R[i]-D[i]);
    if (res>INF-1000) printf("-1\n");
    else printf("%lld\n",res);

    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&m,&n);
     ~~~~~^~~~~~~~~~~~~~
pinball.cpp:44:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=0;i<m;i++) scanf("%lld%lld%lld%lld",&A[i],&B[i],&C[i],&D[i]);
                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8568 KB Output is correct
2 Correct 8 ms 8568 KB Output is correct
3 Correct 8 ms 8600 KB Output is correct
4 Correct 9 ms 8600 KB Output is correct
5 Correct 8 ms 8648 KB Output is correct
6 Correct 9 ms 8652 KB Output is correct
7 Correct 9 ms 8660 KB Output is correct
8 Correct 8 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8568 KB Output is correct
2 Correct 8 ms 8568 KB Output is correct
3 Correct 8 ms 8600 KB Output is correct
4 Correct 9 ms 8600 KB Output is correct
5 Correct 8 ms 8648 KB Output is correct
6 Correct 9 ms 8652 KB Output is correct
7 Correct 9 ms 8660 KB Output is correct
8 Correct 8 ms 8660 KB Output is correct
9 Correct 8 ms 8792 KB Output is correct
10 Correct 9 ms 8792 KB Output is correct
11 Correct 9 ms 8864 KB Output is correct
12 Correct 11 ms 8864 KB Output is correct
13 Correct 9 ms 8864 KB Output is correct
14 Correct 9 ms 8864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8568 KB Output is correct
2 Correct 8 ms 8568 KB Output is correct
3 Correct 8 ms 8600 KB Output is correct
4 Correct 9 ms 8600 KB Output is correct
5 Correct 8 ms 8648 KB Output is correct
6 Correct 9 ms 8652 KB Output is correct
7 Correct 9 ms 8660 KB Output is correct
8 Correct 8 ms 8660 KB Output is correct
9 Correct 8 ms 8792 KB Output is correct
10 Correct 9 ms 8792 KB Output is correct
11 Correct 9 ms 8864 KB Output is correct
12 Correct 11 ms 8864 KB Output is correct
13 Correct 9 ms 8864 KB Output is correct
14 Correct 9 ms 8864 KB Output is correct
15 Correct 10 ms 8864 KB Output is correct
16 Correct 9 ms 8864 KB Output is correct
17 Correct 9 ms 8880 KB Output is correct
18 Correct 10 ms 8880 KB Output is correct
19 Correct 10 ms 8880 KB Output is correct
20 Correct 11 ms 8880 KB Output is correct
21 Correct 11 ms 8880 KB Output is correct
22 Correct 12 ms 8880 KB Output is correct
23 Correct 9 ms 8884 KB Output is correct
24 Correct 13 ms 8884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8568 KB Output is correct
2 Correct 8 ms 8568 KB Output is correct
3 Correct 8 ms 8600 KB Output is correct
4 Correct 9 ms 8600 KB Output is correct
5 Correct 8 ms 8648 KB Output is correct
6 Correct 9 ms 8652 KB Output is correct
7 Correct 9 ms 8660 KB Output is correct
8 Correct 8 ms 8660 KB Output is correct
9 Correct 8 ms 8792 KB Output is correct
10 Correct 9 ms 8792 KB Output is correct
11 Correct 9 ms 8864 KB Output is correct
12 Correct 11 ms 8864 KB Output is correct
13 Correct 9 ms 8864 KB Output is correct
14 Correct 9 ms 8864 KB Output is correct
15 Correct 10 ms 8864 KB Output is correct
16 Correct 9 ms 8864 KB Output is correct
17 Correct 9 ms 8880 KB Output is correct
18 Correct 10 ms 8880 KB Output is correct
19 Correct 10 ms 8880 KB Output is correct
20 Correct 11 ms 8880 KB Output is correct
21 Correct 11 ms 8880 KB Output is correct
22 Correct 12 ms 8880 KB Output is correct
23 Correct 9 ms 8884 KB Output is correct
24 Correct 13 ms 8884 KB Output is correct
25 Correct 24 ms 9536 KB Output is correct
26 Correct 51 ms 10660 KB Output is correct
27 Correct 136 ms 13772 KB Output is correct
28 Correct 156 ms 15840 KB Output is correct
29 Correct 105 ms 15840 KB Output is correct
30 Correct 174 ms 15912 KB Output is correct
31 Correct 215 ms 15912 KB Output is correct
32 Correct 208 ms 15932 KB Output is correct
33 Correct 34 ms 15932 KB Output is correct
34 Correct 103 ms 15932 KB Output is correct
35 Correct 148 ms 15932 KB Output is correct
36 Correct 265 ms 15932 KB Output is correct
37 Correct 221 ms 15932 KB Output is correct
38 Correct 174 ms 15932 KB Output is correct