Submission #705824

#TimeUsernameProblemLanguageResultExecution timeMemory
705824delreyBaloni (COCI15_baloni)C++14
100 / 100
706 ms96816 KiB
#include <bits/stdc++.h> using namespace std; int n, h[1000000]; bool dp[1000000]; set <int> p[1000010]; int main() { cin>>n; for(int i = 0; i < n; i++) { cin>>h[i]; p[h[i]].insert(i); } for(int i = n - 1; i >= 0; i--) { auto it = p[h[i] - 1].upper_bound(i); dp[i] = true; if(it != p[h[i] - 1].end()) { dp[*it] = false; p[h[i] - 1].erase(it); } } int res = 0; for(int i = 0; i < n; i++) res += dp[i]; cout<<res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...