시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB115625414422.642%

문제

수아는 보물 지도를 얻었다. 보물 지도는 N × M 크기이고 1 × 1크기의 정사각형으로 나누어져 있다. 보물 지도의 각 칸은 바다이거나 섬의 일부이다. 그리고, 지도에는 보물과 부산의 해적선의 위치도 있다. 마지막으로 수아는 자신의 위치를 지도에 표시했다.

자 이제, 수아는 보물을 가지기 위한 경로를 정해야 한다. 경로는 현재 수아의 위치에서 시작해야 하고, 보물의 위치에서 끝나야 한다. 매번 수아가 이동할 때, 수아는 위, 아래, 오른쪽, 왼쪽 중의 한 방향으로 이동해야 하고, 섬으로 들어가면 안 된다. 하지만, 부산의 해적도 수아와 같은 방식으로 이동할 것이므로, 부산의 해적을 조심해야 한다. 매번 수아가 이동한 후에, 해적은 수아의 이동에 대해서 이동할지 멈춰있을지 결정할 수 있다. 수아의 움직임과 해적의 반응을 턴이라고 부르면, 매 턴이 지난 후에 다음과 같이 2가지 방법으로확인할 수 있다.

  • 만약 수아가 해적과 바라보고 있다면 (해적과 수직선, 수평선상에 수아가 있고, 오직 그 사이에 바다만 있을 때) 수아는 죽는다.
  • 만약, 수아가 아직 죽지 않았고, 보물 위치에 있다면, 수아는 보물은 얻은 것이다.

부산의 해적이 어떻게 움직이건 관계없이 수아가 죽지않고 보물을 얻을 수 있는 경로를 구하는 프로그램을 작성하시오. 

입력

첫째 줄에 N과 M이 주어진다. 둘째 줄부터 N개의 줄에 보물 지도가 주어진다. 각 줄은 M개의 문자로 구성되어 있는데, .은 바다이고, I는 섬이고, V는 해적의 위치이고, Y는 현재 수아의 위치이고, T는 보물의 위치이다. V, Y, T는 모두 한 번씩 등장한다. (1 ≤ N, M ≤ 700)

출력

첫째 줄에 수아가 보물을 얻을 수 있으면 YES를 출력하고, 그렇지 않으면 NO를 출력한다.

예제 입력 1

5 7
Y.....V
..I....
..IIIII
.......
...T...

예제 출력 1

YES

예제 입력 2

5 7
Y....V.
..I....
..IIIII
.......
...T...

예제 출력 2

NO

예제 입력 3

2 3
.YT
VII

예제 출력 3

NO

힌트

첫 번째 예제의 경우 아래 아래 아래 오른쪽 오른쪽 오른쪽 아래와 같이 움직이면 수아는 보물을 얻을 수 있다.

W3sicHJvYmxlbV9pZCI6IjI0MjQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJkODBcdWMwYjBcdWM3NTggXHVkNTc0XHVjODAxIiwiZGVzY3JpcHRpb24iOiI8cD5cdWMyMThcdWM1NDRcdWIyOTQgXHViY2Y0XHViYjNjIFx1YzljMFx1YjNjNFx1Yjk3YyBcdWM1YmJcdWM1YzhcdWIyZTQuIFx1YmNmNFx1YmIzYyBcdWM5YzBcdWIzYzRcdWIyOTQgTiAmdGltZXM7IE0gXHVkMDZjXHVhZTMwXHVjNzc0XHVhY2UwIDEgJnRpbWVzOyAxXHVkMDZjXHVhZTMwXHVjNzU4IFx1YzgxNVx1YzBhY1x1YWMwMVx1ZDYxNVx1YzczY1x1Yjg1YyBcdWIwOThcdWIyMDRcdWM1YjRcdWM4MzggXHVjNzg4XHViMmU0LiBcdWJjZjRcdWJiM2MgXHVjOWMwXHViM2M0XHVjNzU4IFx1YWMwMSBcdWNlNzhcdWM3NDAgXHViYzE0XHViMmU0XHVjNzc0XHVhYzcwXHViMDk4IFx1YzEyY1x1Yzc1OCBcdWM3N2NcdWJkODBcdWM3NzRcdWIyZTQuIFx1YWRmOFx1YjlhY1x1YWNlMCwgXHVjOWMwXHViM2M0XHVjNWQwXHViMjk0IFx1YmNmNFx1YmIzY1x1YWNmYyBcdWJkODBcdWMwYjBcdWM3NTggXHVkNTc0XHVjODAxXHVjMTIwXHVjNzU4IFx1YzcwNFx1Y2U1OFx1YjNjNCBcdWM3ODhcdWIyZTQuIFx1YjljOFx1YzljMFx1YjljOVx1YzczY1x1Yjg1YyBcdWMyMThcdWM1NDRcdWIyOTQgXHVjNzkwXHVjMmUwXHVjNzU4IFx1YzcwNFx1Y2U1OFx1Yjk3YyBcdWM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9ubHkgbGluZSBvZiB0aGUgb3V0cHV0IG11c3QgY29udGFpbiB0aGUgc3RyaW5nIFlFUywgaWYgaXQgaXMgcG9zc2libGUgdG8gc2V0IHVwIGEgcm91dGUgdG8gZ2V0IHRoZSB0cmVhc3VyZSwgb3IgTk8gb3RoZXJ3aXNlLjxcL3A+XHJcbiIsImhpbnQiOiI8cD5JbiB0aGUgZmlyc3QgZXhhbXBsZSwgdGhlIGZvbGxvd2luZyByb3V0ZSB3aWxsIGxldCB5b3UgZ2V0IHRoZSB0cmVhc3VyZTogRG93biwgRG93biwgRG93biwgUmlnaHQsIFJpZ2h0LCBSaWdodCwgRG93bi48XC9wPlxyXG5cclxuPHA+SW4gdGhlIHNlY29uZCBhbmQgdGhpcmQgZXhhbXBsZXMsIHRoZXJlIGlzIG5vIHJvdXRlIHRvIHRoZSB0cmVhc3VyZSB0aGF0IHlvdSB3aWxsIHN1cnZpdmUuPFwvcD5cclxuIiwib3JpZ2luYWwiOiIxIiwiaHRtbF90aXRsZSI6IjAiLCJwcm9ibGVtX2xhbmdfdGNvZGUiOiJFbmdsaXNoIiwibGltaXQiOiI8dWw+XHJcblx0PGxpPjEgJmxlOyBOLCBNICZsZTsgNzAwPFwvbGk+XHJcbjxcL3VsPlxyXG4ifV0=

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2011 4번

  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: jh05013