제출 #819814

#제출 시각아이디문제언어결과실행 시간메모리
819814Abrar_Al_Samit식물 비교 (IOI20_plants)C++17
0 / 100
1 ms1032 KiB
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;

const int nax = 2e5 + 2;
int n, k;
int head[nax], pos[nax];

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

	memset(head, -1, sizeof head);

	int p = -1;
	for(int i=0; i<n; ++i) {
		int pr = (i - 1 + n) % n;

		if(!r[pr] && r[i]) { //down
			p = i;
			break;
		}
	}
	assert(p!=-1);

	int st = p;
	while(1) {
		int j = p;
		pos[p] = 1;
		head[p] = p;
		int at = 1;
		while(r[j]) {
			j = (j+1)%n;
			head[j] = p;
			pos[j] = ++at;
		}

		while(!r[j]) j = (j+1)%n;

		if(j==st) break;

		p = j;
	}
}

int compare_plants(int x, int y) {
	if(head[x] == head[y] && head[x]!=-1) {
		return (pos[x] < pos[y]) ? -1 : 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...