Submission #574029

# Submission time Handle Problem Language Result Execution time Memory
574029 2022-06-07T15:21:22 Z Vanilla Secret (JOI14_secret) C++17
100 / 100
524 ms 12168 KB
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
const int maxn = 1001;
int pref [maxn][maxn];
int sg [maxn][maxn];
 
void build (int l, int r) {
	if (l >= r) return;
	int mid = (l + r) / 2;
    for (int i = l; i <= mid; i++){
        for (int j = mid + 1; j <= r; j++){
            sg[i][j] = mid;
        }
    }
    for (int i = mid + 2; i <= r; i++){
		pref[mid + 1][i] = Secret(pref[mid + 1][i-1], pref[i][i]);
	}
	for (int i = mid - 1; i >= l; i--){
		pref[i][mid] = Secret(pref[i][i], pref[i + 1][mid]);
	}
	build (l, mid);
	build (mid + 1, r);
 
}
 
void Init(int N, int A[]) {
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++) {
			pref[i][j] = -1;
		}
	}
    for (int i = 0; i < N; i++){
		pref[i][i] = A[i];
    }
	build(0, N);
}
 
int Query(int L, int R) {
	if (pref[L][R] != -1) return pref[L][R];
	int mid = sg[L][R];
	return Secret(pref[L][mid], pref[mid + 1][R]);
}
# Verdict Execution time Memory Grader output
1 Correct 125 ms 6304 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
2 Correct 124 ms 6364 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
3 Correct 124 ms 6352 KB Output is correct - number of calls to Secret by Init = 3604, maximum number of calls to Secret by Query = 1
4 Correct 433 ms 12052 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
5 Correct 441 ms 12116 KB Output is correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 1
6 Correct 448 ms 12076 KB Output is correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 1
7 Correct 466 ms 12052 KB Output is correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 1
8 Correct 441 ms 12100 KB Output is correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 1
9 Correct 524 ms 12020 KB Output is correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 1
10 Correct 463 ms 12168 KB Output is correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 1