B. Race Against Time

Codeforces
IDCF868B
Time2000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a _really_ strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time _h_ hours, _m_ minutes, _s_ seconds. Last time Misha talked with the coordinator at _t_1 o'clock, so now he stands on the number _t_1 on the clock face. The contest should be ready by _t_2 o'clock. In the terms of paradox it means that Misha has to go to number _t_2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction. Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way). Given the hands' positions, _t_1, and _t_2, find if Misha can prepare the contest on time (or should we say _on space_?). That is, find if he can move from _t_1 to _t_2 by the clock face. ## Input Five integers _h_, _m_, _s_, _t_1, _t_2 (1 ≤ _h_ ≤ 12, 0 ≤ _m_, _s_ ≤ 59, 1 ≤ _t_1, _t_2 ≤ 12, _t_1 ≠ _t_2). Misha's position and the target time do not coincide with the position of any hand. ## Output Print "_YES_" (quotes for clarity), if Misha can prepare the contest on time, and "_NO_" otherwise. You can print each character either upper- or lowercase ("_YeS_" and "_yes_" are valid when the answer is "_YES_"). [samples] ## Note The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. <center>![image](https://espresso.codeforces.com/bce115ce252800c8518f002b1f3de40c04fa0f2d.png)</center>
[{"iden":"statement","content":"你是否曾试图向协调员解释,距离比赛还有八个小时,却一个题目都没准备好?米沙试过。而这次他有一个_真正_强大的借口:他遭遇了时空悖论!空间和时间互换了位置。\n\n整个宇宙变成了一块巨大的钟面,有三根指针——时针、分针和秒针。时间凝固了,钟表现在显示的是 #cf_span[h] 小时、#cf_span[m] 分钟、#cf_span[s] 秒。\n\n上次米沙与协调员交谈时是 #cf_span[t1] 点,因此现在他站在钟面上的 #cf_span[t1] 位置。比赛必须在 #cf_span[t2] 点前准备完毕。在悖论的术语中,这意味着米沙必须以某种方式到达 #cf_span[t2] 位置。注意,他不必只向前移动:在这种情况下,时间没有方向。\n\n钟表指针非常长,米沙无法绕过它们。他也不能跨过指针,否则会导致时空坍塌。也就是说,如果时针指向 12,而米沙站在 11,那么他不能沿着上弧线直接移动到 1。他必须沿着钟面中心绕行一圈(当然,如果他的路径上没有其他指针的话)。\n\n给定指针的位置、#cf_span[t1] 和 #cf_span[t2],判断米沙能否按时(或者说_按空间_)准备好比赛。也就是说,判断他能否沿着钟面从 #cf_span[t1] 移动到 #cf_span[t2]。\n\n五个整数 #cf_span[h], #cf_span[m], #cf_span[s], #cf_span[t1], #cf_span[t2](#cf_span[1 ≤ h ≤ 12],#cf_span[0 ≤ m, s ≤ 59],#cf_span[1 ≤ t1, t2 ≤ 12],#cf_span[t1 ≠ t2])。\n\n米沙的位置和目标时间与任何指针的位置都不重合。\n\n如果米沙能按时准备好比赛,输出 \"_YES_\"(引号仅用于清晰),否则输出 \"_NO_\"。\n\n你可以以任意大小写输出每个字符(\"_YeS_\" 和 \"_yes_\" 在答案为 \"_YES_\" 时都是合法的)。\n\n下面三张图从左到右展示了三个例子。米沙的起始位置用绿色表示,终点位置用粉红色表示。请注意,图中指针的位置并非精确值,但接近真实值,且答案相同。"},{"iden":"input","content":"五个整数 #cf_span[h], #cf_span[m], #cf_span[s], #cf_span[t1], #cf_span[t2](#cf_span[1 ≤ h ≤ 12],#cf_span[0 ≤ m, s ≤ 59],#cf_span[1 ≤ t1, t2 ≤ 12],#cf_span[t1 ≠ t2])。米沙的位置和目标时间与任何指针的位置都不重合。"},{"iden":"output","content":"如果米沙能按时准备好比赛,输出 \"_YES_\"(引号仅用于清晰),否则输出 \"_NO_\"。你可以以任意大小写输出每个字符(\"_YeS_\" 和 \"_yes_\" 在答案为 \"_YES_\" 时都是合法的)。"},{"iden":"examples","content":"输入12 30 45 3 11输出NO输入12 0 1 12 1输出YES输入3 47 0 4 9输出YES"},{"iden":"note","content":"下面三张图从左到右展示了三个例子。米沙的起始位置用绿色表示,终点位置用粉红色表示。请注意,图中指针的位置并非精确值,但接近真实值,且答案相同。 "}]}
**Definitions** Let the clock face be a circle of 12 units, with positions $ 1, 2, \dots, 12 $ equally spaced. Let $ h, m, s \in \mathbb{Z} $ be the hour, minute, and second readings, respectively. Define the angular positions (in units) of the three hands: - Hour hand: $ H = h + \frac{m}{60} + \frac{s}{3600} $ - Minute hand: $ M = \frac{m}{5} + \frac{s}{300} $ - Second hand: $ S = \frac{s}{5} $ All positions are reduced modulo 12 to lie in $ [0, 12) $. Let $ t_1, t_2 \in \{1, 2, \dots, 12\} $ be Misha’s start and target positions, with $ t_1 \ne t_2 $. **Constraints** 1. $ 1 \le h \le 12 $ 2. $ 0 \le m, s \le 59 $ 3. $ 1 \le t_1, t_2 \le 12 $, $ t_1 \ne t_2 $ 4. $ t_1, t_2 \notin \{H, M, S\} $ (mod 12) — Misha does not stand on any hand. **Objective** Determine if there exists a continuous path from $ t_1 $ to $ t_2 $ along the circle (clock face) that does not intersect any of the three hands at positions $ H, M, S $. Equivalently: Let $ P = \{H, M, S\} \mod 12 $ be the set of hand positions. Sort $ P \cup \{t_1, t_2\} $ in increasing order modulo 12. Misha can move from $ t_1 $ to $ t_2 $ if and only if $ t_1 $ and $ t_2 $ lie in the same arc between two consecutive hand positions (i.e., they are not separated by any hand). Output "YES" if such a path exists; "NO" otherwise.
Samples
Input #1
12 30 45 3 11
Output #1
NO
Input #2
12 0 1 12 1
Output #2
YES
Input #3
3 47 0 4 9
Output #3
YES
API Response (JSON)
{
  "problem": {
    "name": "B. Race Against Time",
    "description": {
      "content": "Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a _really_ strong excuse: he fac",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF868B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a _really_ strong excuse: he fac...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "[{\"iden\":\"statement\",\"content\":\"你是否曾试图向协调员解释,距离比赛还有八个小时,却一个题目都没准备好?米沙试过。而这次他有一个_真正_强大的借口:他遭遇了时空悖论!空间和时间互换了位置。\\n\\n整个宇宙变成了一块巨大的钟面,有三根指针——时针、分针和秒针。时间凝固了,钟表现在显示的是 #cf_span[h] 小时、#cf_span[m] 分钟、#cf_span[s]...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet the clock face be a circle of 12 units, with positions $ 1, 2, \\dots, 12 $ equally spaced.  \nLet $ h, m, s \\in \\mathbb{Z} $ be the hour, minute, and second readings, respectively...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments