Submission #785018

#TimeUsernameProblemLanguageResultExecution timeMemory
785018tvladm2009Secret (JOI14_secret)C++17
0 / 100
388 ms8336 KiB
#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 + 1][r + 1] != -1) { return Secret(hint[l][i], hint[i + 1][r + 1]); } } return hint[l][r + 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...