Submission #781128

#TimeUsernameProblemLanguageResultExecution timeMemory
781128definitelynotmeeAmusement Park (CEOI19_amusementpark)C++17
63 / 100
3069 ms6484 KiB
#include<bits/stdc++.h> #define ff first #define ss second #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using matrix = vector<vector<T>>; const ll MOD = 998244353; int main(){ cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; vector<int> adj(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; adj[a]+=1<<b; } vector<ll> incomp(1<<n); for(int i = 0; i < (1<<n); i++){ int ok = 0; for(int j = 0; j < n; j++){ if((1<<j)&i){ ok|=adj[j]; } } incomp[i] = !bool(ok&i); // cerr << bitset<4>(ok) << ' ' << bitset<4>(i) << "->" << incomp[i] << '\n'; } vector<ll> sum(1<<n), dp(1<<n); dp[0] = 1; array<ll,2> parity = {MOD-1,1}; vector<int> cur; auto calc =[&](int i, int taken, int cursum, int sub, int mask, auto calc){ if(i == cur.size()){ if(!taken) return; const int comp = mask^sub; dp[mask]+=parity[taken&1]*dp[comp]; sum[mask]+=parity[taken&1]*(cursum*dp[comp]%MOD+sum[comp]); dp[mask]%=MOD; sum[mask]%=MOD; // cerr << i << ' ' << taken << ' ' << cursum << ' ' << bitset<4>(sub) << ' ' << bitset<4>(mask) << '\n'; // cerr << "=> " << parity[taken&1]*dp[comp] << ' ' << parity[taken&1]*(cursum*dp[comp]%MOD+sum[comp]) << '\n'; return; } const int id = cur[i]; if(incomp[sub|(1<<id)]){ calc(i+1,taken+1,cursum+__builtin_popcount(adj[id]&mask),sub|(1<<id),mask,calc); } calc(i+1,taken,cursum,sub,mask,calc); }; for(int mask = 1; mask < (1<<n); mask++){ cur.clear(); for(int j = 0 ; j < n; j++){ if(mask&(1<<j)) cur.push_back(j); } calc(0,0,0,0,mask,calc); // cerr << "dp[" << bitset<4>(mask) << "] = " << dp[mask] << '\n'; // cerr << "sum[" << bitset<4>(mask) << "] = " << sum[mask] << '\n'; } cout << sum[(1<<n)-1] << '\n'; }

Compilation message (stderr)

amusementpark.cpp: In instantiation of 'main()::<lambda(int, int, int, int, int, auto:23)> [with auto:23 = main()::<lambda(int, int, int, int, int, auto:23)>]':
amusementpark.cpp:76:31:   required from here
amusementpark.cpp:51:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         if(i == cur.size()){
      |            ~~^~~~~~~~~~~~~
#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...