J. Jumpity Digits

Codeforces
IDCF10227J
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Seo is an expert in electronics (as well as codeforces). Also, he is a very very good friend of B21. One time, B21 call him for help: the electricity board that shows the distance between Earth and the nearest black hole in _nanometres_ has a glitch. As B21 said: there were two "*jumpity digits*" that made the numbers display on the board became false. Right now, the number on the board is $X$. B21 states that the number that must be displayed on the board is smaller than $X$, and as optimistic as the person B21 is, he states that it should be the greatest possible number. Help Seo find the number that must be displayed, or determine that it is impossible, which means there were some fallacies in B21's statements. The only line in the input contains an integer: $X$ ($1 <= X <= 10^(100)$) - the number that is displaying on the board. Print "_-1_" if it is impossible to find the number. Else, print that number on a single line. ## Input The only line in the input contains an integer: $X$ ($1 <= X <= 10^(100)$) - the number that is displaying on the board. ## Output Print "_-1_" if it is impossible to find the number. Else, print that number on a single line. [samples]
**Definitions** Let $ X \in \mathbb{Z}^+ $ be the displayed number, with decimal representation $ d_1 d_2 \dots d_n $, where $ d_1 \neq 0 $ and $ n = \lfloor \log_{10} X \rfloor + 1 $. **Constraints** 1. $ 1 \leq X \leq 10^{100} $ 2. The true number $ Y $ must satisfy: - $ Y < X $ - $ Y $ is obtained by swapping exactly two digits in $ X $ (the "jumpity digits") - $ Y $ is maximized under these constraints - Leading zeros are not allowed (i.e., $ Y $ must not start with '0') **Objective** Find the maximum $ Y < X $ such that $ Y $ is a permutation of $ X $ with exactly two digits swapped. If no such $ Y $ exists, output $-1$.
API Response (JSON)
{
  "problem": {
    "name": "J. Jumpity Digits",
    "description": {
      "content": "Seo is an expert in electronics (as well as codeforces). Also, he is a very very good friend of B21. One time, B21 call him for help: the electricity board that shows the distance between Earth and t",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10227J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Seo is an expert in electronics (as well as codeforces). Also, he is a very very good friend of B21.\n\nOne time, B21 call him for help: the electricity board that shows the distance between Earth and t...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ X \\in \\mathbb{Z}^+ $ be the displayed number, with decimal representation $ d_1 d_2 \\dots d_n $, where $ d_1 \\neq 0 $ and $ n = \\lfloor \\log_{10} X \\rfloor + 1 $.\n\n**Constraint...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments