답안 #666471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666471 2022-11-28T16:52:02 Z finn__ Amusement Park (CEOI19_amusementpark) C++17
42 / 100
861 ms 588 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 998244353

int main()
{
    size_t n, m;
    cin >> n >> m;

    vector<vector<bool>> g(n, vector<bool>(n, 0));
    for (size_t i = 0; i < m; i++)
    {
        unsigned u, v;
        cin >> u >> v;
        g[u - 1][v - 1] = 1;
    }

    vector<int64_t> dp(1 << n, 0);
    dp[0] = 1;

    for (unsigned i = 1; i < 1 << n; i++)
    {
        unsigned const p = __builtin_popcount(i);
        vector<unsigned> s;
        for (unsigned k = 0; k < n; k++)
            if (i & (1 << k))
                s.push_back(k);

        for (unsigned j = 0; j < 1 << p; j++)
        {
            bool is_independent = 1;

            for (unsigned k = 0; k < p && is_independent; k++)
                if (j & (1 << k))
                    for (unsigned h = 0; h < p && is_independent; h++)
                        if (j & (1 << h))
                            if (g[s[k]][s[h]] || g[s[h]][s[k]])
                                is_independent = 0;

            if (is_independent)
            {
                unsigned t = 0;
                for (unsigned k = 0; k < p; k++)
                    if (j & (1 << k))
                        t ^= (1 << s[k]);

                dp[i] = (dp[i] +
                         ((__builtin_popcount(t) & 1) ? 1 : -1) * dp[i ^ t]) %
                        MOD;
            }
        }
    }

    cout << (((dp[(1 << n) - 1] * m) % MOD) * 499122177) % MOD << '\n';
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:22:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   22 |     for (unsigned i = 1; i < 1 << n; i++)
      |                          ~~^~~~~~~~
amusementpark.cpp:30:32: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   30 |         for (unsigned j = 0; j < 1 << p; j++)
      |                              ~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 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 2 ms 212 KB Output is correct
40 Correct 2 ms 212 KB Output is correct
41 Correct 2 ms 304 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 300 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 296 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 2 ms 300 KB Output is correct
49 Correct 2 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 2 ms 212 KB Output is correct
52 Correct 5 ms 212 KB Output is correct
53 Correct 4 ms 300 KB Output is correct
54 Correct 4 ms 212 KB Output is correct
55 Correct 3 ms 212 KB Output is correct
56 Correct 2 ms 212 KB Output is correct
57 Correct 2 ms 212 KB Output is correct
58 Correct 2 ms 300 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 2 ms 212 KB Output is correct
61 Correct 6 ms 212 KB Output is correct
62 Correct 4 ms 296 KB Output is correct
63 Correct 5 ms 212 KB Output is correct
64 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 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 2 ms 212 KB Output is correct
40 Correct 2 ms 212 KB Output is correct
41 Correct 2 ms 304 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 300 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 296 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 2 ms 300 KB Output is correct
49 Correct 2 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 2 ms 212 KB Output is correct
52 Correct 5 ms 212 KB Output is correct
53 Correct 4 ms 300 KB Output is correct
54 Correct 4 ms 212 KB Output is correct
55 Correct 3 ms 212 KB Output is correct
56 Correct 2 ms 212 KB Output is correct
57 Correct 2 ms 212 KB Output is correct
58 Correct 2 ms 300 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 2 ms 212 KB Output is correct
61 Correct 6 ms 212 KB Output is correct
62 Correct 4 ms 296 KB Output is correct
63 Correct 5 ms 212 KB Output is correct
64 Correct 4 ms 212 KB Output is correct
65 Correct 242 ms 424 KB Output is correct
66 Correct 183 ms 340 KB Output is correct
67 Correct 173 ms 424 KB Output is correct
68 Correct 126 ms 424 KB Output is correct
69 Correct 723 ms 428 KB Output is correct
70 Correct 489 ms 460 KB Output is correct
71 Correct 499 ms 340 KB Output is correct
72 Correct 550 ms 424 KB Output is correct
73 Correct 325 ms 460 KB Output is correct
74 Correct 331 ms 428 KB Output is correct
75 Correct 383 ms 424 KB Output is correct
76 Correct 413 ms 428 KB Output is correct
77 Correct 861 ms 552 KB Output is correct
78 Correct 721 ms 588 KB Output is correct
79 Correct 515 ms 556 KB Output is correct
80 Correct 508 ms 588 KB Output is correct
81 Incorrect 433 ms 552 KB Output isn't correct
82 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 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 2 ms 212 KB Output is correct
40 Correct 2 ms 212 KB Output is correct
41 Correct 2 ms 304 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 300 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 296 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 2 ms 300 KB Output is correct
49 Correct 2 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 2 ms 212 KB Output is correct
52 Correct 5 ms 212 KB Output is correct
53 Correct 4 ms 300 KB Output is correct
54 Correct 4 ms 212 KB Output is correct
55 Correct 3 ms 212 KB Output is correct
56 Correct 2 ms 212 KB Output is correct
57 Correct 2 ms 212 KB Output is correct
58 Correct 2 ms 300 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 2 ms 212 KB Output is correct
61 Correct 6 ms 212 KB Output is correct
62 Correct 4 ms 296 KB Output is correct
63 Correct 5 ms 212 KB Output is correct
64 Correct 4 ms 212 KB Output is correct
65 Correct 242 ms 424 KB Output is correct
66 Correct 183 ms 340 KB Output is correct
67 Correct 173 ms 424 KB Output is correct
68 Correct 126 ms 424 KB Output is correct
69 Correct 723 ms 428 KB Output is correct
70 Correct 489 ms 460 KB Output is correct
71 Correct 499 ms 340 KB Output is correct
72 Correct 550 ms 424 KB Output is correct
73 Correct 325 ms 460 KB Output is correct
74 Correct 331 ms 428 KB Output is correct
75 Correct 383 ms 424 KB Output is correct
76 Correct 413 ms 428 KB Output is correct
77 Correct 861 ms 552 KB Output is correct
78 Correct 721 ms 588 KB Output is correct
79 Correct 515 ms 556 KB Output is correct
80 Correct 508 ms 588 KB Output is correct
81 Incorrect 433 ms 552 KB Output isn't correct
82 Halted 0 ms 0 KB -