fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. const int N = 2000;
  5.  
  6. int n;
  7. char a[N][N];
  8. int l, r, u, d;
  9. int k;
  10. int ai, aj, bi, bj;
  11.  
  12. char read_char()
  13. {
  14. int c = getchar();
  15.  
  16. while (c == ' ' || c == '\n' || c == '\r')
  17. c = getchar();
  18.  
  19. return static_cast<char>(c);
  20. }
  21.  
  22. int main()
  23. {
  24. freopen("input.txt", "rt", stdin);
  25. freopen("output.txt", "wt", stdout);
  26.  
  27. scanf("%d", &n);
  28.  
  29. l = n - 1, r = 0;
  30. u = n - 1, d = 0;
  31.  
  32. for (int i = 0; i < n; i++)
  33. {
  34. for (int j = 0; j < n; j++)
  35. {
  36. a[i][j] = read_char();
  37.  
  38. if (a[i][j] == '#')
  39. {
  40. u = std::min(u, i);
  41. d = std::max(d, i);
  42. l = std::min(l, j);
  43. r = std::max(r, j);
  44. }
  45. }
  46. }
  47.  
  48. if (a[u][l] == '#' && a[d][r] == '#')
  49. {
  50. for (k = 0; k < n; k++)
  51. {
  52. if (u + k >= n || a[u + k][l] != '#')
  53. break;
  54.  
  55. if (l + k >= n || a[u][l + k] != '#')
  56. break;
  57.  
  58. if (d - k < 0 || a[d - k][r] != '#')
  59. break;
  60.  
  61. if (r - k < 0 || a[d][r - k] != '#')
  62. break;
  63. }
  64.  
  65. ai = u;
  66. aj = l;
  67. bi = d - k + 1;
  68. bj = r - k + 1;
  69. }
  70. else
  71. {
  72. for (k = 0; k < n; k++)
  73. {
  74. if (u + k >= n || a[u + k][r] != '#')
  75. break;
  76.  
  77. if (r - k < 0 || a[u][r - k] != '#')
  78. break;
  79.  
  80. if (d - k < 0 || a[d - k][l] != '#')
  81. break;
  82.  
  83. if (l + k >= n || a[d][l + k] != '#')
  84. break;
  85. }
  86.  
  87. ai = u;
  88. aj = r - k + 1;
  89. bi = d - k + 1;
  90. bj = l;
  91. }
  92.  
  93. printf("%d\n", k);
  94. printf("%d %d\n", ai + 1, aj + 1);
  95. printf("%d %d", bi + 1, bj + 1);
  96.  
  97. return 0;
  98. }
Success #stdin #stdout 0s 19144KB
stdin
Standard input is empty
stdout
Standard output is empty