Submission #103848

#TimeUsernameProblemLanguageResultExecution timeMemory
103848E869120Bali Sculptures (APIO15_sculpture)C++14
100 / 100
96 ms896 KiB
#include <iostream> #include <algorithm> using namespace std; long long N, A, B, L[1 << 12], dp[2009][2009], dp2[2009]; bool solve_1(long long E) { for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) dp[i][j] = 0; } dp[0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (dp[i][j] == 0) continue; long long R = 0; for (int k = i + 1; k <= N; k++) { R += L[k - 1]; if ((R | E) == E) dp[k][j + 1] = 1; } } } for (int i = A; i <= B; i++) { if (dp[N][i] == 1) return true; } return false; } bool solve_2(long long E) { for (int i = 0; i <= N; i++) dp2[i] = (1LL << 30); dp2[0] = 0; for (int i = 0; i <= N; i++) { long long R = 0; for (int k = i + 1; k <= N; k++) { R += L[k - 1]; if ((R | E) == E) dp2[k] = min(dp2[k], dp2[i] + 1); } } if (dp2[N] <= B) return true; return false; } int main() { cin >> N >> A >> B; for (int i = 0; i < N; i++) cin >> L[i]; if (A >= 2) { long long cx = (1LL << 45) - 1; for (int i = 44; i >= 0; i--) { bool t = solve_1(cx - (1LL << i)); if (t == true) cx -= (1LL << i); } cout << cx << endl; } else { long long cx = (1LL << 45) - 1; for (int i = 44; i >= 0; i--) { bool t = solve_2(cx - (1LL << i)); if (t == true) cx -= (1LL << i); } cout << cx << endl; } 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...