CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » June Long Contest 2011 » Mushroom Cave

Mushroom Cave

Problem code: CAVE

  • All Submissions

All submissions for this problem are available.

Chef is exploring a large cave looking for exotic mushrooms. It is very dark in the cave, so Chef uses torches to help him see. Torches do not last forever, so as Chef explores the cave he must find new torches to light. Specifically, once Chef picks up a torch, he may only travel K steps before it will burn out. If Chef doesn't find another torch within K steps, he will likely be eaten by a grue. Whenever Chef finds a torch, he immediately lights it, and drops any currently held torch to the ground, rendering it unusable. Chef wants to explore as much of the cave as possible before exiting. Chef begins at the northwest corner of the cave and must end at the southeast corner.

You will be given the layout of the cave, including the locations of all torches. Your task is to plot a route through the cave from the northwest corner to the southeast corner that visits as many distinct cells of the cave as possible. Chef must be able to follow your route without running out of torch light. Chef must also still have a burning torch when he finishes the route. Note that optimal routes are not required, and your submission will be scored relative to others' submissions. Any route that leads Chef from the northwest corner to the southeast corner will be accepted.

Input

Input will begin with an integer T, the number of test cases (between 3 and 10). Each test case begins with 3 integers M, N, K (M, N ? 100, 2 ? K ? 15). M and N are the dimensions of the cave, K is the duration of each torch. M lines follow of N characters each, describing the cave. Rows proceed from north to south, and columns from west to east. A '.' character indicates an empty cell, a '#' character indicates an impassable cell, and a 't' character indicates a torch. The cell in the northwest corner will always be a 't', and the cell in the southeast corner will never be '#'.

Output

For each test case, output a string of 'N', 'W', 'S', and 'E' characters (corresponding to the cardinal directions North, West, South, and East, respectively) giving a route from the northwest corner to southeast. It is guaranteed that at least one such route will exist.

Scoring

Your score for each test case is the total number of cells visited by your route (visiting the same cell multiple times only counts once toward the total) divided by the total number of passable cells. Your score for each file is the average of your scores on the individual test cases. Your overall score is the average of your scores on the individual test files.

Sample Input

2
4 5 3
ttttt
.##..
.t...
##t..
6 6 4
tt#...
...##t
...tt.
..t.t#
....t.
..t..t

Sample Output

SSEESEE
SENSSSESSENNNWEEENSWSSESWE

The score for the first test case is 8/16=0.5. The score for the second test case is 23/32=0.71875. The overall score is thus (0.5+0.71875)/2=0.609375. Note that the solution to the first test case is unique (in particular, the solution "EEEESSS" is invalid because Chef would run out of torch light during his final step), but in the second test case there are many alternate solutions (including some that visit more than 23 distinct cells).

Test Case Generation

M and N are chosen randomly and uniformly between 10 and 100, inclusive, and K is chosen randomly and uniformly between 2 and 15. Additionally, a real number D is chosen randomly and uniformly between .05 and .2, inclusive. Each cell is chosen as '#' with probability D, 't' with probability (1-D)/K, and '.' with probability (1-D)*(K-1)/K. If no valid path exists from the northwest to southeast corner, the process is restarted with the same values of M, N, K, and D.


Author: pieguy
Date Added: 26-02-2011
Time Limit: 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

@admin For this submission

gultus @ 4 Jun 2011 07:15 PM
@admin For this submission http://www.codechef.com/viewsolution/564319 I am getting a SIGFPE error which is possibly a div by 0 which could occur only when n=0, in fact if I skip a case when m<=0 or n<=0 in http://www.codechef.com/viewsolution/564321 I don't get this error. In the test case generation it is written m and n are randomly chosen between 10 and 100 then how could n ever be 0.

Just ignore my previous

gultus @ 5 Jun 2011 06:37 AM
Just ignore my previous comment I was using an illegal syntax for scanf which was not causing the exception to occur on cygwin for me. I tried executing in a linux environment to find out the issue.

Hi, My solution works fine

amzdecoder @ 6 Jun 2011 01:41 AM
Hi, My solution works fine when i tested it, but it shows me a wrong answer when i submit any clue why this is happening ??

Generate test cases by

gultus @ 6 Jun 2011 04:58 PM
Generate test cases by writing a small code following the logic explained in test case generation and tweak that manually to make sure of path existence. Use that as an input to your program and see if it gives results, thats how I tested mine.

I bet my solution

manoharsingh23 @ 6 Jun 2011 08:15 PM
I bet my solution http://www.codechef.com/viewsolution/565722 is 100% correct . Please admin check if test cases are 100% correct ?

Admin should also provide

manoharsingh23 @ 6 Jun 2011 08:25 PM
Admin should also provide test files and output files after contest ends

are there any hand-made cases

aseem_pandey @ 7 Jun 2011 12:07 AM
are there any hand-made cases also ?

I too agree with Manohar. The

gultus @ 7 Jun 2011 01:54 AM
I too agree with Manohar. The test cases (maybe output is not really needed as we can execute against any of the accepted solutions of others) should be made available after the contest. It is a good learning process to see where I am going wrong and try to fix it than read others code and find out the actual solution in the process.

i've submited

m0rpheu5 @ 9 Jun 2011 07:25 AM
i've submited http://www.codechef.com/viewsolution/568793 , i always get runtime error but in my PC works just fine. Is in Java, i didnt use classes ( only Main ). I cant understand why the error remains.

made another try, now

m0rpheu5 @ 9 Jun 2011 07:49 AM
made another try, now creating an object in the Main class , still the same error.

2admin: Problem statement

login_test @ 10 Jun 2011 07:16 AM
2admin: Problem statement says "Chef must also still have a burning torch when he finishes the route" Does this mean we can move one more step with the same torch when we reach the last cell or that should be the last step?

i have tested my solution on

sparknet @ 10 Jun 2011 07:18 AM
i have tested my solution on my PC it gives correct output as per problem.but when i submit it it shows run-time error...

I have one doubt. Time limit

prakash1529 @ 11 Jun 2011 11:57 PM
I have one doubt. Time limit exceeded includes run going for infinite loop ??

@prakash1529: May be ur

theeporithirumugam @ 12 Jun 2011 02:47 PM
@prakash1529: May be ur solution is not optimal

No one manage to do it with

m0rpheu5 @ 13 Jun 2011 08:17 PM
No one manage to do it with Java... Must mean anything.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
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
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
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.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com