Submission #470055

# Submission time Handle Problem Language Result Execution time Memory
470055 2021-09-02T19:14:09 Z flashmt Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2675 ms 2380 KB
#include <bits/stdc++.h>
using namespace std;
const int BASE = 998244353;

long long power(int x, int y)
{
  if (!y)
    return 1;
  long long res = power(x, y / 2);
  res = res * res % BASE;
  if (y % 2)
    res = res * x % BASE;
  return res;
}

int main()
{
  int n, m, x, y, a[18][18] = {0};
  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    cin >> x >> y;
    --x;
    --y;
    a[x][y] = a[y][x] = 1;
  }

  int hasEdge[1 << 18] = {0};
  for (int mask = 0; mask < 1 << n; mask++)
    for (int i = 0; i < n; i++)
      if (mask >> i & 1)
        for (int j = i + 1; j < n; j++)
          if ((mask >> j & 1) && a[i][j])
            hasEdge[mask] = 1;

  int f[1 << 18] = {0};
  f[0] = 1;
  for (int mask = 1; mask < 1 << n; mask++)
    for (int submask = mask; submask; submask = (submask - 1) & mask)
      if (!hasEdge[submask])
      {
        if (__builtin_popcount(submask) % 2)
        {
          f[mask] += f[mask ^ submask];
          if (f[mask] >= BASE)
            f[mask] -= BASE;
        }
        else
        {
          f[mask] -= f[mask ^ submask];
          if (f[mask] < 0)
            f[mask] += BASE;
        }
      }

  cout << 1LL * f[(1 << n) - 1] * m % BASE * power(2, BASE - 2) % BASE << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 1 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 1 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 1 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 1 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 1 ms 2252 KB Output is correct
10 Correct 1 ms 2252 KB Output is correct
11 Correct 1 ms 2340 KB Output is correct
12 Correct 1 ms 2252 KB Output is correct
13 Correct 2 ms 2252 KB Output is correct
14 Correct 1 ms 2252 KB Output is correct
15 Correct 1 ms 2252 KB Output is correct
16 Correct 2 ms 2252 KB Output is correct
17 Correct 2 ms 2340 KB Output is correct
18 Correct 2 ms 2252 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 2 ms 2252 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 1 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 1 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 1 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 1 ms 2252 KB Output is correct
10 Correct 1 ms 2252 KB Output is correct
11 Correct 1 ms 2340 KB Output is correct
12 Correct 1 ms 2252 KB Output is correct
13 Correct 2 ms 2252 KB Output is correct
14 Correct 1 ms 2252 KB Output is correct
15 Correct 1 ms 2252 KB Output is correct
16 Correct 2 ms 2252 KB Output is correct
17 Correct 2 ms 2340 KB Output is correct
18 Correct 2 ms 2252 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 2 ms 2252 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 1 ms 2252 KB Output is correct
25 Correct 2 ms 2268 KB Output is correct
26 Correct 2 ms 2252 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 2 ms 2252 KB Output is correct
29 Correct 2 ms 2252 KB Output is correct
30 Correct 2 ms 2228 KB Output is correct
31 Correct 2 ms 2252 KB Output is correct
32 Correct 2 ms 2252 KB Output is correct
33 Correct 2 ms 2252 KB Output is correct
34 Correct 2 ms 2252 KB Output is correct
35 Correct 2 ms 2340 KB Output is correct
36 Correct 2 ms 2280 KB Output is correct
37 Correct 2 ms 2340 KB Output is correct
38 Correct 2 ms 2252 KB Output is correct
39 Correct 2 ms 2252 KB Output is correct
40 Correct 2 ms 2252 KB Output is correct
41 Correct 2 ms 2252 KB Output is correct
42 Correct 2 ms 2340 KB Output is correct
43 Correct 2 ms 2252 KB Output is correct
44 Correct 2 ms 2252 KB Output is correct
45 Correct 2 ms 2252 KB Output is correct
46 Correct 2 ms 2252 KB Output is correct
47 Correct 2 ms 2252 KB Output is correct
48 Correct 2 ms 2252 KB Output is correct
49 Correct 2 ms 2252 KB Output is correct
50 Correct 2 ms 2252 KB Output is correct
51 Correct 2 ms 2252 KB Output is correct
52 Correct 2 ms 2252 KB Output is correct
53 Correct 2 ms 2252 KB Output is correct
54 Correct 2 ms 2252 KB Output is correct
55 Correct 2 ms 2292 KB Output is correct
56 Correct 2 ms 2336 KB Output is correct
57 Correct 2 ms 2252 KB Output is correct
58 Correct 2 ms 2336 KB Output is correct
59 Correct 2 ms 2252 KB Output is correct
60 Correct 2 ms 2252 KB Output is correct
61 Correct 3 ms 2252 KB Output is correct
62 Correct 2 ms 2328 KB Output is correct
63 Correct 2 ms 2252 KB Output is correct
64 Correct 2 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 1 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 1 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 1 ms 2252 KB Output is correct
10 Correct 1 ms 2252 KB Output is correct
11 Correct 1 ms 2340 KB Output is correct
12 Correct 1 ms 2252 KB Output is correct
13 Correct 2 ms 2252 KB Output is correct
14 Correct 1 ms 2252 KB Output is correct
15 Correct 1 ms 2252 KB Output is correct
16 Correct 2 ms 2252 KB Output is correct
17 Correct 2 ms 2340 KB Output is correct
18 Correct 2 ms 2252 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 2 ms 2252 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 1 ms 2252 KB Output is correct
25 Correct 2 ms 2268 KB Output is correct
26 Correct 2 ms 2252 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 2 ms 2252 KB Output is correct
29 Correct 2 ms 2252 KB Output is correct
30 Correct 2 ms 2228 KB Output is correct
31 Correct 2 ms 2252 KB Output is correct
32 Correct 2 ms 2252 KB Output is correct
33 Correct 2 ms 2252 KB Output is correct
34 Correct 2 ms 2252 KB Output is correct
35 Correct 2 ms 2340 KB Output is correct
36 Correct 2 ms 2280 KB Output is correct
37 Correct 2 ms 2340 KB Output is correct
38 Correct 2 ms 2252 KB Output is correct
39 Correct 2 ms 2252 KB Output is correct
40 Correct 2 ms 2252 KB Output is correct
41 Correct 2 ms 2252 KB Output is correct
42 Correct 2 ms 2340 KB Output is correct
43 Correct 2 ms 2252 KB Output is correct
44 Correct 2 ms 2252 KB Output is correct
45 Correct 2 ms 2252 KB Output is correct
46 Correct 2 ms 2252 KB Output is correct
47 Correct 2 ms 2252 KB Output is correct
48 Correct 2 ms 2252 KB Output is correct
49 Correct 2 ms 2252 KB Output is correct
50 Correct 2 ms 2252 KB Output is correct
51 Correct 2 ms 2252 KB Output is correct
52 Correct 2 ms 2252 KB Output is correct
53 Correct 2 ms 2252 KB Output is correct
54 Correct 2 ms 2252 KB Output is correct
55 Correct 2 ms 2292 KB Output is correct
56 Correct 2 ms 2336 KB Output is correct
57 Correct 2 ms 2252 KB Output is correct
58 Correct 2 ms 2336 KB Output is correct
59 Correct 2 ms 2252 KB Output is correct
60 Correct 2 ms 2252 KB Output is correct
61 Correct 3 ms 2252 KB Output is correct
62 Correct 2 ms 2328 KB Output is correct
63 Correct 2 ms 2252 KB Output is correct
64 Correct 2 ms 2252 KB Output is correct
65 Correct 16 ms 2340 KB Output is correct
66 Correct 15 ms 2380 KB Output is correct
67 Correct 13 ms 2252 KB Output is correct
68 Correct 14 ms 2340 KB Output is correct
69 Correct 28 ms 2344 KB Output is correct
70 Correct 22 ms 2344 KB Output is correct
71 Correct 22 ms 2344 KB Output is correct
72 Correct 20 ms 2336 KB Output is correct
73 Correct 18 ms 2344 KB Output is correct
74 Correct 18 ms 2340 KB Output is correct
75 Correct 20 ms 2336 KB Output is correct
76 Correct 17 ms 2252 KB Output is correct
77 Correct 46 ms 2252 KB Output is correct
78 Correct 40 ms 2320 KB Output is correct
79 Correct 39 ms 2324 KB Output is correct
80 Correct 36 ms 2252 KB Output is correct
81 Correct 33 ms 2252 KB Output is correct
82 Correct 34 ms 2252 KB Output is correct
83 Correct 33 ms 2252 KB Output is correct
84 Correct 29 ms 2324 KB Output is correct
85 Correct 93 ms 2320 KB Output is correct
86 Correct 69 ms 2252 KB Output is correct
87 Correct 60 ms 2328 KB Output is correct
88 Correct 56 ms 2252 KB Output is correct
89 Correct 52 ms 2252 KB Output is correct
90 Correct 47 ms 2332 KB Output is correct
91 Correct 46 ms 2252 KB Output is correct
92 Correct 46 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 1 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 1 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 1 ms 2252 KB Output is correct
10 Correct 1 ms 2252 KB Output is correct
11 Correct 1 ms 2340 KB Output is correct
12 Correct 1 ms 2252 KB Output is correct
13 Correct 2 ms 2252 KB Output is correct
14 Correct 1 ms 2252 KB Output is correct
15 Correct 1 ms 2252 KB Output is correct
16 Correct 2 ms 2252 KB Output is correct
17 Correct 2 ms 2340 KB Output is correct
18 Correct 2 ms 2252 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 1 ms 2252 KB Output is correct
21 Correct 2 ms 2252 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 1 ms 2252 KB Output is correct
25 Correct 2 ms 2268 KB Output is correct
26 Correct 2 ms 2252 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 2 ms 2252 KB Output is correct
29 Correct 2 ms 2252 KB Output is correct
30 Correct 2 ms 2228 KB Output is correct
31 Correct 2 ms 2252 KB Output is correct
32 Correct 2 ms 2252 KB Output is correct
33 Correct 2 ms 2252 KB Output is correct
34 Correct 2 ms 2252 KB Output is correct
35 Correct 2 ms 2340 KB Output is correct
36 Correct 2 ms 2280 KB Output is correct
37 Correct 2 ms 2340 KB Output is correct
38 Correct 2 ms 2252 KB Output is correct
39 Correct 2 ms 2252 KB Output is correct
40 Correct 2 ms 2252 KB Output is correct
41 Correct 2 ms 2252 KB Output is correct
42 Correct 2 ms 2340 KB Output is correct
43 Correct 2 ms 2252 KB Output is correct
44 Correct 2 ms 2252 KB Output is correct
45 Correct 2 ms 2252 KB Output is correct
46 Correct 2 ms 2252 KB Output is correct
47 Correct 2 ms 2252 KB Output is correct
48 Correct 2 ms 2252 KB Output is correct
49 Correct 2 ms 2252 KB Output is correct
50 Correct 2 ms 2252 KB Output is correct
51 Correct 2 ms 2252 KB Output is correct
52 Correct 2 ms 2252 KB Output is correct
53 Correct 2 ms 2252 KB Output is correct
54 Correct 2 ms 2252 KB Output is correct
55 Correct 2 ms 2292 KB Output is correct
56 Correct 2 ms 2336 KB Output is correct
57 Correct 2 ms 2252 KB Output is correct
58 Correct 2 ms 2336 KB Output is correct
59 Correct 2 ms 2252 KB Output is correct
60 Correct 2 ms 2252 KB Output is correct
61 Correct 3 ms 2252 KB Output is correct
62 Correct 2 ms 2328 KB Output is correct
63 Correct 2 ms 2252 KB Output is correct
64 Correct 2 ms 2252 KB Output is correct
65 Correct 16 ms 2340 KB Output is correct
66 Correct 15 ms 2380 KB Output is correct
67 Correct 13 ms 2252 KB Output is correct
68 Correct 14 ms 2340 KB Output is correct
69 Correct 28 ms 2344 KB Output is correct
70 Correct 22 ms 2344 KB Output is correct
71 Correct 22 ms 2344 KB Output is correct
72 Correct 20 ms 2336 KB Output is correct
73 Correct 18 ms 2344 KB Output is correct
74 Correct 18 ms 2340 KB Output is correct
75 Correct 20 ms 2336 KB Output is correct
76 Correct 17 ms 2252 KB Output is correct
77 Correct 46 ms 2252 KB Output is correct
78 Correct 40 ms 2320 KB Output is correct
79 Correct 39 ms 2324 KB Output is correct
80 Correct 36 ms 2252 KB Output is correct
81 Correct 33 ms 2252 KB Output is correct
82 Correct 34 ms 2252 KB Output is correct
83 Correct 33 ms 2252 KB Output is correct
84 Correct 29 ms 2324 KB Output is correct
85 Correct 93 ms 2320 KB Output is correct
86 Correct 69 ms 2252 KB Output is correct
87 Correct 60 ms 2328 KB Output is correct
88 Correct 56 ms 2252 KB Output is correct
89 Correct 52 ms 2252 KB Output is correct
90 Correct 47 ms 2332 KB Output is correct
91 Correct 46 ms 2252 KB Output is correct
92 Correct 46 ms 2324 KB Output is correct
93 Correct 1580 ms 2324 KB Output is correct
94 Correct 1626 ms 2320 KB Output is correct
95 Correct 1598 ms 2320 KB Output is correct
96 Correct 1279 ms 2316 KB Output is correct
97 Correct 1065 ms 2320 KB Output is correct
98 Correct 1226 ms 2320 KB Output is correct
99 Correct 132 ms 2320 KB Output is correct
100 Correct 107 ms 2332 KB Output is correct
101 Correct 102 ms 2252 KB Output is correct
102 Correct 91 ms 2320 KB Output is correct
103 Correct 884 ms 2320 KB Output is correct
104 Correct 496 ms 2252 KB Output is correct
105 Correct 424 ms 2316 KB Output is correct
106 Correct 334 ms 2324 KB Output is correct
107 Correct 2675 ms 2316 KB Output is correct
108 Correct 1145 ms 2320 KB Output is correct
109 Correct 871 ms 2324 KB Output is correct
110 Correct 727 ms 2328 KB Output is correct
111 Correct 98 ms 2252 KB Output is correct
112 Correct 77 ms 2320 KB Output is correct
113 Correct 76 ms 2252 KB Output is correct
114 Correct 232 ms 2252 KB Output is correct
115 Correct 173 ms 2372 KB Output is correct
116 Correct 168 ms 2320 KB Output is correct
117 Correct 164 ms 2320 KB Output is correct
118 Correct 141 ms 2316 KB Output is correct
119 Correct 135 ms 2252 KB Output is correct
120 Correct 129 ms 2372 KB Output is correct
121 Correct 128 ms 2252 KB Output is correct
122 Correct 280 ms 2252 KB Output is correct
123 Correct 234 ms 2252 KB Output is correct
124 Correct 220 ms 2320 KB Output is correct
125 Correct 223 ms 2332 KB Output is correct
126 Correct 211 ms 2320 KB Output is correct
127 Correct 193 ms 2336 KB Output is correct
128 Correct 171 ms 2252 KB Output is correct
129 Correct 200 ms 2252 KB Output is correct
130 Correct 156 ms 2252 KB Output is correct
131 Correct 675 ms 2324 KB Output is correct
132 Correct 527 ms 2320 KB Output is correct
133 Correct 507 ms 2332 KB Output is correct
134 Correct 478 ms 2320 KB Output is correct
135 Correct 426 ms 2372 KB Output is correct
136 Correct 417 ms 2320 KB Output is correct
137 Correct 384 ms 2320 KB Output is correct
138 Correct 364 ms 2252 KB Output is correct
139 Correct 340 ms 2324 KB Output is correct
140 Correct 339 ms 2324 KB Output is correct
141 Correct 294 ms 2320 KB Output is correct
142 Correct 645 ms 2324 KB Output is correct
143 Correct 646 ms 2252 KB Output is correct
144 Correct 559 ms 2316 KB Output is correct
145 Correct 512 ms 2320 KB Output is correct
146 Correct 492 ms 2324 KB Output is correct
147 Correct 454 ms 2252 KB Output is correct
148 Correct 679 ms 2372 KB Output is correct
149 Correct 623 ms 2324 KB Output is correct
150 Correct 604 ms 2320 KB Output is correct
151 Correct 795 ms 2320 KB Output is correct
152 Correct 787 ms 2372 KB Output is correct
153 Correct 1286 ms 2320 KB Output is correct
154 Correct 1233 ms 2320 KB Output is correct
155 Correct 1127 ms 2320 KB Output is correct
156 Correct 1124 ms 2324 KB Output is correct
157 Correct 1188 ms 2320 KB Output is correct
158 Correct 1160 ms 2328 KB Output is correct
159 Correct 1082 ms 2320 KB Output is correct
160 Correct 999 ms 2320 KB Output is correct
161 Correct 887 ms 2332 KB Output is correct
162 Correct 878 ms 2320 KB Output is correct
163 Correct 849 ms 2320 KB Output is correct
164 Correct 796 ms 2316 KB Output is correct
165 Correct 770 ms 2252 KB Output is correct
166 Correct 754 ms 2320 KB Output is correct
167 Correct 735 ms 2320 KB Output is correct