# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486337 | XII | Amusement Park (CEOI19_amusementpark) | C++17 | 0 ms | 204 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;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI19_amusementpark"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 18;
int n, m;
vector<int> adj[N], radj[N];
const int MOD = 998244353;
int dp[1 << N]; /// number of reverse edge
int f[1 << N]; /// number of state
int main(){
IOS;
Fi();
cin >> n >> m;
FORU(i, 1, m){
int u, v; cin >> u >> v;
--u, --v;
adj[u].eb(v), radj[v].eb(u);
}
f[0] = 1;
FOR(mask, 0, 1 << n){
FOR(u, 0, n) if(!(mask & (1 << u))){
int rev = 0;
for(int v: adj[u]) if(mask & (1 << v)) ++rev;
(dp[mask | (1 << u)] += f[mask] * rev + dp[mask]) %= MOD;
(f[mask | (1 << u)] += f[mask]) %= MOD;
}
}
// FOR(mask, 0, 1 << n){
// cout << bitset<10>(mask) << "\n";
// cout << f[mask] << " " << dp[mask] << "\n";
// }
cout << dp[(1 << n) - 1];
return 0;
}
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... |