답안 #720673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720673 2023-04-08T22:53:20 Z Juan Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e2 + 5, INF = 1e18;

int ans = 0, L, mx=0;
int dp[maxn][maxn][maxn][2];
int T[maxn], X[maxn];

int32_t main(){
	int n; cin >> n >> L;
	for(int i = 1; i <= n; i++) cin >> X[i];
	for(int i = 1; i <= n; i++) cin >> T[i], mx = max(mx, T[i]);
	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] = dp[i][j][k][1] = INF;
			}
		}
	}

	priority_queue<tuple<int, int, int, int, int>> pq;
	pq.push({0, 0, n+1, 0, 0});
	dp[0][n+1][0][0] = 0;
	while(pq.size()){
		auto[t, l, r, s, d] = pq.top();
		pq.pop();
		ans = max(ans, s);
		if(l==r-1 || t>mx || t>dp[l][r][s][d]) continue;

		if(d==0){
			int t1 = X[l+1]-X[l];
			int add1 = (t1+t <= T[l+1]);
			int &m1 = dp[l+1][r][s+add1][d];

			int t2 = X[l]+(L-X[r-1]);
			int add2 = (t2+t <= T[r-1]);
			int &m2 = dp[l][r-1][s+add2][1-d];

			if(m1 > t+t1) m1= t+t1, pq.push({t+t1, l+1, r, s+add1, d});
			if(m2 > t+t2) m2= t+t2, pq.push({t+t2, l, r-1, s+add2, 1-d});
		}
		else{
			int t1 = X[r]-X[r-1];
			int add1 = (t1+t <= T[r-1]);
			int &m1 = dp[l][r-1][s+add1][d];

			int t2 = X[l+1]+(L-X[r]);
			int add2 = (t2+t <= T[l+1]);
			int &m2 = dp[l+1][r][s+add2][1-d];

			if(m1 > t+t1) m1= t+t1, pq.push({t+t1, l, r-1, s+add1, d});
			if(m2 > t+t2) m2= t+t2, pq.push({t+t2, l+1, r, s+add2, 1-d});
		}
	}

	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -