# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
235505 |
2020-05-28T11:44:44 Z |
doowey |
Holding (COCI20_holding) |
C++14 |
|
992 ms |
45176 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 102;
const int S = (int)2e4 + 100;
const int M = S/2;
const int inf = (int)1e9;
int dpL[2][N][S]; // pick i items, indice sum j
int dpR[2][N][S];
int a[N];
int li[N][S];
int ri[N][S];
void upd(int &a, int b){
a = min(a, b);
}
int main(){
fastIO;
int n, l, r, k;
cin >> n >> l >> r >> k;
for(int q = 0; q < 2; q ++ ){
for(int d = 0; d <= n; d ++ ){
for(int s = 0; s < S; s ++ ){
dpL[q][d][s] = inf;
dpR[q][d][s] = inf;
}
}
}
dpL[0][0][M]=0;
int ans = 0;
for(int i = 1; i <= n; i ++ ){
cin >> a[i];
if(i >= l && i <= r) ans += a[i];
}
for(int i = 1; i <= r; i ++ ){
for(int j = 0 ; j <= n ; j ++ ){
for(int x = 0; x < S ; x ++ ){
if(i < l){
if(dpL[0][j][x] == inf) continue;
dpL[1][j + 1][x - i] = min(dpL[1][j + 1][x - i], dpL[0][j][x] + a[i]);
dpL[1][j][x] = min(dpL[1][j][x], dpL[0][j][x]);
}
else{
if(dpL[0][j][x] == inf) continue;
if(j) dpL[1][j - 1][x + i] = min(dpL[1][j - 1][x + i], dpL[0][j][x]);
dpL[1][j][x] = min(dpL[1][j][x], dpL[0][j][x] + a[i]);
}
}
}
for(int j = 0 ; j <= n; j ++ ){
for(int x = 0 ; x < S; x ++ ){
dpL[0][j][x]=dpL[1][j][x];
dpL[1][j][x]=inf;
}
}
for(int x = 0; x < S; x ++ ){
li[i][x]=dpL[0][0][x];
}
}
for(int x = 0 ;x <= k; x ++ ){
if(li[r][M + x] == 0){
ans = min(ans, li[r][M + x]);
}
}
for(int x = 0; x <= k ; x ++ ){
ans = min(ans, li[r][x + M]);
}
dpR[0][0][M]=0;
for(int i = n; i >= l ; i -- ){
for(int j = 0 ; j <= n; j ++ ){
for(int x = 0; x < S; x ++ ){
if(dpR[0][j][x] == inf) continue;
if(i > r){
dpR[1][j + 1][x + i] =min(dpR[1][j + 1][x + i], dpR[0][j][x] + a[i]);
dpR[1][j][x] = min(dpR[1][j][x], dpR[0][j][x]);
}
else{
if(j) dpR[1][j - 1][x - i] = min(dpR[1][j - 1][x - i], dpR[0][j][x]);
dpR[1][j][x] = min(dpR[1][j][x], dpR[0][j][x] + a[i]);
}
}
}
for(int j = 0 ; j <= n; j ++ ){
for(int x = 0; x < S; x ++ ){
dpR[0][j][x]=dpR[1][j][x];
dpR[1][j][x]=inf;
}
}
for(int x = 0 ; x < S; x ++ ){
ri[i][x]=dpR[0][0][x];
}
}
for(int x = 0; x <= k ; x ++ ){
ans = min(ans, ri[l][x + M]);
}
for(int i = l ; i + 1 <= r; i ++ ){
for(int x = 0; x <= k; x ++ ){
if(li[i][x + M] == inf) continue;
for(int y = 0; x + y <= k; y ++ ){
if(ri[i + 1][y + M] == inf) continue;
ans = min(ans, li[i][x + M] + ri[i + 1][y + M]);
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2816 KB |
Output is correct |
2 |
Correct |
17 ms |
6400 KB |
Output is correct |
3 |
Correct |
18 ms |
6784 KB |
Output is correct |
4 |
Correct |
18 ms |
6784 KB |
Output is correct |
5 |
Correct |
19 ms |
6656 KB |
Output is correct |
6 |
Correct |
20 ms |
6784 KB |
Output is correct |
7 |
Correct |
17 ms |
6016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2816 KB |
Output is correct |
2 |
Correct |
17 ms |
6400 KB |
Output is correct |
3 |
Correct |
18 ms |
6784 KB |
Output is correct |
4 |
Correct |
18 ms |
6784 KB |
Output is correct |
5 |
Correct |
19 ms |
6656 KB |
Output is correct |
6 |
Correct |
20 ms |
6784 KB |
Output is correct |
7 |
Correct |
17 ms |
6016 KB |
Output is correct |
8 |
Correct |
122 ms |
21428 KB |
Output is correct |
9 |
Correct |
133 ms |
21624 KB |
Output is correct |
10 |
Correct |
142 ms |
22264 KB |
Output is correct |
11 |
Correct |
154 ms |
22776 KB |
Output is correct |
12 |
Correct |
157 ms |
23544 KB |
Output is correct |
13 |
Correct |
200 ms |
22464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2816 KB |
Output is correct |
2 |
Correct |
17 ms |
6400 KB |
Output is correct |
3 |
Correct |
18 ms |
6784 KB |
Output is correct |
4 |
Correct |
18 ms |
6784 KB |
Output is correct |
5 |
Correct |
19 ms |
6656 KB |
Output is correct |
6 |
Correct |
20 ms |
6784 KB |
Output is correct |
7 |
Correct |
17 ms |
6016 KB |
Output is correct |
8 |
Correct |
122 ms |
21428 KB |
Output is correct |
9 |
Correct |
133 ms |
21624 KB |
Output is correct |
10 |
Correct |
142 ms |
22264 KB |
Output is correct |
11 |
Correct |
154 ms |
22776 KB |
Output is correct |
12 |
Correct |
157 ms |
23544 KB |
Output is correct |
13 |
Correct |
200 ms |
22464 KB |
Output is correct |
14 |
Correct |
96 ms |
20472 KB |
Output is correct |
15 |
Correct |
112 ms |
20708 KB |
Output is correct |
16 |
Correct |
112 ms |
20984 KB |
Output is correct |
17 |
Correct |
114 ms |
20984 KB |
Output is correct |
18 |
Correct |
127 ms |
21496 KB |
Output is correct |
19 |
Correct |
214 ms |
22520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2816 KB |
Output is correct |
2 |
Correct |
17 ms |
6400 KB |
Output is correct |
3 |
Correct |
18 ms |
6784 KB |
Output is correct |
4 |
Correct |
18 ms |
6784 KB |
Output is correct |
5 |
Correct |
19 ms |
6656 KB |
Output is correct |
6 |
Correct |
20 ms |
6784 KB |
Output is correct |
7 |
Correct |
17 ms |
6016 KB |
Output is correct |
8 |
Correct |
122 ms |
21428 KB |
Output is correct |
9 |
Correct |
133 ms |
21624 KB |
Output is correct |
10 |
Correct |
142 ms |
22264 KB |
Output is correct |
11 |
Correct |
154 ms |
22776 KB |
Output is correct |
12 |
Correct |
157 ms |
23544 KB |
Output is correct |
13 |
Correct |
200 ms |
22464 KB |
Output is correct |
14 |
Correct |
96 ms |
20472 KB |
Output is correct |
15 |
Correct |
112 ms |
20708 KB |
Output is correct |
16 |
Correct |
112 ms |
20984 KB |
Output is correct |
17 |
Correct |
114 ms |
20984 KB |
Output is correct |
18 |
Correct |
127 ms |
21496 KB |
Output is correct |
19 |
Correct |
214 ms |
22520 KB |
Output is correct |
20 |
Correct |
433 ms |
40952 KB |
Output is correct |
21 |
Correct |
375 ms |
40440 KB |
Output is correct |
22 |
Correct |
401 ms |
40824 KB |
Output is correct |
23 |
Correct |
436 ms |
40184 KB |
Output is correct |
24 |
Correct |
575 ms |
45176 KB |
Output is correct |
25 |
Correct |
992 ms |
44088 KB |
Output is correct |