Submission #865952

#TimeUsernameProblemLanguageResultExecution timeMemory
865952RequiemAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1269 ms3448 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 998244353 #define INF 1e18 #define fi first #define se second #define endl "\n" #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define pi 3.14159265359 #define TASKNAME "amusepark" template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 3e2 + 9; ii edge[MAXN]; int n,m,ans=0; int pos[MAXN]; int prep[MAXN]; int N[MAXN]; void add(int &a,int b){ a += b; if (a>=MOD) a-=MOD; } void sub(int &a,int b){ a -= b; if (a < 0) a += MOD; } int dp[(1<<19)]; bool independent[(1<<19)]; int power(int a,int b){ int res = 1; while(b>0){ if (b&1) res = (res * a) %MOD; b>>=1; a = (a * a) % MOD; } return res; } main() { fast; // freopen(TASKNAME".inp","r",stdin); // freopen(TASKNAME".out","w",stdout); cin>>n>>m; for(int i=1;i<=m;i++){ cin>>edge[i].fi>>edge[i].se; // edge[i].fi--; // edge[i].se--; N[edge[i].se-1] |= (1<<(edge[i].fi-1)); N[edge[i].fi-1] |= (1<<(edge[i].se-1)); } vector<int> bit; for(int i=1;i<(1<<n);i++){ bit.clear(); for(int j=0;j<n;j++){ if (i&(1<<j)){ bit.pb(j); } } independent[i] = true; for(int j=0;j<bit.size();j++){ for(int k=0;k<bit.size();k++){ if (N[bit[j]] & (1<<bit[k])){ independent[i] = false; } } } } dp[0] = 1; for(int i=1;i<(1<<n);i++){ for(int j=i;j>0;j=(j-1)&i){ int numbit = __builtin_popcount(j); if (independent[j]){ if (numbit & 1) add(dp[i],dp[i^j]); else sub(dp[i],dp[i^j]); } } } cout<<((dp[(1<<n)-1] * m)%MOD * power(2,MOD-2))%MOD<<endl; }

Compilation message (stderr)

amusementpark.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main()
      | ^~~~
amusementpark.cpp: In function 'int main()':
amusementpark.cpp:68:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for(int j=0;j<bit.size();j++){
      |                     ~^~~~~~~~~~~
amusementpark.cpp:69:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int k=0;k<bit.size();k++){
      |                         ~^~~~~~~~~~~
#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...