QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#514935 | #7612. Matrix Inverse | Neil_Qian | WA | 215ms | 242848kb | C++14 | 2.6kb | 2024-08-11 13:37:57 | 2024-08-11 13:37:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;
const int N=2002,MOD=1e9+7;mt19937_64 rnd(time(0));
const int M=2e7+2;char *p1,*p2,buf[M];
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,M,stdin),p1==p2)?EOF:*p1++)
inline int read(){
register int x=0,f=1;register char ch=nc();
while(ch<48||ch>57)ch=nc();
while(ch>=48&&ch<=57)x=(x<<3)+(x<<1)+(ch^48),ch=nc();
return x*f;
}
inline ll qpow(ll x,ll y=MOD-2){
ll res=1;
while(y){
if(y&1)(res*=x)%=MOD;
(x*=x)%=MOD,y>>=1;
}
return res;
}
struct ANS{
ll x,y,w;
bool operator <(const ANS b){return (x!=b.x?x<b.x:y<b.y);}
};vector<ANS> ans;
struct matrix{
ll n,m,a[N][N];
inline void reset(ll r,ll c,ll opt=-1){
n=r,m=c;
if(!opt)memset(a,0,sizeof(a));
else if(opt==1){
memset(a,0,sizeof(a));
for(int i=1;i<=min(n,m);i++)a[i][i]=1;
}
else if(opt==2){
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=rnd()%MOD;
}
}
matrix operator *(const matrix b){
matrix res;res.reset(n,b.m,0);
for(int i=1;i<=n;i++)for(int j=1;j<=b.m;j++)for(int k=1;k<=m;k++)
(res.a[i][j]+=a[i][k]*b.a[k][j]%MOD)%=MOD;
return res;
}
}a,b,v,va;ll n,idcol[N],idrow[N],recol[N],rerow[N],x[N][15],res[15];vector<ll> col,row;
inline void solve(){
for(int i=1,r,tp;i<=(int)row.size()+1;i++){
tp=r=tp+1;
for(int j=tp+1;j<=n;j++)if(x[j][i]>x[r][i])r=j;
if(r!=tp)swap(x[tp],x[r]);
if(!x[tp][i]){tp--;continue;}
ll one=qpow(x[tp][i]);
for(int j=1;j<=n;j++)if(j!=tp){
ll mul=(x[j][i]*one)%MOD;
for(int k=1;k<=(int)row.size()+1;k++)(x[j][k]+=MOD-(x[tp][k]*mul)%MOD)%=MOD;
}
}
for(int i=1;i<=(int)row.size();i++)res[i]=(x[i][row.size()+1]*qpow(x[i][i]))%MOD;
}
int main(){
n=read(),a.reset(n,n),b.reset(n,n);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a.a[i][j]=read();
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)b.a[i][j]=read();
v.reset(1,n,2),va=(v*a)*b;
for(int i=1;i<=n;i++)if(v.a[1][i]!=va.a[1][i])
col.emplace_back(i),idcol[i]=col.size(),recol[col.size()]=i;
v.reset(n,1,2),va=b*(a*v);
for(int i=1;i<=n;i++)if(v.a[i][1]!=va.a[i][1])
row.emplace_back(i),idrow[i]=row.size(),rerow[row.size()]=i;
for(ll c:col){
for(int i=1;i<=n;i++){
ll to=(i==c),now=0;
for(int j=1;j<=n;j++)
(idrow[j]?x[i][idrow[j]]=a.a[i][j]:(now+=a.a[i][j]*b.a[j][c]%MOD)%=MOD);
x[i][row.size()+1]=(to-now+MOD)%MOD;
}
solve();
for(int i=1;i<=(int)row.size();i++)
if(b.a[rerow[i]][c]!=res[i])ans.emplace_back(ANS{rerow[i],c,res[i]});
}
sort(ans.begin(),ans.end()),printf("%lld\n",ans.size());
for(ANS x:ans)printf("%lld %lld %lld\n",x.x,x.y,x.w);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 31ms
memory: 136728kb
input:
1 953176428 107682094
output:
0
result:
ok single line: '0'
Test #2:
score: -100
Wrong Answer
time: 215ms
memory: 242848kb
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:
4 827 238 196780498 827 499 713564622 1466 238 609983454 1466 499 910277249
result:
wrong answer 1st lines differ - expected: '2', found: '4'