QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#17774. 年鑑整理

Statistiques

本棚には $n$ 本の年鑑が並んでいる。最初、第 $i$ 本目 ($1 \le i \le n$) の年鑑の破損度は $a_i$ である。

移動を行うたびに、まず位置 $p$ ($1 \le p \le n - 1$) を選択し、第 $p+1$ 本目の年鑑を第 $p$ 本目の年鑑の前に移動させる。移動後、その年鑑の破損度は $1$ 増加する。

時間が限られているため、合計で $n^2 - n$ 回を超えない回数しか移動を行うことができない。年鑑を閲覧する参加者の一人として、最終的に本棚の年鑑の破損度が左から右へ厳密に増加するように、具体的な移動計画を立てる手助けをしてほしい。

入力

各テストケースには複数のテストデータが含まれる。入力の最初の行には正整数 $T$ ($1 \le T \le 10$) が含まれ、データセットの数を示す。各テストデータについて:

  • 第 1 行には正整数 $n$ ($2 \le n \le 500$) が含まれ、年鑑の数を示す。
  • 第 2 行には $n$ 個の正整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) が含まれ、それぞれ初期状態における各年鑑の破損度を示す。

出力

各テストデータについて、実行可能な移動計画が存在する場合:

  • 第 1 行に非負整数 $k$ ($0 \le k \le n^2 - n$) を出力し、移動回数を示す。
  • 第 2 行に $k$ 個の正整数 $p_1, p_2, \dots, p_k$ ($1 \le p_i \le n - 1$) を出力し、それぞれ各移動で選択した位置を示す。

最終的に本棚の年鑑の破損度を左から右へ厳密に増加させることができない場合は、$-1$ を 1 行に出力する。

入出力例

入力 1

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

出力 1

0

-1
2
2 1

注記

1 番目のテストデータについては、初期状態で本棚の年鑑の破損度は左から右へ厳密に増加している。

2 番目のテストデータについては、$n^2 - n$ 回以内の移動で最終的に本棚の年鑑の破損度を左から右へ厳密に増加させることは不可能であることが証明できる。

3 番目のテストデータについては、実行可能な移動計画の一例は以下の通りである。

  • 1 回目の移動で位置 2 を選択すると、すべての年鑑の破損度は $[4, 2, 5]$ になる。
  • 2 回目の移動で位置 1 を選択すると、すべての年鑑の破損度は $[3, 4, 5]$ になる。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.