답안 #751932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751932 2023-06-01T20:32:15 Z Desh03 비밀 (JOI14_secret) C++17
100 / 100
438 ms 12396 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> mid, v;

void dc(int l, int r, int a[]) {
    if (l > r) return;
    int m = l + r >> 1;
    for (int i = l; i <= r; i++)
        v[i][i] = a[i];
    for (int i = l; i <= m; i++)
        for (int j = m + 1; j <= r; j++)
            mid[i][j] = m;
    for (int i = m - 1; i >= l; i--)
        v[i][m] = Secret(a[i], v[i + 1][m]);
    for (int i = m + 2; i <= r; i++)
        v[m + 1][i] = Secret(v[m + 1][i - 1], a[i]);
    dc(l, m - 1, a);
    dc(m + 1, r, a);
}

void Init(int n, int a[]) {
    mid = v = vector<vector<int>> (n, vector<int> (n, -1));
    dc(0, n - 1, a);
}

int Query(int l, int r) {
    if (v[l][r] != -1) return v[l][r];
    int m = mid[l][r];
    return Secret(v[l][m], v[m + 1][r]);
}

Compilation message

secret.cpp: In function 'void dc(int, int, int*)':
secret.cpp:9:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    9 |     int m = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 4504 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 121 ms 4432 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
3 Correct 120 ms 4536 KB Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1
4 Correct 427 ms 12260 KB Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1
5 Correct 432 ms 12216 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
6 Correct 420 ms 12316 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
7 Correct 428 ms 12160 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
8 Correct 430 ms 12396 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
9 Correct 438 ms 12184 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
10 Correct 423 ms 12364 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1