Submission #572790

#TimeUsernameProblemLanguageResultExecution timeMemory
572790kartelComparing Plants (IOI20_plants)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
//#include "grader.cpp"
#include "plants.h"
#define pb push_back
#define sz(x) (int)x.size()
using namespace std;

const int N = 1e6 + 500;

int le[N], ri[N];

void init(int k, vector <int> r) {
    int n = sz(r);

    vector <vector <int> > g(n);
    for (int i = 0; i < n * 3; i++) {
        if (!r[i % n]) {
            le[i] = (i - 1 >= 0 ? le[i - 1] : -1);
        } else {
            le[i] = i;
        }
    }

    for (int i = n * 3 - 1; i >= 0; i--) {
        if (r[i % n]) {
            ri[i] = ri[i + 1];
        } else {
            ri[i] = i;
        }
    }
}

int compare_plants(int x, int y) {
    if (le[x + n - 1] + 1 <= y && y <= ri[x + n]) {
        return 1;
    }
    if (le[x + n - 1] + 1 <= y + n && y + n <= ri[x + n]) {
        return 1;
    }
    if (le[x + n - 1] + 1 <= y + 2 * n && y + 2 * n <= ri[x + n]) {
        return 1;
    }

    if (le[y + n - 1] + 1 <= x && x <= ri[y + n]) {
        return -1;
    }
    if (le[y + n - 1] + 1 <= x + n && x + n <= ri[y + n]) {
        return -1;
    }
    if (le[y + n - 1] + 1 <= x + 2 * n && x + 2 * n <= ri[y + n]) {
        return -1;
    }

    return 0;
}

Compilation message (stderr)

plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:34:16: error: 'n' was not declared in this scope
   34 |     if (le[x + n - 1] + 1 <= y && y <= ri[x + n]) {
      |                ^
plants.cpp:37:16: error: 'n' was not declared in this scope
   37 |     if (le[x + n - 1] + 1 <= y + n && y + n <= ri[x + n]) {
      |                ^
plants.cpp:40:16: error: 'n' was not declared in this scope
   40 |     if (le[x + n - 1] + 1 <= y + 2 * n && y + 2 * n <= ri[x + n]) {
      |                ^
plants.cpp:44:16: error: 'n' was not declared in this scope
   44 |     if (le[y + n - 1] + 1 <= x && x <= ri[y + n]) {
      |                ^
plants.cpp:47:16: error: 'n' was not declared in this scope
   47 |     if (le[y + n - 1] + 1 <= x + n && x + n <= ri[y + n]) {
      |                ^
plants.cpp:50:16: error: 'n' was not declared in this scope
   50 |     if (le[y + n - 1] + 1 <= x + 2 * n && x + 2 * n <= ri[y + n]) {
      |                ^