답안 #670210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670210 2022-12-08T09:57:51 Z Alexandruabcde Amusement Park (CEOI19_amusementpark) C++14
100 / 100
2859 ms 1780 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int MOD = 998244353;
constexpr int INVMOD2 = 499122177;
constexpr int NMAX = 18;
constexpr int SMAX = (1<<NMAX);

int N, M;

bool edge[NMAX][NMAX];
bool good[SMAX];

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (int i = 1; i <= M; ++ i ) {
        int x, y;
        cin >> x >> y;

        --x, --y;

        edge[x][y] = true;
    }
}

vector <int> V;
void Precompute () {
    for (int mask = 0; mask < (1<<N); ++ mask ) {
        V.clear();
        for (int i = 0; i < N; ++ i )
            if ((mask&(1<<i))) V.push_back(i);

        bool ok = true;
        for (int i = 0; i < V.size(); ++ i ) {
            for (int j = 0; j < V.size(); ++ j ) {
                if (i == j) continue;

                ok &= (!edge[V[i]][V[j]]);
            }
        }

        good[mask] = ok;
    }
}

int dp[SMAX];

void Add (int &x, int y) {
    x += y;

    if (x < 0) x += MOD;
    if (x >= MOD) x -= MOD;
}

void ComputeFor (int mask, int k, int mask_take, int last_pos) {
    if (k > 0) {
        int sgn = (k % 2 == 1 ? 1 : -1);

        if (good[mask_take])
            Add(dp[mask], sgn * dp[mask^mask_take]);
    }

    if (last_pos == V.size()-1) return;

    for (int i = last_pos+1; i < V.size(); ++ i )
        ComputeFor(mask, k+1, (mask_take^(1<<V[i])), i);
}

void Solve () {
    dp[0] = 1;

    for (int mask = 1; mask < (1<<N); ++ mask ) {
        V.clear();
        for (int i = 0; i < N; ++ i )
            if ((mask&(1<<i))) V.push_back(i);

        ComputeFor(mask, 0, 0, -1);
    }

    cout << ((1LL * M * INVMOD2) % MOD * 1LL * dp[(1<<N)-1]) % MOD << '\n';
}

int main () {
    Read();
    Precompute();
    Solve();

    return 0;
}

Compilation message

amusementpark.cpp: In function 'void Precompute()':
amusementpark.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 0; i < V.size(); ++ i ) {
      |                         ~~^~~~~~~~~~
amusementpark.cpp:40:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for (int j = 0; j < V.size(); ++ j ) {
      |                             ~~^~~~~~~~~~
amusementpark.cpp: In function 'void ComputeFor(int, int, int, int)':
amusementpark.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     if (last_pos == V.size()-1) return;
      |         ~~~~~~~~~^~~~~~~~~~~~~
amusementpark.cpp:70:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (int i = last_pos+1; i < V.size(); ++ i )
      |                              ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 332 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 336 KB Output is correct
13 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 332 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 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 332 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 336 KB Output is correct
13 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 332 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 0 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 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 336 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 1 ms 212 KB Output is correct
39 Correct 1 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 1 ms 332 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 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 328 KB Output is correct
52 Correct 1 ms 328 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 328 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 332 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 336 KB Output is correct
13 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 332 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 0 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 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 336 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 1 ms 212 KB Output is correct
39 Correct 1 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 1 ms 332 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 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 328 KB Output is correct
52 Correct 1 ms 328 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 328 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 28 ms 360 KB Output is correct
66 Correct 27 ms 340 KB Output is correct
67 Correct 27 ms 376 KB Output is correct
68 Correct 27 ms 388 KB Output is correct
69 Correct 32 ms 340 KB Output is correct
70 Correct 31 ms 492 KB Output is correct
71 Correct 31 ms 332 KB Output is correct
72 Correct 32 ms 388 KB Output is correct
73 Correct 29 ms 332 KB Output is correct
74 Correct 29 ms 380 KB Output is correct
75 Correct 29 ms 396 KB Output is correct
76 Correct 30 ms 392 KB Output is correct
77 Correct 80 ms 404 KB Output is correct
78 Correct 80 ms 400 KB Output is correct
79 Correct 80 ms 448 KB Output is correct
80 Correct 77 ms 388 KB Output is correct
81 Correct 76 ms 424 KB Output is correct
82 Correct 75 ms 400 KB Output is correct
83 Correct 81 ms 596 KB Output is correct
84 Correct 74 ms 424 KB Output is correct
85 Correct 93 ms 376 KB Output is correct
86 Correct 86 ms 408 KB Output is correct
87 Correct 87 ms 464 KB Output is correct
88 Correct 94 ms 488 KB Output is correct
89 Correct 86 ms 460 KB Output is correct
90 Correct 83 ms 380 KB Output is correct
91 Correct 82 ms 440 KB Output is correct
92 Correct 84 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 332 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 336 KB Output is correct
13 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 332 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 0 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 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 336 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 1 ms 212 KB Output is correct
39 Correct 1 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 1 ms 332 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 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 328 KB Output is correct
52 Correct 1 ms 328 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 328 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 28 ms 360 KB Output is correct
66 Correct 27 ms 340 KB Output is correct
67 Correct 27 ms 376 KB Output is correct
68 Correct 27 ms 388 KB Output is correct
69 Correct 32 ms 340 KB Output is correct
70 Correct 31 ms 492 KB Output is correct
71 Correct 31 ms 332 KB Output is correct
72 Correct 32 ms 388 KB Output is correct
73 Correct 29 ms 332 KB Output is correct
74 Correct 29 ms 380 KB Output is correct
75 Correct 29 ms 396 KB Output is correct
76 Correct 30 ms 392 KB Output is correct
77 Correct 80 ms 404 KB Output is correct
78 Correct 80 ms 400 KB Output is correct
79 Correct 80 ms 448 KB Output is correct
80 Correct 77 ms 388 KB Output is correct
81 Correct 76 ms 424 KB Output is correct
82 Correct 75 ms 400 KB Output is correct
83 Correct 81 ms 596 KB Output is correct
84 Correct 74 ms 424 KB Output is correct
85 Correct 93 ms 376 KB Output is correct
86 Correct 86 ms 408 KB Output is correct
87 Correct 87 ms 464 KB Output is correct
88 Correct 94 ms 488 KB Output is correct
89 Correct 86 ms 460 KB Output is correct
90 Correct 83 ms 380 KB Output is correct
91 Correct 82 ms 440 KB Output is correct
92 Correct 84 ms 460 KB Output is correct
93 Correct 2324 ms 1508 KB Output is correct
94 Correct 2314 ms 1780 KB Output is correct
95 Correct 2361 ms 1548 KB Output is correct
96 Correct 2144 ms 1676 KB Output is correct
97 Correct 2109 ms 1472 KB Output is correct
98 Correct 2163 ms 1672 KB Output is correct
99 Correct 237 ms 572 KB Output is correct
100 Correct 227 ms 624 KB Output is correct
101 Correct 236 ms 952 KB Output is correct
102 Correct 221 ms 616 KB Output is correct
103 Correct 937 ms 908 KB Output is correct
104 Correct 775 ms 1012 KB Output is correct
105 Correct 727 ms 1180 KB Output is correct
106 Correct 666 ms 952 KB Output is correct
107 Correct 2859 ms 1692 KB Output is correct
108 Correct 2101 ms 1700 KB Output is correct
109 Correct 2011 ms 1596 KB Output is correct
110 Correct 1941 ms 1676 KB Output is correct
111 Correct 219 ms 632 KB Output is correct
112 Correct 219 ms 588 KB Output is correct
113 Correct 214 ms 600 KB Output is correct
114 Correct 272 ms 588 KB Output is correct
115 Correct 259 ms 588 KB Output is correct
116 Correct 262 ms 556 KB Output is correct
117 Correct 263 ms 564 KB Output is correct
118 Correct 238 ms 584 KB Output is correct
119 Correct 244 ms 556 KB Output is correct
120 Correct 240 ms 564 KB Output is correct
121 Correct 253 ms 588 KB Output is correct
122 Correct 651 ms 904 KB Output is correct
123 Correct 643 ms 876 KB Output is correct
124 Correct 650 ms 1016 KB Output is correct
125 Correct 647 ms 1112 KB Output is correct
126 Correct 631 ms 844 KB Output is correct
127 Correct 629 ms 948 KB Output is correct
128 Correct 621 ms 936 KB Output is correct
129 Correct 666 ms 936 KB Output is correct
130 Correct 626 ms 904 KB Output is correct
131 Correct 848 ms 960 KB Output is correct
132 Correct 756 ms 884 KB Output is correct
133 Correct 841 ms 944 KB Output is correct
134 Correct 790 ms 892 KB Output is correct
135 Correct 709 ms 1176 KB Output is correct
136 Correct 745 ms 932 KB Output is correct
137 Correct 733 ms 972 KB Output is correct
138 Correct 741 ms 1104 KB Output is correct
139 Correct 676 ms 948 KB Output is correct
140 Correct 667 ms 912 KB Output is correct
141 Correct 704 ms 1048 KB Output is correct
142 Correct 1902 ms 1456 KB Output is correct
143 Correct 1907 ms 1560 KB Output is correct
144 Correct 1859 ms 1540 KB Output is correct
145 Correct 1844 ms 1708 KB Output is correct
146 Correct 1849 ms 1484 KB Output is correct
147 Correct 1846 ms 1608 KB Output is correct
148 Correct 1913 ms 1500 KB Output is correct
149 Correct 1887 ms 1568 KB Output is correct
150 Correct 1917 ms 1544 KB Output is correct
151 Correct 1966 ms 1524 KB Output is correct
152 Correct 1950 ms 1496 KB Output is correct
153 Correct 2152 ms 1540 KB Output is correct
154 Correct 2220 ms 1684 KB Output is correct
155 Correct 2357 ms 1548 KB Output is correct
156 Correct 2397 ms 1504 KB Output is correct
157 Correct 2268 ms 1584 KB Output is correct
158 Correct 2235 ms 1584 KB Output is correct
159 Correct 2033 ms 1712 KB Output is correct
160 Correct 2189 ms 1592 KB Output is correct
161 Correct 2115 ms 1680 KB Output is correct
162 Correct 1960 ms 1484 KB Output is correct
163 Correct 2114 ms 1584 KB Output is correct
164 Correct 1993 ms 1544 KB Output is correct
165 Correct 1996 ms 1564 KB Output is correct
166 Correct 2012 ms 1572 KB Output is correct
167 Correct 2029 ms 1484 KB Output is correct