답안 #866282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866282 2023-10-25T18:14:30 Z Tudy006 비밀 (JOI14_secret) C++14
100 / 100
396 ms 8528 KB
#include <bits/stdc++.h>
#include "secret.h"

using namespace std;

const int NMAX = 1000;

int answer[NMAX][NMAX];
int N;

void divide_init( int l, int r, int* v ) {
    if ( l == r ) {
        answer[l][r] = v[l];
        return;
    }
    int mij = ( l + r ) / 2;
    answer[mij][mij] = v[mij];
    answer[mij + 1][mij + 1] = v[mij + 1];

    for ( int i = mij - 1; i >= l; i -- ) {
        answer[i][mij] = Secret( v[i], answer[i + 1][mij] );
    }
    for ( int i = mij + 2; i <= r; i ++ ) {
        answer[mij + 1][i] = Secret( answer[mij + 1][i - 1], v[i] );
    }
    divide_init( l, mij, v );
    divide_init( mij + 1, r, v );
}

int divide_query( int st, int dr, int l, int r ) {
    int mij = ( st + dr ) / 2;
    if ( l <= mij && mij <= r ) {
        if ( mij == r ) return answer[l][r];
        return Secret( answer[l][mij], answer[mij + 1][r] );
    }
    if ( mij < l ) return divide_query( mij + 1, dr, l, r );
    return divide_query( st, mij, l, r );
}
void Init(int n, int v[] ) {
    N = n;
    divide_init( 0, n - 1, v );
}
int Query( int l, int r ) {
    return divide_query( 0, N - 1, l, r );
}
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 6760 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 110 ms 6736 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 116 ms 6740 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 390 ms 8276 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 380 ms 8224 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 387 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 386 ms 8284 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 390 ms 8528 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 382 ms 8276 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 396 ms 8276 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1