답안 #861666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861666 2023-10-16T16:01:47 Z dsyz Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
119 ms 129064 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N,L;
	cin>>N>>L;
	ll X[N + 2], T[N + 2];
	for(ll i = 1;i <= N;i++){
		cin>>X[i];
	}
	for(ll i = 1;i <= N;i++){
		cin>>T[i];
	}
	X[0] = 0, T[0] = -1;
	X[N + 1] = L, T[N + 1] = -1;
	ll dp[N + 2][N + 2][N + 1][2];
	for(ll l = 0;l <= N + 1;l++){
		for(ll r = 0;r <= N + 1;r++){
			for(ll k = 0;k <= N;k++){
				dp[l][r][k][0] = 1e18;
				dp[l][r][k][1] = 1e18;
			}
		}
	}
	dp[0][N + 1][0][0] = 0;
	dp[0][N + 1][0][1] = 0;
	for(ll l = 0;l <= N + 1;l++){
		for(ll r = N + 1;r > l;r--){
			for(ll k = 0;k <= N;k++){
				if(l >= 1){
					dp[l][r][k][0] = min(dp[l][r][k][0],dp[l - 1][r][k - 1][0] + min(X[l] - X[l - 1],L - (X[l] - X[l - 1])));
					dp[l][r][k][0] = min(dp[l][r][k][0],dp[l - 1][r][k - 1][1] + min(X[r] - X[l],L - (X[r] - X[l])));
					if(dp[l][r][k][0] > T[l]) dp[l][r][k][0] = 1e18;
					
					dp[l][r][k][0] = min(dp[l][r][k][0],dp[l - 1][r][k][0] + min(X[l] - X[l - 1],L - (X[l] - X[l - 1])));
					dp[l][r][k][0] = min(dp[l][r][k][0],dp[l - 1][r][k][1] + min(X[r] - X[l],L - (X[r] - X[l])));
				}
				if(r <= N){
					dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r + 1][k - 1][1] + min(X[r + 1] - X[r],L - (X[r + 1] - X[r])));
                    dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r + 1][k - 1][0] + min(X[r] - X[l],L - (X[r] - X[l])));
                    if(dp[l][r][k][1] > T[r]) dp[l][r][k][1] = 1e18;
                    
                    dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r + 1][k][1] + min(X[r + 1] - X[r],L - (X[r + 1] - X[r])));
                    dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r + 1][k][0] + min(X[r] - X[l],L - (X[r] - X[l])));
				}
			}
		}
	}
	ll ans = 0;
	for(ll l = 0;l <= N + 1;l++){
		for(ll r = 0;r <= N + 1;r++){
			for(ll k = 0;k <= N;k++){
				if(min(dp[l][r][k][0],dp[l][r][k][1]) < 1e18){
					ans = max(ans,k);
				}
			}
		}
	}
	cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 456 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 460 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 81 ms 92756 KB Output is correct
19 Correct 40 ms 44004 KB Output is correct
20 Correct 15 ms 17236 KB Output is correct
21 Correct 39 ms 40284 KB Output is correct
22 Correct 56 ms 59488 KB Output is correct
23 Correct 13 ms 13648 KB Output is correct
24 Correct 8 ms 9560 KB Output is correct
25 Correct 14 ms 13060 KB Output is correct
26 Correct 3 ms 3420 KB Output is correct
27 Correct 13 ms 14136 KB Output is correct
28 Correct 7 ms 8540 KB Output is correct
29 Correct 13 ms 14428 KB Output is correct
30 Correct 9 ms 10076 KB Output is correct
31 Correct 11 ms 13108 KB Output is correct
32 Correct 4 ms 5212 KB Output is correct
33 Correct 12 ms 13320 KB Output is correct
34 Correct 3 ms 2908 KB Output is correct
35 Correct 11 ms 12748 KB Output is correct
36 Correct 4 ms 4440 KB Output is correct
37 Correct 13 ms 13912 KB Output is correct
38 Correct 5 ms 5724 KB Output is correct
39 Correct 14 ms 14792 KB Output is correct
40 Correct 6 ms 6748 KB Output is correct
41 Correct 119 ms 126936 KB Output is correct
42 Correct 67 ms 70224 KB Output is correct
43 Correct 117 ms 127060 KB Output is correct
44 Correct 66 ms 68948 KB Output is correct
45 Correct 116 ms 126852 KB Output is correct
46 Correct 65 ms 70228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 456 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 460 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 81 ms 92756 KB Output is correct
37 Correct 40 ms 44004 KB Output is correct
38 Correct 15 ms 17236 KB Output is correct
39 Correct 39 ms 40284 KB Output is correct
40 Correct 56 ms 59488 KB Output is correct
41 Correct 13 ms 13648 KB Output is correct
42 Correct 8 ms 9560 KB Output is correct
43 Correct 14 ms 13060 KB Output is correct
44 Correct 3 ms 3420 KB Output is correct
45 Correct 13 ms 14136 KB Output is correct
46 Correct 7 ms 8540 KB Output is correct
47 Correct 13 ms 14428 KB Output is correct
48 Correct 9 ms 10076 KB Output is correct
49 Correct 11 ms 13108 KB Output is correct
50 Correct 4 ms 5212 KB Output is correct
51 Correct 12 ms 13320 KB Output is correct
52 Correct 3 ms 2908 KB Output is correct
53 Correct 11 ms 12748 KB Output is correct
54 Correct 4 ms 4440 KB Output is correct
55 Correct 13 ms 13912 KB Output is correct
56 Correct 5 ms 5724 KB Output is correct
57 Correct 14 ms 14792 KB Output is correct
58 Correct 6 ms 6748 KB Output is correct
59 Correct 119 ms 126936 KB Output is correct
60 Correct 67 ms 70224 KB Output is correct
61 Correct 117 ms 127060 KB Output is correct
62 Correct 66 ms 68948 KB Output is correct
63 Correct 116 ms 126852 KB Output is correct
64 Correct 65 ms 70228 KB Output is correct
65 Correct 100 ms 108776 KB Output is correct
66 Correct 87 ms 95860 KB Output is correct
67 Correct 83 ms 89656 KB Output is correct
68 Correct 74 ms 79444 KB Output is correct
69 Correct 99 ms 107136 KB Output is correct
70 Correct 97 ms 100632 KB Output is correct
71 Correct 93 ms 102744 KB Output is correct
72 Correct 94 ms 103912 KB Output is correct
73 Correct 92 ms 92624 KB Output is correct
74 Correct 82 ms 83980 KB Output is correct
75 Correct 90 ms 97436 KB Output is correct
76 Correct 111 ms 119420 KB Output is correct
77 Correct 106 ms 119408 KB Output is correct
78 Correct 75 ms 81024 KB Output is correct
79 Correct 93 ms 85296 KB Output is correct
80 Correct 112 ms 115904 KB Output is correct
81 Correct 80 ms 86612 KB Output is correct
82 Correct 86 ms 94288 KB Output is correct
83 Correct 115 ms 126804 KB Output is correct
84 Correct 91 ms 100436 KB Output is correct
85 Correct 105 ms 114104 KB Output is correct
86 Correct 102 ms 110504 KB Output is correct
87 Correct 93 ms 97620 KB Output is correct
88 Correct 119 ms 128592 KB Output is correct
89 Correct 119 ms 128784 KB Output is correct
90 Correct 90 ms 98900 KB Output is correct
91 Correct 118 ms 128680 KB Output is correct
92 Correct 117 ms 129064 KB Output is correct
93 Correct 112 ms 125052 KB Output is correct