Submission #819831

# Submission time Handle Problem Language Result Execution time Memory
819831 2023-08-10T14:01:49 Z Abrar_Al_Samit Comparing Plants (IOI20_plants) C++17
0 / 100
2 ms 1876 KB
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;

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

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][0] = 1;
		head[p][0] = p;
		int at = 1;
		while(r[j]) {
			j = (j+1)%n;
			head[j][0] = p;
			pos[j][0] = ++at;
		}

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

		if(j==st) break;
		p = j;
	}
}

int compare_plants(int x, int y) {
	if(head[x][0] == head[y][0] && head[x][0] != -1) {
		return (pos[x][0] < pos[y][0]) ? -1 : 1;
	}
	if(head[x][1] == head[y][1] && head[x][1] != -1) {
		return (pos[x][0] > pos[y][0]) ? -1 : 1;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Incorrect 1 ms 1844 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1848 KB Output is correct
3 Incorrect 1 ms 1876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1848 KB Output is correct
3 Incorrect 1 ms 1876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Incorrect 1 ms 1848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1848 KB Output is correct
3 Incorrect 1 ms 1876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1844 KB Output is correct
2 Correct 1 ms 1840 KB Output is correct
3 Incorrect 1 ms 1876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Incorrect 1 ms 1844 KB Output isn't correct
5 Halted 0 ms 0 KB -