Submission #152818

# Submission time Handle Problem Language Result Execution time Memory
152818 2019-09-09T16:26:36 Z zscoder Lokahian Relics (FXCUP4_lokahia) C++17
0 / 100
3 ms 652 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];
struct DSU
{
	int S;
	
	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;
	
	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}
	
	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}
	
	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}
	
	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(rand()&1) swap(u, v);
		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}
	
	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}
	
	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

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));
	vector<pair<vi,vi> > cmps;
	pair<vi,vi> cur;
	for(int i=0;i<n;i++)
	{
		if(cur.fi.empty())
		{
			cur.fi.pb(i); continue;
		}
		int newrt = ask(cur.fi[0],i);
		if(newrt==-1)
		{
			cur.se.pb(i);
		}
		else
		{
			cur.fi.pb(i);
			cur.fi[0]=newrt;
		}
		if(cur.fi.size()==cur.se.size())
		{
			cmps.pb(cur); cur={{},{}};
		}
	}
	if(cur.fi.empty())
	{
		return -1;
	}
	cmps.pb(cur);
	int u = cmps.back().fi[0];
	int cnt=0;
	for(auto V:cmps)
	{
		int rt = ask(V.fi[0],u);
		if(rt==-1)
		{
			for(int x:V.se)
			{
				rt = ask(x,u);
				if(rt!=-1)
				{
					u=rt; cnt++;
				}
			}
		}
		else
		{
			cnt+=V.fi.size();
			u=rt;
		}
	}
	if(cnt*2>n) return u;
	else return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 552 KB Wrong
2 Correct 2 ms 632 KB Correct : C = 60
3 Incorrect 3 ms 632 KB Wrong
4 Incorrect 2 ms 632 KB Wrong
5 Incorrect 2 ms 504 KB Wrong
6 Incorrect 2 ms 504 KB Wrong
7 Incorrect 3 ms 632 KB Wrong
8 Incorrect 3 ms 632 KB Wrong
9 Incorrect 1 ms 652 KB Wrong
10 Incorrect 3 ms 504 KB Wrong
11 Incorrect 3 ms 504 KB Wrong
12 Correct 3 ms 632 KB Correct : C = 111
13 Incorrect 3 ms 636 KB Wrong
14 Incorrect 3 ms 632 KB Wrong
15 Incorrect 3 ms 632 KB Wrong
16 Correct 2 ms 376 KB Correct : C = 0
17 Incorrect 3 ms 632 KB Wrong
18 Incorrect 3 ms 632 KB Wrong
19 Incorrect 3 ms 548 KB Wrong
20 Incorrect 2 ms 504 KB Wrong
21 Correct 2 ms 632 KB Correct : C = 100
22 Incorrect 2 ms 504 KB Wrong
23 Incorrect 2 ms 504 KB Wrong
24 Incorrect 2 ms 636 KB Wrong
25 Incorrect 2 ms 504 KB Wrong
26 Incorrect 2 ms 504 KB Wrong
27 Incorrect 3 ms 632 KB Wrong