Submission #296222

#TimeUsernameProblemLanguageResultExecution timeMemory
296222patrikpavic2Secret (JOI14_secret)C++17
100 / 100
591 ms8800 KiB
#include "secret.h" #include <cstring> const int N = 1e3 + 50; int n, A[N], Q[N][N]; void calc(int l, int r){ if(l + 2 > r) return; int mid = (l + r) / 2; for(int i = mid - 1;i >= l;i--) Q[i][mid] = Secret(A[i], Q[i + 1][mid]); for(int i = mid + 2;i <= r;i++) Q[mid + 1][i] = Secret(Q[mid + 1][i - 1], A[i]); calc(l, mid); calc(mid + 1, r); } void Init(int nn, int AA[]) { n = nn; memset(Q, -1, sizeof(Q)); for(int i = 0;i < n;i++){ A[i] = AA[i]; Q[i][i] = A[i]; } calc(0, n - 1); } int Query(int l, int r) { if(Q[l][r] != -1) return Q[l][r]; for(int k = l;k < r;k++){ if(Q[l][k] != -1 && Q[k + 1][r] != -1) return Secret(Q[l][k], Q[k + 1][r]); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...