Space Walls
Time limit15sMemory limit2048 MB
Given a union of axis-aligned unit cubes and robots walking on its exposed faces, find the first time two robots share a face or swap positions.
- Level
Medium7 of 10
- Topics
- Simulation, Implementation, Graph
- Solved
- No attempts yet
Problem
Place-Y Technology Corp. plans to launch a new space station soon. The company CEO is known for being obsessed with perfection. For example, he insists that all the outer surfaces of the space station are regularly polished and cleaned of what he calls "space debris," mainly so the station looks good in photos. The engineering team tried to convince the CEO that this was not needed, but failed. So instead they developed a new technology that maintains the surfaces while minimizing human work outside the station. Several small robots perform the maintenance by moving over the station surface, much like robotic vacuum cleaners. Before the first flight, Place-Y needs to assess the risk of collisions during robot operation. That is where you come in.
In this problem, the space station is modeled as a collection of axis-aligned unit cubes. The cubes do not need to be connected. Each robot starts at time at the center of an exposed face of one of the station's unit cubes. An exposed face is a face that is not shared with another station cube. The robot faces one of the four directions parallel to an edge of that face. Every time unit, the robot moves straight ahead to another cube face. It may pivot 90 degrees across a station edge so that it always stays in contact with the station. If two cubes share an edge, the robot cannot pass between them, because there is no gap.

Figure K.1: Illustration of Sample Input 1. The dots mark the starting points of two robots.
Given the station layout and the starting positions of all robots, find the time of the earliest collision, if any. A collision happens at a time unit when two or more robots are inside the same cube face, or when two robots try to swap locations. See Sample Input 3 for the swap case.
Input
The first line contains two integers and . Here () is the number of regions that describe the station shape, and () is the number of robots.
Each of the next lines contains six integers , , , , , and with , , and . Each line describes one region. Every point with , , and belongs to the station. A unit cube may be covered by more than one region.
Each of the next lines gives the starting position of one robot. The line contains coordinates , , , and two directions and . The robot starts on the face of the unit cube - determined by . Its initial direction of movement is . Each direction is one of the strings x+, x-, y+, y-, z+, or z-. For example, x+ means the positive x-axis direction . The axis letters of and are always different. The starting cube belongs to the station, and the given face is exposed.
Output
Print the time of the first collision. If no collision ever happens, print ok.