-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10830.cpp
More file actions
55 lines (49 loc) · 1.13 KB
/
Copy path10830.cpp
File metadata and controls
55 lines (49 loc) · 1.13 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
#include <stdio.h>
#include <vector>
using namespace std;
vector<vector<int>> mulMatrix(vector<vector<int>> A, vector<vector<int>> B)
{
int size = A.size();
vector<vector<int>> re(size, vector<int>(size, 0));
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
for (int k = 0; k < size; k++)
{
re[i][j] += A[i][k] * B[k][j];
re[i][j] %= 1000;
}
}
}
return re;
}
int main()
{
int N;
long long B;
vector<vector<int>> mat(N, vector<int>(N, 0));
scanf("%d %lld", &N, &B);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
scanf("%d", &mat[i][j]);
vector<vector<int>> answer(N, vector<int>(N, 0));
for (int i = 0; i < N; i++)
answer[i][i] = 1;
while (B > 0)
{
if (B % 2)
answer = mulMatrix(answer, mat);
mat = mulMatrix(mat, mat);
B /= 2;
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
printf("%d ", answer[i][j]);
}
printf("\n");
}
return 0;
}