Submission #680696

# Submission time Handle Problem Language Result Execution time Memory
680696 2023-01-11T14:20:46 Z ethening Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
1443 ms 135256 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll dp[205][205][205][2];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	ll l;
	cin >> n >> l;
	vector<ll> X(n + 2, 0);
	vector<ll> T(n + 2, 0);
	X[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> X[i];
	}
	X[n + 1] = l;
	for (int i = 1; i <= n; i++) {
		cin >> T[i];
	}
	memset(dp, -1, sizeof(dp));

	int ans = 0;

	dp[0][0][0][0] = 0;
	dp[0][0][0][1] = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i == 0 && j == 0) continue;
			if (i + j > n) continue;
			for (int k = 1; k <= n; k++) {
				if (k > i + j) break;
				for (int lst = i - 1; lst >= 0; lst--) {
					if (k - 1 > lst + j) break;
					// cout << "@@@ " << i << " " << j << " " << k << " " << 0 << " <- " << lst << " " << j << " " << k - 1 << " " << 0 << endl;
					if (dp[lst][j][k - 1][0] != -1) {
						ll dst = abs(X[i] - X[lst]);
						dst = min(dst, l - dst);
						ll tme = dp[lst][j][k - 1][0] + dst;
						if (tme <= T[i]) {
							if (dp[i][j][k][0] == -1) dp[i][j][k][0] = tme;
							dp[i][j][k][0] = min(dp[i][j][k][0], tme);
							ans = max(ans, k);
						}
					}
					if (dp[lst][j][k - 1][1] != -1) {
						ll dst = abs(X[i] - X[n + 1 - j]);
						dst = min(dst, l - dst);
						ll tme = dp[lst][j][k - 1][1] + dst;
						if (tme <= T[i]) {
							if (dp[i][j][k][0] == -1) dp[i][j][k][0] = tme;
							dp[i][j][k][0] = min(dp[i][j][k][0], tme);
							ans = max(ans, k);
						}
					}
				}
				for (int lst = j - 1; lst >= 0; lst--) {
					if (k - 1 > lst + i) break;
					if (dp[i][lst][k - 1][1] != -1) {
						ll dst = abs(X[n + 1 - j] - X[n + 1 - lst]);
						dst = min(dst, l - dst);
						ll tme = dp[i][lst][k - 1][1] + dst;
						if (tme <= T[n + 1 - j]) {
							if (dp[i][j][k][1] == -1) dp[i][j][k][1] = tme;
							dp[i][j][k][1] = min(dp[i][j][k][1], tme);
							ans = max(ans, k);
						}
					}
					if (dp[i][lst][k - 1][0] != -1) {
						ll dst = abs(X[n + 1 - j] - X[i]);
						dst = min(dst, l - dst);
						ll tme = dp[i][lst][k - 1][0] + dst;
						if (tme <= T[n + 1 - j]) {
							if (dp[i][j][k][1] == -1) dp[i][j][k][1] = tme;
							dp[i][j][k][1] = min(dp[i][j][k][1], tme);
							ans = max(ans, k);
						}
					}
				}
			}
		}
	}

	// for (int i = 0; i <= n; i++) {
	// 	for (int j = 0; j <= n; j++) {
	// 		for (int k = 0; k <= n; k++) {
	// 			for (int l = 0; l <= 1; l++) {
	// 				cout << i << " " << j << " " << k << " " << l << "   :" << dp[i][j][k][l] << endl;
	// 			}
	// 		}
	// 	}
	// }
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 135164 KB Output is correct
2 Correct 49 ms 135108 KB Output is correct
3 Correct 50 ms 135060 KB Output is correct
4 Correct 51 ms 135108 KB Output is correct
5 Correct 49 ms 135152 KB Output is correct
6 Correct 50 ms 135104 KB Output is correct
7 Correct 51 ms 135096 KB Output is correct
8 Correct 50 ms 135144 KB Output is correct
9 Correct 52 ms 135168 KB Output is correct
10 Correct 50 ms 135124 KB Output is correct
11 Correct 51 ms 135100 KB Output is correct
12 Correct 49 ms 135116 KB Output is correct
13 Correct 60 ms 135076 KB Output is correct
14 Correct 52 ms 135160 KB Output is correct
15 Correct 51 ms 135064 KB Output is correct
16 Correct 52 ms 135080 KB Output is correct
17 Correct 52 ms 135148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 135164 KB Output is correct
2 Correct 49 ms 135108 KB Output is correct
3 Correct 50 ms 135060 KB Output is correct
4 Correct 51 ms 135108 KB Output is correct
5 Correct 49 ms 135152 KB Output is correct
6 Correct 50 ms 135104 KB Output is correct
7 Correct 51 ms 135096 KB Output is correct
8 Correct 50 ms 135144 KB Output is correct
9 Correct 52 ms 135168 KB Output is correct
10 Correct 50 ms 135124 KB Output is correct
11 Correct 51 ms 135100 KB Output is correct
12 Correct 49 ms 135116 KB Output is correct
13 Correct 60 ms 135076 KB Output is correct
14 Correct 52 ms 135160 KB Output is correct
15 Correct 51 ms 135064 KB Output is correct
16 Correct 52 ms 135080 KB Output is correct
17 Correct 52 ms 135148 KB Output is correct
18 Correct 51 ms 135140 KB Output is correct
19 Correct 50 ms 135116 KB Output is correct
20 Correct 50 ms 135160 KB Output is correct
21 Correct 52 ms 135164 KB Output is correct
22 Correct 52 ms 135156 KB Output is correct
23 Correct 57 ms 135112 KB Output is correct
24 Correct 54 ms 135088 KB Output is correct
25 Correct 53 ms 135080 KB Output is correct
26 Correct 51 ms 135116 KB Output is correct
27 Correct 54 ms 135116 KB Output is correct
28 Correct 49 ms 135176 KB Output is correct
29 Correct 50 ms 135156 KB Output is correct
30 Correct 54 ms 135164 KB Output is correct
31 Correct 54 ms 135160 KB Output is correct
32 Correct 52 ms 135068 KB Output is correct
33 Correct 52 ms 135052 KB Output is correct
34 Correct 49 ms 135108 KB Output is correct
35 Correct 49 ms 135068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 135164 KB Output is correct
2 Correct 49 ms 135108 KB Output is correct
3 Correct 50 ms 135060 KB Output is correct
4 Correct 51 ms 135108 KB Output is correct
5 Correct 49 ms 135152 KB Output is correct
6 Correct 50 ms 135104 KB Output is correct
7 Correct 51 ms 135096 KB Output is correct
8 Correct 50 ms 135144 KB Output is correct
9 Correct 52 ms 135168 KB Output is correct
10 Correct 50 ms 135124 KB Output is correct
11 Correct 51 ms 135100 KB Output is correct
12 Correct 49 ms 135116 KB Output is correct
13 Correct 60 ms 135076 KB Output is correct
14 Correct 52 ms 135160 KB Output is correct
15 Correct 51 ms 135064 KB Output is correct
16 Correct 52 ms 135080 KB Output is correct
17 Correct 52 ms 135148 KB Output is correct
18 Correct 559 ms 135176 KB Output is correct
19 Correct 277 ms 135176 KB Output is correct
20 Correct 110 ms 135176 KB Output is correct
21 Correct 244 ms 135132 KB Output is correct
22 Correct 397 ms 135184 KB Output is correct
23 Correct 127 ms 135064 KB Output is correct
24 Correct 73 ms 135108 KB Output is correct
25 Correct 131 ms 135176 KB Output is correct
26 Correct 59 ms 135116 KB Output is correct
27 Correct 137 ms 135144 KB Output is correct
28 Correct 70 ms 135168 KB Output is correct
29 Correct 105 ms 135116 KB Output is correct
30 Correct 79 ms 135232 KB Output is correct
31 Correct 122 ms 135140 KB Output is correct
32 Correct 64 ms 135116 KB Output is correct
33 Correct 105 ms 135176 KB Output is correct
34 Correct 58 ms 135096 KB Output is correct
35 Correct 79 ms 135116 KB Output is correct
36 Correct 57 ms 135108 KB Output is correct
37 Correct 77 ms 135104 KB Output is correct
38 Correct 64 ms 135160 KB Output is correct
39 Correct 84 ms 135128 KB Output is correct
40 Correct 64 ms 135100 KB Output is correct
41 Correct 1223 ms 135196 KB Output is correct
42 Correct 398 ms 135180 KB Output is correct
43 Correct 1198 ms 135180 KB Output is correct
44 Correct 360 ms 135192 KB Output is correct
45 Correct 1189 ms 135180 KB Output is correct
46 Correct 297 ms 135232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 135164 KB Output is correct
2 Correct 49 ms 135108 KB Output is correct
3 Correct 50 ms 135060 KB Output is correct
4 Correct 51 ms 135108 KB Output is correct
5 Correct 49 ms 135152 KB Output is correct
6 Correct 50 ms 135104 KB Output is correct
7 Correct 51 ms 135096 KB Output is correct
8 Correct 50 ms 135144 KB Output is correct
9 Correct 52 ms 135168 KB Output is correct
10 Correct 50 ms 135124 KB Output is correct
11 Correct 51 ms 135100 KB Output is correct
12 Correct 49 ms 135116 KB Output is correct
13 Correct 60 ms 135076 KB Output is correct
14 Correct 52 ms 135160 KB Output is correct
15 Correct 51 ms 135064 KB Output is correct
16 Correct 52 ms 135080 KB Output is correct
17 Correct 52 ms 135148 KB Output is correct
18 Correct 51 ms 135140 KB Output is correct
19 Correct 50 ms 135116 KB Output is correct
20 Correct 50 ms 135160 KB Output is correct
21 Correct 52 ms 135164 KB Output is correct
22 Correct 52 ms 135156 KB Output is correct
23 Correct 57 ms 135112 KB Output is correct
24 Correct 54 ms 135088 KB Output is correct
25 Correct 53 ms 135080 KB Output is correct
26 Correct 51 ms 135116 KB Output is correct
27 Correct 54 ms 135116 KB Output is correct
28 Correct 49 ms 135176 KB Output is correct
29 Correct 50 ms 135156 KB Output is correct
30 Correct 54 ms 135164 KB Output is correct
31 Correct 54 ms 135160 KB Output is correct
32 Correct 52 ms 135068 KB Output is correct
33 Correct 52 ms 135052 KB Output is correct
34 Correct 49 ms 135108 KB Output is correct
35 Correct 49 ms 135068 KB Output is correct
36 Correct 559 ms 135176 KB Output is correct
37 Correct 277 ms 135176 KB Output is correct
38 Correct 110 ms 135176 KB Output is correct
39 Correct 244 ms 135132 KB Output is correct
40 Correct 397 ms 135184 KB Output is correct
41 Correct 127 ms 135064 KB Output is correct
42 Correct 73 ms 135108 KB Output is correct
43 Correct 131 ms 135176 KB Output is correct
44 Correct 59 ms 135116 KB Output is correct
45 Correct 137 ms 135144 KB Output is correct
46 Correct 70 ms 135168 KB Output is correct
47 Correct 105 ms 135116 KB Output is correct
48 Correct 79 ms 135232 KB Output is correct
49 Correct 122 ms 135140 KB Output is correct
50 Correct 64 ms 135116 KB Output is correct
51 Correct 105 ms 135176 KB Output is correct
52 Correct 58 ms 135096 KB Output is correct
53 Correct 79 ms 135116 KB Output is correct
54 Correct 57 ms 135108 KB Output is correct
55 Correct 77 ms 135104 KB Output is correct
56 Correct 64 ms 135160 KB Output is correct
57 Correct 84 ms 135128 KB Output is correct
58 Correct 64 ms 135100 KB Output is correct
59 Correct 1223 ms 135196 KB Output is correct
60 Correct 398 ms 135180 KB Output is correct
61 Correct 1198 ms 135180 KB Output is correct
62 Correct 360 ms 135192 KB Output is correct
63 Correct 1189 ms 135180 KB Output is correct
64 Correct 297 ms 135232 KB Output is correct
65 Correct 735 ms 135188 KB Output is correct
66 Correct 665 ms 135240 KB Output is correct
67 Correct 584 ms 135188 KB Output is correct
68 Correct 507 ms 135184 KB Output is correct
69 Correct 766 ms 135188 KB Output is correct
70 Correct 1273 ms 135180 KB Output is correct
71 Correct 569 ms 135256 KB Output is correct
72 Correct 1388 ms 135180 KB Output is correct
73 Correct 502 ms 135184 KB Output is correct
74 Correct 1020 ms 135188 KB Output is correct
75 Correct 515 ms 135184 KB Output is correct
76 Correct 1253 ms 135184 KB Output is correct
77 Correct 666 ms 135184 KB Output is correct
78 Correct 857 ms 135184 KB Output is correct
79 Correct 487 ms 135180 KB Output is correct
80 Correct 1281 ms 135180 KB Output is correct
81 Correct 439 ms 135188 KB Output is correct
82 Correct 461 ms 135188 KB Output is correct
83 Correct 810 ms 135180 KB Output is correct
84 Correct 511 ms 135256 KB Output is correct
85 Correct 607 ms 135188 KB Output is correct
86 Correct 627 ms 135184 KB Output is correct
87 Correct 570 ms 135200 KB Output is correct
88 Correct 1435 ms 135184 KB Output is correct
89 Correct 1193 ms 135120 KB Output is correct
90 Correct 470 ms 135184 KB Output is correct
91 Correct 1443 ms 135180 KB Output is correct
92 Correct 1176 ms 135188 KB Output is correct
93 Correct 615 ms 135180 KB Output is correct