Submission #969241

# Submission time Handle Problem Language Result Execution time Memory
969241 2024-04-24T18:29:20 Z imann Amusement Park (CEOI19_amusementpark) C++17
0 / 100
7 ms 14684 KB
#include <iostream>
#include <array>

using ll = long long;

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

std::array<std::array<int, MAX_N>, MAX_N> graph;
std::array<std::array<int, (1 << MAX_N)>, MAX_N> costs;
std::array<std::pair<ll, ll>, (1 << MAX_N)> dp;

int solve(int n) {
  for (int s = 1; s < (1 << n); ++s) {
    for (int i = 0; i < n; ++i) {
      if (s & (1 << i)) {
        int c = 0;
        for (int j = 0; j < n; ++j) {
          if (s & (1 << j)) {
            if (graph[j][i]) {
              c++;
            }
          }
        }
        costs[s][i] = c;
      }
    }
  }

  dp[0].first = 1;
  for (int s = 1; s < (1 << n); ++s) {
    for (int i = 0; i < n; ++i) {
      if (s & (1 << i)) {
        dp[s].first = (dp[s].first + dp[s ^ (1 << i)].first) % MOD;
        dp[s].second = (dp[s].second + (dp[s ^ (1 << i)].second + dp[s ^ (1 << i)].first * costs[s][i])) % MOD;
      }
    }
  }

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

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] = 1;
  }
  std::cout << solve(n) << std::endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Incorrect 7 ms 14684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Incorrect 7 ms 14684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Incorrect 7 ms 14684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Incorrect 7 ms 14684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Incorrect 7 ms 14684 KB Output isn't correct
4 Halted 0 ms 0 KB -