题解:
大致题意为给定
n
∗
n
n*n
n∗n的矩阵A,B,C,判断矩阵C是否为
A
∗
B
A*B
A∗B。n的范围是1e3。
显然无法用
n
3
n^3
n3的矩阵乘法暴力求解实现。因此我们想到如何降低维度,发现矩阵乘法的复杂度与矩阵的形状有关,如果是一个
1
∗
n
1*n
1∗n的矩阵乘,那么结果就是
n
2
n^2
n2的解出。
于是想到能不能将等式左边同时乘上
1
∗
n
1*n
1∗n的D矩阵,即
D
∗
A
∗
B
D*A*B
D∗A∗B=
D
∗
C
D*C
D∗C。于是我们用茅台随机出D矩阵,进行check操作即可(实验发现一次随机即可得出答案)
代码:
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//ÄæÔª
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}
ll a[1200][1200],b[1200][1200],c[1200][1200],d[3][1200];
ll res1[3][1200],res2[3][1200],tmp[3][1200];
int n;
void mul(ll aa[][1200],ll bb[][1200]){
for(int i=1;i<=n;i++){
tmp[1][i]=0;
for(int k=1;k<=n;k++){
tmp[1][i]+=aa[1][k]*bb[k][i]%mod;
tmp[1][i]%=mod;
}
}
for(int i=1;i<=n;i++){
aa[1][i]=tmp[1][i];
}
}
bool judge(){
for(int i=1;i<=n;i++){
if(res1[1][i]!=res2[1][i]) return false;
}
return true;
}
int main(){
//freopen("i.txt","r",stdin);
//ios::sync_with_stdio(false);
scanf("%d",&n);
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++){
for(int j=1;j<=n;j++){
scanf("%lld",&b[i][j]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%lld",&c[i][j]);
}
}
bool mark=true;
for(int t=1;t<=1;t++){
for(int i=1;i<=n;i++){
d[1][i]=rand_()%mod;
res1[1][i]=d[1][i];
res2[1][i]=d[1][i];
}
mul(res1,a);
mul(res1,b);
mul(res2,c);
if(!judge()){
mark=false;
break;
}
}
if(mark) puts("YES");
else puts("NO");
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}