# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
932648 | atom | Money (IZhO17_money) | C++17 | 837 ms | 62136 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n + 5);
for (int i = 1; i <= n; ++i) cin >> a[i];
vector <int> dp(n + 5, 1e9);
set <int> S; // Maintaining outer-most segment
S.insert(0); S.insert(1e9);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
// Make a new segment. Any segment should be non-decreasing.
dp[i] = min(dp[i], dp[i - 1] + 1);
// Continue current segment
// The outer-most segment is [l, r], any segment (i..j) is valid if l <= a(i) <= r.
int l = *(--S.upper_bound(a[i]));
int r = *(S.upper_bound(a[i]));
int j = i + 1;
while (j <= n && l <= a[j] && a[j] <= r && a[j - 1] <= a[j]) ++j;
debug(j, dp[i], l, r);
for (int k = i; k < j; ++k) dp[k] = min(dp[k], dp[i - 1] + 1);
S.insert(a[i]);
}
cout << dp[n] << "\n";
}
Compilation message (stderr)
# | 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... |