#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=2010;
ll n, m, k, u, v, x, y, t, a, b, ans;
int A[N][N];
int L[N], R[N];
ll sum[N];
ll C2(ll x){
return x*(x+1)/2;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin>>n>>m;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
char ch;
cin>>ch;
if (ch=='.') A[i][j]=(A[i-1][j]+1);
}
for (int i=1; i<=n; i++) for (int j=1; j<=i; j++) sum[i]+=j*(i-j+1ll);
for (int i=1; i<=n; i++){
for (int j=1; j<=m; j++) for (L[j]=j-1; L[j] && A[i][L[j]]>=A[i][j]; L[j]=L[L[j]]);
for (int j=m; j; j--) for (R[j]=j+1; R[j]<=m && A[i][R[j]]>A[i][j]; R[j]=R[R[j]]);
for (int j=1; j<=m; j++) ans+=1ll*C2(A[i][j])*(sum[R[j]-L[j]-1]-sum[R[j]-j-1]-sum[j-L[j]-1]);
}
cout<<ans<<'\n';
return 0;
}
/*
2 3
.#.
..#
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2048 KB |
Output is correct |
2 |
Correct |
9 ms |
1928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2048 KB |
Output is correct |
2 |
Correct |
9 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2048 KB |
Output is correct |
2 |
Correct |
8 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
7032 KB |
Output is correct |
2 |
Correct |
104 ms |
12408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
11004 KB |
Output is correct |
2 |
Correct |
159 ms |
15736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
63 ms |
7160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
8832 KB |
Output is correct |
2 |
Correct |
122 ms |
15356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
16260 KB |
Output is correct |
2 |
Correct |
176 ms |
16248 KB |
Output is correct |