結果

問題 No.927 Second Permutation
ユーザー maspy
提出日時 2020-01-24 01:33:44
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-09-13 04:05:48
合計ジャッジ時間 3,082 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X = read().decode().rstrip()

X = sorted(X, reverse = True)

if X[0] == X[-1]:
    print(-1)
    exit()
if sum(x > '0' for x in X) == 1:
    print(-1)
    exit()    

for i in range(len(X)-2,-1,-1):
    if X[i] == X[i+1]:
        continue
    X[i], X[i+1] = X[i+1], X[i]
    break

answer = ''.join(X)
print(answer)
0