#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pi pair <int, int>
#define pii pair <pi, int>
#define rep(i,n) for(ll i = 1; i <= n; i++)
#define fi first
#define se second
using namespace std;
int n, a[1000010],mx,mi;
bool vis[1000010];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>n;
rep(i,n)cin>>a[i];
int ans=1;
mx=a[n];
for(int i=n; i>1; i--){
if(a[i-1]>a[i]){
vis[mi]=true;
vis[mx]=true;
mx=a[i-1];
ans++;
//cout<<1;
}else{
mi=a[i-1];
if(a[i]!=a[i-1]+1&&!vis[mx-1]){
ans++;
vis[mi]=true;
vis[mx]=true;
mx=a[i-1];
//cout<<2;
}else if(a[i]!=a[i-1]+1&&!vis[mi+1]){
ans++;
vis[mi]=true;
vis[mx]=true;
mx=a[i-1];
//cout<<3;
}
}
mi=a[i-1];
//cout<<mi<<' '<<mx<<' '<<ans<<endl;
//rep(i,n)cout<<vis[i];cout<<endl;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |