답안 #386818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386818 2021-04-07T11:21:14 Z saarang123 비밀 (JOI14_secret) C++17
100 / 100
538 ms 8548 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_N = 1000;
 
int ans[MAX_N][MAX_N], N;
 
void PreCompute(int left, int right) {
    int mid = (left + right) >> 1;
    if(right - left <= 2)
        return;
    for(int i = mid - 2; i >= left; i--) {
        ans[i][mid - 1] = Secret(ans[i][i], ans[i + 1][mid - 1]);
    }
    for(int i = mid + 1; i < right; i++) {
        ans[mid][i] = Secret(ans[mid][i - 1], ans[i][i]);
    }
    PreCompute(left, mid);
    PreCompute(mid, right);
}
 
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] = (i == j) ? A[i] : -1; 
        }
    }
    PreCompute(0, N);
}
 
int Compute(int left, int right, int ql, int qr) {
    int mid = (left + right) >> 1;
    if(ql >= mid) {
        return Compute(mid, right, ql, qr);
    }
    else if(qr < mid) {
        return Compute(left, mid, ql, qr);
    }
    return Secret(ans[ql][mid - 1], ans[mid][qr]);
}
 
int Query(int L, int R) {
    if(L == R)
        return ans[L][L];
    if(L == R - 1)
        return Secret(ans[L][L], ans[R][R]);
    return Compute(0, N, L, R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 4460 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 144 ms 4460 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 144 ms 4460 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 511 ms 8428 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 508 ms 8184 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 530 ms 8248 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 507 ms 8448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 516 ms 8548 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 507 ms 8172 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 538 ms 8300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1