fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int dd[110][110];
  5. char a[110][110];
  6. int n;
  7. int main()
  8. {
  9. cin>>n;
  10. for (int i=1;i<=n;i++){
  11. for (int j=1;j<=n;j++) cin>>a[i][j];
  12. }
  13. for (int i=1;i<=n;i++){
  14. for (int j=1;j<=n;j++)
  15. for (int p=1;p<=n;p++)
  16. for (int q=1;q<=n;q++)
  17. if (a[i][j]=='I' && a[p][q]=='C' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=1;
  18. }
  19. for (int i=1;i<=n;i++){
  20. for (int j=1;j<=n;j++)
  21. for (int p=1;p<=n;p++)
  22. for (int q=1;q<=n;q++)
  23. if (dd[i][j]==1 && a[p][q]=='P' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=2;
  24. }
  25. for (int i=1;i<=n;i++){
  26. for (int j=1;j<=n;j++)
  27. for (int p=1;p<=n;p++)
  28. for (int q=1;q<=n;q++)
  29. if (dd[i][j]==2 && a[p][q]=='C' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=3;
  30. }
  31. for (int i=1;i<=n;i++){
  32. for (int j=1;j<=n;j++)
  33. for (int p=1;p<=n;p++)
  34. for (int q=1;q<=n;q++)
  35. if (dd[i][j]==3 && a[p][q]=='A' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=4;
  36. }
  37.  
  38. for (int i=1;i<=n;i++){
  39. for (int j=1;j<=n;j++)
  40. for (int p=1;p<=n;p++)
  41. for (int q=1;q<=n;q++)
  42. if (dd[i][j]==4 && a[p][q]=='S' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=5;
  43. }
  44.  
  45. for (int i=1;i<=n;i++){
  46. for (int j=1;j<=n;j++)
  47. for (int p=1;p<=n;p++)
  48. for (int q=1;q<=n;q++)
  49. if (dd[i][j]==5 && a[p][q]=='I' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=6;
  50. }
  51.  
  52. for (int i=1;i<=n;i++){
  53. for (int j=1;j<=n;j++)
  54. for (int p=1;p<=n;p++)
  55. for (int q=1;q<=n;q++)
  56. if (dd[i][j]==6 && a[p][q]=='A' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=7;
  57. }
  58.  
  59. for (int i=1;i<=n;i++){
  60. for (int j=1;j<=n;j++)
  61. for (int p=1;p<=n;p++)
  62. for (int q=1;q<=n;q++)
  63. if (dd[i][j]==7 && a[p][q]=='S' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=8;
  64. }
  65. for (int i=1;i<=n;i++){
  66. for (int j=1;j<=n;j++)
  67. for (int p=1;p<=n;p++)
  68. for (int q=1;q<=n;q++)
  69. if (dd[i][j]==8 && a[p][q]=='G' && ((i-p)*(i-p)+(j-q)*(j-q)==5)) dd[p][q]=9;
  70. }
  71.  
  72. for (int i=1;i<=n;i++){
  73. for (int j=1;j<=n;j++)
  74. for (int p=1;p<=n;p++)
  75. for (int q=1;q<=n;q++)
  76. if (dd[i][j]==9){
  77. cout<<"YES";
  78. return 0;
  79. }
  80. }
  81. cout<<"NO";
  82. return 0;
  83. }
Success #stdin #stdout 0s 15296KB
stdin
Standard input is empty
stdout
NO