11953 - Battleships

All about problems in Volume 119. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Re: 11953 - Battleships

Post by faraa_T »

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
Location: Bangladesh

Re: 11953 - Battleships

Post 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

Code: Select all

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

Re: 11953 - Battleships

Post by faraa_T »

Thank you so much :)
Thank you very very much... :D
jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Re: 11953 - Battleships

Post by jddantes »

[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

Post by brianfry713 »

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

Post by jddantes »

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

Re: 11953 - Battleships

Post by uDebug »

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!

Find us on Facebook. Follow us on Twitter.
prnvkrjha
New poster
Posts: 1
Joined: Sat May 23, 2015 5:08 pm

Re: 11953 - Battleships

Post 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.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Re: 11953 - Battleships

Post 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
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)
Post Reply

Return to “Volume 119 (11900-11999)”