Submission #152802

# Submission time Handle Problem Language Result Execution time Memory
152802 2019-09-09T15:17:07 Z zscoder Lokahian Relics (FXCUP4_lokahia) C++17
39 / 100
9 ms 760 KB
#include "lokahia.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int used[222];
int rtnumber[222];

map<ii,int> ma;

int ask(int u, int v)
{
	if(ma.find({u,v})!=ma.end()) return ma[{u,v}];
	return (ma[{u,v}]=ma[{v,u}]=CollectRelics(u,v));
}

int FindBase(int N)
{
	int n=N;
	if(n==1) return 0;
	if(n==2)
	{
		return ask(0,1);
	}
	memset(used,0,sizeof(used));
	set<int> S;
	int rt=-1;
	for(int i=0;i<n;i++)
	{
		if(used[i]) continue;
		if(rt==-1)
		{
			S.insert(i); used[i]=1; rt=i; continue;
		}
		int newrt = ask(rt,i);
		if(newrt==-1)
		{
			auto it = (prev(S.end()));
			if(S.size()==1)
			{
				used[rt]=used[i]=1;
				S.clear(); rt=-1; continue; 
			}
			while((*it)==rt)
			{
				it--;
			}
			S.erase(it);
			used[i]=1;
			continue;
		}
		S.insert(i); 
		S.insert(newrt);
		used[i]=used[newrt]=1;
		rt=newrt;
	}
	if(S.empty())
	{
		return -1;
	}
	int u = (*S.begin());
	int mx=-1;
	int cnt=1;
	for(int i=0;i<n;i++)
	{
		if(i!=u)
		{
			rtnumber[i]=ask(i,u);
			mx=max(mx,rtnumber[i]);
		}
	}
	if(mx<0) return -1;
	for(int i=0;i<n;i++)
	{
		if(i==mx) continue;
		cnt+=(ask(i,mx)!=-1);
	}
	if(cnt*2>n) return mx;
	else return -1;
}
# Verdict Execution time Memory Grader output
1 Partially correct 3 ms 632 KB Partially correct : C = 397
2 Partially correct 3 ms 760 KB Partially correct : C = 407
3 Correct 9 ms 632 KB Correct : C = 128
4 Correct 2 ms 632 KB Correct : C = 235
5 Partially correct 3 ms 632 KB Partially correct : C = 397
6 Partially correct 3 ms 632 KB Partially correct : C = 403
7 Correct 3 ms 632 KB Correct : C = 211
8 Correct 2 ms 504 KB Correct : C = 209
9 Correct 2 ms 504 KB Correct : C = 60
10 Correct 3 ms 632 KB Correct : C = 204
11 Partially correct 3 ms 632 KB Partially correct : C = 347
12 Partially correct 3 ms 632 KB Partially correct : C = 344
13 Correct 2 ms 504 KB Correct : C = 126
14 Partially correct 3 ms 632 KB Partially correct : C = 395
15 Partially correct 3 ms 632 KB Partially correct : C = 503
16 Correct 2 ms 504 KB Correct : C = 177
17 Correct 2 ms 376 KB Correct : C = 7
18 Correct 2 ms 504 KB Correct : C = 0
19 Correct 2 ms 632 KB Correct : C = 297
20 Partially correct 3 ms 760 KB Partially correct : C = 395
21 Correct 3 ms 632 KB Correct : C = 125
22 Partially correct 3 ms 632 KB Partially correct : C = 303
23 Correct 3 ms 636 KB Correct : C = 100
24 Correct 3 ms 632 KB Correct : C = 206
25 Correct 2 ms 504 KB Correct : C = 123
26 Correct 2 ms 632 KB Correct : C = 237
27 Correct 2 ms 504 KB Correct : C = 239