The first two matrices are all mod3.
S[i][j][k] indicates that the nth bit of the row/column of the first I (0/1) matrix is J (1/2).
Then if a couple of moments on the corresponding bit is 1, 1, multiply is 1;
1, 2:2;
2, 1:2;
2, 2:1.
Then divide the bitset and up in these four cases, then count the number of counts () and calculate the contribution to the position of the answer matrix.
#include <cstdio> #include <bitset>using namespace std; #define N 801int N,x;bitset<n>s[2][2][n];int Main () {while (scanf ("%d", &n)!=eof) {for (int i=1;i<=n;++i) {s[0][0 ][i].reset (); S[0][1][i].reset (); S[1][0][i].reset (); S[1][1][i].reset (); } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {scanf ("%d", &x); int op=x%3-1; if (op!=-1) s[0][op][i][j]=1; } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {scanf ("%d", &x); int op=x%3-1; if (op!=-1) s[1][op][j][i]=1; }for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {printf ("%d", ((S[0][0][i]&s[1][0][j]). COUNT () + ((S[0][0][i]&s[1][1][j]). Count () <<1) + ((S[0][1][i]&s[1][0][j]). Count () <<1) + (s[0][1][ I]&S[1][1][J]). Count ())%3); Putchar (j==n? ') \ n ': '); }}return 0;}
"Bitset" hdu4920 Matrix multiplication