用户输出
1 3
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#3106 | #1005. 兜圈子 | Accepted | 100 | 2022 ms | 31224 K | Python 3 / 758 B | s230026068 | 2023-11-23 3:21:48 |
def grid_movement(h, w, grid):
i, j = 1, 1
visited = set()
while 1 <= i <= h and 1 <= j <= w:
if (i, j) in visited:
return -1
visited.add((i, j))
direction = grid[i - 1][j - 1]
if direction == 'U' and i != 1:
i -= 1
elif direction == 'D' and i != h:
i += 1
elif direction == 'L' and j != 1:
j -= 1
elif direction == 'R' and j != w:
j += 1
else:
# Cannot move further
return f"{i} {j}"
return -1
# 读取输入
h, w = map(int, input().split())
grid = [input().strip() for _ in range(h)]
# 输出结果
result = grid_movement(h, w, grid)
print(result)
用户输出
1 3
系统信息
Exited with return code 0
9 44
RRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR
RRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD
DRDLR
<310 bytes omitted>
用户输出
9 5
系统信息
Exited with return code 0
500 500
RRUURUUURDRURLLLUDDRLRUUUURRRLRUUULRLURDUDUURDRRUDDRDLLLRRLLLLULRUULRRLDDRURDLULDUDDLRRRLUDR
<250408 bytes omitted>
用户输出
1 3
系统信息
Exited with return code 0
500 500
DDDUUULULDUUUUDRULURDLLULUURDLRUULDLUDRLLDDDULUURDLLDLDDRDULUUURULDRDUDUDDRDLLLLRDDUULLRLUUD
<250408 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
500 500
LULRRLLRDDULRUULRDULRUDUDLDDULRUDLLRRDULDRLDUDLDRULUUDUURLLLDRRLLDUUULUURRLRLLLDDRLDLDDRUDRD
<250408 bytes omitted>
用户输出
1 1
系统信息
Exited with return code 0
500 500
RRRDLURDUUDLRRRUURUDLUDRURURUURUDDRUDDDDURUDURULDLRRRLDRDDRDDULURDDDLRDURUDDRLUUDRLUDLLDURRL
<250408 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
500 500
RRRRRDDLDLDLRRRRDLRLLLLLRUUURRUDRURDULLDLUUDLULLDLURUDDLRLRRLLRLRUUURLURDURULLRRRDULRDLDDLUU
<250408 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
500 500
DRDULLRDDURDLLLUDULRLLRRDLDUDDUULDDURUDDURDDRLRDRDRRLURDRUDLRULDRDRDURUUUDDRDDRLRDRLRUURRRUL
<250408 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
500 500
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
<250408 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
500 500
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
<250408 bytes omitted>
用户输出
341 1
系统信息
Exited with return code 0
500 500
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
<250408 bytes omitted>
用户输出
500 432
系统信息
Exited with return code 0
500 500
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
<250408 bytes omitted>
用户输出
432 500
系统信息
Exited with return code 0