QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#698. 友军之火

Statistics

你被一个邪恶组织俘虏了,他们试图利用你的算法技能来改进他们的武器。他们强迫你做的第一项任务是编写制导鱼雷的程序。当然,你的目标是尽可能让鱼雷避开每一艘船。

鱼雷的使用场景是一个二维平面,鱼雷从 $(0, 0)$ 出发,向 $y$ 轴正方向发射,目标是 $m$ 艘船。每艘船都是一条平行于 $x$ 轴的线段,端点坐标均为整数。鱼雷被视为一个点,每一秒它都会从 $(x, y)$ 移动到 $(x - 1, y + 1)$、$(x, y + 1)$ 或 $(x + 1, y + 1)$。换句话说,它总是向前移动一个单位,但你的程序决定了它在横向上移动多少。如果鱼雷击中了任何一艘船(包括船的端点),它就会爆炸并摧毁该船。另一方面,如果鱼雷在 $n$ 秒内保持完整,它的燃料就会耗尽,并无害地沉入海底。

编写一个程序,在给定 $m$ 艘船的位置后,判断是否有可能避开所有船只,如果可以,输出避开它们的指令。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($2 \le n \le 500\,000$ 且 $0 \le m \le 200\,000$),分别表示鱼雷燃料耗尽前的秒数和船的数量。

接下来 $m$ 行,每行包含三个整数 $x_1, x_2, y$ ($-n \le x_1 \le x_2 \le n$ 且 $1 \le y < n$),表示一艘端点为 $(x_1, y)$ 和 $(x_2, y)$ 的船。

你可以假设没有任何两艘船会相互接触。

输出格式

如果可以避开所有船只,输出一个长度为 $n$ 的字符串,包含字符 $-, 0, +$。该字符串表示鱼雷在 $n$ 个时间步长中每一步的转向。例如,如果第一个字符是 $+$,则鱼雷将从 $(0, 0)$ 移动到 $(1, 1)$。如果有多种解,输出其中任意一个即可。如果无法避开所有船只,输出 “impossible”。

样例

样例输入 1

5 6
-3 -2 3
-2 -2 4
2 3 3
-1 1 2
0 1 4
2 5 1

样例输出 1

--+0-

样例输入 2

3 2
1 2 1
-2 0 2

样例输出 2

0+-

样例输入 3

3 2
1 2 1
-2 1 2

样例输出 3

impossible

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.