CF1545E1.AquaMoon and Time Stop (easy version)
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Note that the differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if both versions are solved.
AquaMoon knew through foresight that some ghosts wanted to curse tourists on a pedestrian street. But unfortunately, this time, these ghosts were hiding in a barrier, and she couldn't enter this barrier in a short time and destroy them. Therefore, all that can be done is to save any unfortunate person on the street from the ghosts.
The pedestrian street can be represented as a one-dimensional coordinate system. There is one person hanging out on the pedestrian street. At the time 0 he is at coordinate x, moving with a speed of 1 unit per second. In particular, at time i the person will be at coordinate x+i.
The ghosts are going to cast n curses on the street. The i-th curse will last from time tli−1+10−18 to time tri+1−10−18 (exclusively) and will kill people with coordinates from li−1+10−18 to ri+1−10−18 (exclusively). Formally that means, that the person, whose coordinate is between (li−1+10−18,ri+1−10−18) in the time range (tli−1+10−18,tri+1−10−18) will die.
To save the person on the street, AquaMoon can stop time at any moment t, and then move the person from his current coordinate x to any coordinate y (t, x and y are not necessarily integers). The movement costs AquaMoon ∣x−y∣ energy. The movement is continuous, so if there exists some cursed area between points x and y at time t, the person will die too.
AquaMoon wants to know what is the minimum amount of energy she needs to spend in order to save the person on the street from all n curses. But she is not good at programming. As her friend, can you help her?
注意:简单版本与困难版本的区别在于对 n 的约束以及时间限制。仅当两个版本均被解决时,才允许进行 hack。
AquaMoon 通过预知得知,一些幽灵打算在一条步行街上诅咒游客。但不幸的是,这一次这些幽灵躲藏在一道屏障内,而她无法在短时间内进入该屏障并消灭它们。因此,目前唯一能做的就是拯救步行街上任何可能遭遇不幸的行人。
这条步行街可以表示为一维坐标系。步行街上有一名行人正在闲逛。在时刻 0,他位于坐标 x 处,并以每秒 1 单位的速度移动。特别地,在时刻 i,该行人将位于坐标 x+i 处。
幽灵们将在步行街上施放 n 个诅咒。第 i 个诅咒持续的时间区间为 (tli−1+10−18,tri+1−10−18)(开区间),影响的坐标范围为 (li−1+10−18,ri+1−10−18)(开区间)。形式化地说,这意味着:若某人在时间区间 (tli−1+10−18,tri+1−10−18) 内处于坐标区间 (li−1+10−18,ri+1−10−18) 中,则此人将死亡。
为拯救步行街上的行人,AquaMoon 可在任意时刻 t 暂停时间,然后将行人从其当前坐标 x 移动至任意坐标 y(其中 t、x 和 y 不必为整数)。该移动操作消耗 AquaMoon 的能量为 ∣x−y∣。移动是连续进行的,因此若在时刻 t,线段 x 到 y 上存在任一被诅咒的区域,则该行人也会死亡。
AquaMoon 想知道:为使该行人免于全部 n 个诅咒,她所需的最小能量消耗是多少?但她不擅长编程。作为她的朋友,你能帮帮她吗?
输入格式
The first line contains a single integer n (1≤n≤2000) — the number of curses.
The next line contains a single integer x (1≤x≤106) — the initial coordinate of the person.
The following n lines contain four integers tli, tri, li, ri each (1≤tli≤tri≤106, 1≤li≤ri≤106).
第一行包含一个整数 n(1≤n≤2000)—— 骂咒的数量。
第二行包含一个整数 x(1≤x≤106)—— 该人的初始坐标。
接下来的 n 行每行包含四个整数 tli、tri、li、ri(1≤tli≤tri≤106,1≤li≤ri≤106)。
输出格式
Print a single integer — the minimum energy which AquaMoon needs to spent, rounded up to the nearest integer (in case there are two nearest integers you should round the answer to the highest of them).
输出一个整数——AquaMoon 所需消耗的最小能量值,向上取整至最接近的整数(若存在两个同样接近的整数,则取较大的那个)。
输入输出样例
输入#1
2 1 1 2 1 2 2 3 2 3
输出#1
2
输入#2
3 4 1 4 1 2 1 4 4 15 6 7 1 4
输出#2
8
输入#3
4 3 1 5 1 1 4 10 1 4 1 2 3 13 1 10 7 19
输出#3
14
输入#4
7 5 78 96 76 91 6 16 18 37 53 63 40 56 83 88 21 38 72 75 17 24 63 63 53 60 34 46 60 60
输出#4
20
输入解题思路,AI测评打分。不知道怎么写?