## 11953 - Battleships

Moderator: Board moderators

faraa_T
New poster
Posts: 8
Joined: Fri Jul 19, 2013 6:16 pm

### Re: 11953 - Battleships

oh!!!!
yessss.
super silly mistake
Thank's a lot.
But why?
Why it causes time limit?!!

shuvokr
Learning poster
Posts: 66
Joined: Tue Oct 02, 2012 8:16 pm

### Re: 11953 - Battleships

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.

Code: Select all

``enjoying life ..... ``

faraa_T
New poster
Posts: 8
Joined: Fri Jul 19, 2013 6:16 pm

### Re: 11953 - Battleships

Thank you so much
Thank you very very much...

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

### Re: 11953 - Battleships

[AC]
Last edited by jddantes on Tue Aug 19, 2014 2:29 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11953 - Battleships

Try input:

Code: Select all

``````1
6
x@x...
......
......
......
......
......
``````
Output should be 1.
Check input and AC output for thousands of problems on uDebug!

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

### Re: 11953 - Battleships

Right, thanks

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 11953 - Battleships

brianfry713,

Thanks for the test cases.

Here's some input I found useful during testing / debugging.

http://www.udebug.com/UVa/11953
Check input and AC output for over 7,500 problems on uDebug!

prnvkrjha
New poster
Posts: 1
Joined: Sat May 23, 2015 5:08 pm

### Re: 11953 - Battleships

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.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

### Re: 11953 - Battleships

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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)