QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#7312. ほぼ Bobo 数

Statistics

正の整数の十進表記が、同じ整数を二つ連結して得られるとき、その整数を bobo 数と呼びます。例えば、$12341234$ と $3232$ は bobo 数ですが、$1234321$ と $1322$ は bobo 数ではありません。

正の整数について、連続する同じ数字をそれぞれ一つにまとめた結果が bobo 数になるとき、その整数をほぼ bobo 数と呼びます。例えば、$1112223112233$ は、連続する同じ数字をすべてまとめると $123123$ になるので、ほぼ bobo 数です。

Bobo は非常に大きな整数 $n$ を持っており、$n$ 未満の最大のほぼ bobo 数を知りたいと考えています。

入力

入力には 0 個以上のテストケースが含まれ、ファイルの終端で終了します。各テストケースは次の形式です。

最初の行には、先頭にゼロのない整数 $n$($1\le n\le 10^{5\,000\,000}$)が与えられます。

入力中のすべての $n$ の十進表記の長さの合計は $5\,000\,000$ を超えないことが保証されます。

出力

各テストケースについて、$n$ より真に小さい最大のほぼ bobo 数を表す、先頭にゼロのない整数を出力してください。そのような整数が存在しない場合は、代わりに $-1$ を出力してください。

入出力例

入力 1

12345
67890
11111
1000
26782641

出力 1

12212
67767
11010
-1
26777267

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.