結果

問題 No.927 Second Permutation
ユーザー nishiwakki
提出日時 2020-03-09 21:35:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-11-14 08:01:00
合計ジャッジ時間 4,465 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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