Submission #721116


Source Code Expand

MOD = 10**9+7
h,w = map(int,raw_input().split(' '))
maze = [map(int,raw_input().split(' ')) for i in xrange(h)]
def how_many(i,j):
	count = []
	dire = [[i-1,j],[i+1,j],[i,j+1],[i,j-1]]
	for k in xrange(4):
		if dire[k][0]<0 or dire[k][0]>=h or dire[k][1]<0 or dire[k][1]>=w:
			continue
		if maze[i][j]<maze[dire[k][0]][dire[k][1]]:
			count.append([dire[k][0],dire[k][1]])
	return count
children = [[how_many(j,i) for i in xrange(w)] for j in xrange(h)]
routs = [[None if children[i][j]!=0 else 0 for j in xrange(w)] for i in xrange(h)]
def how_many_all(i,j):
	count = 0
	for child in children[i][j]:
		if routs[child[0]][child[1]]==None:
			count += (how_many_all(child[0],child[1])+1)%MOD
		else:
			count += (routs[child[0]][child[1]]+1)%MOD
	routs[i][j] = count
	return count
count = 0
for i in xrange(h):
	for j in xrange(w):
		count+=(how_many_all(i,j)+1)%MOD
print count%MOD

Submission Info

Submission Time
Task D - 経路
User yasuke
Language Python (2.7.6)
Score 0
Code Size 909 Byte
Status TLE
Exec Time 2115 ms
Memory 105220 KiB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 10
TLE × 12
Set Name Test Cases
sample sample01.txt, sample02.txt
All 00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
00.txt TLE 2111 ms 104580 KiB
01.txt TLE 2111 ms 105220 KiB
02.txt TLE 2110 ms 84996 KiB
03.txt AC 28 ms 2696 KiB
04.txt AC 27 ms 2696 KiB
05.txt AC 28 ms 2696 KiB
06.txt AC 33 ms 2820 KiB
07.txt AC 36 ms 2948 KiB
08.txt AC 32 ms 2696 KiB
09.txt AC 28 ms 2696 KiB
10.txt AC 52 ms 3460 KiB
11.txt TLE 2115 ms 102404 KiB
12.txt TLE 2110 ms 97540 KiB
13.txt TLE 2114 ms 100356 KiB
14.txt TLE 2115 ms 102404 KiB
15.txt TLE 2115 ms 103044 KiB
16.txt TLE 2115 ms 102404 KiB
17.txt TLE 2114 ms 100100 KiB
18.txt TLE 2112 ms 71044 KiB
19.txt TLE 2109 ms 39300 KiB
sample01.txt AC 27 ms 2696 KiB
sample02.txt AC 26 ms 2696 KiB