Submission #705100

#TimeUsernameProblemLanguageResultExecution timeMemory
705100bebraBali Sculptures (APIO15_sculpture)C++17
21 / 100
6 ms1128 KiB
#include <bits/stdc++.h> using namespace std; #define dbg(x) cerr << #x << ": " << x << endl; const int MAX_N = 2000 + 5; const int MAX_X = 20; const int INF = 1e9; int a[MAX_N]; int dp[MAX_N][MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, l, r; cin >> n >> l >> r; for (int i = 1; i <= n; ++i) { cin >> a[i]; } // minimize (a1 + a2 + ... + a_(k - 1)) | (a_k + a_(k + 1) + ...) | ... // IMPORTANT NOTE: IN LAST GROUP n = 2000 and l = 1 // maybe greedy bit by bit? minimize first, then second, ... for (int i = 0; i <= n; ++i) { for (int j = 0; j < MAX_N; ++j) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 1; i <= n; ++i) { int s = 0; for (int j = i; j > 0; --j) { s += a[j]; for (int x = 0; x <= j * MAX_X + 5; ++x) { dp[i][s | x] = min(dp[i][s | x], dp[j - 1][x] + 1); } } } int ans = INF; for (int x = 0; x < MAX_N; ++x) { if (dp[n][x] <= r) { ans = min(ans, x); } } cout << ans << '\n'; return 0; } /* 6 1 3 8 1 2 1 5 4 */
#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...