oh!!!!
yessss.
super silly mistake
Thank's a lot.
But why?
Why it causes time limit?!!
11953 - Battleships
Moderator: Board moderators
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.![:D](./images/smilies/icon_biggrin.gif)
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)
Code: Select all
enjoying life .....
Re: 11953 - Battleships
Thank you so much
Thank you very very much...![:D](./images/smilies/icon_biggrin.gif)
![:)](./images/smilies/icon_smile.gif)
Thank you very very much...
![:D](./images/smilies/icon_biggrin.gif)
Re: 11953 - Battleships
[AC]
Last edited by jddantes on Tue Aug 19, 2014 2:29 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11953 - Battleships
Try input:Output should be 1.
Code: Select all
1
6
x@x...
......
......
......
......
......
Check input and AC output for thousands of problems on uDebug!
Re: 11953 - Battleships
Right, thanks ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
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
Thanks for the test cases.
Here's some input I found useful during testing / debugging.
http://www.udebug.com/UVa/11953
Re: 11953 - Battleships
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.
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!
![:-?](./images/smilies/icon_confused.gif)
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.
-
- 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.
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)
Born from ashes - restarting counter of problems (800+ solved problems)