CF510B.Fox And Two Dots
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n×m cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots d1,d2,...,dk a cycle if and only if it meets the following condition:
- These k dots are different: if i=j then di is different from dj .
- k is at least 4.
- All dots belong to the same color.
- For all 1<=i<=k−1 : di and di+1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.
Determine if there exists a cycle on the field.
输入格式
The first line contains two integers n and m ( 2<=n,m<=50 ): the number of rows and columns of the board.
Then n lines follow, each line contains a string consisting of m characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.
输出格式
Output "Yes" if there exists a cycle, and "No" otherwise.
输入输出样例
输入#1
3 4 AAAA ABCA AAAA
输出#1
Yes
输入#2
3 4 AAAA ABCA AADA
输出#2
No
输入#3
4 4 YYYR BYBY BBBY BBBY
输出#3
Yes
输入#4
7 6 AAAAAB ABBBAB ABAAAB ABABBB ABAAAB ABBBAB AAAAAB
输出#4
Yes
输入#5
2 13 ABCDEFGHIJKLM NOPQRSTUVWXYZ
输出#5
No
说明/提示
In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).