QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#447078 | #7612. Matrix Inverse | Iratis | WA | 479ms | 50832kb | C++14 | 2.3kb | 2024-06-17 21:11:48 | 2024-06-17 21:11:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
bool ST;
const int N=2005,mod=1e9+7;
namespace Math
{
inline void add(int &x,const int &y){x+=y;if(x>=mod)x-=mod;}
inline void dec(int &x,const int &y){x-=y;if(x<0)x+=mod;}
inline int qp(int a,int n){int b=1;while(n){if(n&1)b=1ll*b*a%mod;a=1ll*a*a%mod,n>>=1;}return b;}
};
using namespace Math;int ned,dir[N],dic[N],dif[N][N];
int n,a[N][N],b[N][N],vec[N],row[N],col[N];mt19937 R(time(0));
inline void rmul(int*a,int b[N][N])
{
static int c[N];
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)add(c[j],1ll*a[i]*b[i][j]%mod);
for(int i=1;i<=n;i++)a[i]=c[i],c[i]=0;
}
inline void lmul(int b[N][N],int*a)
{
static int c[N];
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)add(c[j],1ll*a[i]*b[j][1]%mod);
for(int i=1;i<=n;i++)a[i]=c[i],c[i]=0;
}
int f[N][14];
inline void calc(int c)
{
if(!ned)return ;
for(int i=1;i<=n;i++)
{
f[i][ned+1]=(i==c);
for(int j=1,k=1;j<=n;j++)
{
if(k<=ned&&dir[k]==j)f[i][k]=a[i][j],k++;
else dec(f[i][ned+1],1ll*a[i][j]*b[j][c]%mod);
}
}
for(int i=1;i<=min(n,ned);i++)
{
for(int j=i;j<=n;j++)if(f[j][i]){for(int k=1;k<=ned+1;k++)swap(f[i][k],f[j][k]);break;}
int iv=qp(f[i][i],mod-2);
for(int j=1;j<=n;j++)if(i!=j)
{
int w=1ll*f[j][i]*iv%mod;
for(int k=1;k<=ned+1;k++)dec(f[j][k],1ll*f[i][k]*w%mod);
}
}
for(int i=1;i<=ned;i++)dif[dir[i]][c]=1ll*f[i][ned+1]*qp(f[i][i],mod-2)%mod;
}
bool ED;
signed main()
{
int time_st=clock();
cerr<<(&ST-&ED)/1024.0/1024<<endl;ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>a[i][j];
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>b[i][j],dif[i][j]=b[i][j];
for(int i=1;i<=n;i++)vec[i]=R(),row[i]=col[i]=vec[i];rmul(row,a),rmul(row,b),lmul(a,col),lmul(b,col);
for(int i=1,p=0,q=0;i<=n;i++){if(row[i]!=vec[i])dic[++q]=i;if(col[i]!=vec[i])dir[++p]=i;ned=max(p,q);}
if(n>=1000)return 0;
for(int i=1;i<=ned;i++)calc(dic[i]);
vector<pair<int,int> >ans;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(dif[i][j]!=b[i][j])ans.push_back({i,j});
cout<<(int)ans.size()<<'\n';for(auto pa:ans){int x=pa.first,y=pa.second;cout<<x<<' '<<y<<' '<<dif[x][y]<<'\n';}
cerr<<(clock()-time_st)/1e6<<endl;return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3920kb
input:
1 953176428 107682094
output:
0
result:
ok single line: '0'
Test #2:
score: -100
Wrong Answer
time: 479ms
memory: 50832kb
input:
1995 586309310 548144807 578573993 437893403 641164340 712256053 172321263 108058526 768610920 123320669 762746291 856047593 979279376 29067913 309867338 292286426 45124325 239705174 675003623 213743652 620561338 116308277 695369179 669459894 682522334 846995555 159510341 999359657 645579085 7499563...
output:
result:
wrong answer 1st lines differ - expected: '2', found: ''