# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
971073 | imann | Amusement Park (CEOI19_amusementpark) | C++17 | 1472 ms | 9012 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |