답안 #676898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676898 2023-01-01T13:46:18 Z Cyanmond Paths (BOI18_paths) C++17
100 / 100
423 ms 57664 KB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    int N, M, K;
    std::cin >> N >> M >> K;
    std::vector<int> C(N);
    for (auto &e : C) {
        std::cin >> e;
        --e;
    }
    std::vector<int> U(M), V(M);
    for (int i = 0; i < M; ++i) {
        std::cin >> U[i] >> V[i];
        --U[i], --V[i];
    }

    std::vector dp(N, std::vector(1 << K, 0ll));
    for (int i = 0; i < N; ++i) {
        dp[i][1 << C[i]] = 1;
    }

    for (int bit = 0; bit < (1 << K); ++bit) {
        for (int i = 0; i < M; ++i) {
            const int a = U[i], b = V[i];
            const int ca = C[a], cb = C[b];
            const bool x = bit & (1 << ca), y = bit & (1 << cb);
            if (x and not y) {
                dp[b][bit | (1 << cb)] += dp[a][bit];
            }
            if (not x and y) {
                dp[a][bit | (1 << ca)] += dp[b][bit];
            }
        }
    }

    i64 answer = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < (1 << K); ++j) {
            if (__builtin_popcount(j) > 1) {
                answer += dp[i][j];
            }
        }
    }

    std::cout << answer << std::endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 5980 KB Output is correct
2 Correct 135 ms 5064 KB Output is correct
3 Correct 311 ms 38744 KB Output is correct
4 Correct 152 ms 8172 KB Output is correct
5 Correct 145 ms 7864 KB Output is correct
6 Correct 250 ms 27864 KB Output is correct
7 Correct 315 ms 38816 KB Output is correct
8 Correct 316 ms 38872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 149 ms 5980 KB Output is correct
12 Correct 135 ms 5064 KB Output is correct
13 Correct 311 ms 38744 KB Output is correct
14 Correct 152 ms 8172 KB Output is correct
15 Correct 145 ms 7864 KB Output is correct
16 Correct 250 ms 27864 KB Output is correct
17 Correct 315 ms 38816 KB Output is correct
18 Correct 316 ms 38872 KB Output is correct
19 Correct 154 ms 5972 KB Output is correct
20 Correct 127 ms 4940 KB Output is correct
21 Correct 304 ms 38828 KB Output is correct
22 Correct 154 ms 8240 KB Output is correct
23 Correct 146 ms 7756 KB Output is correct
24 Correct 272 ms 27952 KB Output is correct
25 Correct 297 ms 38732 KB Output is correct
26 Correct 302 ms 38876 KB Output is correct
27 Correct 155 ms 5064 KB Output is correct
28 Correct 180 ms 6856 KB Output is correct
29 Correct 423 ms 57616 KB Output is correct
30 Correct 306 ms 31964 KB Output is correct
31 Correct 304 ms 31832 KB Output is correct
32 Correct 423 ms 57664 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 69 ms 1964 KB Output is correct
3 Correct 43 ms 1876 KB Output is correct
4 Correct 86 ms 12992 KB Output is correct
5 Correct 85 ms 13008 KB Output is correct
6 Correct 164 ms 31660 KB Output is correct
7 Correct 49 ms 1960 KB Output is correct
8 Correct 111 ms 19260 KB Output is correct
9 Correct 108 ms 19248 KB Output is correct
10 Correct 112 ms 19208 KB Output is correct
11 Correct 106 ms 16796 KB Output is correct
12 Correct 136 ms 24412 KB Output is correct
13 Correct 116 ms 16880 KB Output is correct
14 Correct 153 ms 31784 KB Output is correct
15 Correct 160 ms 31812 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct