Submission #362265

# Submission time Handle Problem Language Result Execution time Memory
362265 2021-02-02T12:26:00 Z denkendoemeer Pinball (JOI14_pinball) C++14
100 / 100
229 ms 23532 KB
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int a[100005],b[100005],c[100005],d[100005],e[400005];
ll r1[1<<20],r2[1<<20];
void add(ll *a,int poz,ll val)
{
    poz+=1<<19;
    while(poz){
        a[poz]=min(a[poz],val);
        poz/=2;
    }
}
ll rem(ll *a,int poz,int poz2)
{
    ll ans=1e18;
    poz+=1<<19;
    poz2+=1<<19;
    while(poz<poz2){
        if (poz&1)
            ans=min(ans,a[poz++]);
        if (~poz2&1)
            ans=min(ans,a[poz2--]);
        poz=poz/2;
        poz2=poz2/2;
    }
    if (poz==poz2)
        ans=min(ans,a[poz]);
    return ans;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int n,m,i;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
    int u=0;
    e[u++]=1;
    e[u++]=m;
    for(i=0;i<n;i++){
        e[u++]=a[i];
        e[u++]=b[i];
        e[u++]=c[i];
    }
    sort(e,e+u);
    u=unique(e,e+u)-e;
    for(i=0;i<n;i++){
        a[i]=lower_bound(e,e+u,a[i])-e;
        b[i]=lower_bound(e,e+u,b[i])-e;
        c[i]=lower_bound(e,e+u,c[i])-e;
    }
    for(i=0;i<(1<<20);i++)
        r1[i]=r2[i]=1e18;
    add(r1,0,0);
    add(r2,u-1,0);
    ll ans=1e18;
    for(i=0;i<n;i++){
        ll aux1=rem(r1,a[i],b[i]),aux2=rem(r2,a[i],b[i]);
        add(r1,c[i],aux1+d[i]);
        add(r2,c[i],aux2+d[i]);
        ans=min(ans,aux1+aux2+d[i]);
    }
    if (ans==1e18)
        printf("-1\n");
    else
        printf("%lld\n",ans);
return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
pinball.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |         scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 11 ms 16896 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 11 ms 16896 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
9 Correct 10 ms 16748 KB Output is correct
10 Correct 11 ms 16748 KB Output is correct
11 Correct 10 ms 16748 KB Output is correct
12 Correct 11 ms 16748 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 10 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 11 ms 16896 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
9 Correct 10 ms 16748 KB Output is correct
10 Correct 11 ms 16748 KB Output is correct
11 Correct 10 ms 16748 KB Output is correct
12 Correct 11 ms 16748 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 10 ms 16748 KB Output is correct
15 Correct 10 ms 16748 KB Output is correct
16 Correct 10 ms 16748 KB Output is correct
17 Correct 13 ms 16748 KB Output is correct
18 Correct 12 ms 16876 KB Output is correct
19 Correct 11 ms 16748 KB Output is correct
20 Correct 13 ms 16748 KB Output is correct
21 Correct 11 ms 16748 KB Output is correct
22 Correct 11 ms 16748 KB Output is correct
23 Correct 11 ms 16748 KB Output is correct
24 Correct 11 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 11 ms 16896 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
9 Correct 10 ms 16748 KB Output is correct
10 Correct 11 ms 16748 KB Output is correct
11 Correct 10 ms 16748 KB Output is correct
12 Correct 11 ms 16748 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 10 ms 16748 KB Output is correct
15 Correct 10 ms 16748 KB Output is correct
16 Correct 10 ms 16748 KB Output is correct
17 Correct 13 ms 16748 KB Output is correct
18 Correct 12 ms 16876 KB Output is correct
19 Correct 11 ms 16748 KB Output is correct
20 Correct 13 ms 16748 KB Output is correct
21 Correct 11 ms 16748 KB Output is correct
22 Correct 11 ms 16748 KB Output is correct
23 Correct 11 ms 16748 KB Output is correct
24 Correct 11 ms 16748 KB Output is correct
25 Correct 23 ms 17260 KB Output is correct
26 Correct 47 ms 18304 KB Output is correct
27 Correct 122 ms 21100 KB Output is correct
28 Correct 122 ms 23276 KB Output is correct
29 Correct 90 ms 20076 KB Output is correct
30 Correct 147 ms 23532 KB Output is correct
31 Correct 183 ms 23276 KB Output is correct
32 Correct 173 ms 23276 KB Output is correct
33 Correct 34 ms 17924 KB Output is correct
34 Correct 94 ms 20204 KB Output is correct
35 Correct 115 ms 23276 KB Output is correct
36 Correct 229 ms 23276 KB Output is correct
37 Correct 170 ms 23404 KB Output is correct
38 Correct 159 ms 23276 KB Output is correct