Submission #1043207

# Submission time Handle Problem Language Result Execution time Memory
1043207 2024-08-04T04:51:04 Z thinknoexit Comparing Plants (IOI20_plants) C++17
0 / 100
1 ms 2648 KB
#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200200;
int n, k;
int ord[N], deg[N], dpl[N], dpr[N];
void init(int K, vector<int> r) {
	n = r.size();
	k = K;
	if (k == 2) {
		for (int i = 0;i < n;i++) {
			if (r[i] == 1) deg[(i + 1) % n]++;
			else deg[i]++;
		}
		for (int i = 0;i < n;i++) {
			if (deg[i] != 0) continue;
			dpl[i] = dpr[i] = 0;
			for (int j = 1, c = 1;j < n;j++, c++) {
				dpr[(i - j + n) % n] = c;
				if (deg[(i - j + n) % n] == 2) break;
			}
			for (int j = 1, c = 1;j < n;j++, c++) {
				dpl[(i + j) % n] = c;
				if (deg[(i + j) % n] == 2) break;
			}
		}
		return;
	}
	memset(ord, -1, sizeof ord);
	for (int i = n;i >= 1;i--) {
		vector<int> v;
		for (int j = 0;j < n;j++) {
			if (ord[j] == -1 && r[j] == 0) {
				v.push_back(j);
			}
		}
		int idx = 0;
		for (int j = 0;j < (int)v.size();j++) {
			if ((v[j] - v[(j + n - 1) % n] + n) % n >= k) idx = v[j];
		}
		ord[idx] = i;
		for (int j = 1;j < k;j++) {
			r[(idx - j + n) % n]--;
		}
	}
}

int compare_plants(int x, int y) {
	if (k != 2) return (ord[x] > ord[y]) ? 1 : -1;
	// check y -> x
	{
		int l = dpl[y], r = dpr[y];
		if (y + l >= n) {
			if (y <= x || x <= (y + l) % n) return -1;
		}
		else {
			if (y <= x && x <= y + l) return -1;
		}
		if (y - r < 0) {
			if (x <= y || (n + y - r) % n <= x) return -1;
		}
		else {
			if (y - r <= x && x <= y) return -1;
		}
	}
	// check x -> y
	{
		int l = dpl[x], r = dpr[x];
		if (x + l >= n) {
			if (x <= y || y <= (x + l) % n) return 1;
		}
		else {
			if (x <= y && y <= x + l) return 1;
		}
		if (x - r < 0) {
			if (y <= x || (n + x - r) % n <= y) return 1;
		}
		else {
			if (x - r <= y && y <= x) return 1;
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2492 KB Output is correct
2 Incorrect 1 ms 2488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -