제출 #40870

#제출 시각아이디문제언어결과실행 시간메모리
40870XmtosXBaloni (COCI15_baloni)C++14
100 / 100
1331 ms89216 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;
}

컴파일 시 표준 에러 (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...