# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
475186 | 2021-09-21T11:36:30 Z | Ahmed57 | Po (COCI21_po) | C++14 | 13 ms | 1224 KB |
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n;cin>>n;long long arr[n+1]={0}; for(int i=1;i<=n;i++)cin>>arr[i];stack<int>s; s.push(0); long long ans = 0; for(int i=1;i<=n;i++){ while(s.top()>arr[i]){ s.pop();ans++; } if(s.top()<arr[i])s.push(arr[i]); } ans+=s.size()-1; cout<<ans<<"\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 5 ms | 588 KB | Output is correct |
5 | Correct | 7 ms | 844 KB | Output is correct |
6 | Correct | 13 ms | 1224 KB | Output is correct |
7 | Correct | 13 ms | 1096 KB | Output is correct |