Submission #425776

#TimeUsernameProblemLanguageResultExecution timeMemory
425776erekleComparing Plants (IOI20_plants)C++17
5 / 100
104 ms5852 KiB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> cntGreater; // how many following this are greater than this
vector<int> cntLess; // how many following this are less than this

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

	cntGreater.resize(n);
	int i = 0;
	while (r[i] == 1) ++i;
	cntGreater[i] = 0;
	for (int j = (i-1+n)%n; j != i; j = (j-1+n)%n) {
		if (r[j] == 1) cntGreater[j] = cntGreater[(j+1)%n] + 1;
		else cntGreater[j] = 0;
	}

	cntLess.resize(n);
	i = 0;
	while (r[i] == 0) ++i;
	cntLess[i] = 0;
	for (int j = (i-1+n)%n; j != i; j = (j-1+n)%n) {
		if (r[j] == 0) cntLess[j] = cntLess[(j+1)%n] + 1;
		else cntLess[j] = 0;
	}

	return;
}

int compare_plants(int x, int y) {
	if (cntGreater[x] >= y-x) return -1;
	if (cntLess[x] >= y-x) return 1;
	if (cntGreater[y] >= n+x-y) return 1;
	if (cntLess[y] >= n+x-y) return -1;
	return 0;
}
#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...