Submission #1178124


Source Code Expand

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return tuple(int(x) for x in sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return sys.stdin.readline()


def main():
    h,w = LI()
    a = tuple(LI() for _ in range(h))
    r = 0
    dy = (0,0,1,-1)
    dx = (1,-1,0,0)

    m = tuple([None]*w for _ in range(h))
    def f(y,x):
        if m[y][x]:
            return m[y][x]

        r = 1
        k = a[y][x]
        for i in range(4):
            ty,tx = y+dy[i], x+dx[i]
            if 0 <= ty < h and 0 <= tx < w:
                if a[ty][tx] >= k:
                    continue
                r += f(ty,tx)
        m[y][x] = r % mod
        return m[y][x]

    return sum(sum(f(i,j) for j in range(w)) % mod for i in range(h)) % mod


print(main())

Submission Info

Submission Time
Task D - 経路
User iehn
Language PyPy3 (2.4.0)
Score 100
Code Size 1096 Byte
Status AC
Exec Time 1453 ms
Memory 142680 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
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, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
00.txt AC 926 ms 120408 KB
01.txt AC 1218 ms 142680 KB
02.txt AC 936 ms 120408 KB
03.txt AC 286 ms 64428 KB
04.txt AC 283 ms 64236 KB
05.txt AC 283 ms 64364 KB
06.txt AC 301 ms 65772 KB
07.txt AC 318 ms 67692 KB
08.txt AC 322 ms 67944 KB
09.txt AC 278 ms 64236 KB
10.txt AC 336 ms 70744 KB
11.txt AC 1389 ms 121432 KB
12.txt AC 1445 ms 120536 KB
13.txt AC 1429 ms 120820 KB
14.txt AC 1415 ms 120920 KB
15.txt AC 1151 ms 120536 KB
16.txt AC 1426 ms 120280 KB
17.txt AC 1453 ms 122072 KB
18.txt AC 926 ms 121304 KB
19.txt AC 813 ms 120536 KB
sample01.txt AC 282 ms 64236 KB
sample02.txt AC 278 ms 64236 KB