# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
548089 |
2022-04-12T11:28:37 Z |
Jomnoi |
Secret (JOI14_secret) |
C++17 |
|
531 ms |
8312 KB |
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
const int MAX_N = 1e3 + 10;
int n;
int dp[MAX_N][MAX_N];
int a[MAX_N];
void solve(int l, int r) {
if(l > r) {
return;
}
if(l == r) {
return void(dp[l][l] = a[l]);
}
int mid = (l + r) / 2;
solve(l, mid);
solve(mid + 1, r);
for(int i = l; i <= mid; i++) {
if(dp[i][r] == -1) {
dp[i][r] = Secret(dp[i][mid], dp[mid + 1][r]);
}
}
for(int i = mid + 1; i <= r; i++) {
if(dp[l][i] == -1) {
dp[l][i] = Secret(dp[l][mid], dp[mid + 1][i]);
}
}
}
void Init(int N, int A[]) {
n = N;
for(int i = 0; i < N; i++) {
a[i] = A[i];
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
dp[i][j] = -1;
}
}
solve(0, (N - 1) / 2);
solve((N - 1) / 2 + 1, N - 1);
}
int Query(int L, int R) {
int l = 0, r = n - 1, mid = (n - 1) / 2;
if(L == R) {
return a[L];
}
while(l <= r) {
mid = (l + r) / 2;
if(L <= mid and mid < R) {
return Secret(dp[L][mid], dp[mid + 1][R]);
}
if(mid >= R) {
r = mid;
}
else {
l = mid + 1;
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
4536 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
148 ms |
4428 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
147 ms |
4384 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
479 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 |
531 ms |
8264 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
479 ms |
8260 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
466 ms |
8300 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
486 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
473 ms |
8296 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
482 ms |
8228 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |