Submission #785020

# Submission time Handle Problem Language Result Execution time Memory
785020 2023-07-16T23:22:52 Z tvladm2009 Secret (JOI14_secret) C++17
100 / 100
418 ms 8328 KB
#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
1 Correct 109 ms 4388 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 128 ms 4376 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 109 ms 4396 KB Output is correct - number of calls to Secret by Init = 3101, maximum number of calls to Secret by Query = 1
4 Correct 388 ms 8188 KB Output is correct - number of calls to Secret by Init = 6989, maximum number of calls to Secret by Query = 1
5 Correct 390 ms 8232 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
6 Correct 389 ms 8136 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
7 Correct 418 ms 8120 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
8 Correct 388 ms 8328 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
9 Correct 389 ms 8148 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
10 Correct 396 ms 8220 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1