Submission #1291751

#TimeUsernameProblemLanguageResultExecution timeMemory
1291751gustavo_dComparing Plants (IOI20_plants)C++20
5 / 100
46 ms7808 KiB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

#define sz(v) (int)(v).size()

const int MAXN = 2e5;

int n;
bool nxtBigger[2*MAXN];
int furthestBigger[2*MAXN], furthestSmaller[2*MAXN];

void init(int k, vector<int> r) {
	n = sz(r);
	for (int i=0; i<2*n-1; i++) {
		nxtBigger[i] = r[i%n];
		// cout << nxtBigger[i] << ' ';
	}
	// cout << '\n';
	for (int i=2*n-2; i>=0; i--) {
		if (!nxtBigger[i]) furthestBigger[i] = -1;
		else if (i == 2*n-2 or !nxtBigger[i+1]) furthestBigger[i] = i+1;
		else furthestBigger[i] = furthestBigger[i+1];
		if (nxtBigger[i]) furthestSmaller[i] = -1;
		else if (i == 2*n-2 or nxtBigger[i+1]) furthestSmaller[i] = i+1;
		else furthestSmaller[i] = furthestSmaller[i+1];
	}
	// for (int i=0; i<2*n-1; i++) cout << furthestSmaller[i] << ' ';
	// cout << '\n';
	// for (int i=0; i<2*n-1; i++) cout << furthestBigger[i] << ' ';
	// cout << '\n';
}

int cmp(int x, int y) {
	if (x > y) y += n;
	if (furthestBigger[x] >= y) return -1;
	if (furthestSmaller[x] >= y) return 1;
	return 0;
}

int compare_plants(int x, int y) {
	int cmpA = cmp(x, y), cmpB = cmp(y, x);
	if (cmpA != 0) return cmpA;
	return cmpB * -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...