303561: CF689A. Mike and Cellphone

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Mike and Cellphone

题意翻译

题目描述 迈克在海滩游泳时不小心将手机放入水中。他买了一个带有老式键盘的手机。键盘只有十个数字大小的键,位于以下方式: | 1 | 2 | 3 | | -----------: | -----------: | -----------: | | 4 | 5 | 6 | | 7 | 8 | 9 | | | 0 | | | 联系人与他的旧手机一起消失了,他现在只能记住他的手指在他输入一些数字时的移动方式。人们可以将手指动作视为连接按下按键的一系列动作。例如,数字“586”的手指移动动作与数字“253”的手指移动动作相同。 Mike通过他的“手指记忆”输入了一个数字并开始调用它,所以他现在担心,有没有其他数字,有相同的手指动作? 输入格式: 输入的第一行包含唯一的整数n(1<=N<=9)表示Mike输入的电话号码中的位数。第二行由1到9组成的n个字符的字符串。 输出格式: 如果没有其他电话号码具有相同的手指移动,则输出“YES”,否则输出“NO”(不带引号)。

题目描述

While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF689A/0342f4147f163e7abcc57c3f34c170ac4ad52a2c.png)Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF689A/1ee471f119d0342dde68609c8abcbc49afcbf489.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF689A/030b9a0e4d0e91a9966bf07663da14ee536572b7.png)Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?

输入输出格式

输入格式


The first line of the input contains the only integer $ n $ ( $ 1<=n<=9 $ ) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of $ n $ digits (characters from '0' to '9') representing the number that Mike put in.

输出格式


If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line.

输入输出样例

输入样例 #1

3
586

输出样例 #1

NO

输入样例 #2

2
09

输出样例 #2

NO

输入样例 #3

9
123456789

输出样例 #3

YES

输入样例 #4

3
911

输出样例 #4

YES

说明

You can find the picture clarifying the first sample case in the statement above.

Input

题意翻译

题目描述 迈克在海滩游泳时不小心将手机放入水中。他买了一个带有老式键盘的手机。键盘只有十个数字大小的键,位于以下方式: | 1 | 2 | 3 | | -----------: | -----------: | -----------: | | 4 | 5 | 6 | | 7 | 8 | 9 | | | 0 | | | 联系人与他的旧手机一起消失了,他现在只能记住他的手指在他输入一些数字时的移动方式。人们可以将手指动作视为连接按下按键的一系列动作。例如,数字“586”的手指移动动作与数字“253”的手指移动动作相同。 Mike通过他的“手指记忆”输入了一个数字并开始调用它,所以他现在担心,有没有其他数字,有相同的手指动作? 输入格式: 输入的第一行包含唯一的整数n(1<=N<=9)表示Mike输入的电话号码中的位数。第二行由1到9组成的n个字符的字符串。 输出格式: 如果没有其他电话号码具有相同的手指移动,则输出“YES”,否则输出“NO”(不带引号)。

加入题单

上一题 下一题 算法标签: