forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
828B-BlackSquare.cpp
30 lines (25 loc) · 924 Bytes
/
828B-BlackSquare.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
int main(){
long n, m; std::cin >> n >> m;
std::vector<std::string> sheet(n);
for(long p = 0; p < n; p++){std::cin >> sheet[p];}
long left(m + 1), right(-1), top(n + 1), bottom(0), count(0);
for(long row = 0; row < n; row++){
for(long col = 0; col < m; col++){
if(sheet[row][col] != 'B'){continue;}
++count;
top = (top < row) ? top : row;
bottom = (bottom > row) ? bottom : row;
left = (left < col) ? left : col;
right = (right > col) ? right : col;
}
}
long height = bottom - top + 1;
long width = right - left + 1;
long side = (height > width) ? height : width;
if(n < side || m < side){std::cout << "-1" << std::endl;}
else if(count <= 0){std::cout << "1" << std::endl;}
else{std::cout << (side * side - count) << std::endl;}
return 0;
}