답안 #518937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518937 2022-01-25T08:48:39 Z valerikk 비밀 (JOI14_secret) C++17
100 / 100
449 ms 8304 KB
#include "secret.h"
#include <assert.h>
#include <string.h>
#include <vector>

static const int N = 1005;

static int n;
static int a[N];
static int b[N][N];

void go(int l, int r) {
	if (l == r) {
		b[l][r] = a[l];
		return;
	}

	int m = (l + r) / 2;

	go(l, m);
	for (int i = m - 1; i >= l; i--) {
		b[i][m] = Secret(a[i], b[i + 1][m]);
	}

	go(m + 1, r);
	for (int i = m + 2; i <= r; i++) {
		b[m + 1][i] = Secret(b[m + 1][i - 1], a[i]);
	}
}

void Init(int grader_N, int grader_A[]) {
	n = grader_N;
	for (int i = 0; i < n; i++) {
		a[i] = grader_A[i];
	}

	memset(b, 255, sizeof(b));

	go(0, n - 1);
}

int Query(int grader_L, int grader_R) {
	int l = grader_L, r = grader_R;

	if (~b[l][r]) {
		return b[l][r];
	}

	for (int m = l; m < r; m++) {
		if (~b[l][m] && ~b[m + 1][r]) {
			return Secret(b[l][m], b[m + 1][r]);
		}
	}

	assert(false);

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 6340 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 121 ms 6304 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 123 ms 6276 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 441 ms 8224 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 449 ms 8304 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 432 ms 8212 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 438 ms 8256 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 430 ms 8288 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 440 ms 8264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 434 ms 8280 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1