Submission #819771

# Submission time Handle Problem Language Result Execution time Memory
819771 2023-08-10T13:21:21 Z Abrar_Al_Samit Comparing Plants (IOI20_plants) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;

const int nax = 5002;
int val[nax], n;

bool cmp(int x, int y) {
	if(x + k - 1 < n) {
		return y > x && y <= x + k - 1;
	} else {
		if(y < x) return (x + k - 1) % n >= y;
		else return y > x;
	}
}
void init(int k, vector<int> r) {
	n = r.size();
	int tg = 1;
	queue<int>q;
	for(int i=0; i<n; ++i) {
		sm[i] = k - r[i] - 1;
		if(sm[i]==0) {
			q.push(i);
		}
	}
	while(!q.empty()) {
		vector<int>cur;
		while(!q.empty()) {
			cur.push_back(q.front());
			q.pop();
		}
		sort(cur.begin(), cur.end(), [&] (int x, int y) {
			if(x + k - 1 < n) {
				return y > x && y <= x + k - 1;
			} else {
				if(y < x) return (x + k - 1) % n >= y;
				else return y > x;
			}
		});

		for(int x : cur) {
			val[x] = ++tg;

			for(int z=x, cnt=0; cnt<=k; ++cnt, z=(z-1+n)%n) {
				if(--sm[z]==0) q.push(z);
			}
		}
	}	
}

int compare_plants(int x, int y) {
	if(val[x]>val[y]) return 1;
	return -1;
}

Compilation message

plants.cpp: In function 'bool cmp(int, int)':
plants.cpp:9:9: error: 'k' was not declared in this scope
    9 |  if(x + k - 1 < n) {
      |         ^
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:21:3: error: 'sm' was not declared in this scope; did you mean 'tm'?
   21 |   sm[i] = k - r[i] - 1;
      |   ^~
      |   tm
plants.cpp:45:10: error: 'sm' was not declared in this scope; did you mean 'tm'?
   45 |     if(--sm[z]==0) q.push(z);
      |          ^~
      |          tm