Submission #40867

# Submission time Handle Problem Language Result Execution time Memory
40867 2018-02-09T15:05:55 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];
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 (s[a].lower_bound(x)!=(--s[a].end()))
            {
                x= (*s[a].lower_bound(x));
                s[a].erase(x);
                a--;
            }
        }
    }
    cout <<ans;
    return 0;
}

Compilation message

baloni.cpp: In function 'int main()':
baloni.cpp:7:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
baloni.cpp:10:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&h);
                       ^
# Verdict Execution time Memory Grader output
1 Correct 128 ms 94200 KB Output is correct
2 Correct 129 ms 94348 KB Output is correct
3 Correct 133 ms 94644 KB Output is correct
4 Correct 133 ms 94672 KB Output is correct
5 Execution timed out 2054 ms 131072 KB Time limit exceeded
6 Execution timed out 2061 ms 131072 KB Time limit exceeded
7 Correct 1535 ms 131072 KB Output is correct
8 Correct 1413 ms 131072 KB Output is correct
9 Execution timed out 2031 ms 131072 KB Time limit exceeded
10 Execution timed out 2094 ms 131072 KB Time limit exceeded