Submission #1190425

#TimeUsernameProblemLanguageResultExecution timeMemory
1190425ildar1Comparing Plants (IOI20_plants)C++20
0 / 100
31 ms3140 KiB
#include <iostream>
#include <vector>

#define MAXN 200001

using namespace std;

int ans[MAXN];

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

	for (int i=0; i<n; i++) {
		int first = 0;
		int prev = 0;
		int next = -1;
		for (int j=0; j<n; j++) {
			if (r[j]==0) {
				//check wether r[j-1], r[j-2], ..., r[j-k+1] are non-zero
				if (first==0) {
					first = j;
					prev = j;
				} else {
					next = j;
					if (next-prev >= k) {
						break;
					} else {
						prev = j;
					}
	
				}
			}
		}
		if (next==-1 || next-prev<k) {
			ans[first] = i;
			for (int i=0; i<=k-1; i++) {
				if (first-i<0) {
					first+=n;
					r[first-i]--;
				} else {
					r[first-i]--;
				}
			}
		} else if (next - prev>=k) {
			ans[next] = i;
			for (int i=0; i<=k-1; i++) {
				if (next - i <0) {
					next +=n;
					r[next - i]--;
				} else {
					r[next -i]--;
				}
			}
		}

	}

	


}

int compare_plants(int x, int y) {

	int a = ans[x];
	int b = ans[y];

	if (a < b) {
		return 1;
	} else {
		return -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...