結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2020-04-10 14:55:09 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 482 bytes |
コンパイル時間 | 420 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-09-15 02:13:01 |
合計ジャッジ時間 | 2,481 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
from collections import Counter x = list(input()) ctr = Counter(x) 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)