Submission #70989473


Source Code Expand

#include <bits/stdc++.h>

typedef long long valueType;
typedef std::vector<valueType> ValueVector;
typedef std::vector<ValueVector> ValueMatrix;
typedef std::vector<ValueMatrix> ValueCube;
typedef std::string string;
typedef std::vector<string> StringVector;
typedef std::vector<bool> bitset;
typedef std::vector<bitset> BitMatrix;
typedef std::pair<valueType, valueType> ValuePair;
typedef std::vector<ValuePair> PairVector;
typedef std::vector<PairVector> PairMatrix;
typedef std::tuple<valueType, valueType, valueType> ValueTuple;
typedef std::vector<ValueTuple> TupleVector;
typedef std::vector<TupleVector> TupleMatrix;
typedef std::set<valueType> ValueSet;

struct Node {
    valueType x, y;
    valueType height, weight;

    Node() = default;
    Node(valueType const x, valueType const y, valueType const height, valueType const weight)
        : x(x), y(y), height(height), weight(weight) {}

    valueType size() const {
        return height * weight;
    }
};

bool Adjacent(Node const &A, Node const &B) {
    bool result = false;

    result = result || (((A.x + A.height == B.x) || (B.x + B.height == A.x)) && !((A.y + A.weight <= B.y) || (B.y + B.weight <= A.y)));
    result = result || (((A.y + A.weight == B.y) || (B.y + B.weight == A.y)) && !((A.x + A.height <= B.x) || (B.x + B.height <= A.x)));

    return result;
}

typedef std::vector<Node> NodeVector;

template<typename T, bool SizeBalanced>
class DSU {};

template<typename T>
class DSU<T, false> {
private:
    T N;
    std::vector<T> father;

public:
    DSU() = default;

    explicit DSU(T n) : N(n), father(N) {
        std::iota(father.begin(), father.end(), 0);
    }

    void resize(T n) {
        N = n;
        father.resize(N);
        std::iota(father.begin(), father.end(), 0);
    }

public:
    T find(T x) {
        return father[x] == x ? x : father[x] = find(father[x]);
    }

    bool merge(T x, T y) { // merge y to x
        if (find(x) == find(y))
            return false;

        father[find(y)] = find(x);

        return true;
    }
};

template<typename T>
class DSU<T, true> {
private:
    T N;
    std::vector<T> father;
    std::vector<T> size;

public:
    DSU() = default;

    explicit DSU(T n) : N(n), father(N), size(N, 1) {
        std::iota(father.begin(), father.end(), 0);
    }

    void resize(T n) {
        N = n;
        father.resize(N);
        size.resize(N);
        std::iota(father.begin(), father.end(), 0);
        std::fill(size.begin(), size.end(), 1);
    }

public:
    T find(T x) {
        return father[x] == x ? x : father[x] = find(father[x]);
    }

    bool merge(T x, T y) { // merge y to x
        if (find(x) == find(y))
            return false;

        if (size[find(x)] < size[find(y)])
            std::swap(x, y);

        father[find(y)] = find(x);
        size[find(x)] += size[find(y)];

        return true;
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    valueType N, X, Y;

    std::cin >> N >> X >> Y;

    NodeVector Nodes(1, Node(0, 0, X, Y));

    for (valueType n = 0; n < N; ++n) {
        NodeVector New;

        char direction;
        valueType A, B;

        std::cin >> direction >> A >> B;

        if (direction == 'X') {
            for (auto const &node : Nodes) {
                if (node.x < A && A <= node.x + node.height - 1) {
                    New.emplace_back(node.x, node.y - B, A - node.x, node.weight);
                    New.emplace_back(A, node.y + B, node.x + node.height - A, node.weight);
                } else if (node.x + node.height - 1 < A) {
                    New.emplace_back(node.x, node.y - B, node.height, node.weight);
                } else { // A <= node.x
                    New.emplace_back(node.x, node.y + B, node.x + node.height, node.weight);
                }
            }
        } else {
            for (auto const &node : Nodes) {
                if (node.y < A && A <= node.y + node.weight - 1) {
                    New.emplace_back(node.x - B, node.y, node.height, A - node.y);
                    New.emplace_back(node.x + B, A, node.height, node.y + node.weight - A);
                } else if (node.y + node.weight - 1 < A) {
                    New.emplace_back(node.x - B, node.y, node.height, node.weight);
                } else { // A <= node.y
                    New.emplace_back(node.x + B, node.y, node.height, node.weight);
                }
            }
        }

        Nodes.swap(New);
    }

    valueType const size = Nodes.size();

    DSU<int, false> dsu(size);

    for (valueType i = 0; i < size; ++i) {
        for (valueType j = 0; j < i; ++j) {
            if (Adjacent(Nodes[i], Nodes[j]))
                dsu.merge(i, j);
        }
    }

    ValueVector Ans(size, 0);

    for (valueType i = 0; i < size; ++i)
        Ans[dsu.find(i)] += Nodes[i].size();

    std::sort(Ans.begin(), Ans.end(), std::greater<valueType>());

    while (Ans.back() == 0)
        Ans.pop_back();

    std::sort(Ans.begin(), Ans.end());

    std::cout << Ans.size() << std::endl;

    for (auto const &ans : Ans)
        std::cout << ans << " ";

    std::cout << std::endl;
}

Submission Info

Submission Time
Task D - Suddenly, A Tempest
User UserUnauthorized
Language C++23 (Clang 21.1.0)
Score 0
Code Size 5378 Byte
Status WA
Exec Time 1 ms
Memory 3016 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 2
AC × 51
WA × 45
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt, 01-56.txt, 01-57.txt, 01-58.txt, 01-59.txt, 01-60.txt, 01-61.txt, 01-62.txt, 01-63.txt, 01-64.txt, 01-65.txt, 01-66.txt, 01-67.txt, 01-68.txt, 01-69.txt, 01-70.txt, 01-71.txt, 01-72.txt, 01-73.txt, 01-74.txt, 01-75.txt, 01-76.txt, 01-77.txt, 01-78.txt, 01-79.txt, 01-80.txt, 01-81.txt, 01-82.txt, 01-83.txt, 01-84.txt, 01-85.txt, 01-86.txt, 01-87.txt, 01-88.txt, 01-89.txt, 01-90.txt, 01-91.txt, 01-92.txt, 01-93.txt, 01-94.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 2780 KiB
00-sample-02.txt AC 1 ms 2964 KiB
01-01.txt WA 1 ms 2812 KiB
01-02.txt WA 1 ms 3016 KiB
01-03.txt WA 1 ms 2848 KiB
01-04.txt AC 1 ms 2904 KiB
01-05.txt AC 1 ms 2964 KiB
01-06.txt WA 1 ms 2780 KiB
01-07.txt WA 1 ms 2880 KiB
01-08.txt WA 1 ms 2896 KiB
01-09.txt WA 1 ms 2880 KiB
01-10.txt WA 1 ms 2904 KiB
01-11.txt AC 1 ms 2780 KiB
01-12.txt AC 1 ms 3016 KiB
01-13.txt WA 1 ms 3000 KiB
01-14.txt WA 1 ms 2780 KiB
01-15.txt AC 1 ms 2908 KiB
01-16.txt AC 1 ms 2856 KiB
01-17.txt AC 1 ms 2896 KiB
01-18.txt AC 1 ms 2908 KiB
01-19.txt WA 1 ms 2880 KiB
01-20.txt WA 1 ms 2880 KiB
01-21.txt AC 1 ms 2964 KiB
01-22.txt AC 1 ms 2964 KiB
01-23.txt WA 1 ms 2812 KiB
01-24.txt WA 1 ms 2848 KiB
01-25.txt AC 1 ms 3000 KiB
01-26.txt AC 1 ms 2904 KiB
01-27.txt AC 1 ms 2896 KiB
01-28.txt AC 1 ms 2880 KiB
01-29.txt AC 1 ms 2864 KiB
01-30.txt AC 1 ms 2812 KiB
01-31.txt AC 1 ms 2992 KiB
01-32.txt AC 1 ms 2992 KiB
01-33.txt AC 1 ms 2780 KiB
01-34.txt AC 1 ms 2896 KiB
01-35.txt AC 1 ms 2888 KiB
01-36.txt AC 1 ms 2968 KiB
01-37.txt AC 1 ms 3000 KiB
01-38.txt AC 1 ms 2708 KiB
01-39.txt AC 1 ms 2964 KiB
01-40.txt AC 1 ms 2880 KiB
01-41.txt AC 1 ms 2880 KiB
01-42.txt AC 1 ms 2848 KiB
01-43.txt AC 1 ms 2780 KiB
01-44.txt AC 1 ms 2904 KiB
01-45.txt AC 1 ms 2992 KiB
01-46.txt AC 1 ms 2896 KiB
01-47.txt AC 1 ms 2964 KiB
01-48.txt AC 1 ms 3000 KiB
01-49.txt AC 1 ms 2896 KiB
01-50.txt AC 1 ms 3016 KiB
01-51.txt AC 1 ms 2904 KiB
01-52.txt AC 1 ms 3004 KiB
01-53.txt AC 1 ms 2964 KiB
01-54.txt AC 1 ms 2904 KiB
01-55.txt AC 1 ms 3000 KiB
01-56.txt AC 1 ms 2908 KiB
01-57.txt AC 1 ms 2908 KiB
01-58.txt AC 1 ms 2904 KiB
01-59.txt WA 1 ms 2800 KiB
01-60.txt WA 1 ms 2896 KiB
01-61.txt WA 1 ms 2812 KiB
01-62.txt WA 1 ms 2980 KiB
01-63.txt WA 1 ms 2904 KiB
01-64.txt WA 1 ms 2848 KiB
01-65.txt WA 1 ms 2896 KiB
01-66.txt WA 1 ms 2880 KiB
01-67.txt WA 1 ms 2880 KiB
01-68.txt WA 1 ms 2880 KiB
01-69.txt AC 1 ms 2820 KiB
01-70.txt AC 1 ms 2964 KiB
01-71.txt AC 1 ms 2780 KiB
01-72.txt WA 1 ms 3000 KiB
01-73.txt WA 1 ms 2812 KiB
01-74.txt WA 1 ms 2964 KiB
01-75.txt WA 1 ms 2964 KiB
01-76.txt WA 1 ms 2888 KiB
01-77.txt WA 1 ms 2964 KiB
01-78.txt AC 1 ms 2880 KiB
01-79.txt WA 1 ms 2884 KiB
01-80.txt WA 1 ms 3016 KiB
01-81.txt AC 1 ms 2980 KiB
01-82.txt WA 1 ms 2964 KiB
01-83.txt WA 1 ms 2904 KiB
01-84.txt WA 1 ms 2880 KiB
01-85.txt WA 1 ms 3016 KiB
01-86.txt WA 1 ms 2904 KiB
01-87.txt WA 1 ms 2896 KiB
01-88.txt WA 1 ms 2836 KiB
01-89.txt WA 1 ms 2808 KiB
01-90.txt WA 1 ms 2964 KiB
01-91.txt WA 1 ms 2964 KiB
01-92.txt WA 1 ms 2980 KiB
01-93.txt WA 1 ms 2896 KiB
01-94.txt WA 1 ms 2880 KiB