제출 #1033414

#제출 시각아이디문제언어결과실행 시간메모리
1033414codefoxAmusement Park (CEOI19_amusementpark)C++14
7 / 100
1 ms360 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target("popcnt") #pragma GCC optimize("Ofast") #define int long long #define pii pair<int, int> const int mod = 998244353; int32_t main() { int n, m; cin >> n >> m; vector<bitset<20>> graph(n, 0); vector<bitset<20>> dgraph(n, 0); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; graph[a][b] = 1; dgraph[a][b] = 1; dgraph[b][a] = 1; } int N = 1<<n; N*=32; vector<pii> dp(N, {0,0}); for(int i = 0; i< n; i++) dp[(1<<i)*32+i] = {1, 0}; for (int i = 0; i < N; i++) { for (int j = 0; j < n; j++) { int ii = i/32; int ij = i%32; if (ij >= n) continue; if (ii&(1<<j)) continue; int d = (graph[j]&(bitset<20>(ii))).count(); //int dd = (dgraph[j]&(bitset<20>(i))).count(); int nj = (ii+(1<<j))*32+j; if (dgraph[j][ij]) { dp[nj].first += dp[i].first; dp[nj].first%=mod; dp[nj].second += dp[i].second+dp[i].first*d; dp[nj].second%=mod; } else if (ij<j) { dp[nj].first += dp[i].first; dp[nj].first%=mod; dp[nj].second += dp[i].second+dp[i].first*d; dp[nj].second%=mod; } } } int sol = 0; for (int i = N-32; i < N; i++) sol += dp[i].second; cout << sol%mod; return 0; }
#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...