이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int inf = 1e9 + 1;
const ll linf = 1e18 + 1;
ll dp[201][201][201][2];
int main(){
ll n, l;
cin >> n >> l;
ll a[n + 2];
ll t[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> t[i];
}
for(int i = 0; i <= 200; i++){
for(int j = 0; j <= 200; j++){
for(int k = 0; k <= 200; k++) dp[i][j][k][0] = dp[i][j][k][1] = linf;
}
}
dp[0][0][0][0] = 0;
a[0] = 0;
a[n + 1] = l;
// 0 marcxniv 1 marjvniv
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i + j > n) continue;
for(int x = 0; x < n; x++){
ll nt = dp[i][j][x][0] + l - a[n - i + 1] + a[j + 1];
nt = min(nt, dp[i][j][x][1] + a[j + 1] - a[j]);
if(nt <= t[j + 1]) dp[i][j + 1][x + 1][1] = min(dp[i][j + 1][x + 1][1], nt);
else dp[i][j + 1][x][1] = min(dp[i][j + 1][x][1], nt);
nt = dp[i][j][x][0] + a[n - i + 1] - a[n - i];
nt = min(nt, dp[i][j][x][1] + l - a[n - i] + a[j]);
if(nt <= t[n - i]) dp[i + 1][j][x + 1][0] = min(dp[i + 1][j][x + 1][0], nt);
else dp[i + 1][j][x][0] = min(dp[i + 1][j][x][0], nt);
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
for(int x = 1; x <= n; x++) {
if(dp[i][n - i][x][0] != linf) ans = max(x, ans);
if(dp[i][n - i][x][1] != linf) ans = max(x, ans);
}
}
cout << ans;
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... |