제출 #486122

#제출 시각아이디문제언어결과실행 시간메모리
486122Duy_eRabbit Carrot (LMIO19_triusis)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define pii pair<long long, long long> #define st first #define nd second #define file "test" using namespace std; const long long oo = 1e18; const long long N = 2e5 + 5; ll n, m, h[N], dp[N], best[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen(file".inp","r",stdin); freopen(file".out","w",stdout); // #endif cin >> n >> m; for (int i = 1; i <= n; i ++) cin >> h[i]; for (int i = 0; i <= n + 1; i ++) dp[i] = oo, best[i] = i - 1; dp[0] = 0; for (int i = 1; i <= n + 1; i ++){ // for (int j = i + 1; j <= n + 1; j ++) // if (h[i] - i*m >= h[j] - j*m) // dp[j] = min(dp[j], dp[i] + j - i - 1); // // cout << dp[i] << ' '; for (int j = i - 1; j >= 0; j = best[j]) if (h[j] + (i - j)*m >= h[i]) { ll cur = dp[j] + i - j - 1; if (cur < dp[i]) dp[i] = cur, best[i] = j; } } cout << dp[n + 1]; return 0; } /** /\_/\ (= ._.) / >0 \>1 ________________________ / Brainstorming section / /=======================/ --- === with two fixed point i, j you are allowed to change every pole between i, j -> could it be changed so that you can go from i->j possible case: + a[j] <= a[i] + h[i] + (j - i)*m >= h[j] === **/ // Before submit: spot the visible bug by reading the code.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...