답안 #645708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645708 2022-09-27T17:13:19 Z Cyanmond Friends (BOI17_friends) C++17
69 / 100
1000 ms 1004 KB
#include <bits/stdc++.h>

int main() {
    int N, P, Q;
    std::cin >> N >> P >> Q;

    std::vector<int> M(N);
    std::vector<std::vector<int>> graph(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> M[i];
        graph[i].resize(M[i]);
        for (int &e : graph[i]) {
            std::cin >> e;
        }
    }

    // check : input is valid ?
    {
        std::set<std::pair<int, int>> s;
        for (int i = 0; i < N; ++i) {
            for (const int e : graph[i]) {
                const auto pair = std::minmax(i, e);
                if (s.find(pair) == s.end()) {
                    s.insert(pair);
                } else {
                    s.erase(pair);
                }
            }
        }

        if (not s.empty()) {
            std::cout << "detention" << std::endl;
            return 0;
        }
    }

    std::vector<std::set<int>> group(N);
    for (int c = 0; c < N; ++c) {
        auto find = [&](auto &&self, std::set<int> set, std::multiset<int> que, const int r) -> void {
            if ((int)set.size() > P) return;
            if (r > Q) return;

            if (que.empty()) {
                if (set.empty()) {
                    return;
                }
                if (group[c].empty() or group[c].size() > set.size()) {
                    group[c] = set;
                }
                return;
            }

            const int from = *que.begin();
            que.erase(que.begin());
            self(self, set, que, r + 1);

            que.erase(from);
            set.insert(from);
            for (const int to : graph[from]) {
                if (set.find(to) == set.end()) {
                    que.insert(to);
                }
            }
            self(self, set, que, r);
        };
        find(find, {}, {c}, 0);
    }

    if (std::any_of(group.begin(), group.end(), [&](const auto &e) { return e.empty(); })) {
        std::cout << "detention" << std::endl;
        return 0;
    }

    std::vector<int> answer_index(N, -1);
    for (int i = 0; i < N; ++i) {
        for (const int e : group[i]) {
            int &x = answer_index[e];
            if (x == -1 or group[x].size() < group[i].size()) {
                x = i;
            }
        }
    }

    std::set<int> answer;
    for (const int e : answer_index) {
        answer.insert(e);
    }
    
    std::cout << "home" << std::endl;
    std::cout << answer.size() << std::endl;
    for (const int i : answer) {
        std::cout << group[i].size();
        for (const int e : group[i]) {
            std::cout << ' ' << e;
        }
        std::cout << std::endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 54 ms 372 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 23 ms 368 KB Output is correct
5 Correct 40 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 37 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 54 ms 372 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 23 ms 368 KB Output is correct
5 Correct 40 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 37 ms 452 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 22 ms 852 KB Output is correct
11 Correct 85 ms 904 KB Output is correct
12 Correct 496 ms 840 KB Output is correct
13 Correct 483 ms 932 KB Output is correct
14 Correct 185 ms 972 KB Output is correct
15 Correct 266 ms 1004 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 54 ms 372 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 23 ms 368 KB Output is correct
13 Correct 40 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 37 ms 452 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 22 ms 852 KB Output is correct
19 Correct 85 ms 904 KB Output is correct
20 Correct 496 ms 840 KB Output is correct
21 Correct 483 ms 932 KB Output is correct
22 Correct 185 ms 972 KB Output is correct
23 Correct 266 ms 1004 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Execution timed out 1080 ms 844 KB Time limit exceeded
27 Halted 0 ms 0 KB -