Submission #971073

#TimeUsernameProblemLanguageResultExecution timeMemory
971073imannAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1472 ms9012 KiB
#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 (stderr)

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) {
      |                     ~~^~~~~~~~~~~~~
#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...