比赛 2022级数学专题练习赛5 评测结果 ATAAATTTTT
题目名称 行列式取模 最终得分 40
用户昵称 op_组撒头屯 运行时间 6.244 s
代码语言 C++ 内存使用 5.45 MiB
提交时间 2023-01-09 20:19:06
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define qi queue<int>
#define sti stack<int>
#define fi first
#define se second
#define pb push_back
const int N=200+5;
int n;
int b[N],len[N];
ll a[N][N],p;
int lowbit(int x){
    return x&(-x);
}
void add(int x){
    for (int i=x;i<=n;i+=lowbit(i))len[i]++;
}
int getsum(int x){
    int t=0;
    for (int i=x;i>0;i-=lowbit(i))t+=len[i];
    return t;
}
int main(){
	freopen ("det.in","r",stdin);
	freopen ("det.out","w",stdout);
	scanf("%d%lld",&n,&p);
	for (int i=1;i<=n;i++){
	    for (int j=1;j<=n;j++){
	        scanf("%lld",&a[i][j]);
        }
    }
    for (int i=1;i<=n;i++)b[i]=i;
    ll ans=0;
    do{
        for (int i=1;i<=n;i++)len[i]=0;
        int cnt=0;ll w=1;
        for (int i=n;i>=1;i--){
            cnt+=getsum(b[i]);
            add(b[i]);
            w=w*a[i][b[i]]%p;
        }
        if (cnt&1)w*=-1;
        ans=((ans+w)%p+p)%p;
    }while(next_permutation(b+1,b+n+1));
    printf("%lld\n",ans);
    return 0;
}