Submission #67839

# Submission time Handle Problem Language Result Execution time Memory
67839 2018-08-15T10:56:27 Z tempytemptemp Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
42 ms 840 KB
/*
  We found Despacito 5 during contest (not clickbait)
*/
#include	"grader.h"
#include	<vector>
#include 	<set>
#include	<cassert>
using namespace std;

#define cl(a,b)	    memset(a,b,sizeof(a))
#define all(x)      x.begin(),x.end()
#define vec         vector
#define vi          vec<int>
#define pb          push_back
#define f(x,y,z)    for(int x=(y); x<(z); x++)
#define fd(x,y,z)   for(int x=(y); x>=(z); x--)
#define fit(x,y)    for(auto x: y)
#define pii         pair<int,int>
#define ppi         pair<pii,int>
#define f1          first
#define s2          second
#define spc			' '
#define endl		'\n'

int findEgg(int N, vector < pair < int, int > > bridges);
int query(vector < int > islands);

const int maxn=512;

int n;
vi e[maxn+7];
bool possible[maxn+7];

vi chosen;
int chosenCnt;
bool chosens[maxn+7];
int rem;
bool vis[maxn+7];

void dfs(int root, int parent){
	if(vis[root])	return;
	vis[root]=1;
//	assert(root>=1 && root<=16);
	chosen.pb(root);
	if(possible[root])
		chosenCnt++;
	chosens[root]=1;
//	assert(rem>1);
	if(chosenCnt==rem/2){
		return;
	}
	fit(child,e[root]){
		if(child==parent)	continue;
		dfs(child,root);
		if(chosenCnt==rem/2){
			return;
		}
	}
}

int findEgg(int N, vector<pii>bridges){
	n=N;
	assert(n<=maxn);
	for(int i=1; i<=n; i++)
		possible[i]=1;
	fit(x,bridges){
		e[x.f1].pb(x.s2);
		e[x.s2].pb(x.f1);
	}
	rem=n;
	while(rem>1){
		chosen.clear();
		cl(chosens,0);
		chosenCnt=0;
		cl(vis,0);
		for(int i=1; i<=n; i++){
			if(possible[i]){
//				cerr<<i<<endl;
				dfs(i,0);
				break;
			}
		}
//		cerr<<chosen.size()<<spc<<chosenCnt<<endl;
//		cerr<<chosen.size()<<": ";
//		f(i,0,chosen.size())
//			cerr<<chosen[i]<<spc;
//		cerr<<endl;
		if(query(chosen)){
			rem=chosenCnt;
			for(int i=1; i<=n; i++)
				if(possible[i] && chosens[i]==0)
					possible[i]=0;
		}
		else{
			rem-=chosenCnt;
			for(int i=0; i<chosen.size(); i++)
				possible[chosen[i]]=0;
		}
	}
	for(int i=1; i<=n; i++)
		if(possible[i])
			return i;
}

//int ___xxx;
//
//int query(vi _temp){
//	fit(__x, _temp)
//		if(__x==___xxx)
//			return true;
//	return false;
//}
//
//int main(){
//	int _n;
//	cin>>_n>>___xxx;
//	vec<pii>_temp;
//	for(int i=0; i<_n-1; i++){
//		int a, b;
//		cin>>a>>b;
//		_temp.pb({a,b});
//	}
//	cout<<findEgg(_n,_temp)<<endl;
//}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:96:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0; i<chosen.size(); i++)
                 ~^~~~~~~~~~~~~~
eastereggs.cpp:103:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Number of queries: 4
2 Correct 4 ms 436 KB Number of queries: 4
3 Correct 4 ms 436 KB Number of queries: 4
4 Correct 4 ms 592 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 11 ms 592 KB Number of queries: 8
2 Correct 32 ms 696 KB Number of queries: 9
3 Correct 41 ms 824 KB Number of queries: 9
4 Correct 36 ms 828 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 17 ms 840 KB Number of queries: 9
2 Correct 23 ms 840 KB Number of queries: 9
3 Correct 27 ms 840 KB Number of queries: 9
4 Correct 42 ms 840 KB Number of queries: 9