luogu#P5033. 跑酷

跑酷

Background

In-contest Q&A

This parkour thing still depends on luck (for example, zm and mt)...

Problem Description

In Minecraft, parkour can be considered a skill. Steve now wants to do parkour on a (2D) track. But Steve does not know whether he can reach the finish, so he checked the MC Wiki to learn more. The details are as follows.

Health Points

  1. We define that each player starts with 2020 health points.
  2. Fall damage calculation:
    • If the player’s height is 33 blocks or less, this damage is ignored.
    • If the player’s height is 44 blocks or more, it causes x3x-3 damage, where xx is the falling height.
    • The height here is relative height, i.e., the height difference between the current block and the next block.
  3. Cases where fall damage is reduced: see Special Blocks.
  4. When health becomes 00, it is considered that the finish cannot be reached.

Parkour

  1. For a player standing on a block, the player can jump forward at most 33 blocks, and can also jump up by 11 block.
  2. For a player standing on a block, the player can also jump forward at most 44 blocks, but cannot jump up by 11 block.
  3. For convenience, we assume the player does not move while falling. That is, if the next block is lower than the current block, we can only fall exactly to the position of the next block.
  4. By default, the finish is the last block.

Special Blocks

  1. Slime Block: It will bounce you up to a height equal to 60%60\% of the falling distance. If there is a decimal part, round down. When you reach the highest point, you can only move forward by one more block. Of course, if you land on a block in front, you will still take fall damage. You can also hold the Shift key to cancel the bounce. We assume that doing parkour on slime blocks is not affected by the slowdown limit.
  2. Cobweb: It makes you ignore damage while falling. We also assume that doing parkour on cobwebs is not affected by the slowdown limit.

Steve found you and asked you to solve this problem. Determine whether Steve can reach the finish.

  • If he can reach the finish, output the minimum number of jumps.
  • If he cannot reach the finish, output: qwq.

Input Format

The first line contains an integer nn, meaning there are nn blocks.

Starting from the second line, the next nn lines describe the nn blocks. Each block has its attributes: xx-coordinate, height, and whether it is a special block. (A normal block is given as P\verb!P!, a slime block as N\verb!N!, and a cobweb as Z\verb!Z!.)

Output Format

If he can reach the finish, output one integer, the minimum number of jumps. If he cannot reach the finish, output qwq.

2
1 4 P
4 5 P
1
3
1 6 P
2 4 N
3 4 P
0
2
5 8 P
7 11 P
qwq

Hint

Constraints and Notes

The testdata guarantees that the input xx-coordinates are strictly increasing. Each xx-coordinate has exactly one block.

The testdata guarantees that there will not be two special blocks between two adjacent xx-coordinates.

For blocks, by default there are no floating blocks; that is, every block has a supporting pillar beneath it.

For convenience, you cannot jump first and then fall. That is, you can only fall onto the block that is one block ahead.

For 30%30\% of the testdata, n10n\le 10. For another 20%20\% of the testdata, it is guaranteed that there are no special blocks. For the first 50%50\% of the testdata, it is guaranteed that Steve’s forward jump can only be either 44 blocks far, or 33 blocks far with 11 block upward. For 100%100\% of the testdata, 1n10001\le n\le 1000, 1xmax100001\le x_{\rm max}\le 10000, 1height10001\le height\le 1000.

The testdata is guaranteed to have a reasonable difficulty gradient.

Translated by ChatGPT 5