Submission #1153921

#TimeUsernameProblemLanguageResultExecution timeMemory
1153921pearl333Po (COCI21_po)C++20
20 / 70
6 ms1608 KiB
#include <bits/stdc++.h> using namespace std; #define int long long // optimise! but answer is correct :) /*int n; set<int> s; int ans = 0; bool first = false; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; int arr[n]; for (int i = 0; i<n;i++) { int t; cin>>t; arr[i]=t; s.insert(t); } for (auto &a: s) { first = false; for (int i = 0;i<n;i++) { if (a!=0) { if (arr[i]==a) { first = true; } if (first and arr[i]<a) { ans+=1; first = false; } } } if (first) { ans+=1; } } cout<<ans; return 0; }*/ int n; stack<int> s; int ans = 0; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; int arr[n]; for (int i = 0;i<n;i++) { cin>>arr[i]; } s.push(arr[0]); for (int i = 1;i<n;i++) { while (s.size()!=0 and s.top()>=arr[i]) { if (s.top()>arr[i]) { ans+=1; s.pop(); } else { s.pop(); } } s.push(arr[i]); } ans+=s.size(); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...