結果

問題 No.688 E869120 and Constructing Array 2
ユーザー xsdxsd
提出日時 2020-07-04 00:15:09
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 713 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 21,580 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 09:05:57
合計ジャッジ時間 956 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Scanf.scanf "%d" (fun k ->
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let calc i map =
        let rec loop b i j map =
            if i + j > 30 then map else
                let map = M.add (b lsl j) (i, j) map in
                loop b i (j + 1) map
        in
        let base = i * (i - 1) / 2 in
        loop base i 0 map
    in
    let rec loop i map =
        if i = 31 then map else
            loop (i + 1) (calc i map)
    in
    let map = loop 2 (M.singleton 0 (1, 0)) in
    let a, b = M.find k map in
    Printf.printf "%d\n" (a + b);
    let _ = Array.init (a + b) (fun i -> if i < b then Printf.printf "0 " else Printf.printf "1 ") in
    print_newline ()
)
0