답안 #303093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303093 2020-09-19T21:52:49 Z tutis 식물 비교 (IOI20_plants) C++17
컴파일 오류
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)
      |                ^