Submission #535483

# Submission time Handle Problem Language Result Execution time Memory
535483 2022-03-10T11:16:14 Z EJam Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
199 ms 135316 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

const int N = 205;
const ll INF = 1e18;
ll dp[N][N][N][2];

void tkmin(ll &a, ll b) { a = min(a, b); }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				dp[i][j][k][0] = INF;
				dp[i][j][k][1] = INF;
			}
		}
	}

	int n, l; cin >> n >> l;
	vll v(n);
	vll t(n);
	for (auto &it: v) cin>>it;
	for (auto &it: t) cin>>it;

	vll v2 = v;
	reverse(v2.begin(), v2.end());
	for (auto &it: v2) it = l-it;
	v.insert(v.begin(), 0);
	v2.insert(v2.begin(), 0);

	vll t2 = t;
	reverse(t2.begin(), t2.end());
	t.insert(t.begin(), 0);
	t2.insert(t2.begin(), 0);

	dp[0][0][0][0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j+i < n; j++) {
			for (int cnt = 0; cnt < n; cnt++) {
				// right side
				ll cur = dp[i][j][cnt][0];

				ll dist = v[i+1] - v[i];
				ll ncnt = cnt;
				if (cur + dist <= t[i+1]) ncnt++;
				tkmin(dp[i+1][j][ncnt][0], cur + dist);

				dist = v2[j+1] + v[i];
				ncnt = cnt;
				if (cur + dist <= t2[j+1]) ncnt++;
				tkmin(dp[i][j+1][ncnt][1], cur + dist);

				// at left side
				cur = dp[i][j][cnt][1];

				dist = v2[j+1] - v2[j];
				ncnt = cnt;
				if (cur + dist <= t2[j+1]) ncnt++;
//				if (cnt == 4 && i == 2 && j == 2) cout << ncnt << ' ' << dp[i][j+1][ncnt][1] << '\n';
				tkmin(dp[i][j+1][ncnt][1], cur + dist);
//				if (cnt == 4 && i == 2 && j == 2) cout << dp[i][j+1][ncnt][1] << '\n';

				dist = v2[j] + v[i+1];
				ncnt = cnt;
				if (cur + dist <= t[i+1]) ncnt++;
				tkmin(dp[i+1][j][ncnt][0], cur + dist);
			}
		}
	}

	ll ans = 0;
	for (int cnt = 0; cnt <= n; cnt++) {
//		cout << cnt <<": \n";
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j+i <= n; j++) {
//				auto p = [] (ll x) { return x >= INF? -1: x; };
//				cout << p(dp[i][j][cnt][0]) << ":" << p(dp[i][j][cnt][1]) << ' ';
				if (dp[i][j][cnt][0] != INF || dp[i][j][cnt][1] != INF) ans = cnt;
			}
//			cout << '\n';
		}
//		cout << '\n';
	}
	cout << ans << '\n';


	return 0;
}

/*
alias csafe='g++ -std=c++17 -Wshadow -Wall -DLOCAL -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g'
*/

# Verdict Execution time Memory Grader output
1 Correct 62 ms 135176 KB Output is correct
2 Correct 62 ms 135140 KB Output is correct
3 Correct 61 ms 135120 KB Output is correct
4 Correct 61 ms 135164 KB Output is correct
5 Correct 64 ms 135116 KB Output is correct
6 Correct 66 ms 135152 KB Output is correct
7 Correct 73 ms 135124 KB Output is correct
8 Correct 60 ms 135100 KB Output is correct
9 Correct 59 ms 135156 KB Output is correct
10 Correct 67 ms 135096 KB Output is correct
11 Correct 62 ms 135108 KB Output is correct
12 Correct 73 ms 135088 KB Output is correct
13 Correct 64 ms 135096 KB Output is correct
14 Correct 61 ms 135080 KB Output is correct
15 Correct 58 ms 135148 KB Output is correct
16 Correct 62 ms 135164 KB Output is correct
17 Correct 68 ms 135184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 135176 KB Output is correct
2 Correct 62 ms 135140 KB Output is correct
3 Correct 61 ms 135120 KB Output is correct
4 Correct 61 ms 135164 KB Output is correct
5 Correct 64 ms 135116 KB Output is correct
6 Correct 66 ms 135152 KB Output is correct
7 Correct 73 ms 135124 KB Output is correct
8 Correct 60 ms 135100 KB Output is correct
9 Correct 59 ms 135156 KB Output is correct
10 Correct 67 ms 135096 KB Output is correct
11 Correct 62 ms 135108 KB Output is correct
12 Correct 73 ms 135088 KB Output is correct
13 Correct 64 ms 135096 KB Output is correct
14 Correct 61 ms 135080 KB Output is correct
15 Correct 58 ms 135148 KB Output is correct
16 Correct 62 ms 135164 KB Output is correct
17 Correct 68 ms 135184 KB Output is correct
18 Correct 62 ms 135064 KB Output is correct
19 Correct 59 ms 135068 KB Output is correct
20 Correct 66 ms 135180 KB Output is correct
21 Correct 60 ms 135076 KB Output is correct
22 Correct 62 ms 135172 KB Output is correct
23 Correct 64 ms 135068 KB Output is correct
24 Correct 63 ms 135128 KB Output is correct
25 Correct 61 ms 135168 KB Output is correct
26 Correct 65 ms 135136 KB Output is correct
27 Correct 60 ms 135116 KB Output is correct
28 Correct 65 ms 135220 KB Output is correct
29 Correct 61 ms 135072 KB Output is correct
30 Correct 63 ms 135112 KB Output is correct
31 Correct 65 ms 135116 KB Output is correct
32 Correct 58 ms 135060 KB Output is correct
33 Correct 60 ms 135156 KB Output is correct
34 Correct 60 ms 135116 KB Output is correct
35 Correct 59 ms 135200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 135176 KB Output is correct
2 Correct 62 ms 135140 KB Output is correct
3 Correct 61 ms 135120 KB Output is correct
4 Correct 61 ms 135164 KB Output is correct
5 Correct 64 ms 135116 KB Output is correct
6 Correct 66 ms 135152 KB Output is correct
7 Correct 73 ms 135124 KB Output is correct
8 Correct 60 ms 135100 KB Output is correct
9 Correct 59 ms 135156 KB Output is correct
10 Correct 67 ms 135096 KB Output is correct
11 Correct 62 ms 135108 KB Output is correct
12 Correct 73 ms 135088 KB Output is correct
13 Correct 64 ms 135096 KB Output is correct
14 Correct 61 ms 135080 KB Output is correct
15 Correct 58 ms 135148 KB Output is correct
16 Correct 62 ms 135164 KB Output is correct
17 Correct 68 ms 135184 KB Output is correct
18 Correct 144 ms 135188 KB Output is correct
19 Correct 103 ms 135176 KB Output is correct
20 Correct 79 ms 135100 KB Output is correct
21 Correct 95 ms 135164 KB Output is correct
22 Correct 129 ms 135180 KB Output is correct
23 Correct 79 ms 135072 KB Output is correct
24 Correct 74 ms 135156 KB Output is correct
25 Correct 74 ms 135120 KB Output is correct
26 Correct 65 ms 135104 KB Output is correct
27 Correct 82 ms 135136 KB Output is correct
28 Correct 76 ms 135212 KB Output is correct
29 Correct 76 ms 135116 KB Output is correct
30 Correct 71 ms 135100 KB Output is correct
31 Correct 74 ms 135140 KB Output is correct
32 Correct 68 ms 135132 KB Output is correct
33 Correct 74 ms 135080 KB Output is correct
34 Correct 69 ms 135080 KB Output is correct
35 Correct 75 ms 135116 KB Output is correct
36 Correct 70 ms 135080 KB Output is correct
37 Correct 85 ms 135192 KB Output is correct
38 Correct 69 ms 135176 KB Output is correct
39 Correct 75 ms 135164 KB Output is correct
40 Correct 71 ms 135148 KB Output is correct
41 Correct 184 ms 135300 KB Output is correct
42 Correct 139 ms 135124 KB Output is correct
43 Correct 170 ms 135168 KB Output is correct
44 Correct 129 ms 135160 KB Output is correct
45 Correct 186 ms 135192 KB Output is correct
46 Correct 137 ms 135184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 135176 KB Output is correct
2 Correct 62 ms 135140 KB Output is correct
3 Correct 61 ms 135120 KB Output is correct
4 Correct 61 ms 135164 KB Output is correct
5 Correct 64 ms 135116 KB Output is correct
6 Correct 66 ms 135152 KB Output is correct
7 Correct 73 ms 135124 KB Output is correct
8 Correct 60 ms 135100 KB Output is correct
9 Correct 59 ms 135156 KB Output is correct
10 Correct 67 ms 135096 KB Output is correct
11 Correct 62 ms 135108 KB Output is correct
12 Correct 73 ms 135088 KB Output is correct
13 Correct 64 ms 135096 KB Output is correct
14 Correct 61 ms 135080 KB Output is correct
15 Correct 58 ms 135148 KB Output is correct
16 Correct 62 ms 135164 KB Output is correct
17 Correct 68 ms 135184 KB Output is correct
18 Correct 62 ms 135064 KB Output is correct
19 Correct 59 ms 135068 KB Output is correct
20 Correct 66 ms 135180 KB Output is correct
21 Correct 60 ms 135076 KB Output is correct
22 Correct 62 ms 135172 KB Output is correct
23 Correct 64 ms 135068 KB Output is correct
24 Correct 63 ms 135128 KB Output is correct
25 Correct 61 ms 135168 KB Output is correct
26 Correct 65 ms 135136 KB Output is correct
27 Correct 60 ms 135116 KB Output is correct
28 Correct 65 ms 135220 KB Output is correct
29 Correct 61 ms 135072 KB Output is correct
30 Correct 63 ms 135112 KB Output is correct
31 Correct 65 ms 135116 KB Output is correct
32 Correct 58 ms 135060 KB Output is correct
33 Correct 60 ms 135156 KB Output is correct
34 Correct 60 ms 135116 KB Output is correct
35 Correct 59 ms 135200 KB Output is correct
36 Correct 144 ms 135188 KB Output is correct
37 Correct 103 ms 135176 KB Output is correct
38 Correct 79 ms 135100 KB Output is correct
39 Correct 95 ms 135164 KB Output is correct
40 Correct 129 ms 135180 KB Output is correct
41 Correct 79 ms 135072 KB Output is correct
42 Correct 74 ms 135156 KB Output is correct
43 Correct 74 ms 135120 KB Output is correct
44 Correct 65 ms 135104 KB Output is correct
45 Correct 82 ms 135136 KB Output is correct
46 Correct 76 ms 135212 KB Output is correct
47 Correct 76 ms 135116 KB Output is correct
48 Correct 71 ms 135100 KB Output is correct
49 Correct 74 ms 135140 KB Output is correct
50 Correct 68 ms 135132 KB Output is correct
51 Correct 74 ms 135080 KB Output is correct
52 Correct 69 ms 135080 KB Output is correct
53 Correct 75 ms 135116 KB Output is correct
54 Correct 70 ms 135080 KB Output is correct
55 Correct 85 ms 135192 KB Output is correct
56 Correct 69 ms 135176 KB Output is correct
57 Correct 75 ms 135164 KB Output is correct
58 Correct 71 ms 135148 KB Output is correct
59 Correct 184 ms 135300 KB Output is correct
60 Correct 139 ms 135124 KB Output is correct
61 Correct 170 ms 135168 KB Output is correct
62 Correct 129 ms 135160 KB Output is correct
63 Correct 186 ms 135192 KB Output is correct
64 Correct 137 ms 135184 KB Output is correct
65 Correct 172 ms 135192 KB Output is correct
66 Correct 150 ms 135176 KB Output is correct
67 Correct 158 ms 135112 KB Output is correct
68 Correct 145 ms 135180 KB Output is correct
69 Correct 175 ms 135272 KB Output is correct
70 Correct 165 ms 135192 KB Output is correct
71 Correct 161 ms 135192 KB Output is correct
72 Correct 166 ms 135112 KB Output is correct
73 Correct 140 ms 135092 KB Output is correct
74 Correct 149 ms 135148 KB Output is correct
75 Correct 145 ms 135120 KB Output is correct
76 Correct 178 ms 135316 KB Output is correct
77 Correct 183 ms 135196 KB Output is correct
78 Correct 148 ms 135088 KB Output is correct
79 Correct 137 ms 135188 KB Output is correct
80 Correct 178 ms 135212 KB Output is correct
81 Correct 147 ms 135196 KB Output is correct
82 Correct 156 ms 135200 KB Output is correct
83 Correct 182 ms 135196 KB Output is correct
84 Correct 169 ms 135244 KB Output is correct
85 Correct 160 ms 135200 KB Output is correct
86 Correct 167 ms 135200 KB Output is correct
87 Correct 159 ms 135120 KB Output is correct
88 Correct 199 ms 135196 KB Output is correct
89 Correct 192 ms 135180 KB Output is correct
90 Correct 170 ms 135192 KB Output is correct
91 Correct 175 ms 135268 KB Output is correct
92 Correct 195 ms 135216 KB Output is correct
93 Correct 199 ms 135184 KB Output is correct