# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50307 | mra2322001 | Money (IZhO17_money) | C++14 | 1523 ms | 101684 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>
#define f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
int n, a[N], f[N];
set <int> s;
int solve(int u, int sl){
if(u== n + 1) return printf("%d", sl), 0;
int v = f[u];
int l = u, r = v, ans = u;
auto it = s.upper_bound(a[u]);
int x = *it;
for(int k = u; k <= f[u]; k++){
if(a[k] > x){
solve(k, sl + 1);
return 0;
}
else{
s.insert(a[k]);
}
}
solve(f[u] + 1, sl + 1);
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
scanf("%d", &n);
f1(i, n) scanf("%d", &a[i]);
for(int i = n; i >= 1; i--){
if(i==n) f[i] = n;
else{
if(a[i] <= a[i + 1]) f[i] = f[i + 1];
else f[i] = i;
}
}
s.insert(0); s.insert(1e6 + 5);
solve(1, 0);
}
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... |