Vous êtes sur la page 1sur 3

Login Signup Login or

Signup with
Have you tried CodeChefs "Code, Compile & Run" Its pretty cool. Try it out by pressing Ctrl+; and
typing "ide" [X]

PRACTICE COMPETE DISCUSS COMMUNITY HELP ABOUT

Home Practice(easy) Treasure Hunting

Treasure Hunting
ALL SUBMISSIONS SUBMIT
Problem code: N1
Like Share 18 people like this. Sign Up to see what your
friends like.

All submissions for this problem are available. SUCCESSFUL SUBMISSIONS


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 User Time Mem Lang Solution
(1,1), and needs to go to the bottom-right corner, which is square (n,n).
pratyushag 0.05 2.5M C View
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). binit 0.06 2.5M C View
In each second, Dave can go to one of its four adjacent squares (if the destination is not blocked).
sitharam 0.06 2.5M C View
Find the earliest time that Dave can reach the destination(n,n) after collecting all the treasures in the
maze.
sbrtady 0.06 2.5M C View
Input
The first line contains t, the number of test cases (about 15). Then t test cases follow. Each test case rambhagat99 0.06 2.5M C View
has the following form.
The first line contains N (1 <= N <= 13), the size of the maze rohitworld4111 0.06 3.1M C++ 4.3.2 View

The N following lines describe the maze. The meaning of the symbols is as follows:
lifeofpie 0.06 3.1M C++ 4.3.2 View
'.' : an empty square
'*' : a treasure goutham7_4 0.06 3.1M C++ 4.3.2 View
'#' : a blocked square
sandeep_sandha 0.06 3.1M C++ 4.3.2 View
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. akashrawat 0.06 3.5M C++ 4.3.2 View
Output
hariram 0.07 2.5M C View
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.
cyb3rpunk 0.07 2.5M C View
Example
Input:
4 1 of 7

3
...
.##
*#. HELP
3
..*
...
...

3
..*
*..
...
4
....
.#.*
.#*.
**#.
Output:
-1
4
6
16

Author: admin
Date Added: 5-02-2010
Time Limit: 2 sec

converted by W eb2PDFConvert.com
Source 50000 Bytes
Limit:
Program should read from standard input and write to
ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.8.1, CPP11, standard output. After you submit a solution you can see
Languages: CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, your results by clicking on the [My Submissions] tab on
NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2,
RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC the problem page. Below are the possible results:

Accepted Your program ran successfully and


gave a correct answer. If there is a score for the
Comments problem, this will be displayed in parenthesis next to
the checkmark.
Please login at the top to post a comment.
Time Limit Exceeded Your program was
greenvirag @ 7 Apr 2010 05:00 PM compiled successfully, but it didn't stop before time
limit. Try optimizing your approach.
I downloaded some accepted solutions for this problem from the March challenge. I started my
Wrong Answer Your program compiled and ran
solution and the others, and then by the help of "diff" I printed out the difference between the outputs succesfully but the output did not match the expected
for 20 test cases. All were the same, but I still get Wrong Answer from the judge.. I really don't output.
understand. By the way, the best solution in March gives 1000000007 for the following (valid) test
case:
Runtime Error Your code compiled and ran but
2 encountered an error. The most common reasons are
.. using too much memory or dividing by zero. For the
specific error codes see the help section.
..
Can you give me some tips or advices? Compilation Error Your code was unable to
compile. When you see this icon, click on it for more
information.
puchica @ 10 Apr 2010 02:01 AM
If you are still having problems, see a sample solution
here.
ADMIN: I need to know what the correct answer to the next case (n = 3) -1 or 6 ...?
...
. #.
# *.
Thanks ;-)

bhetrick @ 13 Apr 2010 06:08 AM

The problem description does not mention a blank line before each test case, but the sample has a
blank line before each test case. Does the input actually have a blank line before each test case?

Kaushikptl @ 15 Apr 2010 05:32 PM

@Manuel G. Araujo A.

the answer is -1 for ur case since before reaching destination u have to pick all treasures!
but in your case it is only possible to get treasure after passing the final destination.

mcsharma1990 @ 3 Jul 2010 01:42 PM

@ kaushik
you are completely wrong. Ans would be 6 in this case.

ripudaman22 @ 30 Mar 2011 01:23 AM

hi Gunjan,
I appreciate your attempt but would u please explain what is going on in solve function with example

brianfry713 @ 4 Jan 2012 11:07 AM

puchica, that kind of input does not occur in the judge data. I tested my program in both ways (output
of -1 and 6 for your test case), and both were accepted.

brianfry713 @ 4 Jan 2012 11:10 AM

ripudaman22, I solved this with a Breadth-first search. I only add an element to the queue if it has not
been previously visited with the same treasures collected.

hsg92 @ 8 Jan 2012 07:31 PM

I need help to solve it--pls tell me relevant concepts or algo that I should read to solve this. !!!!!

converted by W eb2PDFConvert.com
s_wrapper @ 24 Feb 2013 07:49 PM

Same here. Can anyone please add tutorial for this problem ? Or atleast tell how to solve this
problem ? That would be a great help !

kuwarbi @ 4 Mar 2013 11:43 AM

4 .... .#.* .#*. **#. path for this case can be 0,0 -> 0,1 -> 0, 2 -> 1,3 -> 2,2 -> 3,1 -> 3,0 ->2,0 ->1,0 ->0,1
->0,2 ->1,2 ->2,3 ->3,3 ???? as we can move diagonally and we have to find the minimum.......by this
way it is 13 hops. Do answer!!!!!

kuwarbi @ 7 Mar 2013 05:46 PM

can you please give more test cases or if you can explain no. 4

abuisson @ 7 Nov 2013 07:48 PM

Question, i submitted a code that run in 4ms on my PC and return the expected output, but I receive
an "Time Limit Exceeded". How can I investigate ? Is there a way to have a look at the execution log ?
Because I don't understand my code can run in more than 3sec .... what kind of server/pc run tests ?

dixitcy @ 6 Dec 2013 04:34 PM

For anyone looking for path-finding algorithms to solve the question , you might consider taking a
look at this interesting article that describes in great detail how to go about solving such problems.
Mind you, it doesn't spoon feed you the solution, just gives pointers for any non-cs majors out there.
http://www.policyalmanac.org/games/aStarTutorial.htm

nil96 @ 10 Mar 2014 09:08 PM

Editorial please???

CodeChef is a non-commercial competitive programming community


About CodeChef About Directi CEO's Corner C-Programming Programming Languages Contact Us
2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ by Sphere Research Labs The time now is: 01:14:35 PM
In order to report copyright violations of any kind, send in an email to copyright@codechef.com Your Ip: 184.173.139.18

CodeChef - A Platform for Aspiring Programmers


CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to
revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have
training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions,
CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.
Practice Section - A Place to hone your 'Computer Programming Skills'
Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+
programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better
prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.
Compete - Monthly Programming Contests and Cook-offs
Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself
up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.
Discuss
Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other
programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the
CodeChef Forums and Wiki section.
CodeChef Community
As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not
the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.
Go For Gold
The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the
ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the
Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC
competition here.

converted by W eb2PDFConvert.com

Vous aimerez peut-être aussi