Submission #225782

# Submission time Handle Problem Language Result Execution time Memory
225782 2020-04-21T15:07:20 Z MKopchev Pinball (JOI14_pinball) C++14
100 / 100
482 ms 72056 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e6+42;
const long long inf=1e18;

int n,m;

struct row
{
    int l,r,go,cost;
};

row inp[nmax];

long long tree[2][4*nmax];

void update(int which,int node,int l,int r,int pos,long long val)
{
    if(l==r)
    {
        tree[which][node]=min(tree[which][node],val);
        return;
    }

    int av=(l+r)/2;
    if(pos<=av)update(which,node*2,l,av,pos,val);
    else update(which,node*2+1,av+1,r,pos,val);

    tree[which][node]=min(tree[which][node],val);
}

long long query(int which,int node,int l,int r,int lq,int rq)
{
    if(l==lq&&r==rq)return tree[which][node];

    long long ret=inf;
    int av=(l+r)/2;

    if(lq<=av)ret=min(ret,query(which,node*2,l,av,lq,min(av,rq)));
    if(av<rq)ret=min(ret,query(which,node*2+1,av+1,r,max(av+1,lq),rq));
    return ret;
}
int help[nmax],pointer=0;

void add(int val)
{
    if(1>val||val>n)return;
    pointer++;
    help[pointer]=val;
}
void note(int val)
{
    add(val-1);
    add(val);
    add(val+1);
}

int where(int val)
{
    int pos=lower_bound(help+1,help+pointer+1,val)-help;
    return pos;
}
int main()
{
    scanf("%i%i",&m,&n);

    add(1);
    add(n);

    for(int i=1;i<=m;i++)
    {
        scanf("%i%i%i%i",&inp[i].l,&inp[i].r,&inp[i].go,&inp[i].cost);

        note(inp[i].l);
        note(inp[i].r);
        note(inp[i].go);
    }

    sort(help+1,help+pointer+1);

    //for(int i=1;i<=pointer;i++)cout<<help[i]<<" ";cout<<endl;

    for(int i=0;i<4*nmax;i++)
    {
        tree[0][i]=inf;
        tree[1][i]=inf;
    }

    update(0,1,1,pointer,where(1),0);

    update(1,1,1,pointer,where(n),0);

    long long output=inf;

    for(int i=1;i<=m;i++)
    {
        long long cost_0=query(0,1,1,pointer,where(inp[i].l),where(inp[i].r));
        long long cost_1=query(1,1,1,pointer,where(inp[i].l),where(inp[i].r));

        //use the current as a meeting point
        output=min(output,cost_0+cost_1+inp[i].cost);

        update(0,1,1,pointer,where(inp[i].go),cost_0+inp[i].cost);

        update(1,1,1,pointer,where(inp[i].go),cost_1+inp[i].cost);
    }

    if(output>=inf)printf("-1\n");
    else printf("%lld\n",output);
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&m,&n);
     ~~~~~^~~~~~~~~~~~~~
pinball.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i%i%i",&inp[i].l,&inp[i].r,&inp[i].go,&inp[i].cost);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 41 ms 62968 KB Output is correct
2 Correct 33 ms 62968 KB Output is correct
3 Correct 33 ms 62976 KB Output is correct
4 Correct 39 ms 62976 KB Output is correct
5 Correct 38 ms 62976 KB Output is correct
6 Correct 39 ms 62848 KB Output is correct
7 Correct 33 ms 62968 KB Output is correct
8 Correct 33 ms 62976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 62968 KB Output is correct
2 Correct 33 ms 62968 KB Output is correct
3 Correct 33 ms 62976 KB Output is correct
4 Correct 39 ms 62976 KB Output is correct
5 Correct 38 ms 62976 KB Output is correct
6 Correct 39 ms 62848 KB Output is correct
7 Correct 33 ms 62968 KB Output is correct
8 Correct 33 ms 62976 KB Output is correct
9 Correct 36 ms 62968 KB Output is correct
10 Correct 36 ms 62968 KB Output is correct
11 Correct 35 ms 62976 KB Output is correct
12 Correct 35 ms 62976 KB Output is correct
13 Correct 37 ms 63104 KB Output is correct
14 Correct 33 ms 62968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 62968 KB Output is correct
2 Correct 33 ms 62968 KB Output is correct
3 Correct 33 ms 62976 KB Output is correct
4 Correct 39 ms 62976 KB Output is correct
5 Correct 38 ms 62976 KB Output is correct
6 Correct 39 ms 62848 KB Output is correct
7 Correct 33 ms 62968 KB Output is correct
8 Correct 33 ms 62976 KB Output is correct
9 Correct 36 ms 62968 KB Output is correct
10 Correct 36 ms 62968 KB Output is correct
11 Correct 35 ms 62976 KB Output is correct
12 Correct 35 ms 62976 KB Output is correct
13 Correct 37 ms 63104 KB Output is correct
14 Correct 33 ms 62968 KB Output is correct
15 Correct 34 ms 62976 KB Output is correct
16 Correct 42 ms 62968 KB Output is correct
17 Correct 41 ms 62972 KB Output is correct
18 Correct 42 ms 63096 KB Output is correct
19 Correct 41 ms 63096 KB Output is correct
20 Correct 36 ms 62968 KB Output is correct
21 Correct 34 ms 62976 KB Output is correct
22 Correct 36 ms 63096 KB Output is correct
23 Correct 35 ms 62968 KB Output is correct
24 Correct 43 ms 62968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 62968 KB Output is correct
2 Correct 33 ms 62968 KB Output is correct
3 Correct 33 ms 62976 KB Output is correct
4 Correct 39 ms 62976 KB Output is correct
5 Correct 38 ms 62976 KB Output is correct
6 Correct 39 ms 62848 KB Output is correct
7 Correct 33 ms 62968 KB Output is correct
8 Correct 33 ms 62976 KB Output is correct
9 Correct 36 ms 62968 KB Output is correct
10 Correct 36 ms 62968 KB Output is correct
11 Correct 35 ms 62976 KB Output is correct
12 Correct 35 ms 62976 KB Output is correct
13 Correct 37 ms 63104 KB Output is correct
14 Correct 33 ms 62968 KB Output is correct
15 Correct 34 ms 62976 KB Output is correct
16 Correct 42 ms 62968 KB Output is correct
17 Correct 41 ms 62972 KB Output is correct
18 Correct 42 ms 63096 KB Output is correct
19 Correct 41 ms 63096 KB Output is correct
20 Correct 36 ms 62968 KB Output is correct
21 Correct 34 ms 62976 KB Output is correct
22 Correct 36 ms 63096 KB Output is correct
23 Correct 35 ms 62968 KB Output is correct
24 Correct 43 ms 62968 KB Output is correct
25 Correct 63 ms 63736 KB Output is correct
26 Correct 119 ms 65272 KB Output is correct
27 Correct 360 ms 68984 KB Output is correct
28 Correct 383 ms 71928 KB Output is correct
29 Correct 233 ms 67448 KB Output is correct
30 Correct 482 ms 72056 KB Output is correct
31 Correct 461 ms 71952 KB Output is correct
32 Correct 460 ms 71928 KB Output is correct
33 Correct 82 ms 64632 KB Output is correct
34 Correct 249 ms 67448 KB Output is correct
35 Correct 266 ms 72056 KB Output is correct
36 Correct 453 ms 71956 KB Output is correct
37 Correct 378 ms 71976 KB Output is correct
38 Correct 375 ms 71928 KB Output is correct