結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,332 KB
testcase_01 AC 38 ms
53,332 KB
testcase_02 AC 39 ms
53,332 KB
testcase_03 AC 39 ms
53,332 KB
testcase_04 AC 38 ms
53,332 KB
testcase_05 AC 41 ms
53,332 KB
testcase_06 AC 39 ms
53,332 KB
testcase_07 WA -
testcase_08 AC 50 ms
66,512 KB
testcase_09 AC 47 ms
61,596 KB
testcase_10 AC 54 ms
71,088 KB
testcase_11 AC 64 ms
77,304 KB
testcase_12 AC 52 ms
68,740 KB
testcase_13 AC 45 ms
61,524 KB
testcase_14 AC 54 ms
73,208 KB
testcase_15 AC 53 ms
68,720 KB
testcase_16 AC 69 ms
77,520 KB
testcase_17 AC 68 ms
77,520 KB
testcase_18 AC 66 ms
77,520 KB
testcase_19 AC 66 ms
77,520 KB
testcase_20 AC 68 ms
77,520 KB
testcase_21 AC 65 ms
77,520 KB
testcase_22 AC 64 ms
77,520 KB
testcase_23 AC 65 ms
77,520 KB
testcase_24 AC 43 ms
58,412 KB
testcase_25 AC 41 ms
58,168 KB
testcase_26 AC 40 ms
55,868 KB
testcase_27 AC 43 ms
58,500 KB
testcase_28 AC 49 ms
65,952 KB
testcase_29 AC 48 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
            ans += second
            ans += key * (d[key] - 1)
        else:
            ans += key * d[key]
        cnt += 1
    
    print(ans)
        

    



    



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