結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー xsdxsd
提出日時 2022-07-27 02:04:19
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 20,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 15:37:47
合計ジャッジ時間 3,093 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 ()
)
0