Submission #577130

# Submission time Handle Problem Language Result Execution time Memory
577130 2022-06-14T07:15:02 Z amunduzbaev Tortoise (CEOI21_tortoise) C++17
48 / 100
227 ms 294516 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int int64_t

const int N = 5005;
const int inf = 1e9;
int dp[2][N][N], a[N];
int l[N], r[N], back[N][N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	for(int i=0;i<n;i++){
		l[i] = n;
		cin>>a[i];
		if(a[i] == -1) l[i] = 0;
		else if(i) l[i] = l[i-1] + 1;
	}
	for(int i=n-1;~i;i--){
		r[i] = n;
		if(a[i] == -1) r[i] = 0;
		else if(i + 1 < n) r[i] = r[i+1] + 1;
	}
	
	memset(dp, 100, sizeof dp);
	memset(back, 100, sizeof back);
	dp[0][0][0] = 0;
	int res = 0;
	for(int i=0;i<=n;i++){
		for(int x=n;~x;x--){
			dp[0][i][x] = min(dp[0][i][x], back[i + r[i]][x] + r[i]);
			dp[0][i+1][x] = min(dp[0][i+1][x], dp[0][i][x] + 1);
			if(a[i+1] == -1) dp[0][i+1][x] = min(dp[0][i+1][x], dp[1][i][x] + 1);
			dp[1][i+1][x] = min(dp[1][i+1][x], dp[1][i][x] + 1);
			for(int z=1, is=1;is && z <= a[i];z++){ is = 0;
				if(dp[0][i][x] + (z - 1) * 2 * min(l[i], r[i])<=2*i){
					is = 1;
					dp[1][i + 1][x + z] = min(dp[1][i + 1][x + z], dp[0][i][x] + (z - 1) * 2 * min(l[i], r[i]) + 1);
					dp[0][i + 1][x + z] = min(dp[0][i + 1][x + z], dp[0][i][x] + z * 2 * min(l[i], r[i]) + 1);
					back[i + r[i]][x + z] = min(back[i + r[i]][x + z], dp[0][i][x] + (z - 1) * 2 * min(l[i], r[i]) + r[i]);
				}
			}
			if(dp[0][i][x] < inf || dp[1][i][x] < inf) res = max(res, x);
		}
	}
	
	//~ cout<<res<<"\n";
	int tot = 0;
	for(int i=0;i<n;i++){
		if(~a[i]) tot += a[i];
	}
	
	cout<<tot - res<<"\n";
}

/*

6
-1 0 0 1 1 -1

*/
# Verdict Execution time Memory Grader output
1 Correct 107 ms 294508 KB Output is correct
2 Correct 105 ms 294324 KB Output is correct
3 Correct 116 ms 294424 KB Output is correct
4 Correct 111 ms 294440 KB Output is correct
5 Correct 122 ms 294440 KB Output is correct
6 Correct 108 ms 294348 KB Output is correct
7 Correct 105 ms 294348 KB Output is correct
8 Correct 106 ms 294416 KB Output is correct
9 Correct 103 ms 294348 KB Output is correct
10 Correct 102 ms 294440 KB Output is correct
11 Correct 104 ms 294516 KB Output is correct
12 Correct 103 ms 294392 KB Output is correct
13 Correct 111 ms 294348 KB Output is correct
14 Correct 110 ms 294400 KB Output is correct
15 Correct 104 ms 294364 KB Output is correct
16 Correct 107 ms 294488 KB Output is correct
17 Correct 104 ms 294400 KB Output is correct
18 Correct 103 ms 294436 KB Output is correct
19 Correct 104 ms 294436 KB Output is correct
20 Correct 111 ms 294392 KB Output is correct
21 Correct 106 ms 294396 KB Output is correct
22 Correct 103 ms 294348 KB Output is correct
23 Correct 111 ms 294364 KB Output is correct
24 Correct 103 ms 294384 KB Output is correct
25 Correct 115 ms 294404 KB Output is correct
26 Correct 105 ms 294368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 294508 KB Output is correct
2 Correct 105 ms 294324 KB Output is correct
3 Correct 116 ms 294424 KB Output is correct
4 Correct 111 ms 294440 KB Output is correct
5 Correct 122 ms 294440 KB Output is correct
6 Correct 108 ms 294348 KB Output is correct
7 Correct 105 ms 294348 KB Output is correct
8 Correct 106 ms 294416 KB Output is correct
9 Correct 103 ms 294348 KB Output is correct
10 Correct 102 ms 294440 KB Output is correct
11 Correct 104 ms 294516 KB Output is correct
12 Correct 103 ms 294392 KB Output is correct
13 Correct 111 ms 294348 KB Output is correct
14 Correct 110 ms 294400 KB Output is correct
15 Correct 104 ms 294364 KB Output is correct
16 Correct 107 ms 294488 KB Output is correct
17 Correct 104 ms 294400 KB Output is correct
18 Correct 103 ms 294436 KB Output is correct
19 Correct 104 ms 294436 KB Output is correct
20 Correct 111 ms 294392 KB Output is correct
21 Correct 106 ms 294396 KB Output is correct
22 Correct 103 ms 294348 KB Output is correct
23 Correct 111 ms 294364 KB Output is correct
24 Correct 103 ms 294384 KB Output is correct
25 Correct 115 ms 294404 KB Output is correct
26 Correct 105 ms 294368 KB Output is correct
27 Correct 102 ms 294336 KB Output is correct
28 Correct 105 ms 294348 KB Output is correct
29 Correct 103 ms 294444 KB Output is correct
30 Correct 106 ms 294348 KB Output is correct
31 Correct 104 ms 294348 KB Output is correct
32 Correct 109 ms 294328 KB Output is correct
33 Correct 104 ms 294396 KB Output is correct
34 Correct 106 ms 294348 KB Output is correct
35 Correct 113 ms 294376 KB Output is correct
36 Correct 104 ms 294340 KB Output is correct
37 Correct 101 ms 294348 KB Output is correct
38 Correct 110 ms 294352 KB Output is correct
39 Correct 111 ms 294416 KB Output is correct
40 Correct 110 ms 294480 KB Output is correct
41 Correct 105 ms 294340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 294508 KB Output is correct
2 Correct 105 ms 294324 KB Output is correct
3 Correct 116 ms 294424 KB Output is correct
4 Correct 111 ms 294440 KB Output is correct
5 Correct 122 ms 294440 KB Output is correct
6 Correct 108 ms 294348 KB Output is correct
7 Correct 105 ms 294348 KB Output is correct
8 Correct 106 ms 294416 KB Output is correct
9 Correct 103 ms 294348 KB Output is correct
10 Correct 102 ms 294440 KB Output is correct
11 Correct 104 ms 294516 KB Output is correct
12 Correct 103 ms 294392 KB Output is correct
13 Correct 111 ms 294348 KB Output is correct
14 Correct 110 ms 294400 KB Output is correct
15 Correct 104 ms 294364 KB Output is correct
16 Correct 107 ms 294488 KB Output is correct
17 Correct 104 ms 294400 KB Output is correct
18 Correct 103 ms 294436 KB Output is correct
19 Correct 104 ms 294436 KB Output is correct
20 Correct 111 ms 294392 KB Output is correct
21 Correct 106 ms 294396 KB Output is correct
22 Correct 103 ms 294348 KB Output is correct
23 Correct 111 ms 294364 KB Output is correct
24 Correct 103 ms 294384 KB Output is correct
25 Correct 115 ms 294404 KB Output is correct
26 Correct 105 ms 294368 KB Output is correct
27 Correct 102 ms 294336 KB Output is correct
28 Correct 105 ms 294348 KB Output is correct
29 Correct 103 ms 294444 KB Output is correct
30 Correct 106 ms 294348 KB Output is correct
31 Correct 104 ms 294348 KB Output is correct
32 Correct 109 ms 294328 KB Output is correct
33 Correct 104 ms 294396 KB Output is correct
34 Correct 106 ms 294348 KB Output is correct
35 Correct 113 ms 294376 KB Output is correct
36 Correct 104 ms 294340 KB Output is correct
37 Correct 101 ms 294348 KB Output is correct
38 Correct 110 ms 294352 KB Output is correct
39 Correct 111 ms 294416 KB Output is correct
40 Correct 110 ms 294480 KB Output is correct
41 Correct 105 ms 294340 KB Output is correct
42 Correct 105 ms 294352 KB Output is correct
43 Correct 105 ms 294388 KB Output is correct
44 Correct 117 ms 294448 KB Output is correct
45 Correct 118 ms 294436 KB Output is correct
46 Correct 111 ms 294380 KB Output is correct
47 Correct 104 ms 294328 KB Output is correct
48 Correct 104 ms 294392 KB Output is correct
49 Correct 111 ms 294492 KB Output is correct
50 Correct 110 ms 294420 KB Output is correct
51 Correct 120 ms 294336 KB Output is correct
52 Correct 109 ms 294376 KB Output is correct
53 Correct 110 ms 294364 KB Output is correct
54 Correct 108 ms 294444 KB Output is correct
55 Correct 103 ms 294356 KB Output is correct
56 Correct 103 ms 294412 KB Output is correct
57 Correct 103 ms 294364 KB Output is correct
58 Correct 105 ms 294348 KB Output is correct
59 Correct 106 ms 294496 KB Output is correct
60 Correct 104 ms 294396 KB Output is correct
61 Correct 103 ms 294332 KB Output is correct
62 Correct 104 ms 294368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 294508 KB Output is correct
2 Correct 105 ms 294324 KB Output is correct
3 Correct 116 ms 294424 KB Output is correct
4 Correct 111 ms 294440 KB Output is correct
5 Correct 122 ms 294440 KB Output is correct
6 Correct 108 ms 294348 KB Output is correct
7 Correct 105 ms 294348 KB Output is correct
8 Correct 106 ms 294416 KB Output is correct
9 Correct 103 ms 294348 KB Output is correct
10 Correct 102 ms 294440 KB Output is correct
11 Correct 104 ms 294516 KB Output is correct
12 Correct 103 ms 294392 KB Output is correct
13 Correct 111 ms 294348 KB Output is correct
14 Correct 110 ms 294400 KB Output is correct
15 Correct 104 ms 294364 KB Output is correct
16 Correct 107 ms 294488 KB Output is correct
17 Correct 104 ms 294400 KB Output is correct
18 Correct 103 ms 294436 KB Output is correct
19 Correct 104 ms 294436 KB Output is correct
20 Correct 111 ms 294392 KB Output is correct
21 Correct 106 ms 294396 KB Output is correct
22 Correct 103 ms 294348 KB Output is correct
23 Correct 111 ms 294364 KB Output is correct
24 Correct 103 ms 294384 KB Output is correct
25 Correct 115 ms 294404 KB Output is correct
26 Correct 105 ms 294368 KB Output is correct
27 Correct 102 ms 294336 KB Output is correct
28 Correct 105 ms 294348 KB Output is correct
29 Correct 103 ms 294444 KB Output is correct
30 Correct 106 ms 294348 KB Output is correct
31 Correct 104 ms 294348 KB Output is correct
32 Correct 109 ms 294328 KB Output is correct
33 Correct 104 ms 294396 KB Output is correct
34 Correct 106 ms 294348 KB Output is correct
35 Correct 113 ms 294376 KB Output is correct
36 Correct 104 ms 294340 KB Output is correct
37 Correct 101 ms 294348 KB Output is correct
38 Correct 110 ms 294352 KB Output is correct
39 Correct 111 ms 294416 KB Output is correct
40 Correct 110 ms 294480 KB Output is correct
41 Correct 105 ms 294340 KB Output is correct
42 Correct 105 ms 294352 KB Output is correct
43 Correct 105 ms 294388 KB Output is correct
44 Correct 117 ms 294448 KB Output is correct
45 Correct 118 ms 294436 KB Output is correct
46 Correct 111 ms 294380 KB Output is correct
47 Correct 104 ms 294328 KB Output is correct
48 Correct 104 ms 294392 KB Output is correct
49 Correct 111 ms 294492 KB Output is correct
50 Correct 110 ms 294420 KB Output is correct
51 Correct 120 ms 294336 KB Output is correct
52 Correct 109 ms 294376 KB Output is correct
53 Correct 110 ms 294364 KB Output is correct
54 Correct 108 ms 294444 KB Output is correct
55 Correct 103 ms 294356 KB Output is correct
56 Correct 103 ms 294412 KB Output is correct
57 Correct 103 ms 294364 KB Output is correct
58 Correct 105 ms 294348 KB Output is correct
59 Correct 106 ms 294496 KB Output is correct
60 Correct 104 ms 294396 KB Output is correct
61 Correct 103 ms 294332 KB Output is correct
62 Correct 104 ms 294368 KB Output is correct
63 Correct 197 ms 294468 KB Output is correct
64 Correct 227 ms 294504 KB Output is correct
65 Incorrect 188 ms 294468 KB Output isn't correct
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 294508 KB Output is correct
2 Correct 105 ms 294324 KB Output is correct
3 Correct 116 ms 294424 KB Output is correct
4 Correct 111 ms 294440 KB Output is correct
5 Correct 122 ms 294440 KB Output is correct
6 Correct 108 ms 294348 KB Output is correct
7 Correct 105 ms 294348 KB Output is correct
8 Correct 106 ms 294416 KB Output is correct
9 Correct 103 ms 294348 KB Output is correct
10 Correct 102 ms 294440 KB Output is correct
11 Correct 104 ms 294516 KB Output is correct
12 Correct 103 ms 294392 KB Output is correct
13 Correct 111 ms 294348 KB Output is correct
14 Correct 110 ms 294400 KB Output is correct
15 Correct 104 ms 294364 KB Output is correct
16 Correct 107 ms 294488 KB Output is correct
17 Correct 104 ms 294400 KB Output is correct
18 Correct 103 ms 294436 KB Output is correct
19 Correct 104 ms 294436 KB Output is correct
20 Correct 111 ms 294392 KB Output is correct
21 Correct 106 ms 294396 KB Output is correct
22 Correct 103 ms 294348 KB Output is correct
23 Correct 111 ms 294364 KB Output is correct
24 Correct 103 ms 294384 KB Output is correct
25 Correct 115 ms 294404 KB Output is correct
26 Correct 105 ms 294368 KB Output is correct
27 Correct 102 ms 294336 KB Output is correct
28 Correct 105 ms 294348 KB Output is correct
29 Correct 103 ms 294444 KB Output is correct
30 Correct 106 ms 294348 KB Output is correct
31 Correct 104 ms 294348 KB Output is correct
32 Correct 109 ms 294328 KB Output is correct
33 Correct 104 ms 294396 KB Output is correct
34 Correct 106 ms 294348 KB Output is correct
35 Correct 113 ms 294376 KB Output is correct
36 Correct 104 ms 294340 KB Output is correct
37 Correct 101 ms 294348 KB Output is correct
38 Correct 110 ms 294352 KB Output is correct
39 Correct 111 ms 294416 KB Output is correct
40 Correct 110 ms 294480 KB Output is correct
41 Correct 105 ms 294340 KB Output is correct
42 Correct 105 ms 294352 KB Output is correct
43 Correct 105 ms 294388 KB Output is correct
44 Correct 117 ms 294448 KB Output is correct
45 Correct 118 ms 294436 KB Output is correct
46 Correct 111 ms 294380 KB Output is correct
47 Correct 104 ms 294328 KB Output is correct
48 Correct 104 ms 294392 KB Output is correct
49 Correct 111 ms 294492 KB Output is correct
50 Correct 110 ms 294420 KB Output is correct
51 Correct 120 ms 294336 KB Output is correct
52 Correct 109 ms 294376 KB Output is correct
53 Correct 110 ms 294364 KB Output is correct
54 Correct 108 ms 294444 KB Output is correct
55 Correct 103 ms 294356 KB Output is correct
56 Correct 103 ms 294412 KB Output is correct
57 Correct 103 ms 294364 KB Output is correct
58 Correct 105 ms 294348 KB Output is correct
59 Correct 106 ms 294496 KB Output is correct
60 Correct 104 ms 294396 KB Output is correct
61 Correct 103 ms 294332 KB Output is correct
62 Correct 104 ms 294368 KB Output is correct
63 Correct 197 ms 294468 KB Output is correct
64 Correct 227 ms 294504 KB Output is correct
65 Incorrect 188 ms 294468 KB Output isn't correct
66 Halted 0 ms 0 KB -