Submission #1085825

# Submission time Handle Problem Language Result Execution time Memory
1085825 2024-09-08T19:20:23 Z vako_p Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
149 ms 132180 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int mxN = 205; 
ll n,x[mxN],t[mxN],L,dp[mxN][mxN][mxN][2],inf = 1e17;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> L;
	for(int i = 1; i <= n; i++) cin >> x[i];
	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 0; i <= n + 1; i++) for(int j = 0; j <= n + 1; j++) for(int k = 0; k <= n + 1; k++){
		dp[i][j][k][0] = dp[i][j][k][1] = inf;
		dp[0][j][k][0] = x[k];
		dp[0][j][k][1] = L - x[j];	
	}
	dp[0][0][0][0] = dp[0][0][0][1] = 0;
	x[n + 1] = L;
	ll ans = 0;
	for(int k = 1; k <= n; k++){
		for(ll i1 = n + 1; i1 >= 1; i1--){
			ll i = i1 % (n + 1);
			if(i1 != n + 1){
				ll num = dp[k - 1][(i + 1) % (n + 1)][0][1];
				dp[k][i][0][1] = min(num + ((t[i] >= num + x[i + 1] - x[i]) ? (x[i + 1] - x[i]) : inf), inf);
				dp[k][i][0][1] = min(dp[k][i][0][1], dp[k][(i + 1) % (n + 1)][0][1] + x[i + 1] - x[i]);
				dp[k][i][0][0] = min(dp[k][i][0][1] + L - x[i], dp[k][(i + 1) % (n + 1)][0][0]);
			}
			for(ll j = 1; j != i1; j++){
				ll num = dp[k - 1][i][j - 1][0];
				dp[k][i][j][0] = min(num + ((t[j] >= num + x[j] - x[j - 1]) ? (x[j] - x[j - 1]) : inf),inf);
				dp[k][i][j][0] = min(dp[k][i][j][0], dp[k][i][j - 1][0] + x[j] - x[j - 1]);
				if(i1 != n + 1){
					dp[k][i][j][0] = min(dp[k][i][j][0], dp[k][(i + 1) % (n + 1)][j][0]);
				}
				else{
					dp[k][0][j][1] = min(dp[k][0][j - 1][1], dp[k][0][j][0] + x[j]); 
					continue;
				}
				num = dp[k - 1][(i + 1) % (n + 1)][j][1];
				dp[k][i][j][1] = min(min(num + ((t[i] >= num + x[i + 1] - x[i]) ? (x[i + 1] - x[i]) : inf),
				dp[k][i][j - 1][1]), inf);
				dp[k][i][j][1] = min(dp[k][i][j][1], dp[k][(i + 1) % (n + 1)][j][1] + x[i + 1] - x[i]);
				dp[k][i][j][0] = min(dp[k][i][j][0], dp[k][i][j][1] + L - x[i] + x[j]);
				dp[k][i][j][1] = min(dp[k][i][j][1], dp[k][i][j][0] + L - x[i] + x[j]);
			}
		}
	}
//5 20
//1 2 17 18 19
//1 8 5 4 3
	for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) for(int k = 0; k <= n; k++){
		if(dp[i][j][k][0] < inf or dp[i][j][k][1] < inf) ans = max(ans, (ll)i);
	}
	cout << ans;
}		
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 0 ms 860 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 0 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 860 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 1 ms 1368 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 0 ms 1116 KB Output is correct
33 Correct 1 ms 1372 KB Output is correct
34 Correct 1 ms 1624 KB Output is correct
35 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 90 ms 106260 KB Output is correct
19 Correct 50 ms 64596 KB Output is correct
20 Correct 26 ms 34652 KB Output is correct
21 Correct 45 ms 61020 KB Output is correct
22 Correct 65 ms 78928 KB Output is correct
23 Correct 19 ms 29528 KB Output is correct
24 Correct 16 ms 23128 KB Output is correct
25 Correct 21 ms 29020 KB Output is correct
26 Correct 5 ms 11352 KB Output is correct
27 Correct 21 ms 30300 KB Output is correct
28 Correct 12 ms 21592 KB Output is correct
29 Correct 19 ms 30812 KB Output is correct
30 Correct 14 ms 24412 KB Output is correct
31 Correct 19 ms 29020 KB Output is correct
32 Correct 8 ms 15452 KB Output is correct
33 Correct 18 ms 29020 KB Output is correct
34 Correct 6 ms 10588 KB Output is correct
35 Correct 16 ms 28448 KB Output is correct
36 Correct 7 ms 13660 KB Output is correct
37 Correct 19 ms 30316 KB Output is correct
38 Correct 10 ms 16732 KB Output is correct
39 Correct 21 ms 31324 KB Output is correct
40 Correct 11 ms 18524 KB Output is correct
41 Correct 106 ms 130856 KB Output is correct
42 Correct 66 ms 88400 KB Output is correct
43 Correct 125 ms 130900 KB Output is correct
44 Correct 66 ms 87348 KB Output is correct
45 Correct 113 ms 130896 KB Output is correct
46 Correct 74 ms 88168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 0 ms 860 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 0 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 860 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 1 ms 1368 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 0 ms 1116 KB Output is correct
33 Correct 1 ms 1372 KB Output is correct
34 Correct 1 ms 1624 KB Output is correct
35 Correct 1 ms 1372 KB Output is correct
36 Correct 90 ms 106260 KB Output is correct
37 Correct 50 ms 64596 KB Output is correct
38 Correct 26 ms 34652 KB Output is correct
39 Correct 45 ms 61020 KB Output is correct
40 Correct 65 ms 78928 KB Output is correct
41 Correct 19 ms 29528 KB Output is correct
42 Correct 16 ms 23128 KB Output is correct
43 Correct 21 ms 29020 KB Output is correct
44 Correct 5 ms 11352 KB Output is correct
45 Correct 21 ms 30300 KB Output is correct
46 Correct 12 ms 21592 KB Output is correct
47 Correct 19 ms 30812 KB Output is correct
48 Correct 14 ms 24412 KB Output is correct
49 Correct 19 ms 29020 KB Output is correct
50 Correct 8 ms 15452 KB Output is correct
51 Correct 18 ms 29020 KB Output is correct
52 Correct 6 ms 10588 KB Output is correct
53 Correct 16 ms 28448 KB Output is correct
54 Correct 7 ms 13660 KB Output is correct
55 Correct 19 ms 30316 KB Output is correct
56 Correct 10 ms 16732 KB Output is correct
57 Correct 21 ms 31324 KB Output is correct
58 Correct 11 ms 18524 KB Output is correct
59 Correct 106 ms 130856 KB Output is correct
60 Correct 66 ms 88400 KB Output is correct
61 Correct 125 ms 130900 KB Output is correct
62 Correct 66 ms 87348 KB Output is correct
63 Correct 113 ms 130896 KB Output is correct
64 Correct 74 ms 88168 KB Output is correct
65 Correct 95 ms 118100 KB Output is correct
66 Correct 87 ms 108604 KB Output is correct
67 Correct 87 ms 103764 KB Output is correct
68 Correct 90 ms 95880 KB Output is correct
69 Correct 93 ms 116816 KB Output is correct
70 Correct 96 ms 111952 KB Output is correct
71 Correct 95 ms 113232 KB Output is correct
72 Correct 90 ms 114428 KB Output is correct
73 Correct 82 ms 106064 KB Output is correct
74 Correct 87 ms 99376 KB Output is correct
75 Correct 87 ms 109636 KB Output is correct
76 Correct 115 ms 125776 KB Output is correct
77 Correct 115 ms 125776 KB Output is correct
78 Correct 78 ms 97104 KB Output is correct
79 Correct 84 ms 100436 KB Output is correct
80 Correct 99 ms 123240 KB Output is correct
81 Correct 80 ms 101468 KB Output is correct
82 Correct 83 ms 107344 KB Output is correct
83 Correct 126 ms 130648 KB Output is correct
84 Correct 92 ms 111952 KB Output is correct
85 Correct 98 ms 121940 KB Output is correct
86 Correct 97 ms 119380 KB Output is correct
87 Correct 84 ms 109784 KB Output is correct
88 Correct 149 ms 132084 KB Output is correct
89 Correct 107 ms 132176 KB Output is correct
90 Correct 89 ms 110936 KB Output is correct
91 Correct 124 ms 132180 KB Output is correct
92 Correct 115 ms 132180 KB Output is correct
93 Correct 103 ms 129600 KB Output is correct