답안 #881979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881979 2023-12-02T11:14:39 Z Alan 비밀 (JOI14_secret) C++17
100 / 100
396 ms 8548 KB
#include <bits/stdc++.h>
using namespace std;

int Secret(int X, int Y);

int ans[1005][1005], N;

void calc (int l, int r) {
	if (l == r) return;
	int mid = (l+r)/2;
	for (int i = mid-1; i >= l; i--) if (ans[i][mid] == -1) ans[i][mid] = Secret(ans[i][i], ans[i+1][mid]);
	for (int i = mid+2; i <= r; i++) if (ans[mid+1][i] == -1) ans[mid+1][i] = Secret(ans[mid+1][i-1], ans[i][i]);
	calc(l, mid);
	calc(mid+1, r);
}

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

int solve (int l, int r, int ql, int qr) {
	int mid = (l+r)/2;
	if (qr <= mid) return solve(l, mid, ql, qr);
	if (mid+1 <= ql) return solve(mid+1, r, ql, qr);
	return Secret(ans[ql][mid], ans[mid+1][qr]);
}

int Query (int L, int R) {
	if (ans[L][R] != -1) return ans[L][R];
	return solve(0, N-1, L, R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 6508 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 107 ms 6736 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 6724 KB Output is correct - number of calls to Secret by Init = 3101, maximum number of calls to Secret by Query = 1
4 Correct 379 ms 8276 KB Output is correct - number of calls to Secret by Init = 6989, maximum number of calls to Secret by Query = 1
5 Correct 381 ms 8280 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
6 Correct 396 ms 8284 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
7 Correct 380 ms 8344 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
8 Correct 384 ms 8548 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
9 Correct 384 ms 8280 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1
10 Correct 381 ms 8280 KB Output is correct - number of calls to Secret by Init = 6997, maximum number of calls to Secret by Query = 1