JUMPGAME - python 런타임 에러

  • kiyeon88
    kiyeon88

    안녕하세요. JUMPGAME 문제를 아래와 같이 책에 있는대로 파이썬으로 바꿔서 제출했고 제 컴터에서는 올바른 답이 나오는데 왜 run time error가 나는거죠? 도저히 모르겠네요...

    import numpy as np
    
    def jump2(y,x,cache):
        if(y>=n or x>=n): return False
        if(y==n-1 and x==n-1): return True
        if(cache[y][x] != None): return cache[y][x]
        jumpSize=board[y][x]
        cache[y][x]=(jump2(y,x+jumpSize,cache) | jump2(y+jumpSize,x,cache))
        return cache[y][x]
    
    for _ in range(int(input())):
        n=int(input())
        raw=list(map(int,input().split()))
        board=np.reshape(raw,(n,n))
        cache=[[None]*(n) for _ in range(n)]
        if (jump2(0,0,cache)==True): print('YES')
        else: print('NO')
    


    5년 전
2개의 댓글이 있습니다.
  • dychoi
    dychoi

    저도 찾아보니.. 그냥 python이 느려서 그렇다는 말도 있구요..
    저도 계속 책 대로 풀어도 시간 초과가 떠서.. ㅎㅎ
    일단 문제 해결 경험을 쌓는데 집중하고, python구조 상 더 빠른 방법이 있는지는 차차 알아보려구요 ㅠㅠ


    5년 전 link
  • gusdud0222
    gusdud0222

    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    c = int(input())
    answer = []

    while c != 0:

    c -= 1
    n = int(input())
    graph = [list(map(int, input().split())) for _ in range(n)]
    d = [[-1] * n for _ in range(n)]
    
    
    def jump2(y, x):
        # 영역 밖으로
        if y >= n or x >= n:
            return 0
        # 마지막칸 도착
        if y == n - 1 and x == n - 1:
            return 1
        # 메모이제이션
        if d[y][x] != -1:
            return d[y][x]
        jumpSize = graph[y][x]
        d[y][x] = (jump2(y + jumpSize, x) or
                   jump2(y, x + jumpSize))
        return d[y][x]
    
    answer.append(jump2(0,0))

    for i in range(len(answer)):
    if answer[i] == 1:
    print("YES")
    else:
    print("NO")

    저도 그러네요 ㅠㅠㅠ 하 30분동안 개고생중


    2년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.