# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217622 | DodgeBallMan | Secret (JOI14_secret) | C++14 | 509 ms | 8568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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( a[i], pre[mid+1][i-1] );
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |