Page 2 of 2

### Re: 11953 - Battleships

Posted: Mon Jul 22, 2013 1:12 am
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
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.

### Re: 11953 - Battleships

Posted: Mon Jul 22, 2013 1:37 am
Thank you so much
Thank you very very much...

### Re: 11953 - Battleships

Posted: Sun Aug 17, 2014 4:34 pm
[AC]

### Re: 11953 - Battleships

Posted: Mon Aug 18, 2014 8:00 pm
Try input:

Code: Select all

``````1
6
x@x...
......
......
......
......
......
``````
Output should be 1.

### Re: 11953 - Battleships

Posted: Tue Aug 19, 2014 2:28 am
Right, thanks

### Re: 11953 - Battleships

Posted: Wed Apr 08, 2015 1:54 pm
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
Ok... So my simple flood fill solution has been accepted with DFS in all four directions.
"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
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