Submission #666471

#TimeUsernameProblemLanguageResultExecution timeMemory
666471finn__Amusement Park (CEOI19_amusementpark)C++17
42 / 100
861 ms588 KiB
#include <bits/stdc++.h> using namespace std; #define MOD 998244353 int main() { size_t n, m; cin >> n >> m; vector<vector<bool>> g(n, vector<bool>(n, 0)); for (size_t i = 0; i < m; i++) { unsigned u, v; cin >> u >> v; g[u - 1][v - 1] = 1; } vector<int64_t> dp(1 << n, 0); dp[0] = 1; for (unsigned i = 1; i < 1 << n; i++) { unsigned const p = __builtin_popcount(i); vector<unsigned> s; for (unsigned k = 0; k < n; k++) if (i & (1 << k)) s.push_back(k); for (unsigned j = 0; j < 1 << p; j++) { bool is_independent = 1; for (unsigned k = 0; k < p && is_independent; k++) if (j & (1 << k)) for (unsigned h = 0; h < p && is_independent; h++) if (j & (1 << h)) if (g[s[k]][s[h]] || g[s[h]][s[k]]) is_independent = 0; if (is_independent) { unsigned t = 0; for (unsigned k = 0; k < p; k++) if (j & (1 << k)) t ^= (1 << s[k]); dp[i] = (dp[i] + ((__builtin_popcount(t) & 1) ? 1 : -1) * dp[i ^ t]) % MOD; } } } cout << (((dp[(1 << n) - 1] * m) % MOD) * 499122177) % MOD << '\n'; }

Compilation message (stderr)

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:22:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   22 |     for (unsigned i = 1; i < 1 << n; i++)
      |                          ~~^~~~~~~~
amusementpark.cpp:30:32: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   30 |         for (unsigned j = 0; j < 1 << p; 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...