제출 #1190431

#제출 시각아이디문제언어결과실행 시간메모리
1190431ildar1식물 비교 (IOI20_plants)C++20
14 / 100
4094 ms5124 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 = -1;
		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==-1) {
					first = j;
					prev = j;
				} else {
					next = j;
					if (next-prev >= k) {
						break;
					} else {
						prev = j;
					}
	
				}
			}
		}
		if (next-prev<k) {
			ans[first] = i;
			for (int j=0; j<=k-1; j++) {
				if (first-j<0) {
					first+=n;
					r[first-j]--;
				} else {
					r[first-j]--;
				}
			}
		} else if (next - prev>=k) {
			ans[next] = i;
			for (int j=0; j<=k-1; j++) {
				if (next - j <0) {
					next +=n;
					r[next - j]--;
				} else {
					r[next -j]--;
				}
			}
		}

	}

	


}

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...