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 » February 2012 Challenge » Smart Chef vs Evil Chef

Smart Chef vs Evil Chef

Problem code: SMVSEVIL

  • All Submissions

All submissions for this problem are available.

Evil Chef recently challenged Smart Chef in the following way: Evil Chef will design a maze, and Smart Chef will provide a route through the maze. The maze consists of a square grid of cells, one of which is marked as the starting point, and one of which is marked as the exit. A robot will be placed at the starting point, which will attempt to execute each move of Smart Chef's route one at a time. If the robot cannot move in the specified direction (either because the cell in that direction is impassable, or because doing so would move the robot off the grid) the move will be ignored. Otherwise it will move one space in the specified direction. It then checks to see if it has exited the maze, and if so ignores the rest of the route. If the robot makes it to the exit, Smart Chef wins. Otherwise Evil Chef wins.

But Smart Chef's task is not as easy as it seems. Smart Chef must provide the route without knowing what the maze looks like. Furthermore, Evil Chef may cheat and change the layout of the maze after he finds out Smart Chef's route. Luckily, Evil Chef is not very smart, and only knows how to make a limited number of mazes. And Smart Chef is so smart that he knows all the mazes Evil Chef is capable of making. He's also smart enough to know when to ask for help, and has asked for your help in designing the route.

Your task is to design a route guarantees Smart Chef will win. In other words, your route must be able to solve all of Evil Chef's mazes. Your goal is to minimize the length of the route, but it is not necessary to find the shortest possible route (see the scoring section for additional details). As long as your route solves all the mazes, does not exceed 10000 moves in length, and no prefix of your route solves all mazes, your solution will be judged as correct.

Input

Input will begin with an integer T, the number of test cases that follow. Each test case begins with an integer K, the number of mazes. K maze descriptions follow. Each maze description begins with 2 integers M and N, the height and width of the maze, respectively. M lines follow with N characters each. A '.' character indicates a passable cell. A '#' character indicates an impassable cell. A 'S' character indicates the starting point, and a 'E' character indicates the exit point. There will be exactly one 'S' character and one 'E' character per maze.

Output

Output one line per test case containing the route Smart Chef should use, as a sequence of 'N', 'E', 'S', and 'W' characters, corresponding to the directions North, East, South, and West, respectively. Your route must not exceed 10000 moves in length.

Scoring

Your score for each test case is the length of your route. Your total score for each test file is the sum 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
2
6 7
.###.##
..#...#
#S#.#..
.....#.
#.##..#
E...#..
6 7
.##.#.#
.......
#.#.#.#
..E#S..
.##..#.
#...#..
3
5 6
...E#.
#.##..
...##.
.##.#.
.....S
5 6
##.###
#...##
E##..#
.##.#.
..S...
6 6
#..###
.#..##
.S.#.#
.#.#.E
#..#.#
##....

Sample Output

SSSWENENNWWWWSSE
ESSSWWWWNWNNESEEEWNNEE

This sample output would score 16+22=38. Note that better scores may be possible.

Test case generation

For each official test file, T is 10. K is chosen uniformly between 2 and 25, inclusive. An integer L is calculated as floor(45/sqrt(K)) and H as floor(70/sqrt(K)). Then for each maze M and N are each chosen uniformly between L and H, inclusive.

Each maze is generated using a random walk algorithm. Initially all cells are marked as impassable. One cell, chosen randomly, is marked as passable, and a marker is placed in this cell. The following process repeated 10000000 times: The marker is moved to a random adjacent cell. Then, if the marker is in a cell adjacent to exactly one passable cell, the cell with the marker becomes passable.

Finally, the exit is chosen randomly among all passable cells with only one passable neighbor, and the start cell is chosen randomly among all remaining passable cells.


Author: pieguy
Date Added: 11-12-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.

Are the routes for all mazes

rushilpaul @ 2 Feb 2012 08:14 PM
Are the routes for all mazes in one test case concatenated and printed??

@admin: There is something

rushilpaul @ 2 Feb 2012 08:28 PM
@admin: There is something wrong with the 1st test case. There's an extra "EN" after "SSSW". Even the 2nd output doesn't seem to be correct. Or maybe I'm not getting it.

@rushilpaul: There is only

david_adm @ 2 Feb 2012 10:44 PM
@rushilpaul: There is only one route per test case. This one route solves all of the given mazes.

okay I got it. I'd overlooked

rushilpaul @ 2 Feb 2012 11:55 PM
okay I got it. I'd overlooked the statement which said that the robot will "ignore" the invalid moves :-)

@admin:please explain

bittu_it @ 3 Feb 2012 01:35 PM
@admin:please explain output??

Don't we need to know Limit

iamhashemi @ 4 Feb 2012 12:56 AM
Don't we need to know Limit of size of mazes?

@admin::what does this mean

ritesh_gupta @ 4 Feb 2012 10:55 PM
@admin::what does this mean "and no prefix of your route solves all mazes, "??

@iamhashemi: The limit on the

david_adm @ 5 Feb 2012 12:26 AM
@iamhashemi: The limit on the size of the mazes can be deduced from the "Test Case Generation" section. @ritesh_gupta: Your solution should have no extra irrelevant moves at the end.

@admin : I keep having a

boki @ 10 Feb 2012 07:56 PM
@admin : I keep having a "wrong answer" error, even if I just print "N" T times as solution. Should it not be a valid solution but with a 0.0 score? My solution produces a result similar to the one given as test, and the computed route does not exceed 1000 moves. Any pointers?

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