답안 #546354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546354 2022-04-07T10:53:53 Z krit3379 Pinball (JOI14_pinball) C++17
100 / 100
336 ms 32468 KB
#include<bits/stdc++.h>
using namespace std;
#define N 400005

int a[N],b[N],c[N],d[N];
long long l,r,ans=1e18;
vector<int> v;

class tree{
public:
    vector<long long> t;
    tree():t(4*N,1e18){}
    void update(int x,int l,int r,int i,long long val){
        if(l>c[i]||r<c[i])return ;
        if(l==r){
            t[x]=min(t[x],val);
            return ;
        }
        int mid=(l+r)/2;
        update(x*2,l,mid,i,val);
        update(x*2+1,mid+1,r,i,val);
        t[x]=min(t[x*2],t[x*2+1]);
    }
    long long sol(int x,int l,int r,int i){
        if(l>b[i]||a[i]>r)return 1e18;
        if(a[i]<=l&&r<=b[i])return t[x];
        int mid=(l+r)/2;
        return min(sol(x*2,l,mid,i),sol(x*2+1,mid+1,r,i));
    }
}t1,t2;

int main(){
    int n,m,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
        v.push_back(a[i]);
        v.push_back(b[i]);
        v.push_back(c[i]);
    }
    v.push_back(-1);
    v.push_back(1);
    v.push_back(m);
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    for(i=1;i<=n;i++){
        a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
        b[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin();
        c[i]=lower_bound(v.begin(),v.end(),c[i])-v.begin();
        if(a[i]!=1)l=t1.sol(1,1,v.size()-1,i);
        else l=0;
        if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
        else r=0;
        ans=min(ans,l+r+d[i]);
        t1.update(1,1,v.size()-1,i,l+d[i]);
        t2.update(1,1,v.size()-1,i,r+d[i]);
    }
    if(ans!=1e18)printf("%lld",ans);
    else printf("-1");
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
      |            ~~~~^~~~~~~~~~~~
pinball.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
pinball.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 25300 KB Output is correct
2 Correct 16 ms 25296 KB Output is correct
3 Correct 19 ms 25336 KB Output is correct
4 Correct 13 ms 25308 KB Output is correct
5 Correct 12 ms 25300 KB Output is correct
6 Correct 12 ms 25300 KB Output is correct
7 Correct 15 ms 25320 KB Output is correct
8 Correct 12 ms 25348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 25300 KB Output is correct
2 Correct 16 ms 25296 KB Output is correct
3 Correct 19 ms 25336 KB Output is correct
4 Correct 13 ms 25308 KB Output is correct
5 Correct 12 ms 25300 KB Output is correct
6 Correct 12 ms 25300 KB Output is correct
7 Correct 15 ms 25320 KB Output is correct
8 Correct 12 ms 25348 KB Output is correct
9 Correct 15 ms 25300 KB Output is correct
10 Correct 12 ms 25404 KB Output is correct
11 Correct 12 ms 25300 KB Output is correct
12 Correct 12 ms 25300 KB Output is correct
13 Correct 19 ms 25300 KB Output is correct
14 Correct 15 ms 25300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 25300 KB Output is correct
2 Correct 16 ms 25296 KB Output is correct
3 Correct 19 ms 25336 KB Output is correct
4 Correct 13 ms 25308 KB Output is correct
5 Correct 12 ms 25300 KB Output is correct
6 Correct 12 ms 25300 KB Output is correct
7 Correct 15 ms 25320 KB Output is correct
8 Correct 12 ms 25348 KB Output is correct
9 Correct 15 ms 25300 KB Output is correct
10 Correct 12 ms 25404 KB Output is correct
11 Correct 12 ms 25300 KB Output is correct
12 Correct 12 ms 25300 KB Output is correct
13 Correct 19 ms 25300 KB Output is correct
14 Correct 15 ms 25300 KB Output is correct
15 Correct 16 ms 25392 KB Output is correct
16 Correct 13 ms 25336 KB Output is correct
17 Correct 15 ms 25428 KB Output is correct
18 Correct 13 ms 25428 KB Output is correct
19 Correct 14 ms 25368 KB Output is correct
20 Correct 13 ms 25428 KB Output is correct
21 Correct 13 ms 25428 KB Output is correct
22 Correct 13 ms 25316 KB Output is correct
23 Correct 12 ms 25428 KB Output is correct
24 Correct 14 ms 25428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 25300 KB Output is correct
2 Correct 16 ms 25296 KB Output is correct
3 Correct 19 ms 25336 KB Output is correct
4 Correct 13 ms 25308 KB Output is correct
5 Correct 12 ms 25300 KB Output is correct
6 Correct 12 ms 25300 KB Output is correct
7 Correct 15 ms 25320 KB Output is correct
8 Correct 12 ms 25348 KB Output is correct
9 Correct 15 ms 25300 KB Output is correct
10 Correct 12 ms 25404 KB Output is correct
11 Correct 12 ms 25300 KB Output is correct
12 Correct 12 ms 25300 KB Output is correct
13 Correct 19 ms 25300 KB Output is correct
14 Correct 15 ms 25300 KB Output is correct
15 Correct 16 ms 25392 KB Output is correct
16 Correct 13 ms 25336 KB Output is correct
17 Correct 15 ms 25428 KB Output is correct
18 Correct 13 ms 25428 KB Output is correct
19 Correct 14 ms 25368 KB Output is correct
20 Correct 13 ms 25428 KB Output is correct
21 Correct 13 ms 25428 KB Output is correct
22 Correct 13 ms 25316 KB Output is correct
23 Correct 12 ms 25428 KB Output is correct
24 Correct 14 ms 25428 KB Output is correct
25 Correct 30 ms 25780 KB Output is correct
26 Correct 87 ms 26320 KB Output is correct
27 Correct 189 ms 27416 KB Output is correct
28 Correct 152 ms 28908 KB Output is correct
29 Correct 134 ms 27228 KB Output is correct
30 Correct 198 ms 28920 KB Output is correct
31 Correct 279 ms 28844 KB Output is correct
32 Correct 241 ms 32408 KB Output is correct
33 Correct 43 ms 26692 KB Output is correct
34 Correct 140 ms 29088 KB Output is correct
35 Correct 183 ms 32468 KB Output is correct
36 Correct 336 ms 32448 KB Output is correct
37 Correct 257 ms 32432 KB Output is correct
38 Correct 238 ms 32448 KB Output is correct