Submission #441145

#TimeUsernameProblemLanguageResultExecution timeMemory
441145hhhhauraAmusement Park (CEOI19_amusementpark)C++14
100 / 100
2003 ms6596 KiB
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define all(x) x.begin(), x.end() #define ceil(a, b) ((a + b - 1) / (b)) #define INF 1000000000000000000 #define MOD 998244353 #define eps (1e-9) using namespace std; #define int long long int #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;} void kout() { cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); } #else #define print(...) 0 #define vprint(...) 0 #endif namespace solver { int n, m, inv2 = 499122177; vector<int> dp, ok, cnt; vector<pii> es; void init_(int _n, int _m) { n = _n, m = _m; es.clear(); dp.assign(1 << n, 0); ok.assign(1 << n, 0); cnt.assign(1 << n, 0); } int solve() { rep(i, 1, (1 << n) - 1) { bool yes = 0; for(auto j : es) { yes |= (((i >> (j.first - 1)) & 1) && ((i >> (j.second - 1)) & 1)); } cnt[i] = __builtin_popcount(i); ok[i] = !yes; } dp[0] = 1; rep(i, 1, (1 << n) - 1) { for(int j = i; j > 0; j = (j - 1) & i) { if(!ok[j]) continue; dp[i] = (dp[i] + ((cnt[j] & 1) ? 1 : -1) * dp[i ^ j]); if(dp[i] < 0) dp[i] += MOD; if(dp[i] >= MOD) dp[i] -= MOD; } } int ans = m * inv2 % MOD * dp[(1 << n) - 1] % MOD; return (ans + MOD) % MOD; } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int n, m; cin >> n >> m; init_(n, m); rep(i, 1, m) { int a, b; cin >> a >> b; es.push_back({a, b}); } cout << solve() << "\n"; return 0; }

Compilation message (stderr)

amusementpark.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
amusementpark.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
amusementpark.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
#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...