답안 #605919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605919 2022-07-26T04:24:23 Z kawaii 비밀 (JOI14_secret) C++14
30 / 100
522 ms 13844 KB
#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
 
int a[1005], pre[1005][1005];
map<pair<int, int>, int> mp;

void Init(int N, int A[]){
    for(int i = 1; i <= N; i++) a[i] = A[i - 1];
    for(int i = 1; i <= N; i++) pre[i][i] = a[i];
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j + (1 << i) - 1 <= N; j++){
            int val = Secret(pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]);
            pre[j][j + (1 << i) - 1] = val;
            mp[{pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]}] = mp[{pre[j + (1 << i - 1)][j + (1 << i) - 1], pre[j][j + (1 << i - 1) - 1]}] = val;
        }
    }
}
 
int Query(int L, int R){
    int ans = -1; L++; R++;
    int diff = R - L + 1;
    // cout << diff <<" ";
    for(int i = 0; i <= 9; i++){
        if((1 << i) & diff){
            if(ans == -1) ans = pre[L][L + (1 << i) - 1];
            else{
                if(mp[{ans, pre[L][L + (1 << i) - 1]}] == 0){
                    int val = Secret(ans, pre[L][L + (1 << i) - 1]);
                    mp[{ans, pre[L][L + (1 << i) - 1]}] = mp[{pre[L][L + (1 << i) - 1], ans}] = val;
                    ans = val;
                }
                else ans = mp[{ans, pre[L][L + (1 << i) - 1]}];
            }
            L += (1 << i);
        }
    }
    return ans;
}

Compilation message

secret.cpp: In function 'void Init(int, int*)':
secret.cpp:13:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   13 |             int val = Secret(pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]);
      |                                               ~~^~~
secret.cpp:13:76: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   13 |             int val = Secret(pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]);
      |                                                                          ~~^~~
secret.cpp:15:36: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   15 |             mp[{pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]}] = mp[{pre[j + (1 << i - 1)][j + (1 << i) - 1], pre[j][j + (1 << i - 1) - 1]}] = val;
      |                                  ~~^~~
secret.cpp:15:63: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   15 |             mp[{pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]}] = mp[{pre[j + (1 << i - 1)][j + (1 << i) - 1], pre[j][j + (1 << i - 1) - 1]}] = val;
      |                                                             ~~^~~
secret.cpp:15:111: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   15 |             mp[{pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]}] = mp[{pre[j + (1 << i - 1)][j + (1 << i) - 1], pre[j][j + (1 << i - 1) - 1]}] = val;
      |                                                                                                             ~~^~~
secret.cpp:15:155: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   15 |             mp[{pre[j][j + (1 << i - 1) - 1], pre[j + (1 << i - 1)][j + (1 << i) - 1]}] = mp[{pre[j + (1 << i - 1)][j + (1 << i) - 1], pre[j][j + (1 << i - 1) - 1]}] = val;
      |                                                                                                                                                         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 168 ms 7372 KB Output is partially correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 7
2 Partially correct 157 ms 7372 KB Output is partially correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 7
3 Partially correct 160 ms 7500 KB Output is partially correct - number of calls to Secret by Init = 3604, maximum number of calls to Secret by Query = 7
4 Partially correct 488 ms 12720 KB Output is partially correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 8
5 Partially correct 485 ms 12860 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 8
6 Partially correct 460 ms 9868 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 2
7 Partially correct 518 ms 13844 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 8
8 Partially correct 506 ms 13152 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 7
9 Partially correct 522 ms 13312 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 8
10 Partially correct 489 ms 13076 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 7