初来乍到的同学先刷"分类"标签下"语言入门"题,参加初试的同学请刷"分类"标签下"数据结构"题。大伙有任何疑问,都可以在QQ群(546311977)里讨论, 群二维码在页面下方~欢迎大家咨询~另外所有通过麓研购买资料进入本OJ的全都是盗版,出题不易,请大家抵制麓研!
Problem B: Lost In CSU

Problem B: Lost In CSU

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 559  Solved: 136
[Submit] [Status] [Web Board] [Creator:]

Description

PIPI and his friend POPO are lost in Central South University, and they both hope to find each other as soon as possible.
PIPI can move twice per second, each time he can move to another space in four directions: up / down / left / right. POPO can move once per second, and each time he can move to another space in eight directions : up / down / left / right / top right / bottom right / top left / bottom left.
How many seconds does it take for PIPI and POPO to meet each other? Give the minimum time.

Input

The first row is two integers N and M(1<=N,M<=1000), representing the rows and columns of the map.
Next is an N × M matrix.
Among them, "D" indicates the position of PIPI, and "C" indicates the position of POPO.
"#" Indicates an obstacle that cannot be passed, and "." Is a position that can pass normally.

Output

If they can meet each other, the first line outputs a YES, and the second line outputs the minimum encounter time.
Otherwise, a NO is output to indicate that they cannot meet each other.

Sample Input

4 5
.....
.###.
...#D
..C#.

Sample Output

YES
3
welcome to PIPIOJ 2025
湘ICP备19004804号