| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1.35 초 | 1024 MB | 42 | 23 | 22 | 55.000% |
For creating a task for CEOI 2024, Ben was given a toy as a present from the scientific committee. The toy is a puzzle which can be imagined as a $H \times W$ grid containing a metal object consisting of two parts: A horizontal 1ドル\times K$ part and a vertical $L \times 1$ part, which are loosely attached to each other. Neither of the parts can be rotated in any way, but each can be slid vertically or horizontally independently of the other one, as long as they always overlap on exactly one square.
Furthermore, the grid contains several obstacles. No part of the metal object can move through an obstacle. Worse yet, the parts also cannot move outside the grid, not even partially. Ben's task is to move the metal object from a designated starting location to a (possibly) different location so that both parts overlap on a designated target square.
However, Ben has been playing with the toy for a while and he has not yet been able to solve the task. In fact, he has gained a suspicion that the organizers have played a prank on him and have given him an unsolvable puzzle. He thus asks for your help by telling him whether the puzzle is solvable or not.
The first line of the input contains four space-separated integers $W,ドル $H,ドル $K$ and $L$ — the width and the height of the puzzle, the width of the horizontal part and the height of the vertical part, respectively. The second line contains four integers $x_h,ドル $y_h,ドル $x_v$ and $y_v$ — the coordinates of the leftmost square occupied by the horizontal part and the coordinates of the topmost square occupied by the vertical part.
The rows are numbered from 0ドル$ to $H-1$ from top to bottom and columns are numbered 0ドル$ to $W-1$ from left to right. The $x$ coordinate denotes the column number and $y$ coordinate denotes the row number.
The next $H$ lines contain $W$ characters each, representing the grid. The character . represents an empty square, the character X represents an obstacle and the character *represents the target square.
It is guaranteed that the initial position of the metal object is valid, i.e., that the two parts overlap on exactly one square and the two parts neither overlap with an obstacle nor stick out from the grid.
There is a single target square, i.e., a single occurrence of the *symbol in the toy, which might overlap with the initial position of the metal object.
Print a single line containing YES if it is possible to move the metal object to the target square, NO otherwise.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 14 | $W, H \le 50$ |
| 2 | 21 | $W, H \le 90$ |
| 3 | 9 | $W, H \le 300$ and $K, L \le 10$ |
| 4 | 29 | $W, H \le 360$ |
| 5 | 27 | no additional constraints |
4 3 2 2 0 1 0 0 .X.* .... ...X
YES
The initial situation looks as follows:
We can reach the target square by first moving the vertical part one square down, followed by alternating movement to the right of the vertical and horizontal parts as long as possible. Then we can move the vertical part up and to the right, reaching the target square, and finally move the horizontal part up, reaching the target as well.
2 3 2 3 0 1 0 0 .X .* .X
NO
There is no way how to move the vertical part without running into an obstacle. Therefore, it can never reach the target square.