fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, flag;
  7. char s[305][305], diag, other;
  8. flag=0;
  9. scanf("%d", &n);
  10. for(int i=0; i<n; i++) scanf("%s\n", s[i]);
  11. diag=s[0][0];
  12. other=s[0][1];
  13. if(diag==other) flag=1;
  14. for(int i=0; i<n; i++) {
  15. for(int j=0; j<n; j++) {
  16. if(i==j || i+j==n-1) {
  17. if(s[i][j]!=diag) {
  18. flag=1;
  19. break;
  20. }
  21. }
  22. else {
  23. if(s[i][j]!=other) {
  24. flag=1;
  25. break;
  26. }
  27. }
  28. }
  29. if(flag) break;
  30. }
  31. if(flag) printf("NO");
  32. else printf("YES");
  33. return 0;
  34. }
Success #stdin #stdout 0s 3344KB
stdin
3
xpx
pxp
xpe
stdout
NO