답안 #546747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546747 2022-04-08T11:28:13 Z krit3379 비밀 (JOI14_secret) C++17
100 / 100
449 ms 8320 KB
#include<bits/stdc++.h>
using namespace std;
#include"secret.h"
#define N 1005

int n,dp[N][N];

void sol(int l,int r,int type,int *a){
    if(l==r)return void(dp[l][r]=a[l]);
    int mid=(l+r)/2;
    sol(l,mid,type,a);
    sol(mid+1,r,type,a);
    for(int i=l;i<=mid;i++)if(dp[i][r]==-1)dp[i][r]=Secret(dp[i][mid],dp[mid+1][r]);
    for(int i=mid+1;i<=r;i++)if(dp[l][i]==-1)dp[l][i]=Secret(dp[l][mid],dp[mid+1][i]);
}

void Init(int nn, int *a){
    n=nn;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)dp[i][j]=-1;
    sol(0,(n-1)/2,1,a);
    if(n>1)sol((n-1)/2+1,n-1,2,a);
}

int Query(int ll, int rr){
    int l=0,r=n-1;
    if(ll==rr)return dp[ll][rr];
    if(ll<=(n-1)/2&&rr>(n-1)/2)return Secret(dp[ll][(n-1)/2],dp[(n-1)/2+1][rr]);
    while(l<=r){
        int mid=(l+r)/2;
        if(ll<=mid&&mid<rr)return Secret(dp[ll][mid],dp[mid+1][rr]);
        if(rr<=mid)r=mid;
        else l=mid+1;
    }
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 4300 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 126 ms 4516 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 125 ms 4344 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 440 ms 8088 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 443 ms 8320 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 438 ms 8268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 445 ms 8188 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 442 ms 8176 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 449 ms 8208 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 442 ms 8192 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1