답안 #84359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84359 2018-11-14T12:57:39 Z zoooma13 Baloni (COCI15_baloni) C++14
100 / 100
1571 ms 89220 KB
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 1000006

int N ,A;
set<int> ss[MAX_N];

int cnt[MAX_N];
vector <int> nxt;

int main()
{
    scanf("%d",&N);
    for(int i=0; i<N; i++)
    {
        scanf("%d",&A);
        ss[A].insert(i);
        if(!cnt[A]++)
            nxt.push_back(A);
    }

    sort(nxt.begin() ,nxt.end());

    int Ans = 0;
    for(int pt = nxt.size()-1; ~pt;)
    {
        int i = nxt[pt] ,j = -1;

        while(true)
        {
            auto it = ss[i].upper_bound(j);
            if(it == ss[i].end())
                break;

            j = *it;
            ss[i].erase(it);
            --cnt[i--];
        }
        while(~pt && !cnt[nxt[pt]])
            pt--;

        Ans++;
    }

    cout << Ans << endl;
}

Compilation message

baloni.cpp: In function 'int main()':
baloni.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
baloni.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&A);
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47480 KB Output is correct
2 Correct 45 ms 47564 KB Output is correct
3 Correct 47 ms 47564 KB Output is correct
4 Correct 46 ms 47568 KB Output is correct
5 Correct 1249 ms 84796 KB Output is correct
6 Correct 1571 ms 89220 KB Output is correct
7 Correct 1151 ms 89220 KB Output is correct
8 Correct 1129 ms 89220 KB Output is correct
9 Correct 1261 ms 89220 KB Output is correct
10 Correct 1307 ms 89220 KB Output is correct