#include <bits/stdc++.h>
using namespace std;
#define num long long
#define MAX_N 2001
#define INF 1e18
num dp[MAX_N][MAX_N];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nbNodes, start, end;
cin >> nbNodes >> start >> end;
vector<num> values(nbNodes);
for (int id = 0; id < nbNodes; id ++)
cin >> values[id];
vector<num> cvalues(nbNodes + 1);
for (int id = 1; id <= nbNodes; id ++)
cvalues[id] = cvalues[id - 1] + values[id - 1];
for (int id = 1; id <= nbNodes; id ++)
dp[id][0] = -INF;
for (int stage = 1; stage <= end; stage ++) {
for (int id = 1; id <= nbNodes; id ++) {
num min_score = INF;
for (int jd = 0; jd < id; jd ++) {
if (dp[jd][stage - 1] == - INF) continue ;
num score = (cvalues[id] - cvalues[jd]) | dp[jd][stage - 1];
//printf("%d %d %lld %lld %lld\n", id, jd, cvalues[id], cvalues[jd], score);
min_score = min(score, min_score);
}
if (min_score == INF) min_score *= -1;
dp[id][stage] = min_score;
//printf("%d %d: %lld\n", id, stage, min_score);
}
}
num min_score = INF;
for (int stage = start; stage <= end; stage ++)
min_score = min(min_score, dp[nbNodes][stage]);
cout << min_score;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |