-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1533.py
More file actions
28 lines (25 loc) · 714 Bytes
/
Copy path1533.py
File metadata and controls
28 lines (25 loc) · 714 Bytes
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
N,S,E,T = map(int, input().split())
mod = 1000003
m = [[0]*N*5 for _ in range(N*5)]
for i in range(N):
q = list(map(int, input()))
for j in range(N):
if q[j] == 0: continue
m[i*5][j*5+q[j]-1] = 1
for j in range(1,5):
m[i*5+j][i*5+j-1] = 1
def sqMat(mat, mat0):
out = [[0]*N*5 for _ in range(N*5)]
for i in range(N*5):
for j in range(N*5):
for k in range(N*5):
out[i][j] = (out[i][j]+mat[i][k]*mat0[k][j])%mod
return out
def fpow(mat, n):
if n == 1: return mat
else:
x = fpow(mat, n//2)
if n % 2 == 0: return sqMat(x,x)
else: return sqMat(sqMat(x,x),mat)
m = fpow(m ,T)
print(m[(S-1)*5][(E-1)*5])