結果

問題 No.927 Second Permutation
ユーザー hiragnhiragn
提出日時 2022-11-10 22:16:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 406 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 10,544 KB
実行使用メモリ 9,520 KB
最終ジャッジ日時 2023-10-01 05:40:46
合計ジャッジ時間 4,208 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,784 KB
testcase_01 AC 16 ms
7,952 KB
testcase_02 AC 15 ms
7,716 KB
testcase_03 AC 16 ms
7,828 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 15 ms
7,952 KB
testcase_06 AC 16 ms
7,960 KB
testcase_07 AC 16 ms
7,716 KB
testcase_08 AC 22 ms
8,584 KB
testcase_09 AC 16 ms
7,884 KB
testcase_10 AC 27 ms
8,748 KB
testcase_11 AC 33 ms
9,284 KB
testcase_12 AC 24 ms
8,628 KB
testcase_13 AC 17 ms
8,024 KB
testcase_14 AC 27 ms
8,744 KB
testcase_15 AC 23 ms
8,624 KB
testcase_16 AC 34 ms
9,520 KB
testcase_17 AC 34 ms
9,332 KB
testcase_18 AC 35 ms
9,324 KB
testcase_19 AC 34 ms
9,504 KB
testcase_20 AC 35 ms
9,324 KB
testcase_21 AC 34 ms
9,324 KB
testcase_22 AC 34 ms
9,292 KB
testcase_23 AC 34 ms
9,332 KB
testcase_24 AC 18 ms
8,824 KB
testcase_25 AC 17 ms
8,580 KB
testcase_26 AC 17 ms
8,348 KB
testcase_27 AC 21 ms
8,324 KB
testcase_28 AC 29 ms
8,840 KB
testcase_29 AC 27 ms
8,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    x = list(input())

    # 桁数字が1種類しかないとき
    if len(set(x)) == 1:
        print(-1)
        exit()

    # 桁数字が2種類以上あるとき
    x.sort()
    i = 0
    while x[i] == x[i + 1]:
        i += 1

    x[i], x[i + 1] = x[i + 1], x[i]
    if x[-1] == "0":
        print(-1)
    else:
        print("".join(x[::-1]))


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