Submission #486712

#TimeUsernameProblemLanguageResultExecution timeMemory
486712XIIAmusement Park (CEOI19_amusementpark)C++17
100 / 100
263 ms39412 KiB
#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; const int MOD = 998244353; int n, m; int edge[N * N]; int f[1 << N][N + 1]; /// number of not connected graph int dp[1 << N][N + 1]; /// number of graph bool noEdge(const int &mask){ FOR(i, 0, m) if((mask & edge[i]) == edge[i]) return false; return true; } void addto(int &a, const int &b){ a = (a + b >= MOD ? a + b - MOD : a + b); } void delto(int &a, const int &b){ a = (a - b < 0 ? a - b + MOD : a - b); } int mul(const int &a, const int &b){ return (1LL * a * b) % MOD; } int powmod(int a, int b){ int ans = 1; for(; b > 0; b >>= 1){ if(b & 1) ans = mul(ans, a); a = mul(a, a); } return ans; } int main(){ IOS; Fi(); cin >> n >> m; FOR(i, 0, m){ int u, v; cin >> u >> v; --u, --v; edge[i] = (1 << u) | (1 << v); } FOR(mask, 0, 1 << n) if(noEdge(mask)){ int nbit = __builtin_popcount(mask); f[mask][nbit] = ((nbit & 1) ? MOD - 1 : 1); // cout << mask << " " << nbit << " " << f[mask][nbit] << "\n"; } for(int i = 1; i < (1 << n); i <<= 1){ /// can remove bit 0...(log2(i)) for(int j = 0; j < (1 << n); j += (i << 1)){ FOR(k, 0, i){ FORU(p, 0, n) addto(f[j | i | k][p], f[j | k][p]); } } } FOR(mask, 0, 1 << n){ // int tmp = dp[mask][0] = pow(f[mask][0], MOD - 2); dp[mask][0] = f[mask][0]; FORU(i, 1, n){ FOR(j, 0, i){ delto(dp[mask][i], mul(dp[mask][j], f[mask][i - j])); // dp[mask][i] = mul(dp[mask][i], tmp); } } } for(int i = 1; i < (1 << n); i <<= 1){ for(int j = 0; j < (1 << n); j += (i << 1)){ FOR(k, 0, i){ FORU(p, 0, n) delto(dp[j | i | k][p], dp[j | k][p]); } } } int ans = dp[(1 << n) - 1][n]; ans = mul(ans, m); ans = mul(ans, (MOD + 1) / 2); /// devide by 2 cout << ans; return 0; }

Compilation message (stderr)

amusementpark.cpp: In function 'void Fi()':
amusementpark.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...