답안 #250930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250930 2020-07-19T13:17:01 Z imeimi2000 비밀 (JOI14_secret) C++17
100 / 100
538 ms 5624 KB
#include "secret.h"
#include <map>
 
using namespace std;
typedef pair<int, int> pii;
 
map<pii, int> mp;
map<pii, int>::iterator it;
int query(int x, int y) {
    if ((it = mp.find(pii(x, y))) != mp.end()) return it->second;
    return mp[pii(x, y)] = Secret(x, y);
}
 
int n;
int a[1000];
int pr[1000][10];
 
void dnc(int s, int e, int d = 0) {
    if (e - s < 2) return;
    int m = (s + e) / 2;
    int x;
    pr[m][d] = a[m];
    for (int i = m - 1; i >= s; --i) {
        pr[i][d] = query(a[i], pr[i + 1][d]);
    }
    pr[m + 1][d] = a[m + 1];
    for (int i = m + 2; i <= e; ++i) {
        pr[i][d] = query(pr[i - 1][d], a[i]);
    }
    dnc(s, m - 1, d + 1);
    dnc(m + 2, e, d + 1);
}
 
void Init(int N, int A[]) {
    n = N;
    for (int i = 0; i < n; ++i) {
        a[i] = A[i];
    }
    dnc(0, n - 1);
}
 
int getAns(int s, int e, int l, int r, int d = 0) {
    if (e - s < 2) throw 0;
    int m = (s + e) / 2;
    if (l <= m && m < r) return query(pr[l][d], pr[r][d]);
    if (l == m + 1) return pr[r][d];
    if (r == m) return pr[l][d];
    if (r < m) return getAns(s, m - 1, l, r, d + 1);
    if (m + 1 < l) return getAns(m + 2, e, l, r, d + 1);
    throw 0;
}
 
int Query(int L, int R) {
    if (R - L < 2) {
        if (L == R) return a[L];
        return query(a[L], a[R]);
    }
    return getAns(0, n - 1, L, R);
}

Compilation message

secret.cpp: In function 'void dnc(int, int, int)':
secret.cpp:21:9: warning: unused variable 'x' [-Wunused-variable]
     int x;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 3360 KB Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1
2 Correct 161 ms 3320 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
3 Correct 152 ms 3324 KB Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1
4 Correct 533 ms 5624 KB Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1
5 Correct 535 ms 5624 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
6 Correct 535 ms 5244 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
7 Correct 538 ms 5496 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
8 Correct 533 ms 5436 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
9 Correct 533 ms 5624 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
10 Correct 530 ms 5516 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1