Submission #217625

# Submission time Handle Problem Language Result Execution time Memory
217625 2020-03-30T11:11:42 Z DodgeBallMan Secret (JOI14_secret) C++14
100 / 100
530 ms 8440 KB
#include <bits/stdc++.h>
#include "secret.h"

const int N = 1e3 + 10;

int n, a[N], pre[N][N];

//int Secret( int a, int b ) { return a + b; }

void solve( int l, int r ) {
    if( l == r ) return ;
    int mid = ( l + r ) / 2;
    for( int i = mid - 1 ; i >= l ; i-- ) pre[i][mid] = Secret( a[i], pre[i+1][mid] );
    for( int i = mid + 2 ; i <= r ; i++ ) pre[mid+1][i] = Secret( pre[mid+1][i-1], a[i] );
    solve( l, mid ), solve( mid+1, r );
}


void Init( int N, int A[] ) {
    n = N;
    memset( pre, -1, sizeof pre );
    for( int i = 0 ; i < n ; i++ ) pre[i][i] = a[i] = A[i];
    solve( 0, n-1 );
}

int Query( int l, int r ) {
    if( pre[l][r] != -1 ) return pre[l][r];
    for( int i = l ; i < r ; i++ ) if( pre[l][i] != -1 && pre[i+1][r] != -1 ) return Secret( pre[l][i], pre[i+1][r] );
}

/*int main()
{
    int n, x[N], q;
    scanf("%d",&n);
    for( int i = 0 ; i < n ; i++ ) scanf("%d",&x[i]);
    Init( n, x );
    scanf("%d",&q);
    while( q-- ) {
        int a, b;
        scanf("%d %d",&a,&b);
        printf("%d\n",Query( a, b ) );
    }
}*/

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 163 ms 6392 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 154 ms 6392 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 150 ms 6368 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 530 ms 8248 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 525 ms 8288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 521 ms 8316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 527 ms 8440 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 519 ms 8288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 530 ms 8308 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 518 ms 8312 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1