Submission #238939

# Submission time Handle Problem Language Result Execution time Memory
238939 2020-06-13T16:17:47 Z DodgeBallMan Pinball (JOI14_pinball) C++14
51 / 100
312 ms 20708 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
int n, m, a[N], b[N], c[N];
long long d[N], t1[N*4], t2[N*4], ans = 1e18;
vector<int> coord;

void update( long long t[], int x, long long va, int l = 1, int r = coord.size(), int idx = 1 ) {
    if( l == r ) return void( t[idx] = min( t[idx], va ) );
    int mid = l + r >> 1;
    if( x <= mid ) update( t, x, va, l, mid, idx<<1 );
    else update( t, x, va, mid+1, r, idx<<1|1 );
    t[idx] = min( t[idx<<1], t[idx<<1|1] );
}

long long query( long long t[], int ll, int rr, int l = 1, int r = coord.size(), int idx = 1 ) {
    //printf("%d %d L : %d R : %d %lld\n",ll,rr,l,r,t[idx]);
    if( l > rr || r < ll ) return 1e18;
    if( l >= ll && r <= rr ) return t[idx];
    int mid = l + r >> 1;
    return min( query( t, ll, rr, l, mid, idx<<1 ), query( t, ll, rr, mid+1, r, idx<<1|1 ) );
}

int get( int x ) { return lower_bound( coord.begin(), coord.end(), x ) - coord.begin() + 1; }

int main()
{
    fill( t1, t1 + N*4, 1e18 ), fill( t2, t2 + N*4, 1e18 );
    scanf("%d %d",&m,&n);
    coord.emplace_back( 1 ), coord.emplace_back( n );
    for( int i = 1 ; i <= m ; i++ ) {
        scanf("%d %d %d %lld",&a[i],&b[i],&c[i],&d[i]);
        coord.emplace_back( a[i] ), coord.emplace_back( b[i] ), coord.emplace_back( c[i] );
    }
    sort( coord.begin(), coord.end() );
    coord.resize( unique( coord.begin(), coord.end() ) - coord.begin() );
    /*for( int i : coord ) printf("%d ",i);
    printf("\n");*/
    update( t1, 1, 0 ), update( t2, coord.size(), 0 );
    for( int i = 1 ; i <= m ; i++ ) {
        int l = get( a[i] ), r = get( b[i] ), x = get( c[i] );
        //printf("%d %d %d\n",l,r,x);
        long long pre = query( t1, l, r ), suf = query( t2, l, r ); 
        ans = min( ans, pre + suf + d[i] );
        //printf("%lld %lld\n",pre,suf);
        update( t1, x, pre + d[i] ), update( t2, x, suf + d[i] );
    }
    if( ans == 1e18 ) printf("-1\n");
    else printf("%lld\n",ans);
    return 0;
}

Compilation message

pinball.cpp: In function 'void update(long long int*, int, long long int, int, int, int)':
pinball.cpp:12:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
pinball.cpp: In function 'long long int query(long long int*, int, int, int, int, int)':
pinball.cpp:22:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
pinball.cpp: In function 'int main()':
pinball.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&m,&n);
     ~~~~~^~~~~~~~~~~~~~~
pinball.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %lld",&a[i],&b[i],&c[i],&d[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12800 KB Output is correct
2 Correct 10 ms 12928 KB Output is correct
3 Correct 11 ms 12928 KB Output is correct
4 Correct 11 ms 12800 KB Output is correct
5 Correct 10 ms 12928 KB Output is correct
6 Correct 11 ms 12928 KB Output is correct
7 Correct 11 ms 12800 KB Output is correct
8 Correct 11 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12800 KB Output is correct
2 Correct 10 ms 12928 KB Output is correct
3 Correct 11 ms 12928 KB Output is correct
4 Correct 11 ms 12800 KB Output is correct
5 Correct 10 ms 12928 KB Output is correct
6 Correct 11 ms 12928 KB Output is correct
7 Correct 11 ms 12800 KB Output is correct
8 Correct 11 ms 12928 KB Output is correct
9 Correct 11 ms 12900 KB Output is correct
10 Correct 11 ms 12928 KB Output is correct
11 Correct 12 ms 12928 KB Output is correct
12 Correct 11 ms 12928 KB Output is correct
13 Correct 11 ms 12800 KB Output is correct
14 Correct 11 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12800 KB Output is correct
2 Correct 10 ms 12928 KB Output is correct
3 Correct 11 ms 12928 KB Output is correct
4 Correct 11 ms 12800 KB Output is correct
5 Correct 10 ms 12928 KB Output is correct
6 Correct 11 ms 12928 KB Output is correct
7 Correct 11 ms 12800 KB Output is correct
8 Correct 11 ms 12928 KB Output is correct
9 Correct 11 ms 12900 KB Output is correct
10 Correct 11 ms 12928 KB Output is correct
11 Correct 12 ms 12928 KB Output is correct
12 Correct 11 ms 12928 KB Output is correct
13 Correct 11 ms 12800 KB Output is correct
14 Correct 11 ms 12928 KB Output is correct
15 Correct 11 ms 12928 KB Output is correct
16 Correct 11 ms 12928 KB Output is correct
17 Correct 12 ms 12928 KB Output is correct
18 Correct 12 ms 12928 KB Output is correct
19 Correct 13 ms 12928 KB Output is correct
20 Correct 12 ms 12928 KB Output is correct
21 Correct 12 ms 12928 KB Output is correct
22 Correct 12 ms 12928 KB Output is correct
23 Correct 12 ms 12928 KB Output is correct
24 Correct 12 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12800 KB Output is correct
2 Correct 10 ms 12928 KB Output is correct
3 Correct 11 ms 12928 KB Output is correct
4 Correct 11 ms 12800 KB Output is correct
5 Correct 10 ms 12928 KB Output is correct
6 Correct 11 ms 12928 KB Output is correct
7 Correct 11 ms 12800 KB Output is correct
8 Correct 11 ms 12928 KB Output is correct
9 Correct 11 ms 12900 KB Output is correct
10 Correct 11 ms 12928 KB Output is correct
11 Correct 12 ms 12928 KB Output is correct
12 Correct 11 ms 12928 KB Output is correct
13 Correct 11 ms 12800 KB Output is correct
14 Correct 11 ms 12928 KB Output is correct
15 Correct 11 ms 12928 KB Output is correct
16 Correct 11 ms 12928 KB Output is correct
17 Correct 12 ms 12928 KB Output is correct
18 Correct 12 ms 12928 KB Output is correct
19 Correct 13 ms 12928 KB Output is correct
20 Correct 12 ms 12928 KB Output is correct
21 Correct 12 ms 12928 KB Output is correct
22 Correct 12 ms 12928 KB Output is correct
23 Correct 12 ms 12928 KB Output is correct
24 Correct 12 ms 12928 KB Output is correct
25 Correct 32 ms 13312 KB Output is correct
26 Correct 69 ms 13948 KB Output is correct
27 Correct 184 ms 15212 KB Output is correct
28 Correct 183 ms 16748 KB Output is correct
29 Correct 145 ms 14832 KB Output is correct
30 Correct 222 ms 16744 KB Output is correct
31 Correct 312 ms 16748 KB Output is correct
32 Correct 298 ms 20332 KB Output is correct
33 Correct 48 ms 14332 KB Output is correct
34 Correct 155 ms 16752 KB Output is correct
35 Incorrect 207 ms 20708 KB Output isn't correct
36 Halted 0 ms 0 KB -