Submission #971061

#TimeUsernameProblemLanguageResultExecution timeMemory
971061imannAmusement Park (CEOI19_amusementpark)C++17
63 / 100
3100 ms6740 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); } } 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 (stderr)

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 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...