Submission #1050371

#TimeUsernameProblemLanguageResultExecution timeMemory
1050371aykhnComparing Plants (IOI20_plants)C++17
11 / 100
4053 ms120672 KiB
#include "plants.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MXN = 5e3 + 5;
 
int n;
int a[MXN], cnt[MXN], f[MXN];
vector<int> adj[MXN];
int big[MXN][MXN], used[MXN];
 
void dfs(int a, int s)
{
	big[s][a] = 1;
	used[a] = 1;
	for (int &v : adj[a])
	{
		if (!used[v]) dfs(v, s);
	}
}
 
void init(int k, vector<int> r) 
{
	n = r.size();
	for (int i = 0; i < n; i++) cnt[i] = k - 1;
	int cur = -1;
	while (cur < n)
	{
		vector<int> idx;
		for (int i = 0; i < n; i++)
		{
			if (f[i]) continue;
			if (r[i] == cnt[i]) idx.push_back(i);
		}
		if (idx.empty()) break;
		int ind = -1;
		int sz = idx.size();
		if (sz == 1) ind = 0;
		else 
		{
			for (int i = 0; i < sz; i++)
			{
				if ((idx[(i + 1) % sz] - idx[i] + n) % n >= k) 
				{
					ind = (i + 1) % sz;
					break;
				}
			}
		}
		assert(!idx.empty());
		// for (int i = (idx[ind] - 1 + n) % n; i != idx[(ind - 1 + sz) % sz]; i = (i - 1 + n) % n)
		// {
		// 	if (!f[i]) adj[idx[ind]].push_back(i);
		// }
		for (int i = (idx[ind] + 1) % n; i != (idx[ind] + k) % n; i = (i + 1) % n)
		{
			if (!f[i]) adj[idx[ind]].push_back(i);
		}
		for (int i = (idx[ind] - 1 + n) % n; i != (idx[ind] - k + n) % n; i = (i - 1 + n) % n)
		{
			if (!f[i]) adj[idx[ind]].push_back(i);
			cnt[i]--;
		}
		f[idx[ind]] = 1;
	}
	for (int i = 0; i < n; i++)
	{
		fill(used, used + n, 0);
		dfs(i, i);
	}
}
 
int compare_plants(int x, int y) 
{
	if (big[x][y]) return -1;
	if (big[y][x]) return 1;
	return 0;
	// return (a[x] > a[y] ? 1 : -1);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...