fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define el cout << '\n'
  5.  
  6. using namespace std;
  7.  
  8. const int maxn = 1e3;
  9. const int INF = 1e9;
  10.  
  11. int n, m, h[maxn + 10], L[maxn + 10], R[maxn + 10];
  12. ll ans[maxn + 10][maxn + 10];
  13. char a[maxn + 10][maxn + 10];
  14. vector<int> st;
  15.  
  16. void solve(int x)
  17. {
  18. st.clear();
  19. st.push_back(0);
  20. h[0] = h[m + 1] = -INF;
  21. for (int i = 1; i <= m; i++)
  22. {
  23. h[i] = a[x][i] == '.' ? h[i] + 1 : 0;
  24. while (h[i] <= h[st.back()])
  25. st.pop_back();
  26. L[i] = st.back();
  27. st.push_back(i);
  28. }
  29. st.clear();
  30. st.push_back(m + 1);
  31. for (int i = m; i >= 1; i--)
  32. {
  33. while (h[i] < h[st.back()])
  34. st.pop_back();
  35. R[i] = st.back();
  36. st.push_back(i);
  37. }
  38. for (int i = 1; i <= m; i++)
  39. {
  40. int A = min(i - L[i], R[i] - i);
  41. int B = max(i - L[i], R[i] - i);
  42. ans[h[i]][1]++;
  43. ans[h[i]][A + 1]--;
  44. ans[h[i]][B + 1]--;
  45. ans[h[i]][A + B + 1]++;
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  52. if (fopen("MAXIMUM.INP", "r"))
  53. {
  54. freopen("MAXIMUM.INP", "r", stdin);
  55. freopen("MAXIMUM.OUT", "w", stdout);
  56. }
  57.  
  58. cin >> n >> m;
  59. for (int i = 1; i <= n; i++)
  60. for (int j = 1; j <= m; j++)
  61. cin >> a[i][j];
  62. for (int i = 1; i <= n; i++)
  63. solve(i);
  64. for (int i = 1; i <= n; i++)
  65. {
  66. for (int j = 1; j <= m; j++)
  67. ans[i][j] += ans[i][j - 1];
  68. for (int j = 1; j <= m; j++)
  69. ans[i][j] += ans[i][j - 1];
  70. }
  71. for (int j = 1; j <= m; j++)
  72. for (int i = n; i >= 1; i--)
  73. ans[i][j] += ans[i + 1][j];
  74. for (int i = 1; i <= n; i++)
  75. {
  76. for (int j = 1; j <= m; j++)
  77. cout << ans[i][j] << ' ';
  78. el;
  79. }
  80. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty