답안 #84358

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

#define MAX_N 1000006

inline int GI() {
	int GIR = 0; char GIC = getchar();
	while(GIC < '0' || '9' < GIC)
		GIC = getchar();
	while('0' <= GIC && GIC <= '9') {
		GIR = (GIR * 10) + (GIC - '0');
		GIC = getchar();
	}
	return GIR;
}

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

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

int main()
{
    N = GI();
    for(int i=0; i<N; i++)
    {
        A = GI();
        ss[A].insert(i);
        if(!cnt[A]++)
            nxt.push_back(A);
    }

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

    int Ans = 0 ,pt = nxt.size()-1;
    while(~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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 47352 KB Output is correct
2 Correct 44 ms 47484 KB Output is correct
3 Correct 48 ms 47544 KB Output is correct
4 Correct 52 ms 47544 KB Output is correct
5 Correct 1139 ms 84736 KB Output is correct
6 Correct 1375 ms 89148 KB Output is correct
7 Correct 1137 ms 89148 KB Output is correct
8 Correct 1117 ms 89148 KB Output is correct
9 Correct 1097 ms 89148 KB Output is correct
10 Correct 1178 ms 89148 KB Output is correct