아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Friendly Fire

면접 대비

시간 제한2초메모리 제한512 MB

요약
어뢰가 n초 동안 매초 위로 한 칸, 좌우로 최대 한 칸 움직일 때, 가로로 놓인 모든 배 선분을 피할 수 있는지 판정하고 이동 지시를 출력한다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 구현, 배열
정답자
아직 제출이 없습니다

문제

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 (0,0)(0,0) towards mm ships in the positive yy-direction. Every ship has the form of a line segment parallel to the xx-axis, with integer coordinate endpoints. The torpedo is shaped like a single point, and every second it will travel from (x,y)(x,y) to either (x−1,y+1)(x-1,y+1), (x,y+1)(x,y+1), or (x+1,y+1)(x+1,y+1). 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 nn seconds, its fuel will run out and it will harmlessly sink to the ocean floor.

Write a program which, given the position of the mm 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 nn and mm (2≤n≤500,0002 \leq n \leq 500\\,000 and 0≤m≤200,0000 \leq m \leq 200\\,000), the number of seconds until the torpedo runs out of fuel, and the number of ships.

Then follow mm lines, each containing three integers x_1,x_2,yx\_1, x\_2, y (−n≤x_1≤x_2≤n-n \leq x\_1 \leq x\_2 \leq n and 1≤y<n1 \leq y < n), indicating a ship with endpoints (x_1,y)(x\_1, y) and (x_2,y)(x\_2, y).

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 nn containing the characters −-, 00, and ++. This string represents how the torpedo should turn in each of the nn time steps. For example, if the first character is ++, then the torpedo will start by going from (0,0)(0,0) to (1,1)(1,1). If there are multiple solutions, output any one of them. If it is impossible to avoid all the ships, output "impossible".

예제3

  1. 예제 1

    입력
    5 6
    -3 -2 3
    -2 -2 4
    2 3 3
    -1 1 2
    0 1 4
    2 5 1
    
    예상 출력
    --+0-
    
  2. 예제 2

    입력
    3 2
    1 2 1
    -2 0 2
    
    예상 출력
    0+-
    
  3. 예제 3

    입력
    3 2
    1 2 1
    -2 1 2
    
    예상 출력
    impossible