Submission #901508

#TimeUsernameProblemLanguageResultExecution timeMemory
901508OAleksaMoney (IZhO17_money)C++14
0 / 100
1 ms2396 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; for (int i = 1;i <= n;i++) { auto manji = st.upper_bound(a[i]); auto veci = st.lower_bound(a[i]); int x, y; if (manji == st.begin()) x = -1; else x = *--manji; if (veci == st.end()) y = 1e9; else y = *veci; int j = i + 1; while (j <= n && a[j] >= x && a[j] <= y && a[j] >= a[j - 1]) j++; dp[j - 1] = min(dp[j - 1], 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...