TopCoder

User's AC Ratio

95.4% (62/65)

Submission's AC Ratio

60.5% (75/124)

Tags

Description

以下乍看之下是一個把矩陣相乘的結果的各個元素相加後模 5 之後輸出的程式碼,可是這份程式碼無法獲得 Accepted。請給出與以下的程式碼 edit distance 不超過 2,且能把矩陣相乘的結果的各個元素相加後模 5 之後輸出並獲得 Accepted 的程式碼。

// =^● ⋏ ●^=
#include<bits/stdc++.h>
using namespace std;
#define small int8_t

small a[10][10],b[10][10];

int main(){
    int n; cin>>n;
    for(small i=0;i<n;++i)for(small j=0;j<n;++j)cin>>a[i][j];
    for(small i=0;i<n;++i)for(small j=0;j<n;++j)cin>>b[j][i];
    int cnt=0;
    for(small i=0;i<n;++i)for(small j=0;j<n;++j)for(small k=0;k<n;++k)cnt+=a[i][k]*b[j][k];
    cout<<cnt%5<<endl;
}

Input Format

第一行是一個正整數 $N$,代表矩陣的大小是 $N \times N$。
接下來的 $N$ 行每行有 $N$ 個數字,依序代表第一個矩陣 $a$ 中的數字。
在這之中,第 $i$ 行的第 $j$ 個數字是 $a _ {i,j}$。
接下來的 $N$ 行每行有 $N$ 個數字,依序代表第二個矩陣 $b$ 中的數字。
在這之中,第 $i$ 行的第 $j$ 個數字是 $b _ {i,j}$。

  • $N \leq 10$
  • $0 \leq a _ {i,j}, b _ {i,j} < 2$

Output Format

請輸出一個數字,代表把矩陣相乘的結果的各個元素相加後模 5 的結果。

Sample Input 1

4
1 1 0 0
1 0 1 1
0 0 0 1
1 1 1 0
0 1 0 1
1 0 0 0
1 1 1 1
0 1 0 0

Sample Output 1

3

Hints

Problem Source

Subtasks

No. Testdata Range Score
1 0~2 1

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 16384 262144 1
1 1000 16384 262144 1
2 1000 16384 262144 1