📌문제
https://www.acmicpc.net/problem/13567
🎖️난이도
✔️풀이
# 정답
M, n = list(map(int, input().split()))
commands = []
[i, j] = [0, 0]
dir = [[0,1], [-1,0], [0, -1], [1, 0]] # (동, 남, 서, 북)
tmp_idx = 0
for _ in range(n):
commands.append(input())
check_answer = 1
for command in commands:
if i >= M or j >= M or i < 0 or j < 0:
break
else:
if command[0] == 'M':
i += dir[tmp_idx][1]*int(command[5:])
j += dir[tmp_idx][0]*int(command[5:])
elif command[5] == '0':
tmp_idx = (tmp_idx + 4 - 1) % 4
elif command[5] == '1':
tmp_idx = (tmp_idx + 1) % 4
if check_answer == -1 or i >= M or j >= M or i < 0 or j < 0:
print(-1)
else :
print(i, j)
'[ 알고리즘 ] > Implementation' 카테고리의 다른 글
[백준] 2438. 별 찍기 - 1 (0) | 2022.06.30 |
---|---|
[CodeUp] 6098. 성실한 개미 (0) | 2022.06.29 |
[CodeUp] 6096. 바둑알 십자 뒤집기 (0) | 2022.06.29 |
[백준] 9455. 박스 (0) | 2022.06.29 |
[백준] 14954. Happy Number (0) | 2022.06.29 |