| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 337834 | aanastasov | Comparing Plants (IOI20_plants) | C++17 | 4077 ms | 2097156 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include "plants.h"
template<typename T> void debug(std::vector<T> v) {
    std::cout << "{";
    for (int i = 0; i < v.size(); ++i) {
        if (i > 0) std::cout << ", ";
        std::cout << v[i];
    }
    std::cout << "}\n";
}
class PlantsSolver {
public:
    PlantsSolver() { }
    PlantsSolver(int k, std::vector<int> r) {
        const int numPlants = r.size();
        const int infty = 1e9;
        maybeShorter = std::vector<std::vector<bool>>(numPlants,
                std::vector<bool>(numPlants, true));
        for (int curPlant = 0; curPlant < numPlants; ++curPlant) {
            auto ranks = std::vector<int>(r.begin(), r.end());
            for (int h = numPlants; h >= 1; --h) {
                auto zeroes = std::vector<int>();
                for (int i = 0; i < numPlants; ++i) if (ranks[i] == 0) {
                    zeroes.push_back(i);
                }
                assert(!zeroes.empty());
                auto candidates = std::vector<int>();
                for (int i = 0; i < zeroes.size(); ++i) {
                    int offset = zeroes[i] - zeroes[(i - 1 + zeroes.size()) % zeroes.size()];
                    if (i == 0) offset += numPlants;
                    if (offset >= k || zeroes.size() == 1) {
                        candidates.push_back(zeroes[i]);
                    }
                }
                assert(!candidates.empty());
                if (candidates.size() == 1 && candidates[0] == curPlant) {
                    break;
                } else {
                    int x = candidates[0] != curPlant ? candidates[0] : candidates[1];
                    maybeShorter[curPlant][x] = false;
                    assert(x != curPlant);
                    ranks[x] = infty;
                    for (int offset = 1; offset < k; ++offset) {
                        int preceding = (x - offset + numPlants) % numPlants;
                        ranks[preceding]--;
                        assert(ranks[preceding] >= 0);
                    }
                }
            }
        }
    }
    int comparePlants(int x, int y) {
        const bool xToY = maybeShorter[x][y];
        const bool yToX = maybeShorter[y][x];
        if (xToY != yToX) {
            if (yToX) return -1;
            else return 1;
        } else {
            return 0;
        }
    }
    std::vector<std::vector<bool>> maybeShorter;
};
PlantsSolver solver;
void init(int k, std::vector<int> r) {
    solver = PlantsSolver(k, r);
}
int compare_plants(int x, int y) {
    return solver.comparePlants(x, y);
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
