結果

問題 No.927 Second Permutation
コンテスト
ユーザー nishiwakki
提出日時 2020-03-09 21:35:08
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 160 ms / 2,000 ms
+ 992µs
コード長 395 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 55 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 12,284 KB
最終ジャッジ日時 2026-09-22 05:26:07
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

x = list(input())
l = len(x)
x.sort()
num = x[0]
idx = -1
for i in range(1, l):
    if num == x[i]:
        pass
    else:
        idx = i
        break

if idx == -1:
    print(-1)
    exit()
if l == 2 and x[0] == '0':
    print(-1)
    exit()
#print(x)
x[idx-1], x[idx] = x[idx], x[idx-1]
ans = ''
while l > 0:
    ans += x.pop()
    l -= 1
if ans[0] == '0':
    print(-1)
else:
    print(ans)
0