#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = (int)1007;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
ll n, m, up[MAXN][MAXN], lft[MAXN], rgt[MAXN];
char c[MAXN][MAXN];
ll sum(ll x)
{
return x * (x + 1) / 2;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> c[i][j];
for (int j = 0; j < m; j++)
if(c[0][j] == '#')
up[0][j] = 0;
else
up[0][j] = -1;
for (int i = 1; i < n; i++)
for (int j = 0; j < m; j++)
if(c[i][j] == '#')
up[i][j] = i;
else
up[i][j] = up[i - 1][j];
ll ans = 0;
for (int i = 0; i < n; i++)
{
stack<ll> S;
for (int j = 0; j < m; j++)
{
while(!S.empty() && up[i][j] > up[i][S.top()])
S.pop();
if(S.empty())
lft[j] = -1;
else
lft[j] = S.top();
S.push(j);
}
while(!S.empty())
S.pop();
for (int j = m - 1; j >= 0; j--)
{
while(!S.empty() && up[i][j] >= up[i][S.top()])
S.pop();
if(S.empty())
rgt[j] = m;
else
rgt[j] = S.top();
S.push(j);
}
for (int j = 0; j < m; j++)
{
ll t = i - up[i][j];
t = sum(t);
ans += t * (rgt[j] - j) * sum(j - lft[j]);
ans += t * (j - lft[j]) * sum(rgt[j] - j - 1);
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
3 ms |
584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2692 KB |
Output is correct |
2 |
Correct |
8 ms |
2820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2820 KB |
Output is correct |
2 |
Correct |
8 ms |
2820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2820 KB |
Output is correct |
2 |
Correct |
8 ms |
2820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
97 ms |
8060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
56 ms |
18640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
90 ms |
18640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
18640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
83 ms |
18640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |