404A - Valera and X - CodeForces Solution


implementation *1000

Please click on ads to support us..

Python Code:

n = int(input())
m = []

for i in range(n):
    m.append(input())

l = m[0][0]
other = m[0][1]

for i in range((n//2)):
    if m[i][i] != l or m[i][n-1-i] != l or m[n-1-i][i] != l or m[n-1-i][n-1-i] != l:
        print("NO")
        exit()
        
if m[((n+1)//2)-1][((n+1)//2)-1] == l and m[((n+1)//2)-1].count(l) == 1:
    for i in range(n):
        for j in range(n):
            if m[i].count(l) > 2 or m[i][j] != other and m[i][j] != l or len(set(m[i])) == 1:
                print("NO")
                exit()
    print("YES")
    exit()
        
print("NO")
                   

C++ Code:

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long

using namespace std;

long long w1,w2,w3,n,k,l,i,j,a,mn,x,b,mx,ans,sum,s5,s1,s2,s3,s4,ch1,ch2,r,so,flag,g,num,f;

pair < ll,ll > pr[100001],rp[100001];

string sd[400],sf,m1,m2,sg;

stringstream ss;

char c1,c2,c3,c4,c;

int main()
{
    mx=1e9;

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n;

    for(i=0;i<n;i++)
    {
        cin >> sd[i];
    }

    c1=sd[0][0];
    c2=sd[0][1];

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(sd[i][j]==c1)
            {
                s1++;
            }
        }
        if(s1>2 or (i==n/2 and s1>=2))
        {
            cout << "NO" << endl;
            return 0;
        }
        s1=0;
        if(sd[i][i]!=c1 or sd[i][i+1]==c1)
        {
            cout << "NO" << endl;
            return 0;
        }

        if(sd[i][n-i-1]!=c1 or sd[i][n-i-2]==c1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(sd[i][j]!=c1 and sd[i][j]!=c2)
            {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}

/*

48

57

*/


Comments

Submit
0 Comments
More Questions

1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum
519A - A and B and Chess
725B - Food on the Plane