結果

問題 No.927 Second Permutation
ユーザー OhnumaOhnuma
提出日時 2020-04-10 14:53:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 9,628 KB
最終ジャッジ日時 2023-10-13 04:40:37
合計ジャッジ時間 2,659 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 19 ms
8,524 KB
testcase_02 AC 18 ms
8,372 KB
testcase_03 AC 19 ms
8,404 KB
testcase_04 AC 18 ms
8,528 KB
testcase_05 AC 19 ms
8,408 KB
testcase_06 AC 18 ms
8,380 KB
testcase_07 AC 18 ms
8,420 KB
testcase_08 AC 23 ms
8,760 KB
testcase_09 AC 19 ms
8,336 KB
testcase_10 AC 24 ms
8,968 KB
testcase_11 AC 29 ms
9,200 KB
testcase_12 AC 24 ms
8,828 KB
testcase_13 AC 19 ms
8,392 KB
testcase_14 AC 25 ms
8,964 KB
testcase_15 AC 23 ms
8,820 KB
testcase_16 AC 30 ms
9,384 KB
testcase_17 AC 31 ms
9,628 KB
testcase_18 AC 30 ms
9,576 KB
testcase_19 AC 30 ms
9,436 KB
testcase_20 AC 30 ms
9,400 KB
testcase_21 AC 31 ms
9,584 KB
testcase_22 AC 31 ms
9,332 KB
testcase_23 AC 31 ms
9,512 KB
testcase_24 AC 27 ms
9,148 KB
testcase_25 AC 24 ms
8,976 KB
testcase_26 AC 23 ms
8,964 KB
testcase_27 AC 22 ms
8,568 KB
testcase_28 AC 26 ms
9,192 KB
testcase_29 AC 25 ms
9,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
x = list(input())
ctr = Counter(x)
t = 0
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