#include "secret.h"
int v[1005][1005];
void solve(int l, int r) {
if (l >= r)
return ;
int med = (l + r) / 2;
solve(l, med);
solve(med + 1, r);
for (int i = med - 1; i >= l; --i)
v[i][med] = Secret(v[i][i], v[i + 1][med]);
for (int i = med + 2; i <= r; ++i)
v[med + 1][i] = Secret(v[med + 1][i - 1], v[i][i]);
}
void Init(int N, int A[]) {
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
v[i][j] = -1;
for (int i = 0; i < N; ++i)
v[i][i] = A[i];
solve(0, N - 1);
}
int Query(int L, int R) {
if (v[L][R] != -1)
return v[L][R];
if (R == L + 1)
return Secret(v[L][L], v[R][R]);
for (int k = L; k < R; ++k)
if (v[L][k] != -1 && v[k + 1][R] != -1)
return Secret(v[L][k], v[k + 1][R]);
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
4472 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
168 ms |
4592 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
182 ms |
4592 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
607 ms |
8304 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
608 ms |
8424 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
594 ms |
8424 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
614 ms |
8424 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
607 ms |
8424 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
623 ms |
8548 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
620 ms |
8548 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |