# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255879 | IOrtroiii | Secret (JOI14_secret) | C++14 | 520 ms | 8460 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 A[1010];
int dp[1010][1010];
void gen(int l, int r) {
if (l == r) {
dp[l][r] = A[l];
return;
}
int md = (l + r) >> 1;
gen(l, md);
gen(md + 1, r);
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[md + 1][i] = Secret(dp[md + 1][i - 1], A[i]);
}
void Init(int N, int _A[]) {
for (int i = 0; i < N; ++i) A[i] = _A[i];
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]);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |