Python/백준 (BOJ)

[BOJ][B2]LUKA - 3234

ㅋㅋ! 2025. 9. 26. 13:00

 

https://www.acmicpc.net/problem/3234

문제 전문은 링크 참조

문제가공

  1. 좌표평면 위에 현재 나의 위치를 입력받는다
  2. 목표물이 몇 번 움직이는지 입력 받는다.
  3. 목표물이 움직이는 방향을 입력 받는다.(1초씩움직임)
  4. 나의 위치에 근접해오는 시간대를 출력한다.(없으면 -1)

코드작성

방향 정보 : ('I': 오른쪽, 'S': 위쪽, 'Z': 왼쪽, 'J': 아래쪽)

me =list( map(int,input().split()))
sec = int(input())
d = input()
target = [0,0]
direction = {'I':[1,0],'S':[0,1],'Z':[-1,0],'J':[0,-1]}
arr=[]
i =0
if abs(me[0]-target[0])<=1 and abs(me[1]-target[1])<=1:
    arr.append(i)
for c in d:
    i+=1
    target[0]+=direction[c][0]
    target[1]+=direction[c][1]
    if abs(me[0]-target[0])<=1 and abs(me[1]-target[1])<=1:
        arr.append(i)
print(*arr if len(arr)>0 else '-1',sep='\\n')