Submission #39614104


Source Code Expand

h, w = [int(i) for i in input().split()]
mat = []
for i in range(h):
    row = [int(i) for i in input().split()]
    mat.append(row)
ans = 0

def dfs(i, j, vis):
    global mat, ans, h, w
    if i == h-1 and j == w-1:
        if mat[i][j] not in vis:
            ans += 1
        return
    if i < h-1:
        if mat[i][j] not in vis:
            vis.add(mat[i][j])
            dfs(i+1, j, vis)
            vis.remove(mat[i][j])
    if j < w-1:
        if mat[i][j] not in vis:
            vis.add(mat[i][j])
            dfs(i, j+1, vis)
            vis.remove(mat[i][j])

dfs(0, 0, set())
print(ans)

Submission Info

Submission Time
Task C - Make Takahashi Happy
User shinever
Language PyPy3 (7.3.0)
Score 300
Code Size 626 Byte
Status AC
Exec Time 113 ms
Memory 70604 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 25
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 87 ms 61760 KiB
001.txt AC 52 ms 61800 KiB
002.txt AC 92 ms 68508 KiB
003.txt AC 83 ms 68420 KiB
004.txt AC 50 ms 61956 KiB
005.txt AC 45 ms 61932 KiB
006.txt AC 82 ms 68576 KiB
007.txt AC 69 ms 67972 KiB
008.txt AC 54 ms 61804 KiB
009.txt AC 52 ms 61648 KiB
010.txt AC 88 ms 68324 KiB
011.txt AC 87 ms 68392 KiB
012.txt AC 92 ms 68436 KiB
013.txt AC 88 ms 68268 KiB
014.txt AC 92 ms 68580 KiB
015.txt AC 113 ms 69396 KiB
016.txt AC 86 ms 68176 KiB
017.txt AC 102 ms 70604 KiB
018.txt AC 113 ms 70296 KiB
019.txt AC 84 ms 68452 KiB
020.txt AC 106 ms 70064 KiB
021.txt AC 77 ms 68132 KiB
022.txt AC 110 ms 70088 KiB
example0.txt AC 52 ms 61744 KiB
example1.txt AC 90 ms 68388 KiB