結果

問題 No.927 Second Permutation
ユーザー tails1434tails1434
提出日時 2019-12-25 21:49:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 2,900 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 77,520 KB
最終ジャッジ日時 2024-04-08 13:44:12
合計ジャッジ時間 5,878 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 46 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 42 ms
58,412 KB
testcase_25 AC 41 ms
58,168 KB
testcase_26 AC 40 ms
55,868 KB
testcase_27 AC 42 ms
58,500 KB
testcase_28 AC 50 ms
65,952 KB
testcase_29 AC 47 ms
63,484 KB
権限があれば一括ダウンロードができます

ソースコード

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 * d[key]
            ans += second
        else:
            ans += key * d[key]
        cnt += 1
    
    print(ans)
        

    



    



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