# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768149 | raysh07 | Secret (JOI14_secret) | C++17 | 401 ms | 8308 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 "secret.h"
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1001;
int a[maxn];
int ans[maxn][maxn];
void dnc(int l, int r){
if (r <= l) return;
int m = (l + r)/2;
if (l != m) ans[m - 1][m] = Secret(a[m - 1], a[m]);
for (int i = m - 2; i >= l; i--) ans[i][m] = Secret(ans[i + 1][m], a[i]);
ans[m + 1][m + 1] = a[m + 1];
for (int i = m + 2; i <= r; i++) ans[m + 1][i] = Secret(ans[m + 1][i - 1], a[i]);
dnc(l, m - 1);
dnc(m + 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 = 0; i < maxn; i++){
for (int j = 0; j < maxn; j++){
ans[i][j] = -1;
}
}
dnc(1, n);
}
int Query(int l, int r) {
l++;
r++;
if (l == r) return a[l];
if (ans[l][r] != -1) return ans[l][r];
for (int i = l + 1; i < r; i++){
if (ans[l][i] != -1 && ans[i + 1][r] != -1) return Secret(ans[l][i], ans[i + 1][r]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |