Submission #151198

# Submission time Handle Problem Language Result Execution time Memory
151198 2019-09-02T06:43:49 Z babo Lokahian Relics (FXCUP4_lokahia) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

int CollectRelics(int,int);

set<pair<int,int> >st,st2;

int FindBase(int N){
	int i;
	for(i=0;i<N;i++)
	{
		st.insert(make_pair(1,i));
	}
	while(st.size()>=2)
	{
		//printf("%d %d %d %d %d\n",st.begin()->y,next(st.begin())->y,st.begin()->x,next(st.begin())->x,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)
			{
				st.erase(next(st.begin()));
				st.insert(make_pair(st.begin()->x*2,temp));
				st.erase(st.begin());	
			}
			else
			{
				st2.insert(*st.begin());
				st.erase(st.begin());
				st2.insert(*st.begin());
				st.erase(st.begin());
			}
		}
		else
		{
			st2.insert(*st.begin());
			st.erase(st.begin());
		}
	}
	if(st.empty()) return -1;
	int las=st.begin()->y;
	int ans=st.begin()->x;
	st.erase(st.begin());
	for(set<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;
		}
	}
	if(ans>N/2)
		return las;
	return -1;
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:22:42: error: cannot convert 'std::set<std::pair<int, int> >::iterator {aka std::_Rb_tree_const_iterator<std::pair<int, int> >}' to 'int' in initialization
    int temp=st.begin()->y,next(st.begin())->y?st.begin()->y:CollectRelics(st.begin()->y,next(st.begin())->y);
                                          ^
lokahia.cpp:25:29: error: 'next' cannot be used as a function
     st.erase(next(st.begin()));
                             ^