結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2019-12-28 22:23:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 719 bytes |
コンパイル時間 | 729 ms |
コンパイル使用メモリ | 82,012 KB |
実行使用メモリ | 77,032 KB |
最終ジャッジ日時 | 2024-10-12 17:19:22 |
合計ジャッジ時間 | 3,421 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
from collections import defaultdict def main(): X = input() if len(set(X)) == 1: print(-1) exit() if ('0' in set(X)) and (len(X) - X.count('0') <= 1): print(-1) exit() d = defaultdict(int) for x in X: d[x] += 1 ans = "" cnt = 0 second = -1 length = len(d) for key in sorted(d.keys(), reverse=True): if cnt == length - 2: ans += key * (d[key] - 1) second = key elif cnt == length - 1: ans += key ans += second ans += key * (d[key] - 1) else: ans += key * d[key] cnt += 1 print(ans) if __name__ == "__main__": main()