#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n;
int a[maxn];
int rec[maxn][maxn];
void prep(int l, int r) {
if(l==r) return ;
int mid = (l+r)/2;
rec[mid][mid] = a[mid];
for(int i=mid-1;i>=l;i--) rec[i][mid] = Secret(a[i], rec[i+1][mid]);
rec[mid+1][mid+1] = a[mid+1];
for(int i=mid+2;i<=r;i++) rec[mid+1][i] = Secret(rec[mid+1][i-1], a[i]);
prep(l,mid); prep(mid+1,r);
}
void Init(int N, int A[]) {
n = N;
for(int i=1;i<=n;i++) a[i] = A[i-1];
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
rec[i][j] = -1;
}
}
prep(1,n);
}
int Query(int L, int R) {
L++; R++;
if(rec[L][R]!=-1) return rec[L][R];
for(int i=L;i<R;i++) {
if(rec[L][i]!=-1 && rec[i+1][R]!=-1) {
return Secret(rec[L][i], rec[i+1][R]);
}
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
4584 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
182 ms |
4832 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
189 ms |
4960 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
641 ms |
8928 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
625 ms |
9104 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
623 ms |
9288 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
607 ms |
9320 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
619 ms |
9360 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
606 ms |
9512 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
634 ms |
9676 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |