답안 #52466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52466 2018-06-26T04:54:12 Z 강태규(#1363) 비밀 (JOI14_secret) C++11
0 / 100
728 ms 5700 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);
}

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 < l) return getAns(m + 2, e, l, r, d + 1);
}

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, 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;
         ^
secret.cpp: In function 'int getAns(int, int, int, int, int)':
secret.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 3136 KB Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1
2 Correct 171 ms 3304 KB Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1
3 Correct 174 ms 3304 KB Output is correct - number of calls to Secret by Init = 3108, maximum number of calls to Secret by Query = 1
4 Correct 728 ms 5476 KB Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1
5 Incorrect 672 ms 5476 KB Wrong Answer: Query(0, 371) - expected : 250238024, actual : 610848016.
6 Incorrect 628 ms 5476 KB Wrong Answer: Query(5, 5) - expected : 429189819, actual : 943276163.
7 Correct 614 ms 5476 KB Output is correct - number of calls to Secret by Init = 7004, maximum number of calls to Secret by Query = 1
8 Correct 599 ms 5520 KB Output is correct - number of calls to Secret by Init = 7004, maximum number of calls to Secret by Query = 1
9 Correct 593 ms 5700 KB Output is correct - number of calls to Secret by Init = 7004, maximum number of calls to Secret by Query = 1
10 Correct 649 ms 5700 KB Output is correct - number of calls to Secret by Init = 7004, maximum number of calls to Secret by Query = 1