結果

問題 No.927 Second Permutation
ユーザー kou_kkk
提出日時 2025-10-02 12:44:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 12,180 KB
最終ジャッジ日時 2025-10-02 12:44:41
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

x = input()
 
sorted_x = sorted(x, reverse=True)
 
set1 = set()
cnt = 0
for c in sorted_x:
    set1.add(c)
    if c == '0': continue
    cnt += 1
 
ans = '-1'
 
if len(set1) < 2 or cnt < 2:
    print(ans)
    exit()
 
for i in range(len(x)-1, 0, -1):
    c1 = sorted_x[i]
    c2 = sorted_x[i-1]
    if c1 != c2:
        list = sorted_x[:i-1]
        list.append(c1)
        list.append(c2)
        list += sorted_x[i+1:]
        break
 
ans = ''.join(list)
 
print(ans)
0