Submission #146649

# Submission time Handle Problem Language Result Execution time Memory
146649 2019-08-24T20:19:12 Z brcode Pinball (JOI14_pinball) C++14
51 / 100
1000 ms 46688 KB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const long long MAXN = 1e6+5;
long long a[MAXN];
long long b[MAXN];
long long ans = 1e17;
long long c[MAXN];
long long d[MAXN];
map<long long,long long> compress;
long long dp[MAXN];
long long dp2[MAXN];
long long seg[12*MAXN];
vector<long long> v1;
void build(long long curr,long long l,long long r){
   
    if(l==r){
        
        seg[curr] = 1e17;
        return;
    }
    long long mid = (l+r)/2;
    build(2*curr,l,mid);
    build(2*curr+1,mid+1,r);
    seg[curr] = min(seg[2*curr],seg[2*curr+1]);
    //cout<<seg[curr]<<endl;
}
long long query(long long curr,long long tl,long long tr,long long l,long long r){
    if(l>tr||r<tl){
        return 1e17;
    }
    if(tl == 5 && tr == 12){
     //   cout<<seg[curr]<<" "<<l<<" "<<r<<endl;
    }
    if(l>=tl && r<=tr){
        return seg[curr];
    }
    long long mid = (l+r)/2;
    return min(query(2*curr,tl,tr,l,mid),query(2*curr+1,tl,tr,mid+1,r));
}
void update(long long curr,long long l,long long r,long long pos,long long val){
    if(l==r){
        seg[curr] = min(seg[curr],val);
        
        return;
    }
    
    long long mid = (l+r)/2;
    if(pos<=mid){
        update(2*curr,l,mid,pos,val);
    }else{
        update(2*curr+1,mid+1,r,pos,val);
    }
    seg[curr] = min(seg[2*curr],seg[2*curr+1]);
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,m;
    cin>>n>>m;
    
    for(long long i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];    
        v1.push_back(a[i]);
        v1.push_back(b[i]);
        v1.push_back(c[i]);
    }
    sort(v1.begin(),v1.end());
    for(long long i=1;i<=3*n;i++){
        compress[v1[i-1]] = i;
    }
    int newcols = v1.size()+1;
   // cout<<newcols<<endl;
        for(long long i=1;i<=n;i++){
        dp[i] = 1e17;
        dp2[i] = 1e17;
    }
    build(1,1,3*newcols);
    for(long long i=1;i<=n;i++){
        if(a[i] == 1){
            dp[i] = d[i];
        }
        
        dp[i] = min(dp[i],d[i] + query(1,compress[a[i]],compress[b[i]],1,3*newcols));
        
        update(1,1,3*newcols,compress[c[i]],dp[i]);
       // cout<<dp[i]<<" "<<compress[b[i]]<<" "<<compress[c[i]]<<endl;
    }
    build(1,1,3*newcols);
    for(long long i=1;i<=n;i++){
        if(b[i] == m){
            dp2[i] = d[i];
        }
        dp2[i] = min(dp2[i],d[i] + query(1,compress[a[i]],compress[b[i]],1,3*newcols));
        update(1,1,3*newcols,compress[c[i]],dp2[i]);
//cout<<<<" "<<dp2[i]<<endl;
    }
    for(long long i=1;i<=n;i++){
        ans = min(ans,dp[i]+dp2[i]-d[i]);
       // cout<<i<<" "<<dp2[i]<<endl;
    }
    if(ans>=1e17){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 5 ms 888 KB Output is correct
20 Correct 5 ms 760 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 5 ms 888 KB Output is correct
24 Correct 5 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 5 ms 888 KB Output is correct
20 Correct 5 ms 760 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 5 ms 888 KB Output is correct
24 Correct 5 ms 888 KB Output is correct
25 Correct 49 ms 4216 KB Output is correct
26 Correct 200 ms 9712 KB Output is correct
27 Correct 533 ms 28180 KB Output is correct
28 Correct 331 ms 24072 KB Output is correct
29 Correct 359 ms 18024 KB Output is correct
30 Correct 586 ms 24928 KB Output is correct
31 Correct 847 ms 34492 KB Output is correct
32 Correct 776 ms 35292 KB Output is correct
33 Correct 91 ms 10336 KB Output is correct
34 Correct 392 ms 23532 KB Output is correct
35 Correct 493 ms 46688 KB Output is correct
36 Execution timed out 1006 ms 46580 KB Time limit exceeded
37 Halted 0 ms 0 KB -