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 21 times, 1 visits today)
By | 2017-07-24T18:01:22+00:00 July 24th, 2017|Categories: C/C++, Programming|0 Comments

About the Author:

Leave A Comment