結果
問題 |
No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:02:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,164 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 82,640 KB |
実行使用メモリ | 55,932 KB |
最終ジャッジ日時 | 2025-03-20 21:03:03 |
合計ジャッジ時間 | 2,052 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
n = input().strip() # Convert each hex character to 4-bit binary string binary_str = ''.join(format(int(c, 16), '04b') for c in n) # Adjust the binary string to have length multiple of 3 by prepending zeros length = len(binary_str) remainder = length % 3 if remainder != 0: pad = (3 - remainder) % 3 binary_str = '0' * pad + binary_str # Split into chunks of 3 bits and convert to octal digits oct_digits = [] for i in range(0, len(binary_str), 3): chunk = binary_str[i:i+3] digit = int(chunk, 2) oct_digits.append(str(digit)) oct_str = ''.join(oct_digits) # Remove leading zeros, but ensure at least one zero remains if needed oct_str = oct_str.lstrip('0') if not oct_str: oct_str = '0' # Count the occurrences of each digit from collections import defaultdict counts = defaultdict(int) for c in oct_str: counts[c] += 1 # Find the maximum count and collect all digits with that count max_count = max(counts.values(), default=0) max_digits = [d for d, cnt in counts.items() if cnt == max_count] # Sort the digits in ascending numerical order max_digits.sort(key=lambda x: int(x)) # Output the result print(' '.join(max_digits))