Submission #958518

#TimeUsernameProblemLanguageResultExecution timeMemory
958518MinaRagy06Bali Sculptures (APIO15_sculpture)C++17
50 / 100
59 ms676 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 2005; const int inf = 1e9; bool dp[N][N]; int dp2[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, l, r; cin >> n >> l >> r; ll a[n + 1], prf[n + 1]{}; for (int i = 1; i <= n; i++) { cin >> a[i]; prf[i] = prf[i - 1] + a[i]; } ll msk = (1ll << 41) - 1; for (int b = 40; b >= 0; b--) { msk ^= 1ll << b; ll gud = 1; if (l > 1) { dp[0][0] = 1; for (int j = 1; j <= n; j++) { for (int i = 1; i <= n; i++) { for (int k = i - 1; k >= 0; k--) { if ((msk | (prf[i] - prf[k])) == msk) { dp[j][i] |= dp[j - 1][k]; } } } } for (int k = l; k <= r; k++) { if (dp[k][n]) { gud = 0; break; } } } else { for (int i = 1; i <= n; i++) { dp2[i] = inf; for (int k = i - 1; k >= 0; k--) { if ((msk | (prf[i] - prf[k])) == msk) { dp2[i] = min(dp2[i], dp2[k] + 1); } } } if (dp2[n] <= r) gud = 0; } msk ^= gud << b; } cout << msk << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...