Friendly Fire
면접 대비시간 제한2초메모리 제한512 MB
어뢰가 n초 동안 매초 위로 한 칸, 좌우로 최대 한 칸 움직일 때, 가로로 놓인 모든 배 선분을 피할 수 있는지 판정하고 이동 지시를 출력한다.
문제
You have been captured by an evil organization which seeks to exploit your algorithm skills to improve their weapons. The first task they forced you to work on was to program guided torpedoes. Naturally, your goal is to instead make the torpedoes miss every ship whenever possible.
A typical scenario where the torpedoes will be used is a 2D plane, where the torpedo is fired from towards ships in the positive -direction. Every ship has the form of a line segment parallel to the -axis, with integer coordinate endpoints. The torpedo is shaped like a single point, and every second it will travel from to either , , or . In other words, it will always go one unit forward, but your program decides how much sideways it should go. If the torpedo hits one of the ships (including one of the endpoints of a ship) it will explode, destroying the ship. On the other hand, if the torpedo stays in one piece for seconds, its fuel will run out and it will harmlessly sink to the ocean floor.
Write a program which, given the position of the ships, finds out whether it is possible to avoid them all, and if so, outputs instructions to do it.
입력
The first line of input contains two integers and ( and ), the number of seconds until the torpedo runs out of fuel, and the number of ships.
Then follow lines, each containing three integers ( and ), indicating a ship with endpoints and .
You may assume that no pair of ships touch each other.
출력
If it is possible to dodge all the ships, output a string of length containing the characters , , and . This string represents how the torpedo should turn in each of the time steps. For example, if the first character is , then the torpedo will start by going from to . If there are multiple solutions, output any one of them. If it is impossible to avoid all the ships, output "impossible".