이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 202;
const int INF = 1e9 + 1;
int n, l, x[N], t[N], dist[N][N], dp[N][N][N][2];
void ReadInput(){
cin >> n >> l;
for(int i = 1; i <= n; i++)
cin >> x[i];
for(int i = 1; i <= n; i++)
cin >> t[i];
}
void minimize(int &x, const int &y){
if (x > y)
x = y;
}
void Solve(){
x[n + 1] = 0;
t[n + 1] = 0;
for(int i = 0; i <= n + 1; i++)
for(int j = 0; j <= n + 1; j++){
dist[i][j] = abs(x[i] - x[j]);
dist[i][j] = min(dist[i][j], l - dist[i][j]);
}
for(int i = 0; i <= n + 1; i++)
for(int j = 0; j <= n + 1; j++)
for(int k = 0; k <= n + 1; k++)
for(int c = 0; c < 2; c++)
dp[i][j][k][c] = INF;
int ans = 0;
dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
for(int l = 0; l <= n; l++)
for(int r = n + 1; r > l + 1; r--)
for(int k = 0; k < n; k++)
for(int c = 0; c < 2; c++){
if (dp[l][r][k][c] == INF)
continue;
int pos, val;
pos = (c == 0? l : r);
val = dp[l][r][k][c] + dist[pos][l + 1];
minimize(dp[l + 1][r][k + (t[l + 1] >= val)][0], val);
val = dp[l][r][k][c] + dist[pos][r - 1];
minimize(dp[l][r - 1][k + (t[r - 1] >= val)][1], val);
}
for(int l = 0; l <= n; l++)
for(int r = n + 1; r > l; r--)
for(int k = 0; k <= n; k++)
for(int c = 0; c < 2; c++)
ans = max(ans, k * (dp[l][r][k][c] < INF));
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ReadInput();
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |