#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define M ll(1e9 + 7)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
int h[2005][2005], lf[2005], rg[2005];
vector <int> g;
int main()
{
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (s[i][j] == '#') {h[i][j] = 0; continue;}
h[i][j] = 1;
if (i != 0) h[i][j] += h[i - 1][j];
}
ll ans = 0;
for (int i = 0; i < n; i++)
{
g.clear();
for (int j = 0; j < m; j++)
{
while (sz(g) && h[i][g.back()] >= h[i][j]) g.pop_back();
if (sz(g)) lf[j] = g.back(); else lf[j] = -1;
g.pb(j);
}
g.clear();
for (int j = m - 1; j >= 0; j--)
{
while (sz(g) && h[i][g.back()] > h[i][j]) g.pop_back();
if (sz(g)) rg[j] = g.back(); else rg[j] = m;
g.pb(j);
}
for (int j = 0; j < m; j++)
{
ll l = j - lf[j], r = rg[j] - j;
ll kl = r * (l * (l + 1)) / 2 + l * (r * (r + 1)) / 2 - r * l;
ll hr = h[i][j];
ans += kl * (hr * (hr + 1)) / 2;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2048 KB |
Output is correct |
2 |
Correct |
8 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2048 KB |
Output is correct |
2 |
Correct |
8 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2048 KB |
Output is correct |
2 |
Correct |
9 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
8064 KB |
Output is correct |
2 |
Correct |
95 ms |
14720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
13440 KB |
Output is correct |
2 |
Correct |
147 ms |
19576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
8704 KB |
Output is correct |
2 |
Correct |
105 ms |
15744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
9088 KB |
Output is correct |
2 |
Correct |
97 ms |
18304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
20352 KB |
Output is correct |
2 |
Correct |
157 ms |
20384 KB |
Output is correct |