이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define F first
#define S second
pair<int, int> dp[200005][4];
const int inf = 1000000000;
signed main()
{
int n, m;
cin >> n >> m;
n++;
int a[n];
a[0]=0;
for(int i=1; i< n; i++)cin >> a[i];
dp[1][0]=dp[1][1]=dp[1][2]=dp[1][3]=mp(0, 0);
for(int i=2; i<=n; i++){
int p=a[i-1];
if(dp[i-1][3].S+m<p){
dp[i][0]=dp[i][1]=mp(inf, 0);
}
else{
if(dp[i-1][2].S+m<p || dp[i-1][2].F>=inf){
dp[i][1]=mp(dp[i-1][3].F, p);
}
else{
dp[i][1]=mp(dp[i-1][2].F, p);
}
}
if(a[i-2]+m<p || dp[i-1][1].F>=inf){
dp[i][0]=mp(inf, 0);
}
else{
if(dp[i-1][0].F>=inf){
dp[i][0]=mp(dp[i-1][1].F, p);
}
else dp[i][0]=mp(min(dp[i-1][1].F, dp[i-1][0].F), p);
}
if(dp[i-1][1].F>=inf && dp[i-1][0].F>=inf){
dp[i][2]=mp(inf, 0);
}
else{
if(dp[i-1][0].F>=inf){
dp[i][2]=mp(dp[i-1][1].F+1, a[i-2]+m);
}
else dp[i][2]=mp(dp[i-1][0].F+1, a[i-2]+m);
}
if(a[i-1]==dp[i-1][3].S+m)dp[i][3]=mp(dp[i-1][3].F, a[i-1]);
else dp[i][3]=mp(dp[i-1][3].F+1, dp[i-1][3].S+m);
}
for(int i=0; i<=n; i++){
// cout << dp[i][0].F << " " << dp[i][0].S << " " << dp[i][1].F << " " << dp[i][1].S << " " << dp[i][2].F << " " << dp[i][2].S << " " << dp[i][3].F << " " << dp[i][3].S << '\n';
}
int mn=min({dp[n][3].F, dp[n][2].F, dp[n][1].F, dp[n][0].F});
cout << mn << '\n';
}
# | 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... |