답안 #35970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
35970 2017-12-04T03:34:03 Z minhtung0404 비밀 (JOI14_secret) C++14
100 / 100
669 ms 9956 KB
#include <bits/stdc++.h>
#include "secret.h"
const int N = 1005;
using namespace std;

int n, a[N], f[N][N];

void cal(int l, int r){
    int mid = (l + r) / 2;
    f[mid][mid] = a[mid];
    f[mid+1][mid+1] = a[mid+1];
    if (r - l <= 1) return;
    for (int i = mid-1; i >= l; i--) f[mid][i] = Secret(a[i], f[mid][i+1]);
    for (int i = mid+2; i <= r; i++) f[mid+1][i] = Secret(f[mid+1][i-1], a[i]);
    cal(l, mid); cal(mid+1, r);
}

int solve(int l, int r, int L, int R){
    if (l == r) return a[l];
    int mid = (l + r) / 2;
    if (R <= mid) return solve(l, mid, L, R);
    if (L >= mid+1) return solve(mid+1, r, L, R);
    return Secret(f[mid][L], f[mid+1][R]);
}

void Init(int x, int y[]){
    n = x; for (int i = 0; i < n; i++) a[i] = y[i];
    cal(0, n-1);
}

int Query(int L, int R){
    return solve(0, n-1, L, R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 9956 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 183 ms 9956 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 176 ms 9956 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 669 ms 9956 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 643 ms 9956 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 646 ms 9956 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 643 ms 9956 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 633 ms 9956 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 656 ms 9956 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 633 ms 9956 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1