#2327622

Solution for 1126: The Secret Number by n_knuu

Source Code Status Test Cases
    Policy: public     Reviewed: 16    
00.36 sec    7940 KB    33 lines     854 bytes    2017-05-20 04:19
drc = [(0, 1), (1, 0)]


def dfs(r, c):
    if (r, c) in memo:
        return memo[r, c]
    ret = ''
    for dr, dc in drc:
        nr, nc = r + dr, c + dc
        if nr < H and nc < W and board[nr][nc].isdigit():
            cand = dfs(nr, nc)
            if len(cand) > len(ret) or (len(cand) == len(ret) and cand > ret):
                ret = cand
    memo[r, c] = board[r][c] + ''.join(ret)
    return board[r][c] + ret


while True:
    W, H = map(int, input().split())
    if not (W | H):
        break
    board = [input() for _ in range(H)]
    memo = dict()
    ans = ''
    for r in range(H):
        for c in range(W):
            if board[r][c].isdigit() and board[r][c] != '0':
                cand = dfs(r, c)
                if len(cand) > len(ans) or (len(cand) == len(ans) and cand > ans):
                    ans = cand
    print(ans)


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 Python3 CPU: 00.36 sec Memory: 7940 KB Length: 854 B 2017-05-20 04:19 2017-05-20 04:19
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.36 sec 7940 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags