#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
pair<int,int>pr[n];
for(int i=0;i<n;i++){
cin>>pr[i].first;
pr[i].second=i;
}
int ans=0;
vector<bool>bl(n+1);
while(1){
int bo=-1;
for(int i=1;i<=n;i++){
if(!bl[i]){
bo=i;
break;
}
}
if(bo==-1)break;
ans++;
int l=-1;
for(int i=0;i<n;i++){
if(pr[i].first==bo&&!bl[pr[i].first]){
l=pr[i].first;
// cout<<l<<' ';
bl[l]=1;
}else if(l!=-1&&pr[i].first>l&&!bl[pr[i].first]){
bool BO=0;
for(int w=pr[i].first;w>l;w--){
if(bl[w]){
// cout<<'g'<<w<<' ';
BO=1;
}
}
if(!BO){
// cout<<pr[i].first<<' ';
l=pr[i].first;
bl[l]=1;
}//else cout<<'f'<<pr[i].first<<' ';
}else if(l!=-1)break;
}
// cout<<endl;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
1579 ms |
212 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
1579 ms |
212 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
1579 ms |
212 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
1579 ms |
212 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |