QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74815#4231. Rafting Tripinfinityf1reWA 131ms10868kbPython31.8kb2023-02-04 09:34:512023-02-04 09:34:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-04 09:34:53]
  • 评测
  • 测评结果:WA
  • 用时:131ms
  • 内存:10868kb
  • [2023-02-04 09:34:51]
  • 提交

answer

global d_sights
d_sights = {}

def trace(arr, n, m, i, j) :
    
    visited = set([])
    direction = {"^": (-1, 0), ">": (0, 1), "v": (1, 0), "<": (0, -1), "#": (0, 0)}
    sights = set([])
    x = i
    y = j
    while 0 <= x < n and 0 <= y < m and arr[x][y] in direction and (x, y) not in visited:
        visited.add((x, y))
        
        if (x, y) in d_sights :
            sights = sights.union(d_sights[(x, y)])
            d_sights[x, y] = sights
            return 
    
        # print(i, j, x, y, sights)
        
        if arr[x][y] == "#" :
            sights.add((x, y))
            break
        
        if x -1 >= 0 and arr[x - 1][y] == "#" :
            sights.add((x-1, y))
        if x + 1 < n and arr[x + 1][y] == "#":
            sights.add((x+1, y))
        if y - 1 >= 0 and arr[x][y - 1] == "#" :
            sights.add((x, y-1))
        if y + 1 < m and arr[x][y + 1] == "#" :
            sights.add((x, y+1))
            
        temp_x = x + direction[arr[x][y]] [0]
        temp_y = y + direction[arr[x][y]] [1]
        
        x, y = temp_x, temp_y
        
    d_sights[(i, j)] = sights
    
    return     
        
def solve(arr, n, m) :
    
    for i in range(n) :
        for j in range(m) :
            trace(arr, n, m, i, j)
          
    return 
            
import random

if __name__ == "__main__" :
    
    n, m = map(int, input().split())
    
    arr = [[random.choice([">", "<", "v", "^", ">", "<", "v", "^", ".", "#"]) for i in range(500)] for j in range(500)]
    
    for i in arr :
        print(i)
        
    # arr = []
    
    # for i in range(n) :
    #     arr.append(list(input().strip()))
        
        
    solve(arr, n, m)
    
    # print(d_sights)
    
    d = [len(d_sights[x]) for x in d_sights]
    
    print(max(d))

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 131ms
memory: 10868kb

input:

5 6
v<<<#v
v#v<.>
>>v<<<
..v##^
#<<<.^

output:

['v', 'v', '>', '>', '<', 'v', '>', '>', '<', '<', '#', '#', '>', '^', '^', '<', '.', '>', '>', 'v', '<', 'v', '.', '^', '<', 'v', '>', '<', 'v', '>', '^', '#', 'v', '<', 'v', '<', 'v', '^', '>', 'v', 'v', '>', '<', '.', '^', 'v', 'v', '^', '<', '<', 'v', 'v', 'v', 'v', '#', 'v', '.', '>', '<', '<',...

result:

wrong answer 1st lines differ - expected: '4', found: '['v', 'v', '>', '>', '<', 'v',..., '<', '.', '>', '>', '.', '.']'