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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 2009;
struct Nod {
int left, right;
int g;///greutatea
};
int dp[N];
Nod v[N];
int stk[N];
long long ans;
string s;
void dfs(int nod) {
if (nod == 0)
return;
dfs(v[nod].left);
dfs(v[nod].right);
int n(v[v[nod].left].g), m(v[v[nod].right].g);
v[nod].g = n + m + 1;
ans += 1LL * dp[nod] * (dp[nod] + 1) / 2 * (n + 1) * (m + 1) * (1.0 * n / 2 + 1.0 * m / 2 + 1);
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> s;
s = '$' + s;
for (int j = 1; j <= m; ++j) {
if (s[j] == '#')
dp[j] = 0;
else
dp[j]++;
}
memset(v, 0, sizeof v);
int top(0);
for (int j = 1; j <= m; ++j) {///acum parctic trebuie sa construiesc arborele cartezian
while (top && dp[stk[top]] > dp[j])
--top;
v[j].left = v[stk[top]].right;
v[stk[top]].right = j;
stk[++top] = j;
}
dfs(stk[1]);
}
cout << ans;
return 0;
}
/*
2 3
.#.
..#
*/
# | 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... |