# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666418 | finn__ | Amusement Park (CEOI19_amusementpark) | C++17 | 0 ms | 212 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 <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<uint64_t> dp(1 << n, 0), nways(1 << n, 0);
nways[0] = 1;
for (unsigned i = 0; i < 1 << n; i++)
{
for (unsigned j = 0; j < n; j++)
{
if (!(i & (1 << j)))
{
uint64_t c = 0;
for (unsigned k = 0; k < n; k++)
c += (i & (1 << k)) && g[k][j];
dp[i ^ (1 << j)] = (dp[i ^ (1 << j)] + dp[i] + c * nways[i]) % MOD;
nways[i ^ (1 << j)] = (nways[i ^ (1 << j)] + nways[i]) % MOD;
}
}
}
cout << dp[(1 << n) - 1] << '\n';
}
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... |