結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2019-12-25 21:49:16 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 705 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 82,128 KB |
実行使用メモリ | 78,088 KB |
最終ジャッジ日時 | 2024-10-01 06:49:11 |
合計ジャッジ時間 | 2,848 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 17 |
ソースコード
from collections import defaultdict def main(): X = input() if len(set(X)) == 1: print(-1) exit() if ('0' in set(X)) and (len(set(X)) == 2): 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 * d[key] ans += second else: ans += key * d[key] cnt += 1 print(ans) if __name__ == "__main__": main()