https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-423-Div-2-rated-based-on-VK-Cup-Finals-problem-B-Black-Square-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals), problem: (B) Black Square Solution In C/C++

#include <bits/stdc++.h>
using namespace std;
int n,m,maxx,minx=1e9,maxy,miny=1e9,T;
char a[105][105];
int main(){
scanf(“%d%d”,&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]==’B’)T++,maxx=max(maxx,i),minx=min(minx,i),maxy=max(maxy,j),miny=min(miny,j);
}
if(!T)puts(“1”);
else{
int c=max(maxx-minx,maxy-miny)+1;
printf(“%d\n”,(c>n||c>m)?-1:c*c-T);
}
}

(Visited 12 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: