답안 #624473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624473 2022-08-08T10:09:28 Z erto 비밀 (JOI14_secret) C++17
100 / 100
455 ms 8464 KB
#include "secret.h"
#include <bits/stdc++.h>
typedef long long int ll;
#define INF 1000000007
#define INF2 998244353
//#define N (ll)(2e5+ 5)
using namespace std;
 
int n;
int ans[1005][1005];
 
void calc(int lb, int rb, int A[]){
    int mid = (lb + rb) / 2;
    
    ans[mid][mid] = A[mid - 1];
    if(lb == rb)return;
 
    for(int i=mid - 1; i>=lb; i--){
        ans[mid][i] = Secret(A[i - 1], ans[mid][i + 1]);
    }
    ans[mid + 1][mid + 1] = A[mid];
    for(int i=mid + 2; i<=rb; i++){
        ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], A[i - 1]);
    }
 
    calc(lb, mid, A);
    calc(mid + 1, rb, A);
}
 
void Init(int N, int A[]){
    n = N;
    calc(1, n, A);
}
 
int Query(int L, int R){
    L++;
    R++;
    int a = 1, b = n;
    if(L == R)return ans[L][L];
    else{
        while(a < b){
            int mid = (a + b) / 2;
            if(L <= mid && mid < R){
                return Secret(ans[mid][L], ans[mid + 1][R]);
            }
            else if(mid == R){
                return ans[mid][L];
            }
            else if(mid < L){
                a = mid + 1; 
            }
            else{
                b = mid;
            }
        }
    }
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
   57 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 4696 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 122 ms 4428 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 130 ms 4604 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 431 ms 8288 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 441 ms 8264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 434 ms 8464 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 446 ms 8224 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 443 ms 8324 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 455 ms 8284 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 440 ms 8436 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1