답안 #411468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411468 2021-05-25T11:25:42 Z benedict0724 비밀 (JOI14_secret) C++17
100 / 100
531 ms 8484 KB
#include "secret.h"

int val[1000][1000];

void init(int l, int r)
{
    if(r - l < 2) return;
    int mid = (l + r)/2;
    for(int i=mid-1;i>=l;i--)
    {
        if(val[i][mid] != -1) continue;
        val[i][mid] = Secret(val[i][i], val[i+1][mid]);
    }
    for(int j=mid+2;j<=r;j++)
    {
        if(val[mid+1][j] != -1) continue;
        val[mid+1][j] = Secret(val[mid+1][j-1], val[j][j]);
    }
    init(l, mid-1);
    init(mid+1, r);
}

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

int Query(int L, int R) {
    if(val[L][R] != -1) return val[L][R];
    for(int i=L;i<R;i++)
    {
        if(val[L][i] != -1 && val[i+1][R] != -1)
        {
            return val[L][R] = Secret(val[L][i], val[i+1][R]);
        }
    }
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 4420 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 147 ms 4360 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 151 ms 4496 KB Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1
4 Correct 520 ms 8208 KB Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1
5 Correct 516 ms 8136 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
6 Correct 506 ms 8248 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
7 Correct 531 ms 8168 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
8 Correct 526 ms 8152 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
9 Correct 515 ms 8484 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
10 Correct 516 ms 8216 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1