K. Running Hero

Codeforces
IDCF10124K
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Aladdin is running through a long cave. He is very fast and can move with a speed of at most v meters per second, but falling stones prevent him from running always at maximum speed. Now imagine a 2-dimensional world with Aladdin being a point moving in the positive or negative direction of the X-axis, and stones, falling down on the Al's head, being segments parallel to the X-axis. Another point in this world is princess Jasmin. She is waiting for Al at the point (G, 0). Aladdin starts his way at the point (0, 0). A stone kills Aladdin if he is located strictly between the endpoints of the stone when the stone reaches the ground. As Jasmin is in a fortified trench, the stones can't hurt her even if they fall down on her head. You are given Aladdin's maximum speed, Jasmin's position and information about times and places of falling stones. Your task is to find the whether it is possible for Aladdin to to reach Jasmin. If it's possible, you also have to find the sequence of actions which gets Aladdin to Jasmin in the minimum amount of time possible. The first line of the input contains three integers v, G and n (1 ≤ v ≤ 105, 0 < |G| ≤ 105, 0 ≤ n ≤ 3000) — Aladdin's maximum speed, Jasmin's x-coordinate and the number of stones. Each of the following n lines contains three integers x1, i, x2, i and ti ( - 105 ≤ x1, i ≤ x2, i ≤ 105, 1 ≤ ti ≤ 105) — left and right endpoints of the i-th stone, and time when the i-th stone reaches the ground. If there is no solution, the output should contain a single integer -1. Otherwise the first line of the output should contain one integer k — the number of instructions for Aladdin. Each of the following k lines should contain a pair of space-separated real numbers — speed w and time t. A pair (w, t) means that Aladdin should run t seconds at speed w. Speed w should be negative, if Aladdin should move in the negative direction of the X-axis and non-negative otherwise. Value t should always be positive. The value w = 0 means that Aladdin doesn't move for time t. If there are many solutions, you may output any of them. All real values should be printed with at least 9 digits after the decimal point. The number of instructions k in your output must not exceed 10000. Aladdin can change his speed instantly. If some stone falls down on Al's head at the moment of or after his meeting with Jasmin, it can't prevent the two from kissing each other and can't change anything. ## Input The first line of the input contains three integers v, G and n (1 ≤ v ≤ 105, 0 < |G| ≤ 105, 0 ≤ n ≤ 3000) — Aladdin's maximum speed, Jasmin's x-coordinate and the number of stones. Each of the following n lines contains three integers x1, i, x2, i and ti ( - 105 ≤ x1, i ≤ x2, i ≤ 105, 1 ≤ ti ≤ 105) — left and right endpoints of the i-th stone, and time when the i-th stone reaches the ground. ## Output If there is no solution, the output should contain a single integer -1.Otherwise the first line of the output should contain one integer k — the number of instructions for Aladdin. Each of the following k lines should contain a pair of space-separated real numbers — speed w and time t. A pair (w, t) means that Aladdin should run t seconds at speed w. Speed w should be negative, if Aladdin should move in the negative direction of the X-axis and non-negative otherwise. Value t should always be positive. The value w = 0 means that Aladdin doesn't move for time t. If there are many solutions, you may output any of them. All real values should be printed with at least 9 digits after the decimal point. The number of instructions k in your output must not exceed 10000. [samples] ## Note Aladdin can change his speed instantly. If some stone falls down on Al's head at the moment of or after his meeting with Jasmin, it can't prevent the two from kissing each other and can't change anything.
**Definitions** Let $ v \in \mathbb{R}^+ $ be Aladdin’s maximum speed. Let $ G \in \mathbb{R} \setminus \{0\} $ be Jasmin’s position on the $ x $-axis. Let $ n \in \mathbb{Z}_{\geq 0} $ be the number of stones. For each stone $ i \in \{1, \dots, n\} $: - Let $ [x_{1,i}, x_{2,i}] \subset \mathbb{R} $ be the horizontal span of the stone. - Let $ t_i \in \mathbb{R}^+ $ be the time at which the stone reaches the ground. Aladdin starts at position $ 0 $ at time $ 0 $, and must reach position $ G $ at some time $ T \geq 0 $. **Constraints** 1. $ 1 \leq v \leq 10^5 $ 2. $ 0 < |G| \leq 10^5 $ 3. $ 0 \leq n \leq 3000 $ 4. For each stone $ i $: $ -10^5 \leq x_{1,i} \leq x_{2,i} \leq 10^5 $, $ 1 \leq t_i \leq 10^5 $ 5. Aladdin’s position at time $ \tau $, denoted $ x(\tau) $, must satisfy $ |x'(\tau)| \leq v $ for all $ \tau \geq 0 $ (where derivative exists). 6. For each stone $ i $, if $ x_{1,i} < x(\tau) < x_{2,i} $ for some $ \tau \in (0, t_i) $, then Aladdin is killed. 7. Aladdin is safe at time $ t_i $ if $ x(t_i) \leq x_{1,i} $ or $ x(t_i) \geq x_{2,i} $. 8. Aladdin must reach $ G $ at some time $ T \geq 0 $, and must not be killed before or at $ T $. **Objective** Determine whether there exists a piecewise-constant velocity function $ w: [0, T] \to [-v, v] $, with finitely many pieces, such that: $$ x(T) = G, \quad x(\tau) = \int_0^\tau w(s)\,ds, \quad \text{and} \quad \forall i, \; \forall \tau \in (0, t_i), \; x(\tau) \notin (x_{1,i}, x_{2,i}) $$ If yes, find such a function with minimal $ T $, represented as a sequence of $ k $ pairs $ (w_j, t_j) $, where $ w_j \in [-v, v] $, $ t_j > 0 $, $ \sum_{j=1}^k t_j = T $, and $ k \leq 10000 $. If no such path exists, output $-1$.
API Response (JSON)
{
  "problem": {
    "name": "K. Running Hero",
    "description": {
      "content": "Aladdin is running through a long cave. He is very fast and can move with a speed of at most v meters per second, but falling stones prevent him from running always at maximum speed. Now imagine a 2-",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10124K"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Aladdin is running through a long cave. He is very fast and can move with a speed of at most v meters per second, but falling stones prevent him from running always at maximum speed.\n\nNow imagine a 2-...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ v \\in \\mathbb{R}^+ $ be Aladdin’s maximum speed.  \nLet $ G \\in \\mathbb{R} \\setminus \\{0\\} $ be Jasmin’s position on the $ x $-axis.  \nLet $ n \\in \\mathbb{Z}_{\\geq 0} $ be the n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments