답안 #957997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957997 2024-04-04T15:39:14 Z wksp 비밀 (JOI14_secret) C++14
0 / 100
376 ms 4916 KB
#include<bits/stdc++.h>
#include "secret.h"
using namespace std;

// int Secret(int X, int Y){
//     int a;
//     cin >> a;
//     return a;
// }
const int n_max = 1024;
const int logn = 12;
int tab[logn][n_max];
// int tabr[log][n_max];
map<pair<int, int>, int> result_in_past; 

int check(int a, int b){
    if(result_in_past.find({a, b}) != result_in_past.end()){
        return result_in_past[{a, b}];
    }else{
        int x = Secret(a, b);
        result_in_past[{a, b}] = x;
        return x;
    }
}

void init_tree(int n, int lvl = 10, int l = 0, int r = n_max - 1){
    if(l > n){
        return;
    }
    if(lvl == 0){
        return;
    }
    int mid = (l+r)/2;
    init_tree(n, lvl - 1, l, mid);
    init_tree(n, lvl - 1, mid + 1, r);
    if(mid >= n){
        return;
    }

    tab[lvl][mid] = tab[0][mid];
    for(int i = mid - 1; i >= l; i--){
        tab[lvl][i] = check(tab[0][i], tab[lvl][i+1]);
    }
    tab[lvl][mid + 1] = tab[0][mid+1];
    for(int i = mid + 2; i <= min(n, r); i++){
        tab[lvl][i] = check(tab[lvl][i-1], tab[0][i]);
    }
}

int find_in_tree(int a, int b, int lvl = 10, int l = 0, int r = n_max - 1){
    int mid = (l+r)/2;
    if(b <= mid){
        return find_in_tree(a, b, lvl - 1, l, mid);
    }
    if(a > mid){
        return find_in_tree(a, b, lvl - 1, mid + 1, r);
    }
    return lvl;
    //return check(tab[lvl][l], tab[lvl][r]);
}

void Init(int N, int A[]){
    for(int i = 0; i < N; i++){
        tab[0][i] = A[i];
    }
    init_tree(N);
}

int Query(int L, int R){
    if(L == R){
        return tab[0][L];
    }
    return find_in_tree(L, R);
}

// int main(){
//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 99 ms 2896 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 6.
2 Incorrect 103 ms 3012 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 9.
3 Incorrect 101 ms 2896 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 9.
4 Incorrect 375 ms 4688 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 9.
5 Incorrect 373 ms 4776 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 9.
6 Incorrect 369 ms 4692 KB Wrong Answer: Query(738, 741) - expected : 983692994, actual : 3.
7 Incorrect 369 ms 4772 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 10.
8 Incorrect 376 ms 4916 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 10.
9 Incorrect 375 ms 4776 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 10.
10 Incorrect 369 ms 4692 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 10.