PivotOJ

A-Mazing Puzzle

시간 제한: 8000ms메모리 제한: 1024MB출처: ICPC ECNA 2022-2023BOJ 27609

문제

The Severely Challenging Archaeological Exploration Division (SCArED) specializes in the investigation of archaeological sites that are too difficult, dangerous or downright terrifying for humans to examine firsthand. Instead they send in one or more mobile robots to investigate, each robot outfitted with a complex set of sensors, recorders and manipulators. Each robot is radio-controlled and has a small nuclear reactor to power what sometimes ends up being an extended stay at the sites.

Recently a complex underground maze of the Desreverezam Civilization has been discovered. SCArED sent in two robots to investigate and over the course of several months they have mapped out the entire maze. But then disaster struck --- due to some unforeseen anomaly they no longer have radio contact with the two robots (the researchers are torn between the cause of this: either some magnetoferritin crystals in the walls or angry poltergeists). After several weeks of trying to regain contact with the two robots they finally have managed to open up a shared channel with them. There's not much bandwidth in the connection, so they can only send three basic commands to the robots: (Move) Forward, (Turn) Left and (Turn) Right. Since this is a shared channel they cannot send differentiated commands to each robot, so if they send the Forward command each robot will try to move forward simultaneously. If there is an opening in front of them that's fine but if there's a wall in front of one of the robots it will bump into the wall and remain where it is. Any Turn command will likewise cause the robots to turn in lockstep.

Figure A.1: Sample Input 11.

The researchers would like to find the minimum number of Forward commands to get both robots out of the maze (the Turn commands take so little time and power that they can be ignored). As soon as either is out of the maze they can return to the surface and ignore any future commands. Consider the situation in Figure A.1 where both robots are currently facing South. One approach to get the robots out of the maze is to first get robot B out as quickly as possible by moving it to locations (6,2)(6,2), (6,1)(6,1), (5,1)(5,1), (4,1)(4,1) and then out of the maze. This takes 55 Forward moves and in the process robot A moves to (3,1)(3,1) and stays there, bumping against walls 44 times. After robot B is out robot A can exit the maze in 66 more Forward moves, for a total of 1111 moves. However, if robot A is moved out as quickly as possible first and then robot B is moved out, only 88 Forward moves are needed. For other mazes, the minimum number of Forward moves may not involve getting either robot out as quickly as possible (see Sample Input 2).

Given a maze and the initial positions and orientations of the robots, help the researchers out by determining the minimum number of Forward commands to get both robots out of the maze. If there are several sets of minimum Forward commands then the one that leads to the least number of wall bumps is preferred. Oh, and one more thing: the robots should never be on top of each other inside the maze --- this may lead to a chain reaction of their nuclear power generators leading to an explosion that could destroy the planet. This should be avoided.

입력

Input starts with a line containing 33 positive integers cc rr ee (c,r50,ec)(c,r \leq 50, e \leq c) indicating the maze has cc columns and rr rows (all numbered starting at 11) and that the exit to the maze is on the southern side of square (e,1)(e,1). Following this is a line of the form c1c_1 r1r_1 d1d_1 c2c_2 r2r_2 d2d_2 (1cic,1rir,di{1 \leq c_i \leq c, 1 \leq r_i \leq r, d_i \in \{N,E,S,W})\}) indicating that the two robots are at locations (c1,r1)(c_1,r_1) and (c2,r2)(c_2,r_2) with orientations d1d_1 and d2d_2, respectively. Locations (c1,r1)(c_1, r_1) and (c2,r2)(c_2, r_2) will never be the same, and d1d_1 and d2d_2 may be different.

After this come two lines which describe the maze. The first line has the form nn c1c_1 r1r_1 c2c_2 r2cnr_2 \ldots c_n rnr_n (nrc,1cic,1ri<rn \leq r*c, 1 \leq c_i \leq c, 1 \leq r_i < r) where each cic_i rir_i pair indicates that there is a horizontal wall between grid squares (ci,ri)(c_i,r_i) and (ci,ri+1)(c_i,r_i+1). The next line is similar, where each cic_i rir_i pair (nrc,1ci<c,1rirn \leq r*c, 1 \leq c_i < c, 1 \leq r_i \leq r) indicates that there is a vertical wall between grid squares (ci,ri)(c_i,r_i) and (ci+1,ri)(c_i+1,r_i). All exterior walls except the exit are assumed to exist and are not listed in these two lines.

출력

Output two values: the minimum number of Forward commands to get the two robots out of the maze and the number of bumps that occur using these commands. If there are several ways to get the robots out with the same minimum number of Forward command, use the one that minimizes the number of bumps. It will be possible for both robots to escape the maze in each input instance.

예제

예제 1

입력
7 4 4
3 2 S 6 3 S
6 1 1 1 2 1 3 2 3 5 1 5 3
11 2 1 3 1 3 2 5 2 6 2 2 3 4 3 5 3 6 3 3 4 6 4
출력
8 1

예제 2

입력
3 4 2
1 3 S 3 2 S
1 3 3
5 1 1 2 1 1 2 1 3 2 3
출력
7 2
코드를 제출하려면 로그인하세요.