結果

問題 No.927 Second Permutation
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2020-07-20 20:06:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 8,428 KB
最終ジャッジ日時 2023-08-25 23:03:03
合計ジャッジ時間 2,698 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
7,776 KB
testcase_01 AC 13 ms
7,768 KB
testcase_02 AC 13 ms
7,836 KB
testcase_03 AC 13 ms
7,804 KB
testcase_04 AC 13 ms
7,856 KB
testcase_05 AC 13 ms
7,772 KB
testcase_06 AC 12 ms
7,724 KB
testcase_07 AC 12 ms
7,860 KB
testcase_08 AC 27 ms
8,196 KB
testcase_09 AC 14 ms
7,892 KB
testcase_10 AC 36 ms
8,200 KB
testcase_11 AC 53 ms
8,364 KB
testcase_12 AC 32 ms
8,212 KB
testcase_13 AC 18 ms
7,816 KB
testcase_14 AC 40 ms
8,188 KB
testcase_15 AC 32 ms
8,252 KB
testcase_16 AC 55 ms
8,396 KB
testcase_17 AC 53 ms
8,412 KB
testcase_18 AC 53 ms
8,300 KB
testcase_19 AC 53 ms
8,428 KB
testcase_20 AC 55 ms
8,420 KB
testcase_21 AC 58 ms
8,312 KB
testcase_22 AC 55 ms
8,256 KB
testcase_23 AC 54 ms
8,428 KB
testcase_24 AC 50 ms
8,248 KB
testcase_25 AC 39 ms
8,288 KB
testcase_26 AC 31 ms
8,232 KB
testcase_27 AC 29 ms
8,216 KB
testcase_28 AC 51 ms
8,220 KB
testcase_29 AC 47 ms
8,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

dic = dict()
for x in input():
    i = int(x)
    if i not in dic: dic[i] = 1
    else: dic[i] += 1

lst = list()
for i in range(10):
    if i in dic: lst.append((i, dic[i]))

ans = ""
while len(lst) > 2:
    k, v = lst.pop()
    ans += str(k) * v

if len(lst) == 2:
    k1, v1 = lst.pop()
    ans += str(k1) * (v1 - 1)

    k0, v0 = lst.pop()
    ans += str(k0) + str(k1)
    ans += str(k0) * (v0 - 1)

if ans == "" or ans[0] == "0": ans = -1
print(ans)
0