Submission #716329

# Submission time Handle Problem Language Result Execution time Memory
716329 2023-03-29T16:58:14 Z Ahmed57 Strah (COCI18_strah) C++14
110 / 110
157 ms 8224 KB
#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
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 416 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1364 KB Output is correct
2 Correct 87 ms 5016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 2784 KB Output is correct
2 Correct 131 ms 7556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1876 KB Output is correct
2 Correct 93 ms 5452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 580 KB Output is correct
2 Correct 98 ms 6124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 4296 KB Output is correct
2 Correct 157 ms 8224 KB Output is correct