-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1148.cpp
71 lines (67 loc) · 1.72 KB
/
1148.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, R[N][N], U[N][N], D[N][N], ans[N][N];
char mat[N][N];
vector<int> A;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> mat[i][j];
}
for (int j = m; j >= 1; --j) {
if (mat[i][j] == '*') {
R[i][j] = 0;
} else {
R[i][j] = R[i][j + 1] + 1;
}
}
}
for (int j = 1; j <= m; ++j) {
A.clear();
for (int i = 1; i <= n; ++i) {
while (!A.empty() && R[i][j] < R[A.back()][j]) A.pop_back();
U[i][j] = A.empty() ? 1 : (A.back() + 1);
A.push_back(i);
}
A.clear();
for (int i = n; i >= 1; --i) {
while (!A.empty() && R[i][j] <= R[A.back()][j]) A.pop_back();
D[i][j] = A.empty() ? n : (A.back() - 1);
A.push_back(i);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
// increase ans[i - Ui + 1] -> ans[Di - Ui + 1]
// ans[i - (Ui + 1) + 1] -> ans[Di - (Ui + 1) + 1]
// ...
// ans[i - i + 1] -> ans[Di - i + 1]
++ans[1][R[i][j]];
--ans[i - U[i][j] + 2][R[i][j]];
--ans[D[i][j] - i + 2][R[i][j]];
++ans[D[i][j] - U[i][j] + 3][R[i][j]];
}
}
for (int j = 1; j <= m; ++j) {
for (int i = 1; i <= n; ++i) {
ans[i][j] += ans[i - 1][j];
}
for (int i = 1; i <= n; ++i) {
ans[i][j] += ans[i - 1][j];
}
}
for (int i = n; i >= 1; --i) {
for (int j = m; j >= 2; --j) {
ans[i][j - 1] += ans[i][j];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cout << ans[i][j] << " \n"[j == m];
}
}
return 0;
}