Codeforces
Space Navigation
john.k
2021. 2. 6. 18:21
반응형
Codeforces Round #699 (Div. 2)
A. Space Navigation
https://codeforces.com/contest/1481/problem/A
Problem - A - Codeforces
codeforces.com
문제 전문은 위 링크에서 확인하실 수 있습니다.
t = int(input())
for _ in range(t):
px, py = [int(i) for i in input().split()]
s = input()
orderDict = {"U": 0, "D": 0, "R": 0, "L": 0}
for i in s:
orderDict[i] += 1
if 0 <= px <= orderDict["R"] and 0 <= py <= orderDict["U"]:
print("YES")
elif 0 <= px <= orderDict["R"] and -1*orderDict["D"] <= py <= 0:
print("YES")
elif -1*orderDict["L"] <= px <= 0 and 0 <= py <= orderDict["U"]:
print("YES")
elif -1*orderDict["L"] <= px <= 0 and -1*orderDict["D"] <= py <= 0:
print("YES")
else:
print("NO")
넘치는 이동 횟수는 지울 수 있으니까
x,y 좌표가 각각 양수, 음수일때를 고려해서 좌표와 이동 횟수의 값 범위를 정해서
YES일 경우에 출력하고 나머지는 NO를 출력했습니다.
반응형