Treasure HuntingProblem code: N1 |
All submissions for this problem are available.
Treasure Hunting is a great computer game that has attracted generations of Bytelandian children.
In the game, there is a maze divided into NxN squares. Dave starts in the top-left corner, which is square (1,1), and needs to go to the bottom-right corner, which is square (n,n).
Some of the squares are blocked and some of the squares contain treasures.
Dave needs to capture all the treasures in the maze before going to square (n,n).
In each second, Dave can go to one of its four adjacent squares (if the destination is not blocked).
Find the earliest time that Dave can reach the destination(n,n) after collecting all the treasures in the maze.
Input
The first line contains t, the number of test cases (about 15). Then t test cases follow. Each test case has the following form.
The first line contains N (1 <= N <= 13), the size of the maze
The N following lines describe the maze. The meaning of the symbols is as follows:
'.' : an empty square
'*' : a treasure
'#' : a blocked square
The number of treasures in the maze does not exceed 13. Squares (1,1) and (n,n) are always empty.
Each test case's input is separated by a blank line.
Output
For each test case, print in a single line the earliest time that Dave can reach the destination after collecting all the treasures. If Dave cannot reach the destination, print -1.
Example
Input: 4 3 ... .## *#. 3 ..* ... ... 3 ..* *.. ... 4 .... .#.* .#*. **#. Output: -1 4 6 16
| Date: | 2010-02-05 |
| Time limit: | 2s |
| Source limit: | 50000 |
| Languages: | C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK TEXT JS |
Comments

Fetching successful submissions

@triplem how do u code too
@triplem
how do u code too fast......
I see the time limit is 2s
I see the time limit is 2s but one successful submission has a time limit of 3.8s
Is that normal or an error?
FAQ
FAQ
@Toxologic The time limit
@Toxologic The time limit stated in each problem applies to each file for that problem; the time given for each submission is the sum of the times for all the files processed by that submission.
Brian Drake, I've read the
Brian Drake, I've read the FAQ. Its clearly written over there that all the test cases are to be considered in one single time limit. I'm assuming that Java is expemted for a few seconds in time limit as stated in FAQ.
Anyways, Stephen and Brian, thanks for the reply!
It also says that if there
It also says that if there are multiple input files, then the reported time is the sum for each file, which can easily exceed two seconds; what Brian said was completely correct :)
The question says, under the
The question says, under the Output: "If Dave cannot reach the destination, print -1." What if he cannot reach a particular treasure, but he can reach the destination?
Do we output the -1 or the shortest distance from 1,1 to n,n taking as many treasures as possible?
Everything that I believe,
Everything that I believe, crawls from underneath the streets. Everything I truly love, comes from somewhere high above. Everything that I believe, is wrong with you is wrong with me. Everything I truly love, I love in you I love me. Take my love, take it down Climbed a mountain and I turned around And if you see my reflection in a snow covered hill Well the landslide bring it down And if you see my reflection in a snow covered hill Well the landslide bring it down Well the landslide bring it down
Take my love, take it down
Climbed a mountain and I turned around
And if you see my reflection in a snow covered hill
Well the landslide bring it down
And if you see my reflection in a snow covered hill
Well the landslide bring it down
Well the landslide bring it down
hi, i get a status saying
hi,
i get a status saying that an internal error occured in the system..
what does that mean??
They're looking into it. You
They're looking into it. You can see the results of your submissions by clicking on the 'My submissions' link on this page.
@Pradeep Print -1.
@Pradeep Print -1.
Suppose we have reached (n,n)
Suppose we have reached (n,n) without collecting all treasures, and then, can we move out from (n,n), collect the remaining treasures and come back to (n,n)? For example in :
...
##.
#*.
Is the answer 6 or -1?
You are allowed to pass
You are allowed to pass through (n,n) part way through your path.
to h umesh the answer will be
to h umesh
the answer will be 6.observe the example 3
@chellusnehasree None of the
@chellusnehasree None of the examples involve Dave passing through (n, n) in the middle of his path.
@admin: my code is runnig
@admin: my code is runnig well within 1 sec for 15 inputs for a test case of 13*13
Then why am i getting timeout ??
Can you give me and example case, where it timeouts?
Thanks.
@admin: I mean running within
@admin: I mean running within 1 sec on my laptop.
@piyush. admin cant help you
@piyush. admin cant help you till contest is over...
What ti the solution for 1 .
What ti the solution for
1
.
@admin what is memory limit
@admin what is memory limit permitted ?
@Admin I'm getting TLE with
@Admin I'm getting TLE with 0k memory used.how is that possible? some memory usage must be recorded by the judge?
please clarify (submission ID 200840)
@Admin Please confirm
@Admin
Please confirm Stephen's answer: "You are allowed to pass through (n,n) part way through your path."
I'm asking because the problem states "Dave needs to capture all the treasures in the maze before going to square (n,n)"
@ADMIN C#2 Solutions not
@ADMIN
C#2 Solutions not being accepted. Please look into the issue ASAP!
@Abhijit This is fixed. Try
@Abhijit This is fixed. Try submitting now.
Can somebody explain this
Can somebody explain this problem. I solved using DFS , BFS , all pairs shortest path and TSP. All three solutions got TLE. I could see there is a much simpler way to do this. Pls explain
DP. There are only 15
DP. There are only 15 important squares (treasures + start + end). Given that you have found a certain subset (2^13) of treasures, and you are at a certain square (15), choose the optimal next treasure to get.
I remember Stephen had solved
I remember Stephen had solved this problem in the 1st 10-15 mins of the contest.....
@Stephen I believe doing so was a cakewalk 4 u, still....Hats off to you...
http://www.spoj.pl/problems/C
http://www.spoj.pl/problems/CLEANRBT/
:P