답안 #146648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146648 2019-08-24T20:18:32 Z brcode Pinball (JOI14_pinball) C++14
51 / 100
1000 ms 38356 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(){
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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 376 KB Output is correct
5 Correct 2 ms 380 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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 376 KB Output is correct
5 Correct 2 ms 380 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 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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 376 KB Output is correct
5 Correct 2 ms 380 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 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 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 4 ms 504 KB Output is correct
17 Correct 7 ms 760 KB Output is correct
18 Correct 6 ms 760 KB Output is correct
19 Correct 8 ms 888 KB Output is correct
20 Correct 7 ms 760 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 7 ms 888 KB Output is correct
23 Correct 7 ms 888 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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 376 KB Output is correct
5 Correct 2 ms 380 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 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 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 4 ms 504 KB Output is correct
17 Correct 7 ms 760 KB Output is correct
18 Correct 6 ms 760 KB Output is correct
19 Correct 8 ms 888 KB Output is correct
20 Correct 7 ms 760 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 7 ms 888 KB Output is correct
23 Correct 7 ms 888 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
25 Correct 73 ms 4216 KB Output is correct
26 Correct 229 ms 9780 KB Output is correct
27 Correct 687 ms 28076 KB Output is correct
28 Correct 557 ms 27920 KB Output is correct
29 Correct 466 ms 19812 KB Output is correct
30 Correct 767 ms 28920 KB Output is correct
31 Execution timed out 1073 ms 38356 KB Time limit exceeded
32 Halted 0 ms 0 KB -