Submission #1311170

#TimeUsernameProblemLanguageResultExecution timeMemory
1311170Ghulam_JunaidSecret (JOI14_secret)C++20
0 / 100
340 ms8224 KiB
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;

const int N = 1005;
int n, a[N], ans[N][N];

void compute(int l, int r){
    if (r - l <= 2) return;

    int mid = (l + r) / 2;
    int prv = a[mid];
    for (int i = mid - 1; i >= l; i --){
        ans[i][mid] = Secret(a[i], prv);
        prv = ans[i][mid];
    }
    prv = a[mid + 1];
    for (int i = mid + 2; i < r; i ++){
        ans[mid + 1][i] = Secret(a[i], prv);
        prv = ans[mid + 1][i];
    }
    compute(l, mid);
    compute(mid + 2, r);
}

void Init(int nn, int aa[]) {
    memset(ans, -1, sizeof ans);
    n = nn;
    for (int i = 0; i < n; i ++)
        a[i] = ans[i][i] = aa[i];
    compute(0, n);
}

int Query(int L, int R) {
    if (ans[L][R] != -1)
        return ans[L][R];
    for (int mid = L; mid + 1 <= R; mid ++)
        if (ans[L][mid] != -1 and ans[mid + 1][R] != -1)
            return Secret(ans[L][mid], ans[mid + 1][R]);
}

Compilation message (stderr)

secret.cpp: In function 'int Query(int, int)':
secret.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...