Submission #823176

# Submission time Handle Problem Language Result Execution time Memory
823176 2023-08-12T08:50:56 Z Sohsoh84 Comparing Plants (IOI20_plants) C++17
0 / 100
1 ms 340 KB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

#define debug(x)		cerr << #x << ": " << x << endl;
#define sep			' '

void add(int u, int v);

const int MAXN = 5000 + 10;

int F[MAXN][MAXN], rem_neg[MAXN], rem_pos[MAXN], n, k, R[MAXN];
bool flag[MAXN];

void check(int u, int v) {
	for (int w = 0; w < n; w++) {
		if (F[u][v] && F[v][w])
			add(u, w);
		
		if (F[w][u] && F[u][v])
			add(w, v);
	}
}

inline void vcheck(int v) {
	if (flag[v]) return;

	rem_neg[v] = R[v];
	rem_pos[v] = k - 1 - R[v];

	debug(v)
	debug(rem_neg[v])
	for (int i = 0; i < k - 1; i++) {
		if (F[v][(v + i) % n]) rem_pos[v]--;
		if (F[(v + i) % n][v]) rem_neg[v]--;
	}

	if (rem_neg[v] == 0) {
		for (int i = 0; i < k - 1; i++)
			if (!F[(v + i) % n][v])
				add(v, (v + i) % n);
		
		flag[v] = true;
	}

	if (rem_pos[v] == 0) {
		for (int i = 0; i < k - 1; i++)
			if (!F[v][(v + i) % n])
				add((v + i) % n, v);		
	
		flag[v] = true;
	}
}

void add(int u, int v) {
	if (F[u][v]) return;	
	F[u][v] = true;

	check(u, v);
	vcheck(u);
	vcheck(v);
}

void init(int k_, std::vector<int> r) {
	k = k_;
	n = r.size();

	for (int i = 0; i < n; i++)
		R[i] = r[i];

	for (int i = 0; i < n; i++)
		vcheck(i);

	for (int i = 0; i < n; i++) {
		if (R[i] < R[(i + 1) % n])
			add((i + 1) % n, i);
		if (R[i] > R[(i + 1) % n])
			add(i, (i + 1) % n);
	}
	return;
}

int compare_plants(int x, int y) {
	if (F[x][y]) return 1;
	if (F[y][x]) return -1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -