結果

問題 No.927 Second Permutation
ユーザー はむ吉🐹はむ吉🐹
提出日時 2019-11-22 21:40:26
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 461 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 9,292 KB
最終ジャッジ日時 2023-08-01 11:15:40
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,816 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 15 ms
7,936 KB
testcase_03 AC 15 ms
7,928 KB
testcase_04 AC 16 ms
7,768 KB
testcase_05 AC 16 ms
7,812 KB
testcase_06 AC 16 ms
7,760 KB
testcase_07 AC 16 ms
7,840 KB
testcase_08 AC 22 ms
8,276 KB
testcase_09 AC 16 ms
7,780 KB
testcase_10 AC 25 ms
8,556 KB
testcase_11 AC 30 ms
9,168 KB
testcase_12 AC 23 ms
8,404 KB
testcase_13 AC 17 ms
8,076 KB
testcase_14 AC 25 ms
8,672 KB
testcase_15 AC 23 ms
8,408 KB
testcase_16 AC 32 ms
9,292 KB
testcase_17 AC 31 ms
9,292 KB
testcase_18 AC 32 ms
9,116 KB
testcase_19 AC 32 ms
9,120 KB
testcase_20 AC 32 ms
9,280 KB
testcase_21 AC 31 ms
9,176 KB
testcase_22 AC 31 ms
9,128 KB
testcase_23 AC 31 ms
9,180 KB
testcase_24 AC 25 ms
8,880 KB
testcase_25 AC 23 ms
8,568 KB
testcase_26 AC 21 ms
8,304 KB
testcase_27 AC 20 ms
8,340 KB
testcase_28 AC 26 ms
8,864 KB
testcase_29 AC 24 ms
8,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


def solve(x):
    cs = sorted(x, reverse=True)
    n = len(cs)
    for i in range(n - 1)[::-1]:
        if cs[i] > cs[i + 1]:
            cs[i], cs[i + 1] = cs[i + 1], cs[i]
            break
    else:
        return
    y = "".join(cs)
    if y.startswith("0"):
        return
    else:
        return y


def main():
    x = input()
    res = solve(x)
    print(res if res is not None else -1)


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