Submission #916334

# Submission time Handle Problem Language Result Execution time Memory
916334 2024-01-25T17:01:33 Z EJIC_B_KEDAX Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>

#define x first
#define y second

using ll = long long;

using namespace std;

int main() {
	int n, L;
	cin >> n >> L;
	vector<pair<int, int>> a(n + 2);
	a[0] = {0, INT64_MAX};
	a[n + 1] = {L, INT64_MAX};
	for (int i = 1; i <= n; i++) {
		cin >> a[i].x;
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i].y;
	}
	n += 2;
	vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(n, INT64_MAX / 2)));
	dp[0][n - 1][0] = 0;
	for (int l = n - 1; l > 0; l--) {
		for (int i = 0; i + l < n; i++) {
			int j = i + l;
			for (int s = 0; s < n; s++) {
				ll dist1 = a[i + 1].x - a[i].x, dist2 = a[i].x + L - a[j - 1].x;
				if (dp[i][j][s] + dist1 <= a[i + 1].y) {
					dp[i + 1][j][s + 1] = min(dp[i + 1][j][s + 1], dp[i][j][s] + dist1);
				} else {
					dp[i + 1][j][s] = min(dp[i + 1][j][s], dp[i][j][s] + dist1);
				}
				if (dp[i][j][s] + dist2 <= a[j - 1].y) {
					dp[j - 1][i][s + 1] = min(dp[j - 1][i][s + 1], dp[i][j][s] + dist2);
				} else {
					dp[j - 1][i][s] = min(dp[j - 1][i][s], dp[i][j][s] + dist2);
				}
			}
		}
		for (int i = l; i < n; i++) {
			int j = i - l;
			for (int s = 0; s < n; s++) {
				ll dist1 = a[i].x - a[i - 1].x, dist2 = L - a[i].x + a[j + 1].x;
				if (dp[i][j][s] + dist1 <= a[i - 1].y) {
					dp[i - 1][j][s + 1] = min(dp[i - 1][j][s + 1], dp[i][j][s] + dist1);
				} else {
					dp[i - 1][j][s] = min(dp[i - 1][j][s], dp[i][j][s] + dist1);
				}
				if (dp[i][j][s] + dist2 <= a[j + 1].y) {
					dp[j + 1][i][s + 1] = min(dp[j + 1][i][s + 1], dp[i][j][s] + dist2);
				} else {
					dp[j + 1][i][s] = min(dp[j + 1][i][s], dp[i][j][s] + dist2);
				}
			}
		}
	}
	for (int s = n - 1; s >= 0; s--) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (dp[i][j][s] < INT64_MAX / 2) {
					cout << s << '\n';
					return 0;
				}
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -