|Online Judge||Problem Set||Authors||Online Contests||User|
Doors and... more doors
When wondering through the labyrinth, the goal is usually to find some kind of door. Well, not this time.
A labyrinth consists of N × N cells, each 1 × 1 meter in size. Cells are separated by doors. Each door opens in a specific direction (as shown on the picture):
1. left outwards;
So a cell can be represented by two numbers describing doors on its eastern and southern sides according to the list above. The doors are just slightly less then 1 meter in width. The traveler in the labyrinth is also slightly less then 1 meter in diameter, so he has following limitations:
* He can not pull doors, only push them.
Your program must find the shortest path for the traveler from north-western cell (1, 1) to south-eastern cell (N, N).
Input file contains labyrinth size N followed by 2 × N2 numbers describing doors for each cell row by row. As there are no doors leading outside of labyrinth, values for eastern doors in the last column and southern doors in the last row are zero.
1 ≤ N ≤ 1000
Output file must contain the shortest path as a list of cell coordinates (column number, then row number), including both (1, 1) and (N, N) cells. If there are several solutions with the same length, output any one of them. If it is impossible to get to a destination cell, output a singe zero.
Sample Input 1 2 2 3 0 4 1 0 0 0 Sample Input 2 3 4 3 1 4 0 1 3 3 2 3 0 4 2 0 1 0 0 0
Sample Output 1 1 1 1 2 2 2 Sample Output 2 1 1 1 2 2 2 2 1 3 1 3 2 2 2 2 3 3 3
Bold texts appearing in the sample sections are informative and do not form part of the actual data.
Northeastern Europe 2006, Far-Eastern Subregion
[Submit] [Go Back] [Status] [Discuss]
Home Page Go Back To top
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator