답안 #40868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40868 2018-02-09T15:10:04 Z XmtosX Baloni (COCI15_baloni) C++14
60 / 100
2000 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;
int n,h,ans;
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);
    }
    for (int i=0;i<=1e6;i++)
        s[i].insert(n);
    for (int i=1e6;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 124 ms 94332 KB Output is correct
2 Correct 136 ms 94436 KB Output is correct
3 Correct 124 ms 94516 KB Output is correct
4 Correct 140 ms 94684 KB Output is correct
5 Execution timed out 2049 ms 131072 KB Time limit exceeded
6 Execution timed out 2069 ms 131072 KB Time limit exceeded
7 Correct 1284 ms 131072 KB Output is correct
8 Correct 1256 ms 131072 KB Output is correct
9 Execution timed out 2049 ms 131072 KB Time limit exceeded
10 Execution timed out 2080 ms 131072 KB Time limit exceeded