이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define int ll
#define y1 yy
#define ppb pop_back
#define gcd(a,b) __gcd(a,b)
#define in insert
const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};
const int inf=1e18;
const int N=1e6;
const int MAX=210;
const int mod=1e9+7;
int n,l;
int x[MAX];
int t[MAX];
int dp[MAX][MAX][MAX][2];
int dist(int x,int y){
if(x>y)swap(x,y);
return min(y-x,l+x-y);
}
void solve(){
cin>>n>>l;
for(int i=1;i<=n;i++)cin>>x[i];
for(int i=1;i<=n;i++)cin>>t[i];
x[n+1]=l;
t[n+1]=inf;
x[0]=l;
t[0]=inf;
n++;
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;
}
}
}
dp[n][0][1][0]=dp[n][0][1][1]=0;
for(int r=n;r>=1;r--){
for(int l=0;l<r;l++){
for(int cnt=1;cnt<=n;cnt++){
for(int k=0;k<2;k++){
int pos;
if(k==1){
pos=x[l];
}
else{
pos=x[r];
}
{
dp[r][l+1][cnt][1]=min(dp[r][l+1][cnt][1],dp[r][l][cnt][k]+dist(pos,x[l+1]));
}
{
dp[r-1][l][cnt][0]=min(dp[r-1][l][cnt][0],dp[r][l][cnt][k]+dist(pos,x[r-1]));
}
if(dp[r][l][cnt][k]+dist(pos,x[l+1])<=t[l+1]){
dp[r][l+1][cnt+1][1]=min(dp[r][l+1][cnt+1][1],dp[r][l][cnt][k]+dist(pos,x[l+1]));
}
if(dp[r][l][cnt][k]+dist(pos,x[r-1])<=t[r-1]){
dp[r-1][l][cnt+1][0]=min(dp[r-1][l][cnt+1][0],dp[r][l][cnt][k]+dist(pos,x[r-1]));
}
}
}
}
}
for(int r=n;r>=1;r--){
for(int l=0;l<=r;l++){
for(int cnt=1;cnt<=n;cnt++){
for(int k=0;k<2;k++){
// cout<<r<<" "<<l<<" "<<cnt<<" "<<k<<" "<<dp[r][l][cnt][k]<<"\n";
}
}
}
}
int ans=1;
for(int i=1;i<n;i++){
for(int cnt=1;cnt<=n;cnt++){
for(int k=0;k<2;k++){
if(dp[i+1][i][cnt][k]!=inf){
ans=max(ans,cnt);
// cout<<i<<" "<<k<<" "<<cnt<<"\n";
}
}
}
}
cout<<ans-1<<"\n";
}
main(){
// freopen("prizes.in", "r", stdin);
// freopen("prizes.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t3.cpp:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
109 | main(){
| ^~~~
# | 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... |