行列式求值52pts求调(玄关
查看原帖
行列式求值52pts求调(玄关
1423269
ini_____楼主2025/2/7 13:40

rt

#include<bits/stdc++.h>
#define LL long long
#define getchar_unlocked getchar
using namespace std;
inline int read(){
	char c=getchar_unlocked();
	int x=0,f=1;
	while(c<'0'||c>'9'){
		if(c=='-')f=0;
		c=getchar_unlocked();
	}
	while(c>='0' && c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar_unlocked();
	}
	return f ? x : -x;
}
const int N=600+5;
LL T,n,m,p;
LL a[N][N];
signed main(){
//	freopen("P7712_1.in","r",stdin);
	n=read(),p=read();
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=read()%p;
	LL res=1;
	for(int i=1;i<=n;i++){
		int Max=i;
		for(int j=i+1;j<=n;j++)if(abs(a[j][i])>abs(a[Max][i]))Max=j;
		if(a[Max][i]==0){
			puts("0");
			return 0; 
		}		
		if(i!=Max)res*=-1;
		for(int j=1;j<=n;j++)swap(a[i][j],a[Max][j]);
		for(int j=i+1;j<=n;j++){
			LL tmp=a[j][i]/a[i][i];
			for(int k=i;k<=n;k++)a[j][k]=(a[j][k]-(a[i][k]*tmp)%p+p)%p;
		}
	}	
	for(int i=1;i<=n;i++)res=res*((a[i][i]+p)%p)%p;
	cout<<res;
}

2025/2/7 13:40
加载中...