結果

問題 No.927 Second Permutation
ユーザー akanaya
提出日時 2020-03-29 16:05:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2025-01-02 14:08:59
合計ジャッジ時間 2,550 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

x = list(input().strip())

c = Counter(x)

if len(c.keys()) == 1:
    print(-1)
elif c['0'] == len(x) - 1:
    print(-1)
else:
    v = sorted(c.keys())[0]
    c[v] -= 1

    e = sorted(c.keys(), reverse=True)
    for i in range(len(e)):
        t = str(e[i])
        if i != len(e) - 2:
            print(t * c[t], end='')
        else:
            print(t * (c[t] - 1), end='')
            print(v, end='')
            print(t, end='')
    print()            




    

0