답안 #577131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577131 2022-06-14T07:17:57 Z amunduzbaev Tortoise (CEOI21_tortoise) C++17
48 / 100
3000 ms 294608 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, 63, sizeof dp);
	memset(back, 63, sizeof back);
	dp[0][0][0] = 0;
	int res = 0;
	for(int i=0;i<=n;i++){
		for(int x=n;~x;x--){
			if(i + r[i] < N) 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);
					if(i + r[i] < N) 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);
		}
	}
	
	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

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 294352 KB Output is correct
2 Correct 106 ms 294400 KB Output is correct
3 Correct 108 ms 294340 KB Output is correct
4 Correct 102 ms 294320 KB Output is correct
5 Correct 104 ms 294428 KB Output is correct
6 Correct 104 ms 294424 KB Output is correct
7 Correct 111 ms 294368 KB Output is correct
8 Correct 125 ms 294332 KB Output is correct
9 Correct 108 ms 294332 KB Output is correct
10 Correct 105 ms 294436 KB Output is correct
11 Correct 107 ms 294424 KB Output is correct
12 Correct 104 ms 294404 KB Output is correct
13 Correct 104 ms 294396 KB Output is correct
14 Correct 105 ms 294332 KB Output is correct
15 Correct 103 ms 294372 KB Output is correct
16 Correct 117 ms 294384 KB Output is correct
17 Correct 111 ms 294420 KB Output is correct
18 Correct 105 ms 294380 KB Output is correct
19 Correct 103 ms 294388 KB Output is correct
20 Correct 109 ms 294428 KB Output is correct
21 Correct 108 ms 294360 KB Output is correct
22 Correct 106 ms 294436 KB Output is correct
23 Correct 104 ms 294336 KB Output is correct
24 Correct 104 ms 294444 KB Output is correct
25 Correct 124 ms 294456 KB Output is correct
26 Correct 109 ms 294432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 294352 KB Output is correct
2 Correct 106 ms 294400 KB Output is correct
3 Correct 108 ms 294340 KB Output is correct
4 Correct 102 ms 294320 KB Output is correct
5 Correct 104 ms 294428 KB Output is correct
6 Correct 104 ms 294424 KB Output is correct
7 Correct 111 ms 294368 KB Output is correct
8 Correct 125 ms 294332 KB Output is correct
9 Correct 108 ms 294332 KB Output is correct
10 Correct 105 ms 294436 KB Output is correct
11 Correct 107 ms 294424 KB Output is correct
12 Correct 104 ms 294404 KB Output is correct
13 Correct 104 ms 294396 KB Output is correct
14 Correct 105 ms 294332 KB Output is correct
15 Correct 103 ms 294372 KB Output is correct
16 Correct 117 ms 294384 KB Output is correct
17 Correct 111 ms 294420 KB Output is correct
18 Correct 105 ms 294380 KB Output is correct
19 Correct 103 ms 294388 KB Output is correct
20 Correct 109 ms 294428 KB Output is correct
21 Correct 108 ms 294360 KB Output is correct
22 Correct 106 ms 294436 KB Output is correct
23 Correct 104 ms 294336 KB Output is correct
24 Correct 104 ms 294444 KB Output is correct
25 Correct 124 ms 294456 KB Output is correct
26 Correct 109 ms 294432 KB Output is correct
27 Correct 115 ms 294348 KB Output is correct
28 Correct 103 ms 294400 KB Output is correct
29 Correct 106 ms 294400 KB Output is correct
30 Correct 104 ms 294408 KB Output is correct
31 Correct 103 ms 294324 KB Output is correct
32 Correct 102 ms 294400 KB Output is correct
33 Correct 104 ms 294368 KB Output is correct
34 Correct 114 ms 294476 KB Output is correct
35 Correct 109 ms 294344 KB Output is correct
36 Correct 104 ms 294424 KB Output is correct
37 Correct 119 ms 294440 KB Output is correct
38 Correct 105 ms 294324 KB Output is correct
39 Correct 113 ms 294464 KB Output is correct
40 Correct 103 ms 294348 KB Output is correct
41 Correct 107 ms 294432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 294352 KB Output is correct
2 Correct 106 ms 294400 KB Output is correct
3 Correct 108 ms 294340 KB Output is correct
4 Correct 102 ms 294320 KB Output is correct
5 Correct 104 ms 294428 KB Output is correct
6 Correct 104 ms 294424 KB Output is correct
7 Correct 111 ms 294368 KB Output is correct
8 Correct 125 ms 294332 KB Output is correct
9 Correct 108 ms 294332 KB Output is correct
10 Correct 105 ms 294436 KB Output is correct
11 Correct 107 ms 294424 KB Output is correct
12 Correct 104 ms 294404 KB Output is correct
13 Correct 104 ms 294396 KB Output is correct
14 Correct 105 ms 294332 KB Output is correct
15 Correct 103 ms 294372 KB Output is correct
16 Correct 117 ms 294384 KB Output is correct
17 Correct 111 ms 294420 KB Output is correct
18 Correct 105 ms 294380 KB Output is correct
19 Correct 103 ms 294388 KB Output is correct
20 Correct 109 ms 294428 KB Output is correct
21 Correct 108 ms 294360 KB Output is correct
22 Correct 106 ms 294436 KB Output is correct
23 Correct 104 ms 294336 KB Output is correct
24 Correct 104 ms 294444 KB Output is correct
25 Correct 124 ms 294456 KB Output is correct
26 Correct 109 ms 294432 KB Output is correct
27 Correct 115 ms 294348 KB Output is correct
28 Correct 103 ms 294400 KB Output is correct
29 Correct 106 ms 294400 KB Output is correct
30 Correct 104 ms 294408 KB Output is correct
31 Correct 103 ms 294324 KB Output is correct
32 Correct 102 ms 294400 KB Output is correct
33 Correct 104 ms 294368 KB Output is correct
34 Correct 114 ms 294476 KB Output is correct
35 Correct 109 ms 294344 KB Output is correct
36 Correct 104 ms 294424 KB Output is correct
37 Correct 119 ms 294440 KB Output is correct
38 Correct 105 ms 294324 KB Output is correct
39 Correct 113 ms 294464 KB Output is correct
40 Correct 103 ms 294348 KB Output is correct
41 Correct 107 ms 294432 KB Output is correct
42 Correct 106 ms 294420 KB Output is correct
43 Correct 105 ms 294516 KB Output is correct
44 Correct 110 ms 294332 KB Output is correct
45 Correct 106 ms 294320 KB Output is correct
46 Correct 120 ms 294372 KB Output is correct
47 Correct 107 ms 294416 KB Output is correct
48 Correct 105 ms 294436 KB Output is correct
49 Correct 108 ms 294348 KB Output is correct
50 Correct 108 ms 294436 KB Output is correct
51 Correct 107 ms 294408 KB Output is correct
52 Correct 104 ms 294400 KB Output is correct
53 Correct 109 ms 294336 KB Output is correct
54 Correct 109 ms 294412 KB Output is correct
55 Correct 111 ms 294348 KB Output is correct
56 Correct 117 ms 294416 KB Output is correct
57 Correct 103 ms 294368 KB Output is correct
58 Correct 119 ms 294400 KB Output is correct
59 Correct 116 ms 294368 KB Output is correct
60 Correct 118 ms 294364 KB Output is correct
61 Correct 104 ms 294320 KB Output is correct
62 Correct 106 ms 294384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 294352 KB Output is correct
2 Correct 106 ms 294400 KB Output is correct
3 Correct 108 ms 294340 KB Output is correct
4 Correct 102 ms 294320 KB Output is correct
5 Correct 104 ms 294428 KB Output is correct
6 Correct 104 ms 294424 KB Output is correct
7 Correct 111 ms 294368 KB Output is correct
8 Correct 125 ms 294332 KB Output is correct
9 Correct 108 ms 294332 KB Output is correct
10 Correct 105 ms 294436 KB Output is correct
11 Correct 107 ms 294424 KB Output is correct
12 Correct 104 ms 294404 KB Output is correct
13 Correct 104 ms 294396 KB Output is correct
14 Correct 105 ms 294332 KB Output is correct
15 Correct 103 ms 294372 KB Output is correct
16 Correct 117 ms 294384 KB Output is correct
17 Correct 111 ms 294420 KB Output is correct
18 Correct 105 ms 294380 KB Output is correct
19 Correct 103 ms 294388 KB Output is correct
20 Correct 109 ms 294428 KB Output is correct
21 Correct 108 ms 294360 KB Output is correct
22 Correct 106 ms 294436 KB Output is correct
23 Correct 104 ms 294336 KB Output is correct
24 Correct 104 ms 294444 KB Output is correct
25 Correct 124 ms 294456 KB Output is correct
26 Correct 109 ms 294432 KB Output is correct
27 Correct 115 ms 294348 KB Output is correct
28 Correct 103 ms 294400 KB Output is correct
29 Correct 106 ms 294400 KB Output is correct
30 Correct 104 ms 294408 KB Output is correct
31 Correct 103 ms 294324 KB Output is correct
32 Correct 102 ms 294400 KB Output is correct
33 Correct 104 ms 294368 KB Output is correct
34 Correct 114 ms 294476 KB Output is correct
35 Correct 109 ms 294344 KB Output is correct
36 Correct 104 ms 294424 KB Output is correct
37 Correct 119 ms 294440 KB Output is correct
38 Correct 105 ms 294324 KB Output is correct
39 Correct 113 ms 294464 KB Output is correct
40 Correct 103 ms 294348 KB Output is correct
41 Correct 107 ms 294432 KB Output is correct
42 Correct 106 ms 294420 KB Output is correct
43 Correct 105 ms 294516 KB Output is correct
44 Correct 110 ms 294332 KB Output is correct
45 Correct 106 ms 294320 KB Output is correct
46 Correct 120 ms 294372 KB Output is correct
47 Correct 107 ms 294416 KB Output is correct
48 Correct 105 ms 294436 KB Output is correct
49 Correct 108 ms 294348 KB Output is correct
50 Correct 108 ms 294436 KB Output is correct
51 Correct 107 ms 294408 KB Output is correct
52 Correct 104 ms 294400 KB Output is correct
53 Correct 109 ms 294336 KB Output is correct
54 Correct 109 ms 294412 KB Output is correct
55 Correct 111 ms 294348 KB Output is correct
56 Correct 117 ms 294416 KB Output is correct
57 Correct 103 ms 294368 KB Output is correct
58 Correct 119 ms 294400 KB Output is correct
59 Correct 116 ms 294368 KB Output is correct
60 Correct 118 ms 294364 KB Output is correct
61 Correct 104 ms 294320 KB Output is correct
62 Correct 106 ms 294384 KB Output is correct
63 Correct 227 ms 294492 KB Output is correct
64 Correct 243 ms 294368 KB Output is correct
65 Correct 203 ms 294608 KB Output is correct
66 Correct 236 ms 294504 KB Output is correct
67 Correct 202 ms 294488 KB Output is correct
68 Correct 205 ms 294412 KB Output is correct
69 Correct 221 ms 294548 KB Output is correct
70 Correct 213 ms 294604 KB Output is correct
71 Execution timed out 3090 ms 294484 KB Time limit exceeded
72 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 294352 KB Output is correct
2 Correct 106 ms 294400 KB Output is correct
3 Correct 108 ms 294340 KB Output is correct
4 Correct 102 ms 294320 KB Output is correct
5 Correct 104 ms 294428 KB Output is correct
6 Correct 104 ms 294424 KB Output is correct
7 Correct 111 ms 294368 KB Output is correct
8 Correct 125 ms 294332 KB Output is correct
9 Correct 108 ms 294332 KB Output is correct
10 Correct 105 ms 294436 KB Output is correct
11 Correct 107 ms 294424 KB Output is correct
12 Correct 104 ms 294404 KB Output is correct
13 Correct 104 ms 294396 KB Output is correct
14 Correct 105 ms 294332 KB Output is correct
15 Correct 103 ms 294372 KB Output is correct
16 Correct 117 ms 294384 KB Output is correct
17 Correct 111 ms 294420 KB Output is correct
18 Correct 105 ms 294380 KB Output is correct
19 Correct 103 ms 294388 KB Output is correct
20 Correct 109 ms 294428 KB Output is correct
21 Correct 108 ms 294360 KB Output is correct
22 Correct 106 ms 294436 KB Output is correct
23 Correct 104 ms 294336 KB Output is correct
24 Correct 104 ms 294444 KB Output is correct
25 Correct 124 ms 294456 KB Output is correct
26 Correct 109 ms 294432 KB Output is correct
27 Correct 115 ms 294348 KB Output is correct
28 Correct 103 ms 294400 KB Output is correct
29 Correct 106 ms 294400 KB Output is correct
30 Correct 104 ms 294408 KB Output is correct
31 Correct 103 ms 294324 KB Output is correct
32 Correct 102 ms 294400 KB Output is correct
33 Correct 104 ms 294368 KB Output is correct
34 Correct 114 ms 294476 KB Output is correct
35 Correct 109 ms 294344 KB Output is correct
36 Correct 104 ms 294424 KB Output is correct
37 Correct 119 ms 294440 KB Output is correct
38 Correct 105 ms 294324 KB Output is correct
39 Correct 113 ms 294464 KB Output is correct
40 Correct 103 ms 294348 KB Output is correct
41 Correct 107 ms 294432 KB Output is correct
42 Correct 106 ms 294420 KB Output is correct
43 Correct 105 ms 294516 KB Output is correct
44 Correct 110 ms 294332 KB Output is correct
45 Correct 106 ms 294320 KB Output is correct
46 Correct 120 ms 294372 KB Output is correct
47 Correct 107 ms 294416 KB Output is correct
48 Correct 105 ms 294436 KB Output is correct
49 Correct 108 ms 294348 KB Output is correct
50 Correct 108 ms 294436 KB Output is correct
51 Correct 107 ms 294408 KB Output is correct
52 Correct 104 ms 294400 KB Output is correct
53 Correct 109 ms 294336 KB Output is correct
54 Correct 109 ms 294412 KB Output is correct
55 Correct 111 ms 294348 KB Output is correct
56 Correct 117 ms 294416 KB Output is correct
57 Correct 103 ms 294368 KB Output is correct
58 Correct 119 ms 294400 KB Output is correct
59 Correct 116 ms 294368 KB Output is correct
60 Correct 118 ms 294364 KB Output is correct
61 Correct 104 ms 294320 KB Output is correct
62 Correct 106 ms 294384 KB Output is correct
63 Correct 227 ms 294492 KB Output is correct
64 Correct 243 ms 294368 KB Output is correct
65 Correct 203 ms 294608 KB Output is correct
66 Correct 236 ms 294504 KB Output is correct
67 Correct 202 ms 294488 KB Output is correct
68 Correct 205 ms 294412 KB Output is correct
69 Correct 221 ms 294548 KB Output is correct
70 Correct 213 ms 294604 KB Output is correct
71 Execution timed out 3090 ms 294484 KB Time limit exceeded
72 Halted 0 ms 0 KB -