Submission #1008845

# Submission time Handle Problem Language Result Execution time Memory
1008845 2024-06-27T01:08:48 Z vjudge1 Patkice (COCI20_patkice) Python 3
0 / 50
1000 ms 3208 KB
def get_O_coordinate(r, c, grid):
    for i in range(r):
        for j in range(c):
            if grid[i][j] == 'o':
                return [i, j]

def get_symbol(grid, position):
    # . / x / > / < / ^ / v
    return grid[position[0]][position[1]]

def where_to_move(position_symbol):
    if position_symbol == '.':
        return 'STOP'
    elif position_symbol == 'x':
        return 'DONE'
    elif position_symbol == '^':
        return 'UP'
    elif position_symbol == 'v':
        return 'DOWN'
    elif position_symbol == '>':
        return 'RIGHT'
    else:
        return 'LEFT'

def update_position(direction, start_position):
    if direction == 'E' or direction == 'RIGHT':
        start_position[1] += 1
    elif direction == 'W' or direction == 'LEFT':
        start_position[1] += -1
    elif direction == 'N' or direction == 'UP':
        start_position[0] += -1
    elif direction == 'S' or direction == 'DOWN':
        start_position[0] += 1
    
    return start_position

def count_step(position, grid):
    """
    return count for each step if possible
    return -1 if not possible
    """
    count = 0
    symbol = get_symbol(grid, position)
    moving = where_to_move(symbol) # up down left right

    while True:
        count += 1
        if moving == 'STOP':
            return -1
        elif moving == 'DONE':
            return count
        else:
            position = update_position(moving, position)
            symbol = get_symbol(grid, position)
            moving = where_to_move(symbol)
    


r, c = map(int, input().split())
grid = []
for _ in range(r):
    grid.append(list(input()))


start_coordinatex = get_O_coordinate(r, c, grid)
start_coordinatey = get_O_coordinate(r, c, grid)
start_coordinatez = get_O_coordinate(r, c, grid)
start_coordinateq = get_O_coordinate(r, c, grid)

count_up = count_step(update_position('N', start_coordinatex), grid)
count_down = count_step(update_position('S', start_coordinatey), grid)
count_right = count_step(update_position('E', start_coordinatez), grid)
count_left = count_step(update_position('W', start_coordinateq), grid)

lst = [[count_right, 'E'], [count_up, 'N'], [count_down, 'S'], [count_left, 'W']]


if count_up == -1 and count_down == -1 and count_right == -1 and count_left == -1:
    print(':(')
else:
    print(':)')
    
    minimum_value = max(count_down, count_left, count_right, count_up)
    for step, wind in lst:
        if step < minimum_value and step != -1:
            minimum_value = step
    
    # alphabetically --> E N S W
    for val, wind in lst:
        if val == minimum_value:
            print(wind)
            break
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3164 KB Output is correct
2 Execution timed out 1061 ms 3208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3164 KB Output is correct
2 Correct 12 ms 3164 KB Output is correct
3 Execution timed out 1004 ms 3164 KB Time limit exceeded
4 Halted 0 ms 0 KB -