#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 1e6 + 6;
int n, a[N], dp[N];
set <int> s;
int main(){
cin >> n;
f(i,1,n+1) cin >> a[i];
a[n+1] = N;
int id = 0;
s.insert(0);
f(i,1,n+1){
dp[i] = 1;
if(a[i] > a[i+1]) break;
}
while(id <= n){
while(id <= n and a[id] <= a[id+1]) s.insert(a[id]), id++;
id++;
int maxi = *s.rbegin();
f(i,id,n+1){
auto it = s.lower_bound(a[i]);
it = prev(it);
int x = *it, j;
j = lower_bound(a+id,a+i+1,x) - a;
dp[i] = dp[j-1] + 1;
if(a[i] > a[i+1]) break;
}
}
cout << dp[n] << "\n";
return 0;
}
Compilation message
money.cpp: In function 'int main()':
money.cpp:27:13: warning: unused variable 'maxi' [-Wunused-variable]
27 | int maxi = *s.rbegin();
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |