QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104520#59. Determinant of A+BzAFewSunsJudging//C++143.5kb2023-05-10 22:15:102024-03-04 04:40:49

Judging History

你现在查看的是测评时间为 2024-03-04 04:40:49 的历史记录

  • [2024-05-05 11:54:08]
  • hack成功,自动添加数据
  • (/hack/617)
  • [2024-05-05 11:38:15]
  • hack成功,自动添加数据
  • (/hack/616)
  • [2024-03-04 04:44:43]
  • 管理员手动重测本题所有提交记录
  • 测评结果:97
  • 用时:1084ms
  • 内存:10632kb
  • [2024-03-04 04:40:49]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:Judging
  • 用时:1437ms
  • 内存:10372kb
  • [2024-03-04 04:35:40]
  • hack成功,自动添加数据
  • (/hack/552)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-10 22:15:12]
  • 评测
  • 测评结果:100
  • 用时:1437ms
  • 内存:10372kb
  • [2023-05-10 22:15:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
#define mod 998244353
ll n,A[550][550],B[550][550],f[550][550],nz=0,ans=1;
bl ck=0;
void gauss1(){
	fr(i,1,n){
		ll tmp=i;
		fr(j,i,n) if(B[j][i]) tmp=j;
		if(i!=tmp){
			swap(A[i],A[tmp]);
			swap(B[i],B[tmp]);
			ans=(mod-ans)%mod;
		}
		tmp=i;
		fr(j,i,n) if(B[i][j]) tmp=j;
		if(i!=tmp){
			fr(j,1,n) swap(A[j][tmp],A[j][i]);
			fr(j,1,n) swap(B[j][tmp],B[j][i]);
			ans=(mod-ans)%mod;
		}
		if(!B[i][i]){
			nz++;
			swap(A[i],B[i]);
		}
		fr(j,1,i-1){
			tmp=B[i][j];
			fr(k,1,n) B[i][k]=(B[i][k]-tmp*B[j][k]%mod+mod)%mod;
			fr(k,1,n) A[i][k]=(A[i][k]-tmp*A[j][k]%mod+mod)%mod;
		}
		tmp=i;
		fr(j,i,n) if(B[i][j]) tmp=j;
		if(i!=tmp){
			fr(j,1,n) swap(A[j][tmp],A[j][i]);
			fr(j,1,n) swap(B[j][tmp],B[j][i]);
			ans=(mod-ans)%mod;
		}
		if(!B[i][i]){
			ck=1;
			return;
		}
		tmp=inv(B[i][i],mod);
		ans=ans*B[i][i]%mod;
		fr(j,1,n) B[i][j]=B[i][j]*tmp%mod;
		fr(j,1,n) A[i][j]=A[i][j]*tmp%mod;
		fr(j,i+1,n){
			tmp=B[j][i];
			fr(k,1,n) B[j][k]=(B[j][k]-tmp*B[i][k]%mod+mod)%mod;
			fr(k,1,n) A[j][k]=(A[j][k]-tmp*A[i][k]%mod+mod)%mod;
		}
	}
	pfr(i,n,1){
		pfr(j,i-1,1){
			ll tmp=B[j][i];
			fr(k,1,n) B[j][k]=(B[j][k]-tmp*B[i][k]%mod+mod)%mod; 
			fr(k,1,n) A[j][k]=(A[j][k]-tmp*A[i][k]%mod+mod)%mod; 
		}
	}
}
void gauss2(){
	fr(i,2,n){
		ll tmp=i;
		fr(j,i,n) if(A[j][i-1]) tmp=j;
		if(i!=tmp){
			swap(A[i],A[tmp]);
			fr(k,1,n) swap(A[k][i],A[k][tmp]);
		}
		if(!A[i][i-1]) continue;
		ll invv=inv(A[i][i-1],mod);
		fr(j,i+1,n){
			tmp=A[j][i-1]*invv%mod;
			fr(k,i-1,n) A[j][k]=(A[j][k]-tmp*A[i][k]%mod+mod)%mod;
			fr(k,1,n) A[k][i]=(A[k][i]+tmp*A[k][j]%mod)%mod;
		}
	}
}
int main(){
	n=read();
	fr(i,1,n) fr(j,1,n) A[i][j]=read();
	fr(i,1,n) fr(j,1,n) B[i][j]=read();
	gauss1();
	if(ck){
		fr(i,0,n) writesp(0);
		return 0;
	}
	gauss2();
	f[0][0]=1;
	fr(i,1,n){
		fr(j,0,n) f[i][j+1]=(f[i][j+1]+f[i-1][j])%mod;
		fr(j,0,n) f[i][j]=(f[i][j]+A[i][i]*f[i-1][j]%mod)%mod;
		ll mul=1;
		pfr(j,i,2){
			mul=mul*A[j][j-1]%mod;
			fr(k,0,n){
				if((i-j+1)&1) f[i][k]=(f[i][k]-mul*A[j-1][i]%mod*f[j-2][k]%mod+mod)%mod;
				else f[i][k]=(f[i][k]+mul*A[j-1][i]%mod*f[j-2][k]%mod)%mod;
			}
		}
	}
	fr(i,nz,n) writesp(f[n][i]*ans%mod);
	fr(i,1,nz) writesp(0);
}