Submission #666472

# Submission time Handle Problem Language Result Execution time Memory
666472 2022-11-28T16:53:58 Z finn__ Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 2260 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 998244353

int main()
{
    int64_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) %
                        MOD;
            }
        }
    }

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

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:12:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   12 |     for (size_t i = 0; i < m; i++)
      |                        ~~^~~
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++)
      |                              ~~^~~~~~~~
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 276 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 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 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 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 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 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 212 KB Output is correct
49 Correct 2 ms 212 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 5 ms 212 KB Output is correct
53 Correct 4 ms 212 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 212 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 212 KB Output is correct
63 Correct 4 ms 212 KB Output is correct
64 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 276 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 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 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 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 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 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 212 KB Output is correct
49 Correct 2 ms 212 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 5 ms 212 KB Output is correct
53 Correct 4 ms 212 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 212 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 212 KB Output is correct
63 Correct 4 ms 212 KB Output is correct
64 Correct 4 ms 212 KB Output is correct
65 Correct 226 ms 420 KB Output is correct
66 Correct 194 ms 420 KB Output is correct
67 Correct 172 ms 416 KB Output is correct
68 Correct 137 ms 340 KB Output is correct
69 Correct 716 ms 424 KB Output is correct
70 Correct 477 ms 420 KB Output is correct
71 Correct 506 ms 424 KB Output is correct
72 Correct 548 ms 424 KB Output is correct
73 Correct 306 ms 416 KB Output is correct
74 Correct 339 ms 420 KB Output is correct
75 Correct 374 ms 416 KB Output is correct
76 Correct 417 ms 416 KB Output is correct
77 Correct 848 ms 548 KB Output is correct
78 Correct 723 ms 544 KB Output is correct
79 Correct 516 ms 544 KB Output is correct
80 Correct 503 ms 552 KB Output is correct
81 Correct 413 ms 468 KB Output is correct
82 Correct 381 ms 548 KB Output is correct
83 Correct 352 ms 548 KB Output is correct
84 Correct 298 ms 556 KB Output is correct
85 Correct 2426 ms 552 KB Output is correct
86 Correct 1606 ms 588 KB Output is correct
87 Correct 1669 ms 552 KB Output is correct
88 Correct 1835 ms 588 KB Output is correct
89 Correct 1016 ms 548 KB Output is correct
90 Correct 1113 ms 468 KB Output is correct
91 Correct 1280 ms 552 KB Output is correct
92 Correct 1400 ms 552 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 276 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 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 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 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 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 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 212 KB Output is correct
49 Correct 2 ms 212 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 5 ms 212 KB Output is correct
53 Correct 4 ms 212 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 212 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 212 KB Output is correct
63 Correct 4 ms 212 KB Output is correct
64 Correct 4 ms 212 KB Output is correct
65 Correct 226 ms 420 KB Output is correct
66 Correct 194 ms 420 KB Output is correct
67 Correct 172 ms 416 KB Output is correct
68 Correct 137 ms 340 KB Output is correct
69 Correct 716 ms 424 KB Output is correct
70 Correct 477 ms 420 KB Output is correct
71 Correct 506 ms 424 KB Output is correct
72 Correct 548 ms 424 KB Output is correct
73 Correct 306 ms 416 KB Output is correct
74 Correct 339 ms 420 KB Output is correct
75 Correct 374 ms 416 KB Output is correct
76 Correct 417 ms 416 KB Output is correct
77 Correct 848 ms 548 KB Output is correct
78 Correct 723 ms 544 KB Output is correct
79 Correct 516 ms 544 KB Output is correct
80 Correct 503 ms 552 KB Output is correct
81 Correct 413 ms 468 KB Output is correct
82 Correct 381 ms 548 KB Output is correct
83 Correct 352 ms 548 KB Output is correct
84 Correct 298 ms 556 KB Output is correct
85 Correct 2426 ms 552 KB Output is correct
86 Correct 1606 ms 588 KB Output is correct
87 Correct 1669 ms 552 KB Output is correct
88 Correct 1835 ms 588 KB Output is correct
89 Correct 1016 ms 548 KB Output is correct
90 Correct 1113 ms 468 KB Output is correct
91 Correct 1280 ms 552 KB Output is correct
92 Correct 1400 ms 552 KB Output is correct
93 Execution timed out 3065 ms 2260 KB Time limit exceeded
94 Halted 0 ms 0 KB -