Submit Info #9282

Problem Lang User Status Time Memory
Hafnian of Matrix cpp TKO919 AC 5294 ms 2.48 MiB

ケース詳細
Name Status Time Memory
example_00 AC 3 ms 0.72 MiB
large_00 AC 54 ms 1.05 MiB
large_01 AC 111 ms 1.30 MiB
large_02 AC 509 ms 1.67 MiB
max_00 AC 5290 ms 2.42 MiB
max_01 AC 5287 ms 2.48 MiB
max_02 AC 5294 ms 2.42 MiB
small_00 AC 2 ms 0.73 MiB
small_01 AC 2 ms 0.72 MiB
small_02 AC 4 ms 0.80 MiB

#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end template<unsigned mod=998244353>struct fp { unsigned v; static unsigned get_mod(){return mod;} unsigned inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp():v(0){} fp(ll x):v(x>=0?x%mod:mod+(x%mod)){} fp operator-()const{return fp(-v);} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){if((v+=x.v)>=mod)v-=mod; return *this;} fp& operator-=(const fp& x){if((v+=mod-x.v)>=mod)v-=mod; return *this;} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} }; using Fp=fp<>; template<typename T>struct hafnian{ typedef vector<T> poly; int n; hafnian(int _n):n(_n){} void add(poly& f,const poly& a,const poly& b)const{ for(int i=0;i<n;i++)for(int j=0;i+j+1<n;j++){ f[i+j+1]+=a[i]*b[j]; } } poly run(vector<vector<poly>> a)const{ poly res(n,0); if(a.empty()){res[0]=1; return res;} const auto x=a.back(); a.pop_back(); const auto y=a.back(); a.pop_back(); int m=a.size(); const poly zero=run(a); for(int i=0;i<n;i++)res[i]-=zero[i]; for(int i=0;i<m;i++)for(int j=0;j<i;j++){ add(a[i][j],x[i],y[j]); add(a[i][j],y[i],x[j]); } const poly all=run(a); add(res,x[m],all); for(int i=0;i<n;i++)res[i]+=all[i]; return res; } }; int main(){ int n; cin>>n; hafnian<Fp> haf(n/2+1); vector<vector<vector<Fp>>> a(n,vector<vector<Fp>>(n,vector<Fp>(n/2+1))); rep(i,0,n)rep(j,0,n)cin>>a[i][j][0].v; Fp res=haf.run(a).back(); cout<<res.v<<endl; return 0; }