목차

장난감 강아지

ps
링크acmicpc.net/…
출처BOJ
문제 번호31287
문제명장난감 강아지
레벨실버 2
분류

시뮬레이션

시간복잡도O(n)
인풋사이즈n<=2000
사용한 언어Python 3.11
제출기록31120KB / 40ms
최고기록40ms
해결날짜2024/02/15

풀이

코드

"""Solution code for "BOJ 31287. 장난감 강아지".

- Problem link: https://www.acmicpc.net/problem/31287
- Solution link: http://www.teferi.net/ps/problems/boj/31287

Tags: [simulation]
"""

DX = {'U': 0, 'D': 0, 'L': -1, 'R': 1}
DY = {'U': 1, 'D': -1, 'L': 0, 'R': 0}


def main():
    N, K = [int(x) for x in input().split()]
    S = input()

    x = y = 0
    visited_pos = {(x := x + DX[c], y := y + DY[c]) for c in S}
    if any((-x * i, -y * i) in visited_pos for i in range(min(N, K))):
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()