답안 #767038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767038 2023-06-26T10:30:56 Z YassineBenYounes 비밀 (JOI14_secret) C++17
100 / 100
389 ms 8180 KB
#include "secret.h"

#define MAX_N 1000

int range[MAX_N + 1][MAX_N + 1];

void Solve(int left, int right) {
  int mid, i;
  if (right - left <= 1) {
    return;
  }
  mid = (left + right) / 2;
  for (i = mid - 1; i >= left; --i) {
    if (range[i][mid] == -1) {
      range[i][mid] = Secret(range[i][i + 1], range[i + 1][mid]);
    }
  }
  for (i = mid + 1; i <= right; ++i) {
    if (range[mid][i] == -1) {
      range[mid][i] = Secret(range[mid][i - 1], range[i - 1][i]);
    }
  }
  Solve(left, mid);
  Solve(mid, right);
}

void Init(int N, int A[]) {
  int i, j;
  for (i = 0; i <= N; ++i) {
    for (j = 0; j <= N; ++j) {
      range[i][j] = -1;
    }
  }
  for (i = 0; i < N; ++i) {
    range[i][i + 1] = A[i];
  }
  Solve(0, N);
}

int Query(int L, int R) {
  int i;
  for (i = L + 1; i <= R; ++i) {
    if (range[L][i] != -1 && range[i][R + 1] != -1) {
      return Secret(range[L][i], range[i][R + 1]);
    }
  }
  return range[L][R + 1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 4348 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 104 ms 4344 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 105 ms 4268 KB Output is correct - number of calls to Secret by Init = 3101, maximum number of calls to Secret by Query = 1
4 Correct 358 ms 8180 KB Output is correct - number of calls to Secret by Init = 6989, maximum number of calls to Secret by Query = 1
5 Correct 363 ms 8116 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
6 Correct 359 ms 8092 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
7 Correct 389 ms 8172 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
8 Correct 362 ms 8148 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
9 Correct 362 ms 8116 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
10 Correct 387 ms 8140 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1