답안 #790485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790485 2023-07-22T17:31:20 Z Andrey 비밀 (JOI14_secret) C++14
100 / 100
419 ms 4356 KB
#include "secret.h"
#include<bits/stdc++.h>
using namespace std;

int pr[1001][10];
int su[1001][10];

void Init(int n, int a[]) {
    for(int i = 0; i < n; i++) {
        pr[i][0] = a[i];
        su[i][0] = a[i];
    }
    for(int i = 1; i < 10; i++) {
        for(int j = 0; j < n; j++) {
            if(j%(1 << i) < (1 << (i-1))) {
                pr[j][i] = pr[j][i-1];
            }
            else {
                pr[j][i] = Secret(pr[j-1][i],a[j]);
            }
        }
    }
    for(int i = 1; i < 10; i++) {
        for(int j = n-1; j >= 0; j--) {
            if(j%(1 << i) == 0) {
                su[j][i] = pr[min(n-1,j+(1 << i)-1)][i];
            }
            else {
                if(j%(1 << i) >= (1 << (i-1)) || j == n-1) {
                    su[j][i] = su[j][i-1];
                }
                else {
                    su[j][i] = Secret(a[j],su[j+1][i]);
                }
            }
        }
    }
}

int Query(int l, int r) {
    if(l == r) {
        return pr[l][0];
    }
    for(int i = 0; i < 10; i++) {
        if(l/(1 << (i+1)) == r/(1 << (i+1))) {
            return Secret(su[l][i],pr[r][i]);
        }
    }
}

Compilation message

secret.cpp: In function 'int Query(int, int)':
secret.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
   49 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 2292 KB Output is correct - number of calls to Secret by Init = 4088, maximum number of calls to Secret by Query = 1
2 Correct 114 ms 2380 KB Output is correct - number of calls to Secret by Init = 4097, maximum number of calls to Secret by Query = 1
3 Correct 116 ms 2336 KB Output is correct - number of calls to Secret by Init = 4097, maximum number of calls to Secret by Query = 1
4 Correct 386 ms 4300 KB Output is correct - number of calls to Secret by Init = 7989, maximum number of calls to Secret by Query = 1
5 Correct 414 ms 4292 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
6 Correct 389 ms 4304 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
7 Correct 392 ms 4356 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
8 Correct 419 ms 4304 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
9 Correct 401 ms 4276 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1
10 Correct 399 ms 4332 KB Output is correct - number of calls to Secret by Init = 7998, maximum number of calls to Secret by Query = 1