#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
int n, m, p[2000], d[2000], l[2000], r[2000];
string g[2000];
ll ans;
void solve() {
stack<int> s;
for (int i = 0; i < m; ++i) {
while(!s.empty() && d[i] <= d[s.top()])
s.pop();
l[i] = s.empty() ? i + 1 : i - s.top();
s.push(i);
}
stack<int>().swap(s);
for (int i = m - 1; ~i; --i) {
while(!s.empty() && d[i] < d[s.top()])
s.pop();
r[i] = s.empty() ? m - i : s.top() - i;
s.push(i);
}
for (int i = 0; i < m; ++i) {
if (!d[i])
continue;
ll a = l[i], b = r[i];
ans += d[i] * (d[i] + 1) / 2 * (a * (a + 1) / 2 * b + b * (b + 1) / 2 * a - a * b);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> g[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
p[j] = max(p[j], i);
while(p[j] < n && g[p[j]][j] == '.')
++p[j];
d[j] = p[j] - i;
}
solve();
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
620 KB |
Output is correct |
2 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
620 KB |
Output is correct |
2 |
Correct |
6 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
2668 KB |
Output is correct |
2 |
Correct |
103 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
5612 KB |
Output is correct |
2 |
Correct |
155 ms |
7932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
3564 KB |
Output is correct |
2 |
Correct |
112 ms |
5740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1004 KB |
Output is correct |
2 |
Correct |
123 ms |
6380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
8684 KB |
Output is correct |
2 |
Correct |
191 ms |
8684 KB |
Output is correct |