結果

問題 No.927 Second Permutation
ユーザー OhnumaOhnuma
提出日時 2020-04-10 14:55:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 10,776 KB
実行使用メモリ 9,564 KB
最終ジャッジ日時 2023-10-13 04:43:14
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,308 KB
testcase_01 AC 19 ms
8,380 KB
testcase_02 AC 19 ms
8,308 KB
testcase_03 AC 20 ms
8,380 KB
testcase_04 AC 19 ms
8,368 KB
testcase_05 AC 19 ms
8,456 KB
testcase_06 AC 20 ms
8,380 KB
testcase_07 AC 19 ms
8,448 KB
testcase_08 AC 24 ms
8,748 KB
testcase_09 AC 19 ms
8,448 KB
testcase_10 AC 26 ms
8,992 KB
testcase_11 AC 30 ms
9,164 KB
testcase_12 AC 25 ms
8,632 KB
testcase_13 AC 20 ms
8,472 KB
testcase_14 AC 26 ms
8,868 KB
testcase_15 AC 24 ms
8,696 KB
testcase_16 AC 30 ms
9,396 KB
testcase_17 AC 31 ms
9,564 KB
testcase_18 AC 30 ms
9,448 KB
testcase_19 AC 30 ms
9,472 KB
testcase_20 AC 31 ms
9,404 KB
testcase_21 AC 31 ms
9,504 KB
testcase_22 AC 30 ms
9,400 KB
testcase_23 AC 30 ms
9,320 KB
testcase_24 AC 27 ms
9,300 KB
testcase_25 AC 25 ms
9,084 KB
testcase_26 AC 23 ms
8,808 KB
testcase_27 AC 22 ms
8,528 KB
testcase_28 AC 26 ms
9,192 KB
testcase_29 AC 25 ms
9,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
x = list(input())
ctr = Counter(x)
if ctr['0']==0:
    if len(ctr.keys())==1:
        print(-1)
        exit()
else:
    t = 0
    for i in range(1, 10):
        t += ctr[str(i)]
    if t==1:
        print(-1)
        exit()
d = dict(sorted(ctr.items(), reverse=True))
ret = ''    
for k,v in d.items():
    ret += k*v
for i in range(len(ret))[::-1]:
    if ret[i]!=ret[i-1]:
        ans = ret[:i-1]+ret[i]+ret[i-1]+ret[i+1:]
        break
print(ans)
0