結果

問題 No.927 Second Permutation
ユーザー TS_KAsTS_KAs
提出日時 2019-11-22 21:59:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 683 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 63,232 KB
最終ジャッジ日時 2024-04-19 11:21:11
合計ジャッジ時間 2,116 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,124 KB
testcase_01 AC 37 ms
51,968 KB
testcase_02 AC 35 ms
51,712 KB
testcase_03 AC 33 ms
52,480 KB
testcase_04 AC 33 ms
52,096 KB
testcase_05 AC 33 ms
52,224 KB
testcase_06 AC 33 ms
52,096 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 39 ms
61,824 KB
testcase_25 AC 35 ms
60,288 KB
testcase_26 AC 36 ms
60,416 KB
testcase_27 AC 36 ms
59,520 KB
testcase_28 AC 37 ms
61,568 KB
testcase_29 AC 36 ms
60,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

X = input()
x = [0] * 10
for i in range(len(X)):
    x[int(X[i])] += 1
first_min = 10
second_min = 10
for i in range(10):
    if x[0] == len(X) - 1:
        print(-1)
        exit()
    if x[i] == len(X):
        print(-1)
        exit()
    if x[i] > 0 and first_min == 10 and second_min == 10:
        first_min = i
        continue
    if x[i] > 0 and first_min != 10 and second_min == 10:
        second_min = i
ans = ''
for i in range(9, -1, -1):
    if i != first_min and i != second_min:
        ans += str(i) * x[i]
    if i == second_min:
        ans += str(i) * (x[i]-1) + str(first_min)
    if i == first_min:
        ans += str(i) * (x[i]-1) + str(second_min)
print(ans)
0