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;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    char arr[n][m];
    for(int i = 0;i<n;i++){
        string s;cin>>s;
        for(int j = 0;j<m;j++){
            arr[i][j] = s[j];
        }
    }
    long long l[m] = {0},left[m],right[m];
    long long all = 0;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(arr[i][j]=='.')l[j]++;
            else l[j] = 0;
        }
        stack<int> s;
        for(int j = 0;j<m;j++){
            while(!s.empty()&&l[s.top()]>=l[j]){
                s.pop();
            }
            if(s.empty())left[j] = -1;
            else left[j] = s.top();
            s.push(j);
        }
        while(!s.empty())s.pop();
        for(int j = m-1;j>=0;j--){
            while(!s.empty()&&l[s.top()]>l[j]){
                s.pop();
            }
            if(s.empty())right[j] = m;
            else right[j] = s.top();
            s.push(j);
        }
        for(int j = 0;j<m;j++){
            long long ans = (l[j]*(l[j]+1))/2;
            long long len = (j-left[j]);
            len = (len*(len+1))/2;
            len*=(right[j]-j);
            if(right[j]-j>1)len+=(((j-left[j])+((j-left[j])*((right[j]-j)-1)))*((right[j]-j)-1))/2;
            ans*=len;
            all+=ans;
        }
    }
    cout<<all<<endl;
}
| # | 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... |