Submission #1032601

#TimeUsernameProblemLanguageResultExecution timeMemory
1032601juicyCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
51 ms66400 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int N = 205, inf = 1e9 + 7;
 
int n, l;
int x[N], t[N], dp[N][N][N][2];
 
int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
 
	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; ++i) {
		for (int j = 0; j <= n + 1; ++j) {
			for (int k = 0; k <= n; ++k) {
				for (int x = 0; x < 2; ++x) {
					dp[i][j][k][x] = inf;
				}
			}
		}
	}
	dp[0][n + 1][0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = n + 1; j > i + 1; --j) {
			for (int cnt = 0; cnt <= n; ++cnt) {
				if (dp[i][j][cnt][0] != inf) {
					int c = dp[i][j][cnt][0] + x[i + 1] - x[i];
					int ncnt = cnt + (c <= t[i + 1]);
					dp[i + 1][j][ncnt][0] = min(dp[i + 1][j][ncnt][0], c);
					c = dp[i][j][cnt][0] + x[i] + l - x[j - 1];
					ncnt = cnt + (c <= t[j - 1]);
					dp[i][j - 1][ncnt][1] = min(dp[i][j - 1][ncnt][1], c);
				} 
				if (dp[i][j][cnt][1] != inf) {
					int c = dp[i][j][cnt][1] + l - x[j] + x[i + 1];
					int ncnt = cnt + (c <= t[i + 1]);
					dp[i + 1][j][ncnt][0] = min(dp[i + 1][j][ncnt][0], c);
					c = dp[i][j][cnt][1] + x[j] - x[j - 1];
					ncnt = cnt + (c <= t[j - 1]);
					dp[i][j - 1][ncnt][1] = min(dp[i][j - 1][ncnt][1], c);
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n + 1; ++j) {
			for (int k = 0; k <= n; ++k) {
				for (int x = 0; x < 2; ++x) {
					if (dp[i][j][k][x] < inf) {
						res = max(res, k);
					}
				}
			}
		}
	}
	cout << res;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...