Saleh127

CF 828B

Oct 3rd, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll r,c,i,j,k,l=0,mx=0,my=0,lx=1000,ly=1000;
  11. char a[102][102];
  12. cin>>r>>c;
  13. for(i=0;i<r;i++)
  14. {
  15. for(j=0;j<c;j++)
  16. {
  17. cin>>a[i][j];
  18. }
  19. }
  20. for(i=0;i<r;i++)
  21. {
  22. for(j=0;j<c;j++)
  23. {
  24. if(a[i][j]=='B')
  25. {
  26. l++;
  27. mx=max(mx,i);
  28. lx=min(lx,i);
  29. my=max(my,j);
  30. ly=min(ly,j);
  31. }
  32. }
  33. }
  34. k=max(mx-lx+1,my-ly+1);
  35. if(l==0) cout<<1<<endl;
  36. else if(k>r || k>c) cout<<-1<<endl;
  37. else cout<<(k*k-l)<<endl;
  38. return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment