답안 #815434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815434 2023-08-08T15:06:41 Z vjudge1 식물 비교 (IOI20_plants) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;
int n, h;
vector<int> v;
void init(int k, vector<int> r)
{
    v = r;
    n = r.size();
    h = k;
}
int compare_plants(int x, int y)
{
    int z = 0, i;
    if (h == 2)
    {
        for (i = x; i < y; i++)
        {
            if (r[i] == 1)
                z--;
            else
                z++;
        }
        if (z == y - x)
            return 1;
        if (z == x - y)
            return -1;
        z = 0;
        for (i = y; i < x + n; i++)
        {
            if (r[i % n] == 1)
                z--;
            else
                z++;
        }
        if (z == y - x)
            return 1;
        if (z == x - y)
            return -1;
        return 0;
    }
    return z;
}

Compilation message

plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:19:17: error: 'r' was not declared in this scope
   19 |             if (r[i] == 1)
      |                 ^
plants.cpp:31:17: error: 'r' was not declared in this scope
   31 |             if (r[i % n] == 1)
      |                 ^