#P17168. [CEOI 2026] Vim

    ID: 19500 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>Special JudgeCEOI(中欧)2026

[CEOI 2026] Vim

Problem Description

It would be hard to find anything more geeky than the oldschool Vim - an editor in which we can do things that we could only dream of in "regular" editors. That is, if we are willing to invest a week of learning and a month of practice so that the unusual but powerful commands it offers become our "muscle memory". Well, just like in other editors, in Vim we have a cursor, which is always located on one of the characters. Initially, it is located on the first character of the text, and just like in other editors, in Vim there is a clipboard, which is intended for storing (and indirectly copying and moving) pieces of text. The clipboard is initially empty.

In this task, we will assume that there is exactly one - (minus) character in the editor at the beginning, and our goal is to finish with exactly nn consecutive minus signs. We will use four commands to help us with this:

  • h: If the cursor is on the first character, then this command does nothing, otherwise it moves the cursor to the character on the left.
  • l: If the cursor is on the last character, then this command does nothing, otherwise it moves the cursor to the character on the right.
  • Y: The sequence of characters extending from the cursor position to the end of the text is copied to the clipboard, "overwriting" any previous contents of the clipboard. (If the cursor is on the first character of the text, the entire text will be copied to the clipboard.)
  • P: A copy of the text stored in the clipboard is inserted before the character on which the cursor is located, and the cursor is moved to the last inserted character. The contents of the clipboard are not changed. If the clipboard is empty, nothing happens.

Write a program that reads the number nn and prints the minimum number of commands needed to finish with exactly nn consecutive - characters in Vim under the described conditions. The program should also print an example of a sequence with the minimum number of commands.

Input Format

The first line contains the number of test cases tt. The next tt lines contain test cases with the desired string length nn.

Output Format

For each test case, print the required minimum number of commands and an example of such a sequence of commands on its own line.

2
21
2
10 YPYPhPYPPP
2 YP

Hint

Comment

As we can see in the following table, in the first case, the sequence YPYPhPYPPP gives the correct result. The = character in the Screen column represents the - character on which the cursor is located.

Step Command Screen Clipboard
00 = (empty)
11 Y -
22 P =-
33 Y --
44 P -=--
55 h =---
66 P -=----
77 Y -----
88 P -----=-----
99 ---------=------
1010 -------------=-------

Constraints

  • 1t1001\le t\le 100
  • 1n1071\le n\le 10^7

Subtasks

If you print only the correct number of commands, but no example or an incorrect example of a sequence of commands, you will receive half the points for that subtask.

  • Subtask 11 (2020 points): n100n\le 100
  • Subtask 22 (88 points): n1000n\le 1000
  • Subtask 33 (1818 points): n104n\le 10^4
  • Subtask 44 (1818 points): n105n\le 10^5
  • Subtask 55 (1818 points): n106n\le 10^6
  • Subtask 66 (1818 points): No additional constraints.