-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSolution.cpp
More file actions
61 lines (55 loc) · 1.47 KB
/
Solution.cpp
File metadata and controls
61 lines (55 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1003;
LL A[N][N], B[N][N], C[N][N];
LL r[N], Br[N], ABr[N], Cr[N];
int main()
{
srand(time(NULL));
int n;
while(scanf("%d", &n) && n)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%lld", &A[i][j]);
B[i][j] = A[i][j];
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%lld", &C[i][j]);
}
}
bool flag = true;
for(int t = 0; t < 20 && flag; t++)
{
for(int i = 0; i < n; i++)
r[i] = abs(rand() & 7);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
Br[i] += B[i][j] * r[j];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
ABr[i] += A[i][j] * Br[j];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
Cr[i] += C[i][j] * r[j];
for(int i = 0; i < n && flag; i++)
if(ABr[i] != Cr[i])
flag = false;
memset(Br, 0, sizeof Br);
memset(ABr, 0, sizeof ABr);
memset(Cr, 0, sizeof Cr);
}
if(flag)
puts("YES");
else
puts("NO");
}
return 0;
}