import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables,macros macro unpack*(rhs: seq,cnt: static[int]): auto = let t = genSym(); result = quote do:(let `t` = `rhs`;()) for i in 0.. Oasis(v *= 2,once) # N <= 200, V <= 500, Lxy <= 9 # x:N * y:N * use:2 => V var dp = newSeqWith(N,newSeqWith(N,[-1,-1])) dp[0][0][0] = V proc seek(x,y,used:int): void = if x == N-1 and y == N-1: echo "YES" quit() for dxdy in [(0,1),(1,0),(0,-1),(-1,0)]: let (dx,dy) = dxdy (nx,ny) = (dx + x,dy + y) if nx < 0 or ny < 0 or nx >= N or ny >= N : continue var n_used = used v = dp[x][y][used] - L[nx][ny] if isOasis(nx,ny) and (not used.bool): n_used = true.int v *= 2 if dp[nx][ny][n_used] < v and v > 0: dp[nx][ny][n_used] = v seek(nx,ny,n_used) seek(0,0,false.int) echo "NO"