Submission #303093

# Submission time Handle Problem Language Result Execution time Memory
303093 2020-09-19T21:52:49 Z tutis Comparing Plants (IOI20_plants) C++17
Compilation error
0 ms 0 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>k0, k1;
int K;
void init(int k, vector<int> r)
{
	K = k;
	if (k == 2)
	{
		int n = r.size();
		k0 = k1 = vector<int>(n, 0);
		for (int t = 0; t < 2; t++)
			for (int i = n - 1; i >= 0; i--)
			{
				if (r[i] == 0)
					k0[i] = 1 + k0[(i + 1) % n];
				else
					k1[i] = 1 + k1[(i + 1) % n];
			}
	}
}

int compare_plants(int x, int y)
{
	assert(x < y);
	if (K == 2)
	{
		if (k0[x] >= y - x)
			return -1;
		if (k1[x] >= y - x)
			return 1;
		if (k0[y] >= n - y + x)
			return -1;
		if (k1[y] >= n - y + x)
			return 1;
		return 0;
	}
	return 0;
}

Compilation message

plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:33:16: error: 'n' was not declared in this scope
   33 |   if (k0[y] >= n - y + x)
      |                ^
plants.cpp:35:16: error: 'n' was not declared in this scope
   35 |   if (k1[y] >= n - y + x)
      |                ^