Submission #800249

# Submission time Handle Problem Language Result Execution time Memory
800249 2023-08-01T12:45:51 Z LittleCube Comparing Plants (IOI20_plants) C++17
0 / 100
0 ms 212 KB
#include "plants.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define ll long long
using namespace std;

int n, state[300];
vector<int> E[300];

void init(int k, vector<int> r)
{
	n = r.size();
	for (int i = 0; i < n; i++)
	{
		r[i] = k - 1 - r[i];
		if (r[i] == 0)
		{
			state[i] = 1;
			for (int t = 1; t < k; t++)
				E[i].emplace_back((i + t) % n);
		}
	}
	for (int it = 0; it < n; it++)
	{
		int cur = -1;
		for (int j = 0; j < n; j++)
			if (state[j] == 1)
			{
				int cnt = 0;
				for (int t = 1; t < k; t++)
					cnt += state[(j - t + n) % n] == 1;
				if (cnt == 0)
				{
					cur = j;
					break;
				}
			}
		// cerr << cur << '\n';
		state[cur] = 2;
		for (int t = 1; t < k; t++)
			if (--r[(cur - t + n) % n] == 0)
				state[(cur - t + n) % n] = 1;

		for (int t = 1; t < k; t++)
			if (state[(cur + t) % n] <= 1)
				E[cur].emplace_back((cur + t) % n);
	}
	return;
}

bool reach(int x, int y)
{
	vector<int> vis(n, 0);
	queue<int> q;
	q.emplace(x);
	vis[x] = 1;
	while (!q.empty())
	{
		int u = q.front();
		if (u == y)
			return true;
		q.pop();
		for (auto v : E[u])
			if (!vis[v])
			{
				vis[v] = 1;
				q.emplace(v);
			}
	}
	return false;
}

int compare_plants(int x, int y)
{
	if (reach(x, y))
		return -1;
	if (reach(y, x))
		return 1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -