# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785020 | tvladm2009 | Secret (JOI14_secret) | C++17 | 418 ms | 8328 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;
const int N = 1000 + 7;
int hint[N][N];
void run(int l, int r) {
if (r - l <= 1) {
return;
}
int m = (l + r) / 2;
for (int i = m - 1; i >= l; i--) {
if (hint[i][m] == -1) {
hint[i][m] = Secret(hint[i][i + 1], hint[i + 1][m]);
}
}
for (int i = m + 1; i <= r; i++) {
if (hint[m][i] == -1) {
hint[m][i] = Secret(hint[m][i - 1], hint[i - 1][i]);
}
}
run(l, m);
run(m, r);
}
void Init(int n, int a[]) {
for (int i = 0; i <= n; i++) {
for (int j = i; j <= n; j++) {
hint[i][j] = -1;
}
}
for (int i = 0; i < n; i++) {
hint[i][i + 1] = a[i];
}
run(0, n);
}
int Query(int l, int r) {
for (int i = l + 1; i <= r; i++) {
if (hint[l][i] != -1 && hint[i][r + 1] != -1) {
return Secret(hint[l][i], hint[i][r + 1]);
}
}
return hint[l][r + 1];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |