結果

問題 No.927 Second Permutation
ユーザー uni_pythonuni_python
提出日時 2020-11-08 15:37:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 86,360 KB
実行使用メモリ 78,428 KB
最終ジャッジ日時 2023-09-29 21:13:04
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,248 KB
testcase_01 AC 60 ms
71,116 KB
testcase_02 AC 65 ms
71,124 KB
testcase_03 AC 61 ms
71,136 KB
testcase_04 AC 61 ms
71,304 KB
testcase_05 AC 67 ms
71,104 KB
testcase_06 AC 62 ms
71,420 KB
testcase_07 AC 65 ms
71,444 KB
testcase_08 AC 82 ms
76,560 KB
testcase_09 AC 69 ms
75,568 KB
testcase_10 AC 79 ms
77,084 KB
testcase_11 AC 89 ms
77,956 KB
testcase_12 AC 74 ms
76,768 KB
testcase_13 AC 64 ms
75,628 KB
testcase_14 AC 79 ms
76,872 KB
testcase_15 AC 74 ms
76,800 KB
testcase_16 AC 90 ms
78,428 KB
testcase_17 AC 88 ms
77,944 KB
testcase_18 AC 92 ms
78,276 KB
testcase_19 AC 92 ms
78,332 KB
testcase_20 AC 96 ms
78,072 KB
testcase_21 AC 92 ms
78,124 KB
testcase_22 AC 90 ms
78,056 KB
testcase_23 AC 90 ms
78,068 KB
testcase_24 AC 65 ms
72,792 KB
testcase_25 AC 65 ms
72,416 KB
testcase_26 AC 65 ms
71,892 KB
testcase_27 AC 68 ms
71,972 KB
testcase_28 AC 71 ms
72,552 KB
testcase_29 AC 70 ms
72,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

S=list(input())
N=len(S)

# 1種類だとダメ
S2=set(S)
if len(S2)==1:
    print(-1)
    exit()

# 最上位以外全部0だとダメ
cnt=S.count("0")
if cnt==N-1:
    print(-1)
    exit()
# print(cnt)
    
    
S.sort(reverse=True)

for i in range(N-1,0,-1):
    if S[i]!=S[i-1]:
        S[i],S[i-1]=S[i-1],S[i]
        break
    
print(''.join(map(str, S)))


0