제출 #1271219

#제출 시각아이디문제언어결과실행 시간메모리
1271219repmannSecret (JOI14_secret)C++20
100 / 100
350 ms8332 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; int N, glob; int A[1001]; int DP[1001][1001]; inline void Divide(int L, int R) { if((R - L) <= 1) return; int S = (L + R) >> 1; for(int i = S - 1; i >= L; i--) {DP[S][i] = Secret(A[i], DP[S][i + 1]);} for(int i = S + 2; i <= R; i++) {DP[S + 1][i] = Secret(DP[S + 1][i - 1], A[i]);} Divide(L, S - 1); Divide(S + 2, R); return; } void Init(int n, int *a) { N = n; for(int i = 1; i <= N; i++) A[i] = a[i - 1]; for(int i = 1; i <= N; i++) { for(int j = 1; j <= N; j++) DP[i][j] = -1; DP[i][i] = A[i]; } Divide(1, N); return; } int Query(int L, int R) { L++, R++; if(L == R) return A[L]; if(DP[L][R] > 0) return DP[L][R]; if(DP[R][L] > 0) return DP[R][L]; for(int i = L; i < R; i++) if((DP[i][L] > 0) && (DP[i + 1][R] > 0)) return Secret(DP[i][L], DP[i + 1][R]); exit(333); }
#Verdict Execution timeMemoryGrader output
Fetching results...