Submission #509702

# Submission time Handle Problem Language Result Execution time Memory
509702 2022-01-14T08:21:46 Z KoD Kutije (COCI21_kutije) C++17
70 / 70
177 ms 10368 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

template <class F> struct RecLambda : private F {
    explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, M, Q;
    std::cin >> N >> M >> Q;
    vector edge(N, vector<char>(N));
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < N; ++j) {
            int p;
            std::cin >> p;
            edge[p - 1][j] = true;
        }
    }
    vector<std::bitset<1000>> reach(N);
    vector<char> done(N);
    vector<int> list;
    const auto forward = RecLambda([&](auto&& dfs, const int u) -> void {
        if (done[u]) return;
        done[u] = true;
        for (int i = 0; i < N; ++i) {
            if (edge[u][i]) {
                dfs(i);
            }
        }
        list.push_back(u);
    });
    for (int u = 0; u < N; ++u) {
        forward(u);
    }
    std::fill(done.begin(), done.end(), false);
    vector<int> comp;
    const auto backward = RecLambda([&](auto&& dfs, const int u) -> void {
        if (done[u]) return;
        done[u] = true;
        for (int i = 0; i < N; ++i) {
            if (edge[i][u]) {
                dfs(i);
            }
        }
        comp.push_back(u);
    });
    vector<int> ord;
    while (!list.empty()) {
        const int u = list.back();
        list.pop_back();
        backward(u);
        for (const int u : comp) {
            for (const int v : comp) {
                reach[u].set(v);
            }
            ord.push_back(u);
        }
        comp.clear();
    }
    for (int i = N - 1; i >= 0; --i) {
        const int u = ord[i];
        for (int j = i + 1; j < N; ++j) {
            const int v = ord[j];
            if (edge[u][v]) {
                reach[u] |= reach[v];
            }
        }
    }
    while (Q--) {
        int a, b;
        std::cin >> a >> b;
        std::cout << (reach[a - 1].test(b - 1) ? "DA" : "NE") << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2980 KB Output is correct
2 Correct 82 ms 2532 KB Output is correct
3 Correct 70 ms 2456 KB Output is correct
4 Correct 104 ms 2884 KB Output is correct
5 Correct 88 ms 2880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2980 KB Output is correct
2 Correct 82 ms 2532 KB Output is correct
3 Correct 70 ms 2456 KB Output is correct
4 Correct 104 ms 2884 KB Output is correct
5 Correct 88 ms 2880 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 156 ms 2972 KB Output is correct
27 Correct 147 ms 2900 KB Output is correct
28 Correct 134 ms 5444 KB Output is correct
29 Correct 177 ms 10132 KB Output is correct
30 Correct 149 ms 8728 KB Output is correct
31 Correct 144 ms 8668 KB Output is correct
32 Correct 159 ms 10352 KB Output is correct
33 Correct 148 ms 10344 KB Output is correct
34 Correct 143 ms 10368 KB Output is correct
35 Correct 152 ms 10052 KB Output is correct