CF404A.Valera and X

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.

Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:

  • on both diagonals of the square paper all letters are the same;
  • all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.

Help Valera, write the program that completes the described task for him.

瓦莱拉是个小男孩。昨天他在学校得到了一份超大的数学家庭作业,因此没有足够的时间为今天的英语课好好学习英文字母表。不幸的是,英语老师今天决定进行一次字母表测验。在测验中,瓦莱拉得到一张正方形的方格纸。正方形边长为 nn 个方格(nn 为奇数),每个单位方格中包含一个英文字母的小写字母。

瓦莱拉需要判断这张正方形方格纸上所写的字母是否构成了字母“X”。瓦莱拉的老师认为,当且仅当满足以下条件时,方格纸上的字母构成一个“X”:

  • 正方形纸的两条对角线上所有字母均相同;
  • 纸上其余所有方格(即不在任一对角线上的方格)均包含同一个字母,且该字母与对角线上的字母不同。

请帮助瓦莱拉编写一个程序,完成上述任务。

输入格式

The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.

第一行包含一个整数 nn(3≤n<3003 \leq n < 300;nn 为奇数)。接下来的 nn 行,每行包含 nn 个小写英文字母——描述瓦列拉的纸张。

输出格式

Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.

如果纸上的字母构成字母“X”,则输出字符串“YES”;否则,输出字符串“NO”。输出的字符串不带引号。

输入输出样例

  • 输入#1

    5
    xooox
    oxoxo
    soxoo
    oxoxo
    xooox

    输出#1

    NO
  • 输入#2

    3
    wsw
    sws
    wsw

    输出#2

    YES
  • 输入#3

    3
    xpx
    pxp
    xpe

    输出#3

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页