Submission #84143

# Submission time Handle Problem Language Result Execution time Memory
84143 2018-11-13T14:38:56 Z Bodo171 Pinball (JOI14_pinball) C++14
100 / 100
691 ms 76316 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <fstream>
using namespace std;
const int nmax=100005;
const long long lim=1LL*1e16;
vector<int> all;
map<int,int> norm;
long long cost[nmax];
long long ans,x,y;
int st[nmax],dr[nmax],out[nmax];
int n,m,i,nr;
struct aint
{
    long long arb[12*nmax];
    void init(int nr)
    {
        for(int i=1;i<=4*nr;i++)
            arb[i]=lim;
    }
    void update(int nod,int l,int r,int poz,long long val)
    {
        arb[nod]=min(arb[nod],val);
        if(l==r)
            return;
        int m=(l+r)/2;
        if(poz<=m) update(2*nod,l,m,poz,val);
        else update(2*nod+1,m+1,r,poz,val);
    }
    long long query(int nod,int l,int r,int st,int dr)
    {
        if(st<=l&&r<=dr)
          return arb[nod];
        int m=(l+r)/2;
        long long ret=lim;
        if(st<=m) ret=min(ret,query(2*nod,l,m,st,dr));
        if(m<dr) ret=min(ret,query(2*nod+1,m+1,r,st,dr));
        return ret;
    }
}leftt,rightt;
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>st[i]>>dr[i]>>out[i]>>cost[i];
        all.push_back(st[i]);
        all.push_back(dr[i]);
        all.push_back(out[i]);
    }
    all.push_back(1);all.push_back(m);
    sort(all.begin(),all.end());
    all.erase(unique(all.begin(),all.end()),all.end());
    nr=all.size();
    for(i=0;i<nr;i++)
       norm[all[i]]=i+1;
    leftt.init(nr);rightt.init(nr);
    leftt.update(1,1,nr,1,0);
    rightt.update(1,1,nr,nr,0);
    ans=lim;
    for(i=1;i<=n;i++)
    {
        st[i]=norm[st[i]];dr[i]=norm[dr[i]];
        out[i]=norm[out[i]];
        x=leftt.query(1,1,nr,st[i],dr[i]);
        y=rightt.query(1,1,nr,st[i],dr[i]);
        if(x+y+cost[i]<ans)
            ans=1LL*x+y+cost[i];
        leftt.update(1,1,nr,out[i],x+cost[i]);
        rightt.update(1,1,nr,out[i],y+cost[i]);
    }
    if(ans==lim) ans=-1;
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
9 Correct 2 ms 652 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 792 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
9 Correct 2 ms 652 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 792 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 3 ms 828 KB Output is correct
17 Correct 4 ms 1040 KB Output is correct
18 Correct 3 ms 1040 KB Output is correct
19 Correct 5 ms 1240 KB Output is correct
20 Correct 4 ms 1240 KB Output is correct
21 Correct 3 ms 1240 KB Output is correct
22 Correct 4 ms 1336 KB Output is correct
23 Correct 4 ms 1376 KB Output is correct
24 Correct 4 ms 1416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
9 Correct 2 ms 652 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 792 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 3 ms 828 KB Output is correct
17 Correct 4 ms 1040 KB Output is correct
18 Correct 3 ms 1040 KB Output is correct
19 Correct 5 ms 1240 KB Output is correct
20 Correct 4 ms 1240 KB Output is correct
21 Correct 3 ms 1240 KB Output is correct
22 Correct 4 ms 1336 KB Output is correct
23 Correct 4 ms 1376 KB Output is correct
24 Correct 4 ms 1416 KB Output is correct
25 Correct 32 ms 3504 KB Output is correct
26 Correct 123 ms 9144 KB Output is correct
27 Correct 350 ms 18156 KB Output is correct
28 Correct 179 ms 18156 KB Output is correct
29 Correct 272 ms 22156 KB Output is correct
30 Correct 318 ms 22156 KB Output is correct
31 Correct 582 ms 39852 KB Output is correct
32 Correct 486 ms 39852 KB Output is correct
33 Correct 63 ms 39852 KB Output is correct
34 Correct 283 ms 42840 KB Output is correct
35 Correct 352 ms 64656 KB Output is correct
36 Correct 691 ms 68704 KB Output is correct
37 Correct 534 ms 72420 KB Output is correct
38 Correct 515 ms 76316 KB Output is correct