This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |