Submission #1222164

#TimeUsernameProblemLanguageResultExecution timeMemory
1222164kargneq식물 비교 (IOI20_plants)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> r;
int n;

void init(int k, const vector<int>& rr) {
    r = rr;
    n = r.size();
}

int compare_plants(int x, int y) {
    // Check if y is one of the next two plants after x (circularly)
    int n1 = (x + 1) % n;
    int n2 = (x + 2) % n;
    if (r[x] == 0 && (y == n1 || y == n2)) return 1; // x is definitely taller
    if (r[x] == 2 && (y == n1 || y == n2)) return -1; // x is definitely shorter

    // Check if x is one of the next two plants after y (circularly)
    int yn1 = (y + 1) % n;
    int yn2 = (y + 2) % n;
    if (r[y] == 0 && (x == yn1 || x == yn2)) return -1; // y is definitely taller
    if (r[y] == 2 && (x == yn1 || x == yn2)) return 1; // y is definitely shorter

    return 0; // inconclusive
}

int main() {
    vector<int> b = {0, 1, 0, 1};
    init(2, b);
    printf("%d\n", compare_plants(0, 3)); // Output: 1
    printf("%d\n", compare_plants(1, 3)); // Output: 0
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccPZ5Vg7.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccETkM4r.o:plants.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccPZ5Vg7.o: in function `main':
grader.cpp:(.text.startup+0x2e9): undefined reference to `init(int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status