답안 #40870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40870 2018-02-09T15:18:30 Z XmtosX Baloni (COCI15_baloni) C++14
100 / 100
1331 ms 89216 KB
#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

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);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 47352 KB Output is correct
2 Correct 40 ms 47456 KB Output is correct
3 Correct 39 ms 47656 KB Output is correct
4 Correct 39 ms 47728 KB Output is correct
5 Correct 1125 ms 84760 KB Output is correct
6 Correct 1331 ms 89216 KB Output is correct
7 Correct 1106 ms 89216 KB Output is correct
8 Correct 1014 ms 89216 KB Output is correct
9 Correct 1094 ms 89216 KB Output is correct
10 Correct 1165 ms 89216 KB Output is correct