Submission #40869

#TimeUsernameProblemLanguageResultExecution timeMemory
40869XmtosXBaloni (COCI15_baloni)C++14
100 / 100
1531 ms104344 KiB
#include <bits/stdc++.h> using namespace std; int n,h,ans,maxx; set <int> s[1000006]; set <int> ::iterator it; int main() { scanf("%d",&n); for (int i=0;i<n;i++) { scanf("%d",&h); s[h].insert(i); maxx=max(maxx,h); } for (int i=0;i<=maxx;i++) s[i].insert(n); for (int i=maxx;i>0;i--) { while (s[i].size()>1) { ans++; int x= (*s[i].begin()); s[i].erase(s[i].begin()); int a=i-1; while ((it=s[a].lower_bound(x))!=(--s[a].end())) { x= (*it); s[a].erase(it); a--; } } } printf("%d",ans); return 0; }

Compilation message (stderr)

baloni.cpp: In function 'int main()':
baloni.cpp:8:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
baloni.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&h);
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...