We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functwoPluses(grid[]string,n,mint32)int32{mx:=int(n)my:=int(m)mr:=mxifmy<mr{mr=my}max:=0// each plus is identified by its center and its radius (x,y,r).// generated all search space, check the constraints, take the best.forx1:=0;x1<mx;x1++{fory1:=0;y1<my;y1++{forr1:=0;r1<mr;r1++{forx2:=0;x2<mx;x2++{fory2:=0;y2<my;y2++{forr2:=0;r2<mr;r2++{if!check(grid,mx,my,mr,x1,y1,r1,x2,y2,r2){continue}f:=(r1*4+1)*(r2*4+1)ifmax<f{max=f}}}}}}}returnint32(max)}funccheck(grid[]string,mx,my,mr,x1,y1,r1,x2,y2,r2int)bool{// check if they are inside the square.if!(0<=x1-r1&&x1+r1<mx&&0<=y1-r1&&y1+r1<my&&0<=x2-r2&&x2+r2<mx&&0<=y2-r2&&y2+r2<my){returnfalse}// check if they overlap// (x2,y1)ify2-r2<=y1&&y1<=y2+r2&&x1-r1<=x2&&x2<=x1+r1{returnfalse}// (x1,y2)ify1-r1<=y2&&y2<=y1+r1&&x2-r2<=x1&&x1<=x2+r2{returnfalse}// y1=y2, dist(x1,x2) <= r1+r2ify1==y2&&x1-x2<=r1+r2&&x2-x1<=r1+r2{returnfalse}// x1=x2, dist(y1,y2) <= r1+r2ifx1==x2&&y1-y2<=r1+r2&&y2-y1<=r1+r2{returnfalse}// check if they only use G cellsfori:=-r1;i<=r1;i++{ifgrid[x1][y1+i]!='G'{returnfalse}ifgrid[x1+i][y1]!='G'{returnfalse}}fori:=-r2;i<=r2;i++{ifgrid[x2][y2+i]!='G'{returnfalse}ifgrid[x2+i][y2]!='G'{returnfalse}}returntrue}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ema's Supercomputer
You are viewing a single comment's thread. Return to all comments →