# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255877 | IOrtroiii | Secret (JOI14_secret) | C++14 | 0 ms | 0 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 dp[1010][1010];
void gen(int l, int r, int A[]) {
if (l == r) {
dp[l][r] = A[l];
return;
}
int md = (l + r) >> 1;
gen(l, md, A);
gen(md + 1, r, A);
for (int i = md - 1; i >= l; --i) dp[i][md] = Secret(A[i], dp[i + 1][md]);
for (int i = md + 2; i <= r; ++i) dp[i][md] = Secret(dp[md + 1][i - 1], A[i]);
}
void Init(int N, int A[]) {
memset(dp, -1, sizeof dp);
gen(0, N - 1);
}
int Query(int l, int r) {
if (l == r) return A[l];
for (int md = l; md < r; ++md) {
if (dp[l][md] >= 0 && dp[md + 1][r] >= 0) {
return Secret(dp[l][md], dp[md + 1][r]);
}
}
}