제출 #1133320

#제출 시각아이디문제언어결과실행 시간메모리
1133320alterio식물 비교 (IOI20_plants)C++20
14 / 100
4094 ms5700 KiB
#include <bits/stdc++.h>
#include "plants.h"

using namespace std;

int n, k;
vector<int> r, vals;

bool check(int pos) {
	pos = (pos - 1 + n) % n;
	for (int i = 0; i < k; i++) {
		if (r[pos] == 0) return 0;
		pos = (pos - 1 + n) % n;
	}
	return 1;
}

void upd(int pos, int val) {
	r[pos]--;
	pos = (pos - 1 + n) % n; 
	for (int i = 0; i < k; i++) {
		if (r[pos] == 0) vals[pos] = val;
		r[pos]--;
		pos = (pos - 1 + n) % n; 
	}
}

void init(int _k, vector<int> _r) {
	r = _r;
	n = r.size();
	k = _k;
	k--;
	vals.resize(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (r[j] == 0) {
				if (check(j)) {
					upd(j, 2 * (n - i) - 1);
					vals[j] = 2 * (n - i);
					break;
				}
			}
		}
	}
}

int compare_plants(int x, int y) {
	if (vals[x] == vals[y]) return 0;
	return (vals[x] > vals[y] ? 1 : -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...