제출 #826243

#제출 시각아이디문제언어결과실행 시간메모리
826243AlphaMale06Rabbit Carrot (LMIO19_triusis)C++14
0 / 100
1 ms256 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...