Logo
(追記) (追記ここまで)

32456번 - Harmonious Passage of Magicians 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB33181477.778%

문제

There is a very narrow alley, and two teams of magicians want to pass through this alley from opposite ends. They do not see the other team until there is only a space that can hold one person between the two teams. Because the alley is so narrow, they cannot turn around or walk backward to avoid falling. However, being magicians, they can use a spell to teleport a short distance, allowing them to pass by another person. Additionally, to maintain order, the magicians in the same team cannot change their order, so they cannot use this spell to pass the magician which is from the same team.

To clarify, we assume that there are $n$ magicians in the first team, starting from the left side and numbered from 1ドル$ to $n,ドル and $m$ magicians in the second team, starting from the right side and numbered from $n + 1$ to $n + m$.

The narrow alley has a total of $n + m + 1$ spaces. The leftmost $n$ spaces are occupied by the first team, facing right, and the rightmost $m$ spaces are occupied by the second team, facing left. The alley configuration will look like this: $[1, 2, \dots , n,\text{space}, n + 1, n + 2, \dots ,n + m]$.

When a magician moves, he must follow these rules:

  • If there is an empty space directly in front of him, he can walk into that space.
  • If there is a magician from the opposite team directly in front of him, and there is an empty space directly behind this magician, he can use the spell to move to that space.

Ultimately, the first team will occupy the rightmost $n$ spaces, and the second team will occupy the leftmost $m$ spaces.

To help them pass the alley, please provide a movement strategy that will allow them to pass. The strategy will be described with a sequence of numbers $a_1, a_2, \dots,ドル where $a_i$ indicates that in the $i$-th step, the magician with number $a_i$ will move to an unoccupied space.

If there are multiple strategies, please output the lexicographically smallest one. Lexicographical order is a way of comparing strings or sequences of elements based on their alphabetical or numerical order. In the context of this problem, the “lexicographically smallest” strategy refers to the strategy that comes first in the numerical order when the strategies are represented as sequences of numbers.

More concretely:

  • Each strategy is represented as a sequence of numbers: $a_1, a_2, \dots$
  • Two strategies are compared element by element:
    • If the first element of one strategy is smaller than the first element of the other, the first strategy is lexicographically smaller.
    • If the first elements are equal, compare the second elements, and so on.

입력

The frst line contains an integer $t,ドル indicating the number of test cases. For the following $t$ lines, each line contains two integers $n$ and $m,ドル indicating the number of magicians from the first team and the number of magicians from the second team, respectively.

출력

Output $t$ lines. The $i$-th line should contain the movement strategy that will help the magicians pass through the narrow alley for the $i$-th test case. If there are multiple strategies, output the lexicographically smallest one.

제한

  • 2ドル ≤ n ≤ 3000$
  • 2ドル ≤ m ≤ 3000$
  • 1ドル ≤ t ≤ 1000$ The sum of $n$’s among all test cases is no more than 3000ドル$.
  • The sum of $m$’s among all test cases is no more than 3000ドル$.

예제 입력 1

2
2 2
2 3

예제 출력 1

2 3 4 2 1 3 4 1
2 3 4 2 1 3 4 5 2 1 5

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2024 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /