답안 #971073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971073 2024-04-27T22:16:52 Z imann Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1472 ms 9012 KB
#include <iostream>
#include <array>
#include <algorithm>

using ll = long long;

const int MAX_N = 18 + 1;
const ll MOD = 998244353;

std::array<std::array<bool, MAX_N>, MAX_N> graph;
std::array<ll, (1 << MAX_N)> dp, sSize;
std::array<bool, (1 << MAX_N)> sInd;

ll solve(int n) {
  sInd.fill(true);
  for (int s = 0; s < (1 << n); ++s) {
    int c = 0;
    for (int i = 0; i < n; ++i) {
      if (s & (1 << i)) {
        for (int j = 0; j < n; ++j) {
          if (s & (1 << j)) {
            if (graph[i][j]) {
              sInd[s] = false;
            }
          }
        }
        c++;
      }
    }
    sSize[s] = c;
  }

  dp[0] = 1;
  for (int s = 1; s < (1 << n); ++s) {
    std::vector<int> ones;
    for (int i = 0; i < n; ++i) {
      if ((1 << i) & s) {
        ones.push_back(i);
      }
    }

    std::vector<int> sss(1 << ones.size());
    sss[0] = 0;
    for (int i = 0; i < ones.size(); ++i) {
      for (int j = 0; j < (1 << i); ++j) {
        sss[(1 << i) + j] = sss[j] + (1 << ones[i]);
      }
    }

    for (int i = 1; i < (1 << ones.size()); ++i) {
      int ss = sss[i];
      if (sInd[ss]) {
        if ((sSize[ss] % 2) == 1) {
          dp[s] = (dp[s] + dp[s - ss]);
        } else {
          dp[s] = (dp[s] - dp[s - ss]);
        }
      }
    }
  }

  return dp[(1 << n) - 1];
}

int main() {
  int n, m; std::cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b; std::cin >> a >> b; a--; b--;
    graph[a][b] = true;
    graph[b][a] = true;
  }
  std::cout << (m * solve(n) / 2) % MOD << std::endl;
}

Compilation message

amusementpark.cpp: In function 'll solve(int)':
amusementpark.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 0; i < ones.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4536 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4536 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4536 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4696 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4536 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4948 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4696 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4544 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 4700 KB Output is correct
52 Correct 1 ms 4700 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 2 ms 4700 KB Output is correct
57 Correct 2 ms 4700 KB Output is correct
58 Correct 1 ms 4700 KB Output is correct
59 Correct 2 ms 4700 KB Output is correct
60 Correct 2 ms 4700 KB Output is correct
61 Correct 1 ms 4700 KB Output is correct
62 Correct 1 ms 4700 KB Output is correct
63 Correct 2 ms 4704 KB Output is correct
64 Correct 1 ms 4704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4536 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4696 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4536 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4948 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4696 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4544 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 4700 KB Output is correct
52 Correct 1 ms 4700 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 2 ms 4700 KB Output is correct
57 Correct 2 ms 4700 KB Output is correct
58 Correct 1 ms 4700 KB Output is correct
59 Correct 2 ms 4700 KB Output is correct
60 Correct 2 ms 4700 KB Output is correct
61 Correct 1 ms 4700 KB Output is correct
62 Correct 1 ms 4700 KB Output is correct
63 Correct 2 ms 4704 KB Output is correct
64 Correct 1 ms 4704 KB Output is correct
65 Correct 20 ms 4700 KB Output is correct
66 Correct 21 ms 4704 KB Output is correct
67 Correct 20 ms 4700 KB Output is correct
68 Correct 20 ms 4704 KB Output is correct
69 Correct 19 ms 4708 KB Output is correct
70 Correct 18 ms 4700 KB Output is correct
71 Correct 18 ms 4704 KB Output is correct
72 Correct 18 ms 4704 KB Output is correct
73 Correct 17 ms 4704 KB Output is correct
74 Correct 18 ms 4704 KB Output is correct
75 Correct 17 ms 4700 KB Output is correct
76 Correct 18 ms 4708 KB Output is correct
77 Correct 51 ms 4728 KB Output is correct
78 Correct 54 ms 4792 KB Output is correct
79 Correct 51 ms 4708 KB Output is correct
80 Correct 51 ms 4748 KB Output is correct
81 Correct 51 ms 4724 KB Output is correct
82 Correct 48 ms 4764 KB Output is correct
83 Correct 46 ms 4700 KB Output is correct
84 Correct 46 ms 4696 KB Output is correct
85 Correct 51 ms 4696 KB Output is correct
86 Correct 46 ms 4696 KB Output is correct
87 Correct 45 ms 4720 KB Output is correct
88 Correct 45 ms 4700 KB Output is correct
89 Correct 44 ms 4700 KB Output is correct
90 Correct 44 ms 4696 KB Output is correct
91 Correct 44 ms 4700 KB Output is correct
92 Correct 44 ms 4720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4536 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4540 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4696 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4536 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4948 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4696 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4544 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 4700 KB Output is correct
52 Correct 1 ms 4700 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 2 ms 4700 KB Output is correct
57 Correct 2 ms 4700 KB Output is correct
58 Correct 1 ms 4700 KB Output is correct
59 Correct 2 ms 4700 KB Output is correct
60 Correct 2 ms 4700 KB Output is correct
61 Correct 1 ms 4700 KB Output is correct
62 Correct 1 ms 4700 KB Output is correct
63 Correct 2 ms 4704 KB Output is correct
64 Correct 1 ms 4704 KB Output is correct
65 Correct 20 ms 4700 KB Output is correct
66 Correct 21 ms 4704 KB Output is correct
67 Correct 20 ms 4700 KB Output is correct
68 Correct 20 ms 4704 KB Output is correct
69 Correct 19 ms 4708 KB Output is correct
70 Correct 18 ms 4700 KB Output is correct
71 Correct 18 ms 4704 KB Output is correct
72 Correct 18 ms 4704 KB Output is correct
73 Correct 17 ms 4704 KB Output is correct
74 Correct 18 ms 4704 KB Output is correct
75 Correct 17 ms 4700 KB Output is correct
76 Correct 18 ms 4708 KB Output is correct
77 Correct 51 ms 4728 KB Output is correct
78 Correct 54 ms 4792 KB Output is correct
79 Correct 51 ms 4708 KB Output is correct
80 Correct 51 ms 4748 KB Output is correct
81 Correct 51 ms 4724 KB Output is correct
82 Correct 48 ms 4764 KB Output is correct
83 Correct 46 ms 4700 KB Output is correct
84 Correct 46 ms 4696 KB Output is correct
85 Correct 51 ms 4696 KB Output is correct
86 Correct 46 ms 4696 KB Output is correct
87 Correct 45 ms 4720 KB Output is correct
88 Correct 45 ms 4700 KB Output is correct
89 Correct 44 ms 4700 KB Output is correct
90 Correct 44 ms 4696 KB Output is correct
91 Correct 44 ms 4700 KB Output is correct
92 Correct 44 ms 4720 KB Output is correct
93 Correct 1039 ms 8760 KB Output is correct
94 Correct 1033 ms 8552 KB Output is correct
95 Correct 1053 ms 8548 KB Output is correct
96 Correct 941 ms 8640 KB Output is correct
97 Correct 930 ms 8528 KB Output is correct
98 Correct 971 ms 8624 KB Output is correct
99 Correct 136 ms 4972 KB Output is correct
100 Correct 129 ms 4948 KB Output is correct
101 Correct 131 ms 4944 KB Output is correct
102 Correct 125 ms 5028 KB Output is correct
103 Correct 538 ms 5440 KB Output is correct
104 Correct 394 ms 5476 KB Output is correct
105 Correct 355 ms 5608 KB Output is correct
106 Correct 347 ms 5348 KB Output is correct
107 Correct 1472 ms 8664 KB Output is correct
108 Correct 984 ms 8504 KB Output is correct
109 Correct 909 ms 8488 KB Output is correct
110 Correct 905 ms 8532 KB Output is correct
111 Correct 126 ms 4948 KB Output is correct
112 Correct 120 ms 4968 KB Output is correct
113 Correct 121 ms 5092 KB Output is correct
114 Correct 140 ms 5200 KB Output is correct
115 Correct 128 ms 4944 KB Output is correct
116 Correct 126 ms 4944 KB Output is correct
117 Correct 119 ms 4944 KB Output is correct
118 Correct 118 ms 5096 KB Output is correct
119 Correct 115 ms 4972 KB Output is correct
120 Correct 118 ms 5000 KB Output is correct
121 Correct 113 ms 5088 KB Output is correct
122 Correct 342 ms 5452 KB Output is correct
123 Correct 320 ms 5440 KB Output is correct
124 Correct 313 ms 5448 KB Output is correct
125 Correct 308 ms 5444 KB Output is correct
126 Correct 303 ms 5348 KB Output is correct
127 Correct 289 ms 5464 KB Output is correct
128 Correct 285 ms 5476 KB Output is correct
129 Correct 272 ms 5440 KB Output is correct
130 Correct 279 ms 5444 KB Output is correct
131 Correct 392 ms 5452 KB Output is correct
132 Correct 363 ms 5484 KB Output is correct
133 Correct 362 ms 5444 KB Output is correct
134 Correct 360 ms 5476 KB Output is correct
135 Correct 338 ms 5724 KB Output is correct
136 Correct 314 ms 5448 KB Output is correct
137 Correct 307 ms 5680 KB Output is correct
138 Correct 302 ms 5472 KB Output is correct
139 Correct 334 ms 5600 KB Output is correct
140 Correct 324 ms 5444 KB Output is correct
141 Correct 306 ms 5476 KB Output is correct
142 Correct 851 ms 9012 KB Output is correct
143 Correct 827 ms 9008 KB Output is correct
144 Correct 799 ms 8628 KB Output is correct
145 Correct 801 ms 8508 KB Output is correct
146 Correct 743 ms 8500 KB Output is correct
147 Correct 725 ms 8492 KB Output is correct
148 Correct 859 ms 8524 KB Output is correct
149 Correct 853 ms 8776 KB Output is correct
150 Correct 841 ms 8592 KB Output is correct
151 Correct 842 ms 8680 KB Output is correct
152 Correct 847 ms 8784 KB Output is correct
153 Correct 933 ms 8876 KB Output is correct
154 Correct 922 ms 8512 KB Output is correct
155 Correct 934 ms 8556 KB Output is correct
156 Correct 937 ms 8512 KB Output is correct
157 Correct 923 ms 8752 KB Output is correct
158 Correct 918 ms 8496 KB Output is correct
159 Correct 888 ms 8548 KB Output is correct
160 Correct 836 ms 8808 KB Output is correct
161 Correct 839 ms 8780 KB Output is correct
162 Correct 811 ms 8764 KB Output is correct
163 Correct 803 ms 8560 KB Output is correct
164 Correct 801 ms 8772 KB Output is correct
165 Correct 786 ms 8388 KB Output is correct
166 Correct 789 ms 8536 KB Output is correct
167 Correct 769 ms 8496 KB Output is correct