Submission #969241

#TimeUsernameProblemLanguageResultExecution timeMemory
969241imannAmusement Park (CEOI19_amusementpark)C++17
0 / 100
7 ms14684 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...