제출 #716329

#제출 시각아이디문제언어결과실행 시간메모리
716329Ahmed57Strah (COCI18_strah)C++14
110 / 110
157 ms8224 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...