#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 = 1, int r = n ) {
if( l == r ) return ;
int mid = l + r >> 1;
for( int i = mid - 1 ; i >= l ; i-- ) pre[i][mid] = Secret( pre[i+1][mid], a[i] );
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 - 1 ; i++ ) pre[i][i] = a[i] = A[i];
solve();
}
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 'void solve(int, int)':
secret.cpp:12:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
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 |
Incorrect |
145 ms |
6360 KB |
Wrong Answer [1] |
2 |
Incorrect |
140 ms |
6392 KB |
Wrong Answer [1] |
3 |
Incorrect |
141 ms |
6392 KB |
Wrong Answer [1] |
4 |
Incorrect |
499 ms |
8568 KB |
Wrong Answer [1] |
5 |
Incorrect |
498 ms |
8312 KB |
Wrong Answer [1] |
6 |
Incorrect |
498 ms |
8312 KB |
Wrong Answer [1] |
7 |
Incorrect |
496 ms |
8288 KB |
Wrong Answer [1] |
8 |
Incorrect |
501 ms |
8440 KB |
Wrong Answer [1] |
9 |
Incorrect |
510 ms |
8312 KB |
Wrong Answer [1] |
10 |
Incorrect |
498 ms |
8312 KB |
Wrong Answer [1] |