結果
| 問題 | No.927 Second Permutation |
| コンテスト | |
| ユーザー |
_KingdomOfMoray
|
| 提出日時 | 2020-01-04 22:34:10 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 952 bytes |
| 記録 | |
| コンパイル時間 | 210 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-11-22 21:37:18 |
| 合計ジャッジ時間 | 2,146 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 1 RE * 21 |
ソースコード
import collections
x = int(input())
x_list = list(str(x))
x_list = [int(e) for e in x_list]
sorted_x = sorted(x_list, reverse=True)
if len(sorted_x) == 2:
if sorted_x[1] == 0 or sorted_x[0] == sorted_x[1]:
res = -1
else:
res = int(str(sorted_x[1]) + str(sorted_x[0]))
elif len(sorted_x) > 2:
sorted_x_clc = collections.Counter(sorted_x)
if len(sorted_x_clc.keys()) == 1:
res = -1
else:
sorted_x_clc_back = collections.Counter(sorted_x[1:])
if len(sorted_x_clc_back.keys()) == 1:
sorted_x[0], sorted_x[1] \
= sorted_x[1], sorted_x[0]
else:
last_index_max = \
(len(sorted_x) - 1) - sorted(sorted_x[1:]).index(max(sorted_x[1:]))
sorted_x[last_index_max], sorted_x[last_index_max + 1] = \
sorted_x[last_index_max + 1], sorted_x[last_index_max]
res = ''.join([str(e) for e in sorted_x])
print(res)
_KingdomOfMoray