#include<bits/stdc++.h>
using namespace std;
int x(int k){
return k * (k + 1)/2;
}
int main(){
int n, m;
cin >> n >> m;
char grid[n][m];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> grid[i][j];
}
}
vector<int> pref(m, 0);
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(grid[i][j] == '.'){
pref[j]++;
}
else{
pref[j] = 0;
}
}
vector<int> v(m, -1);
vector<int> v2(m, m);
stack<int> s;
for(int j = 0; j < m; j++){
while(!s.empty() && pref[j] <= pref[s.top()]){
v[s.top()] = j;
s.pop();
}
s.push(j);
}
while(!s.empty()){
s.pop();
}
for(int j = m - 1; j >= 0; j--){
while(!s.empty() && pref[j] < pref[s.top()]){
v2[s.top()] = j;
s.pop();
}
s.push(j);
}
for(int j = 0; j < m; j++){
int val = v[j] + 1;
int val2 = v2[j] - 1;
int length1 = j - val + 1;
int length2 = val2 - j + 1;
ans += ((x(val2 + 1) - x(j) * length1 - (x(j) - x(val - 1)) * length2) * (x(pref[j])));
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
144 ms |
5200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
3408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
190 ms |
8144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |