Submission #901521

#TimeUsernameProblemLanguageResultExecution timeMemory
901521OAleksaMoney (IZhO17_money)C++14
45 / 100
1540 ms23788 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define f first #define s second const int N = 1e6 + 69; int n, a[N], dp[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1;i <= n;i++) { cin >> a[i]; dp[i] = 1e9; } set<int> st; dp[0] = 0; st.insert(0); st.insert(1e9); for (int i = 1;i <= n;i++) { dp[i] = min(dp[i], dp[i - 1] + 1); for (auto u = st.begin();u != st.end();u++) { auto t = u; ++t; if (*u > a[i]) break; int x = *u, y = *t; int j = i + 1; while (j <= n && a[j] >= x && a[j] <= y && a[j] >= a[j - 1]) j++; for (int k = i;k < j;k++) dp[k] = min(dp[k], dp[i - 1] + 1); } st.insert(a[i]); } cout << dp[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...