답안 #409410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409410 2021-05-20T16:43:44 Z wildturtle Pinball (JOI14_pinball) C++14
0 / 100
1 ms 332 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define sc second
#define pb push_back
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,tree[3000006][4],minn,dp1[100005],dp2[100005];
pair < pair <ll,ll> , pair < ll , ll > > A[100005];
vector <ll> v;
map <ll,ll> mp;
void update(ll node,ll le,ll ri,ll idx,ll val,ll type) {
    if(ri<idx || le>idx) return;
    if(le==ri) { tree[node][type]=min(tree[node][type],val); return; }
    update(2*node,le,(le+ri)/2,idx,val,type);
    update(2*node+1,(le+ri)/2+1,ri,idx,val,type);
    tree[node][type]=min(tree[2*node][type],tree[2*node+1][type]);
}
ll getmin(ll node,ll le,ll ri,ll start,ll end,ll type) {
    if(ri<start || le>end) return 1e17;
    if(start<=le && ri<=end) { return tree[node][type]; }
a=min(getmin(2*node,le,(le+ri)/2,start,end,type),getmin(2*node+1,(le+ri)/2+1,ri,start,end,type));
    return a;
}
int main() {
    cin>>n>>m;
    for(ll i=1;i<=n;i++) {
        cin>>A[i].f.f>>A[i].f.sc>>A[i].sc.f>>A[i].sc.sc;
        v.pb(A[i].f.f);
        v.pb(A[i].f.sc);
        v.pb(A[i].sc.f);
        dp1[i]=1e17; dp2[i]=1e17;
    }
    v.pb(m);
    sort(v.begin(),v.end());
    k=1; mp[v[0]]=k;
    for(ll i=1;i<v.size();i++) {
        if(v[i]>v[i-1]) k++;
        mp[v[i]]=k;
    }
    for(ll i=1;i<=n;i++) {
        A[i].f.f=mp[A[i].f.f];
        A[i].f.sc=mp[A[i].f.sc];
        A[i].sc.f=mp[A[i].sc.f];
        //cout<<A[i].f.f<<" "<<A[i].f.sc<<" "<<A[i].sc.f<<endl;
    }
    m=mp[m];
    for(ll i=0;i<=4*m;i++) {
        tree[i][1]=1e17;
        tree[i][2]=1e17;
    }
    minn=1e17;
    for(ll i=1;i<=n;i++) {
        if(A[i].f.f==1) dp1[i]=A[i].sc.sc;
        if(A[i].f.sc==m) dp2[i]=A[i].sc.sc;
        if(dp1[i]==1e17) {
            //cout<<"* "<<getmin(1,1,m,A[i].f.f,A[i].f.sc,1)<<" ";
            dp1[i]=getmin(1,1,m,A[i].f.f,A[i].f.sc,1)+A[i].sc.sc;
        }
        if(dp2[i]==1e17) {
          //  cout<<"^";
            dp2[i]=getmin(1,1,m,A[i].f.f,A[i].f.sc,2)+A[i].sc.sc;
        }
        //cout<<dp1[i]<<" "<<dp2[i]<<endl;
        update(1,1,m,A[i].sc.f,dp1[i],1);
        update(1,1,m,A[i].sc.f,dp2[i],2);
        minn=min(minn,dp1[i]+dp2[i]-A[i].sc.sc);
    }
    if(minn==1e17) cout<<-1;
    else cout<<minn;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:36:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(ll i=1;i<v.size();i++) {
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -