結果

問題 No.927 Second Permutation
ユーザー tails1434
提出日時 2019-12-25 21:51:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 734 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,072 KB
実行使用メモリ 77,652 KB
最終ジャッジ日時 2024-10-01 06:49:40
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def main():
    X = input()
    if len(set(X)) == 1:
        print(-1)
        exit()
    if ('0' in set(X)) and (len(set(X)) == 2):
        print(-1)
        exit()
    
    d = defaultdict(int)
    for x in X:
        d[x] += 1

    ans = ""
    cnt = 0
    second = -1
    length = len(d)
    for key in sorted(d.keys(), reverse=True):
        if cnt == length - 2:
            ans += key * (d[key] - 1)
            second = key
        elif cnt == length - 1:
            ans += key
            ans += second
            ans += key * (d[key] - 1)
        else:
            ans += key * d[key]
        cnt += 1
    
    print(ans)
        

    



    



if __name__ == "__main__":
    main()
0