結果

問題 No.927 Second Permutation
ユーザー chanpukuchanpuku
提出日時 2019-11-22 23:12:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 78,976 KB
最終ジャッジ日時 2024-04-19 12:29:45
合計ジャッジ時間 2,241 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,776 KB
testcase_01 AC 34 ms
52,972 KB
testcase_02 AC 32 ms
52,728 KB
testcase_03 AC 32 ms
53,292 KB
testcase_04 AC 34 ms
53,104 KB
testcase_05 AC 31 ms
52,208 KB
testcase_06 AC 30 ms
52,560 KB
testcase_07 AC 32 ms
52,672 KB
testcase_08 AC 43 ms
68,240 KB
testcase_09 AC 37 ms
61,092 KB
testcase_10 AC 44 ms
70,860 KB
testcase_11 AC 50 ms
76,800 KB
testcase_12 AC 45 ms
68,224 KB
testcase_13 AC 40 ms
61,568 KB
testcase_14 AC 46 ms
71,808 KB
testcase_15 AC 43 ms
68,224 KB
testcase_16 AC 50 ms
78,848 KB
testcase_17 AC 52 ms
78,976 KB
testcase_18 AC 51 ms
78,208 KB
testcase_19 AC 51 ms
78,336 KB
testcase_20 AC 52 ms
78,464 KB
testcase_21 AC 52 ms
78,848 KB
testcase_22 AC 54 ms
78,592 KB
testcase_23 AC 55 ms
78,848 KB
testcase_24 AC 39 ms
65,024 KB
testcase_25 AC 39 ms
63,104 KB
testcase_26 AC 37 ms
62,208 KB
testcase_27 AC 37 ms
61,056 KB
testcase_28 AC 39 ms
65,408 KB
testcase_29 AC 40 ms
64,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

X=input()
num=[0]*10
for i in range(len(X)):
    num[9-int(X[i])]=num[9-int(X[i])]+1

mi=-1
mi2=-1
for i in range(10):
    if not num[9-i]==0:
        if mi==-1:
            mi=9-i
        else:
            mi2=9-i
            break
if mi2==-1 or sum(num)<num[9]+2:
    print(-1)
else:
    l=[]
    for i in range(10):
        if i==mi2:
            for j in range(num[i]-1):
                l.append(9-i)
            l.append(9-mi)
        elif i==mi:
            l.append(9-mi2)
            for j in range(num[i]-1):
                l.append(9-i)
        else:
            for j in range(num[i]):
                l.append(9-i)
    print(''.join(map(str,l)))
0