Submission #53828

# Submission time Handle Problem Language Result Execution time Memory
53828 2018-07-01T09:00:07 Z TadijaSebez Pinball (JOI14_pinball) C++11
51 / 100
1000 ms 45416 KB
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
const int N=200050;
const int M=32*N*2;
const ll inf=1e18;
int ls[M],rs[M],tsz,root,root2;ll Min[M];
void Set(int &c, int ss, int se, int qi, ll val)
{
    if(!c) c=++tsz,Min[c]=val;
    Min[c]=min(Min[c],val);
    if(ss==se) return;
    int mid=ss+se>>1;
    if(qi<=mid) Set(ls[c],ss,mid,qi,val);
    else Set(rs[c],mid+1,se,qi,val);
}
ll Get(int c, int ss, int se, int qs, int qe)
{
    if(qs>se || ss>qe) return inf;
    if(qs<=ss && qe>=se) return Min[c];
    int mid=ss+se>>1;
    return min(Get(ls[c],ss,mid,qs,qe),Get(rs[c],mid+1,se,qs,qe));
}
map<int,ll> dp1,dp2;
int a[N],b[N],c[N];
ll d1[N],d2[N],d[N];
int main()
{
    Min[0]=inf;
    int n,m,i;
    scanf("%i %i",&n,&m);
    for(i=1;i<=n;i++) scanf("%i %i %i %lld",&a[i],&b[i],&c[i],&d[i]),dp1[c[i]]=dp2[c[i]]=inf,d1[i]=d2[i]=inf;
    for(i=1;i<=n;i++)
    {
        ll y;
        if(a[i]==1)
        {
            ll x=dp1[c[i]];y=d[i];
            dp1[c[i]]=min(x,y);
            Set(root,1,m,c[i],d[i]);
        }
        else
        {
            ll x=dp1[c[i]];y=Get(root,1,m,a[i],b[i])+d[i];
            dp1[c[i]]=min(x,y);
            Set(root,1,m,c[i],dp1[c[i]]);
        }
        d1[i]=y;
    }
    for(i=1;i<=n;i++)
    {
        ll y;
        if(b[i]==m)
        {
            ll x=dp2[c[i]];y=d[i];
            dp2[c[i]]=min(x,y);
            Set(root2,1,m,c[i],d[i]);
        }
        else
        {
            ll x=dp2[c[i]];y=Get(root2,1,m,a[i],b[i])+d[i];
            dp2[c[i]]=min(x,y);
            Set(root2,1,m,c[i],dp2[c[i]]);
        }
        d2[i]=y;
    }
    ll sol=inf;
    for(i=1;i<=n;i++) sol=min(sol,dp1[c[i]]+dp2[c[i]]),sol=min(sol,d1[i]+d2[i]-d[i]);
    if(sol>=inf) printf("-1\n");
    else printf("%lld\n",sol);
    //for(i=1;i<=n;i++) printf("%lld %lld\n",d1[i],d2[i]);
    return 0;
}

Compilation message

pinball.cpp: In function 'void Set(int&, int, int, int, long long int)':
pinball.cpp:15:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=ss+se>>1;
             ~~^~~
pinball.cpp: In function 'long long int Get(int, int, int, int, int)':
pinball.cpp:23:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=ss+se>>1;
             ~~^~~
pinball.cpp: In function 'int main()':
pinball.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
pinball.cpp:34:93: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++) scanf("%i %i %i %lld",&a[i],&b[i],&c[i],&d[i]),dp1[c[i]]=dp2[c[i]]=inf,d1[i]=d2[i]=inf;
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 3 ms 644 KB Output is correct
11 Correct 2 ms 704 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 832 KB Output is correct
14 Correct 3 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 3 ms 644 KB Output is correct
11 Correct 2 ms 704 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 832 KB Output is correct
14 Correct 3 ms 832 KB Output is correct
15 Correct 3 ms 832 KB Output is correct
16 Correct 4 ms 832 KB Output is correct
17 Correct 6 ms 1148 KB Output is correct
18 Correct 6 ms 1148 KB Output is correct
19 Correct 10 ms 1404 KB Output is correct
20 Correct 6 ms 1404 KB Output is correct
21 Correct 4 ms 1404 KB Output is correct
22 Correct 7 ms 1404 KB Output is correct
23 Correct 6 ms 1412 KB Output is correct
24 Correct 6 ms 1412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 3 ms 644 KB Output is correct
11 Correct 2 ms 704 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 832 KB Output is correct
14 Correct 3 ms 832 KB Output is correct
15 Correct 3 ms 832 KB Output is correct
16 Correct 4 ms 832 KB Output is correct
17 Correct 6 ms 1148 KB Output is correct
18 Correct 6 ms 1148 KB Output is correct
19 Correct 10 ms 1404 KB Output is correct
20 Correct 6 ms 1404 KB Output is correct
21 Correct 4 ms 1404 KB Output is correct
22 Correct 7 ms 1404 KB Output is correct
23 Correct 6 ms 1412 KB Output is correct
24 Correct 6 ms 1412 KB Output is correct
25 Correct 44 ms 3636 KB Output is correct
26 Correct 172 ms 11816 KB Output is correct
27 Correct 581 ms 25652 KB Output is correct
28 Correct 354 ms 25652 KB Output is correct
29 Correct 428 ms 25652 KB Output is correct
30 Correct 502 ms 25652 KB Output is correct
31 Execution timed out 1043 ms 45416 KB Time limit exceeded
32 Halted 0 ms 0 KB -