Submission #971061

# Submission time Handle Problem Language Result Execution time Memory
971061 2024-04-27T21:40:57 Z imann Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 6740 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);
      }
    }
    for (int ss = 1; ss < (1 << ones.size()); ++ss) {
      int ssI = 0;
      for (int j = 0; j < ones.size(); ++j) {
        if (ss & (1 << j)) {
          ssI += (1 << ones[j]);
        }
      }
      if (sInd[ssI]) {
        if ((sSize[ssI] % 2) == 1) {
          dp[s] = (dp[s] + dp[s - ssI]);
        } else {
          dp[s] = (dp[s] - dp[s - ssI]);
        }
      }
    }
  }

  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:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       for (int j = 0; j < ones.size(); ++j) {
      |                       ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 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 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 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 2 ms 4696 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 4540 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 5144 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 2 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 4696 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 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 2 ms 4696 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 4540 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 5144 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 2 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 4696 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4696 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 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 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4696 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4696 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 2 ms 4696 KB Output is correct
51 Correct 1 ms 4896 KB Output is correct
52 Correct 3 ms 4700 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 2 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 2 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 2 ms 4700 KB Output is correct
62 Correct 2 ms 4700 KB Output is correct
63 Correct 2 ms 4700 KB Output is correct
64 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 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 2 ms 4696 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 4540 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 5144 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 2 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 4696 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4696 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 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 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4696 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4696 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 2 ms 4696 KB Output is correct
51 Correct 1 ms 4896 KB Output is correct
52 Correct 3 ms 4700 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 2 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 2 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 2 ms 4700 KB Output is correct
62 Correct 2 ms 4700 KB Output is correct
63 Correct 2 ms 4700 KB Output is correct
64 Correct 2 ms 4700 KB Output is correct
65 Correct 183 ms 4716 KB Output is correct
66 Correct 179 ms 4700 KB Output is correct
67 Correct 178 ms 4700 KB Output is correct
68 Correct 182 ms 4700 KB Output is correct
69 Correct 192 ms 4700 KB Output is correct
70 Correct 188 ms 4700 KB Output is correct
71 Correct 187 ms 4944 KB Output is correct
72 Correct 175 ms 4700 KB Output is correct
73 Correct 183 ms 4700 KB Output is correct
74 Correct 187 ms 4704 KB Output is correct
75 Correct 183 ms 4700 KB Output is correct
76 Correct 174 ms 4700 KB Output is correct
77 Correct 594 ms 4696 KB Output is correct
78 Correct 595 ms 4948 KB Output is correct
79 Correct 586 ms 4700 KB Output is correct
80 Correct 601 ms 4692 KB Output is correct
81 Correct 599 ms 4720 KB Output is correct
82 Correct 587 ms 4704 KB Output is correct
83 Correct 588 ms 4720 KB Output is correct
84 Correct 593 ms 4704 KB Output is correct
85 Correct 623 ms 4700 KB Output is correct
86 Correct 612 ms 4732 KB Output is correct
87 Correct 619 ms 4696 KB Output is correct
88 Correct 583 ms 4716 KB Output is correct
89 Correct 585 ms 4948 KB Output is correct
90 Correct 601 ms 4704 KB Output is correct
91 Correct 607 ms 4716 KB Output is correct
92 Correct 581 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4700 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 2 ms 4696 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 4540 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 5144 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 2 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 4696 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4696 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 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 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4696 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4696 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 2 ms 4696 KB Output is correct
51 Correct 1 ms 4896 KB Output is correct
52 Correct 3 ms 4700 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 2 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 2 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 2 ms 4700 KB Output is correct
62 Correct 2 ms 4700 KB Output is correct
63 Correct 2 ms 4700 KB Output is correct
64 Correct 2 ms 4700 KB Output is correct
65 Correct 183 ms 4716 KB Output is correct
66 Correct 179 ms 4700 KB Output is correct
67 Correct 178 ms 4700 KB Output is correct
68 Correct 182 ms 4700 KB Output is correct
69 Correct 192 ms 4700 KB Output is correct
70 Correct 188 ms 4700 KB Output is correct
71 Correct 187 ms 4944 KB Output is correct
72 Correct 175 ms 4700 KB Output is correct
73 Correct 183 ms 4700 KB Output is correct
74 Correct 187 ms 4704 KB Output is correct
75 Correct 183 ms 4700 KB Output is correct
76 Correct 174 ms 4700 KB Output is correct
77 Correct 594 ms 4696 KB Output is correct
78 Correct 595 ms 4948 KB Output is correct
79 Correct 586 ms 4700 KB Output is correct
80 Correct 601 ms 4692 KB Output is correct
81 Correct 599 ms 4720 KB Output is correct
82 Correct 587 ms 4704 KB Output is correct
83 Correct 588 ms 4720 KB Output is correct
84 Correct 593 ms 4704 KB Output is correct
85 Correct 623 ms 4700 KB Output is correct
86 Correct 612 ms 4732 KB Output is correct
87 Correct 619 ms 4696 KB Output is correct
88 Correct 583 ms 4716 KB Output is correct
89 Correct 585 ms 4948 KB Output is correct
90 Correct 601 ms 4704 KB Output is correct
91 Correct 607 ms 4716 KB Output is correct
92 Correct 581 ms 4948 KB Output is correct
93 Execution timed out 3100 ms 6740 KB Time limit exceeded
94 Halted 0 ms 0 KB -