Submission #768156

# Submission time Handle Problem Language Result Execution time Memory
768156 2023-06-27T15:32:36 Z raysh07 Secret (JOI14_secret) C++17
100 / 100
390 ms 8316 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

int n;
const int maxn = 1001;
int seg[4 * maxn];
int a[maxn];
int ans[maxn][maxn];

void dnc(int l, int r){
    if (r <= l) return;
    int m = (l + r)/2;
    
    if (l != m) ans[m - 1][m] = Secret(a[m - 1], a[m]);
    for (int i = m - 2; i >= l; i--) ans[i][m] = Secret(a[i], ans[i + 1][m]);
    
    if (r != (m + 1)) ans[m + 1][m + 2] = Secret(a[m + 1], a[m + 2]);
    for (int i = m + 3; i <= r; i++) ans[m + 1][i] = Secret(ans[m + 1][i - 1], a[i]);
    
    dnc(l, m);
    dnc(m + 1, r);
}

void Init(int N, int A[]) {
    n = N;
    for (int i = 1; i <= n; i++) a[i] = A[i - 1];
    
    for (int i = 0; i < maxn; i++){
        for (int j = 0; j < maxn; j++){
            ans[i][j] = -1;
            if (i == j) ans[i][i] = a[i];
        }
    }
    
    dnc(1, n);
}

int Query(int l, int r) {
    l++;
    r++;
    
    if (l == r) return a[l];
    if (ans[l][r] != -1) return ans[l][r];
    
    for (int i = l; i < r; i++){
        if (ans[l][i] != -1 && ans[i + 1][r] != -1) {
            // cout << l << " " << i << " " << i + 1 << " " << r << "\n";
            // cout << ans[l][i] << " " << ans[i + 1][r] << "\n";
            return Secret(ans[l][i], ans[i + 1][r]);
        }
    }
    assert(false);
}
# Verdict Execution time Memory Grader output
1 Correct 114 ms 6236 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 111 ms 6280 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 110 ms 6236 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 388 ms 8236 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 383 ms 8184 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 388 ms 8200 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 388 ms 8180 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 388 ms 8168 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 387 ms 8144 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 390 ms 8316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1