Page 2 of 2
Re: 11953 - Battleships
Posted: Mon Jul 22, 2013 1:12 am
by faraa_T
oh!!!!
yessss.
super silly mistake
Thank's a lot.
But why?
Why it causes time limit?!!
Re: 11953 - Battleships
Posted: Mon Jul 22, 2013 1:29 am
by shuvokr
because when you write
int r = x + ar
[0];
int c = x + ar[1];
here y have no change. As a result
if (x == (grid.length - 1) || y == (grid.length - 1) || x == 0 || y == 0 || grid[x][y] == '.')
this line y == (grid.length - 1) and y == 0 condition don't work any time and for this cause you got TLE,
And another things is
First judge cheak that there is any TLE, if there is not occurs TLE
then judge its wrong or right. ![:D](./images/smilies/icon_biggrin.gif)
Re: 11953 - Battleships
Posted: Mon Jul 22, 2013 1:37 am
by faraa_T
Thank you so much
Thank you very very much...
![:D](./images/smilies/icon_biggrin.gif)
Re: 11953 - Battleships
Posted: Sun Aug 17, 2014 4:34 pm
by jddantes
[AC]
Re: 11953 - Battleships
Posted: Mon Aug 18, 2014 8:00 pm
by brianfry713
Try input:
Code: Select all
1
6
x@x...
......
......
......
......
......
Output should be 1.
Re: 11953 - Battleships
Posted: Tue Aug 19, 2014 2:28 am
by jddantes
Right, thanks
![:)](./images/smilies/icon_smile.gif)
Re: 11953 - Battleships
Posted: Wed Apr 08, 2015 1:54 pm
by uDebug
brianfry713,
Thanks for the test cases.
Here's some input I found useful during testing / debugging.
http://www.udebug.com/UVa/11953
Re: 11953 - Battleships
Posted: Sat May 23, 2015 5:18 pm
by prnvkrjha
Ok... So my simple flood fill solution has been accepted with DFS in all four directions.
But I am confused about this line in the question...
"Ships in battleship game can vary in size from 1 × 1 to 1 × N/2"
And I don't think my solutions adheres to this condition!
Also here.
http://www.udebug.com/UVa/11953
8
@@@..@..
.....x..
..x..xx@
x..@x...
x.@x.xx.
.......x
@@.....x
..x.@...
For this test case ... the ans should be 9 (given the width of each ship is 1)
but it says 7.
Re: 11953 - Battleships
Posted: Fri Sep 02, 2016 9:06 pm
by Dominik Michniewski
According to problem statement your case is incorrect.
Ships can be placed only horizontally or vertically, but look at bolded places - there are incorrectly placed ships.
8
@@@..@..
.....x..
..x..xx@
x..@x...
x.@x.xx.
.......x