結果
| 問題 |
No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-27 02:04:19 |
| 言語 | OCaml (5.2.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,233 bytes |
| コンパイル時間 | 1,007 ms |
| コンパイル使用メモリ | 21,888 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-16 15:23:10 |
| 合計ジャッジ時間 | 2,177 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
Scanf.scanf "%s" (fun n ->
let hist = Array.make 8 0 in
let il x = String.index "ABCDEF" x + 10 in
let rec loop i m =
if i >= 0 then (
let k =
match m with
| 0 -> (il n.[i]) land 7
| 1 -> (((il n.[i]) land 3) lsl 1) lor (((il n.[i + 1]) lsr 3) land 1)
| 2 -> (((il n.[i]) land 1) lsl 2) lor (((il n.[i + 1]) lsr 2) land 3)
| _ -> (il n.[i]) lsr 1
in
hist.(k) <- hist.(k) + 1;
loop (if m = 2 then i else i - 1) ((m + 1) mod 4)
) else (
let q =
match m with
| 1 -> ((il n.[i + 1]) lsr 3) land 1
| 2 -> ((il n.[i + 1]) lsr 2) land 3
| _ -> -1
in
if q >= 0 then hist.(q) <- hist.(q) + 1
)
in
loop (String.length n - 1) 0;
let rec loop i mx mxl =
if i = 8 then mxl else
if hist.(i) > mx then loop (i + 1) hist.(i) [ i ] else
if hist.(i) = mx then loop (i + 1) hist.(i) (i :: mxl) else
loop (i + 1) mx mxl
in
let l = loop 0 0 [] in
List.iter (Printf.printf "%d ") @@ List.rev l;
print_newline ()
)