답안 #151457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151457 2019-09-03T09:14:33 Z babo 로카히아 유적 (FXCUP4_lokahia) C++17
100 / 100
3 ms 632 KB
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

int CollectRelics(int,int);

multiset<pair<int,int> >st,st2,st3;

int FindBase(int N){
	int i;
	for(i=0;i<N;i++)
	{
		st.insert(make_pair(1,i));
	}
	while(st.size()>=2)
	{
		//printf("sz %d , %d %d %d %d %d\n",st.size(),st.begin()->y,next(st.begin())->y,st.begin()->x,next(st.begin())->x);
		//printf(" %d\n",CollectRelics(st.begin()->y,next(st.begin())->y));
		if(st.begin()->x==next(st.begin())->x)
		{
			int temp=st.begin()->y==next(st.begin())->y?st.begin()->y:CollectRelics(st.begin()->y,next(st.begin())->y);
			if(temp!=-1)
			{
				//printf("%d\n",st.size());
				st.erase(next(st.begin()));
				st.insert(make_pair(st.begin()->x*2,temp));
				st.erase(st.begin());	
				//printf("%d\n",st.size());
			}
			else
			{
				st2.insert(*st.begin());
				st.erase(st.begin());
				st2.insert(*st.begin());
				st.erase(st.begin());
			}
		}
		else
		{
			st3.insert(*st.begin());
			st.erase(st.begin());
		}
	}
	int las,ans;
	if(st.empty())
	{
		if(st3.empty())
			return -1;
		else
		{
			las=st3.rbegin()->y;
			ans=st3.rbegin()->x;
			st3.erase(prev(st3.end()));
		}
	}
	else
	{
		las=st.begin()->y;
		ans=st.begin()->x;
		st.erase(st.begin());
	}
	for(multiset<pair<int,int> >::iterator it=st2.begin();it!=st2.end();it++)
	{
		int temp=las==it->y?las:CollectRelics(las,it->y);
		if(temp!=-1)
		{
			las=temp;
			ans+=it->x;
		}
	}
	for(multiset<pair<int,int> >::iterator it=st3.begin();it!=st3.end();it++)
	{
		int temp=las==it->y?las:CollectRelics(las,it->y);
		if(temp!=-1)
		{
			las=temp;
			ans+=it->x;
		}
	}
	if(ans>N/2)
		return las;
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Correct : C = 60
2 Correct 2 ms 632 KB Correct : C = 100
3 Correct 2 ms 504 KB Correct : C = 60
4 Correct 3 ms 632 KB Correct : C = 135
5 Correct 3 ms 632 KB Correct : C = 100
6 Correct 3 ms 632 KB Correct : C = 229
7 Correct 2 ms 632 KB Correct : C = 231
8 Correct 3 ms 632 KB Correct : C = 147
9 Correct 3 ms 632 KB Correct : C = 243
10 Correct 3 ms 632 KB Correct : C = 100
11 Correct 3 ms 632 KB Correct : C = 147
12 Correct 3 ms 632 KB Correct : C = 274
13 Correct 3 ms 632 KB Correct : C = 104
14 Correct 3 ms 632 KB Correct : C = 219
15 Correct 3 ms 632 KB Correct : C = 102
16 Correct 2 ms 504 KB Correct : C = 3
17 Correct 2 ms 472 KB Correct : C = 125
18 Correct 3 ms 632 KB Correct : C = 242
19 Correct 3 ms 632 KB Correct : C = 241
20 Correct 2 ms 504 KB Correct : C = 150
21 Correct 3 ms 632 KB Correct : C = 60
22 Correct 2 ms 504 KB Correct : C = 150
23 Correct 3 ms 632 KB Correct : C = 250
24 Correct 2 ms 632 KB Correct : C = 297
25 Correct 2 ms 376 KB Correct : C = 0
26 Correct 2 ms 504 KB Correct : C = 177
27 Correct 3 ms 632 KB Correct : C = 204