Submission #722859
Source Code Expand
def dfs(x,y):
if memo[y][x] >= 0:
return memo[y][x]
dxdy = [(1,0), (0,1), (-1,0), (0,-1)]
ret = 0
for dx, dy in dxdy:
xdx = x+dx
if 0 <= xdx < W and 0<= y+dy < H and B[y][x] < B[y+dy][xdx]:
if memo[y+dy][xdx] >= 0:
hoge = memo[y+dy][xdx]
else:
hoge = dfs(xdx,y+dy)
memo[y+dy][xdx] = hoge
ret += hoge + 1
memo[y][x] = ret
return ret
import sys
sys.setrecursionlimit(1000000)
H,W = map(int,input().split())
B = [list(map(int,input().split())) for i in range(H)]
memo = [[-1]*W for j in range(H)]
ans = 0
for h in range(H):
for w in range(W):
ans += dfs(w,h)
print((ans + H*W) % (1000000007))
Submission Info
| Submission Time | |
|---|---|
| Task | D - 経路 |
| User | cpthgli |
| Language | PyPy3 (2.4.0) |
| Score | 0 |
| Code Size | 754 Byte |
| Status | TLE |
| Exec Time | 2130 ms |
| Memory | 242868 KiB |
Judge Result
| Set Name | sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 100 | ||||||
| Status |
|
|
| 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 | 2125 ms | 189236 KiB |
| 01.txt | TLE | 2130 ms | 242868 KiB |
| 02.txt | AC | 1261 ms | 72028 KiB |
| 03.txt | AC | 359 ms | 42992 KiB |
| 04.txt | AC | 363 ms | 42992 KiB |
| 05.txt | AC | 364 ms | 42992 KiB |
| 06.txt | AC | 416 ms | 44144 KiB |
| 07.txt | AC | 441 ms | 47576 KiB |
| 08.txt | AC | 374 ms | 43632 KiB |
| 09.txt | AC | 359 ms | 42992 KiB |
| 10.txt | AC | 475 ms | 49256 KiB |
| 11.txt | AC | 1954 ms | 88028 KiB |
| 12.txt | AC | 1989 ms | 88540 KiB |
| 13.txt | AC | 1924 ms | 87388 KiB |
| 14.txt | AC | 1943 ms | 88412 KiB |
| 15.txt | TLE | 2118 ms | 114228 KiB |
| 16.txt | TLE | 2027 ms | 89308 KiB |
| 17.txt | AC | 1930 ms | 87644 KiB |
| 18.txt | AC | 1248 ms | 71516 KiB |
| 19.txt | AC | 1065 ms | 67548 KiB |
| sample01.txt | AC | 370 ms | 42992 KiB |
| sample02.txt | AC | 360 ms | 42992 KiB |