用户输出
1 3
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#2382 | #1005. 兜圈子 | Accepted | 100 | 2099 ms | 31156 K | Python 3 / 865 B | harkerbest | 2023-11-17 12:19:36 |
def find_stopped_position(H, W, grid):
visited = set()
current_position = (1, 1)
while True:
i, j = current_position
if current_position in visited:
return -1
visited.add(current_position)
if grid[i-1][j-1] == 'U' and i > 1:
current_position = (i - 1, j)
elif grid[i-1][j-1] == 'D' and i < H:
current_position = (i + 1, j)
elif grid[i-1][j-1] == 'L' and j > 1:
current_position = (i, j - 1)
elif grid[i-1][j-1] == 'R' and j < W:
current_position = (i, j + 1)
else:
return current_position
H, W = map(int, input().split())
grid = [input().strip() for _ in range(H)]
result = find_stopped_position(H, W, grid)
if result == -1:
print(-1)
else:
print(result[0], result[1])
用户输出
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