#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;
A[i][j]=(A[i-1][j]+1)*(ch=='.');
}
for (int i=1; i<=n; i++) for (int j=1; j<=i; j++) sum[i]+=j*(i-j+1);
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
.#.
..#
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2048 KB |
Output is correct |
2 |
Correct |
9 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2048 KB |
Output is correct |
2 |
Correct |
9 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2048 KB |
Output is correct |
2 |
Correct |
8 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8056 KB |
Output is correct |
2 |
Correct |
102 ms |
14584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
13176 KB |
Output is correct |
2 |
Correct |
156 ms |
19320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
8572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
8960 KB |
Output is correct |
2 |
Correct |
109 ms |
18092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
19960 KB |
Output is correct |
2 |
Correct |
164 ms |
20168 KB |
Output is correct |