#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 |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
140 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
80 ms |
1944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
191 ms |
4184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |