Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
See pages that link to and include this page.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.
This is a BFS shortest path problem with move restrictions. In a standard BFS problem, visiting the same square more than once is avoided, but the same square can be visited more than once, so long as it is visited in a new state. I am not sure if any of the test data features a case where the same square must be visited 3 times, or if this is even necessary.
How I approached this problem:
Since only the shortest distance is required, not the actual path, the maze that is input can be destroyed (within reason). It might be easier to store as much information as possible on the grid than make the queue bigger. How can we identify which square we are in and what state it is in? Remember, don't run over or into walls.
I solved this in .200s with 800+ lines of code.
In general 800 lines of code is a lot for an ACM problem.
This problem can be solved with < 200 lines of code.
My suggestion is rather than destroying the maze, create three 2D vectors to store the visited property for step sizes of 1, 2 and 3.
The rest of your statements are perfect :D