結果

問題 No.927 Second Permutation
ユーザー Tsubo
提出日時 2020-03-11 08:48:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,872 KB
最終ジャッジ日時 2024-11-16 00:04:14
合計ジャッジ時間 2,355 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    X=list(readline().strip())
    X.sort(reverse=True)
    
    s=set(X)
    if len(s)>=3:
        flag=True
    elif len(s)==2:
        no_zero=0
        for i in range(len(X)):
            if X[i]!="0":
                no_zero+=1
            elif X[i]=="0":
                flag=False
                break
            if no_zero>=2:
                flag=True
                break
    elif len(s)==1:
        flag=False

    if flag==False:
        print(-1)
    else:
        n=0
        for i in range(len(X)-1,-1,-1):
            if i==len(X)-1:
                n=X[i]
            else:
                if X[i]!=n:
                    X[i],X[i+1]=X[i+1],X[i]
                    break
    
        print("".join(X))

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