結果

問題 No.83 最大マッチング
ユーザー xsdxsd
提出日時 2020-06-20 01:53:54
言語 OCaml
(5.1.0)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 1,143 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 21,580 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-04-17 09:00:20
合計ジャッジ時間 1,445 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 21 ms
9,984 KB
testcase_10 AC 136 ms
30,848 KB
testcase_11 AC 197 ms
43,520 KB
testcase_12 AC 182 ms
43,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Scanf.scanf "%d" (fun n ->
    let module M = struct
        type t = int * int array
        let max (la, a) (lb, b) =
            if la > lb then la, a else
            if la < lb then lb, b else
                (la, max a b)
        let inc digit (l, m) = l + 1, (m.(9 - digit) <- m.(9 - digit) + 1; m)
        let copy (l, m) = l, Array.copy m
        let zero = 0, Array.make 10 0
        let none = -1, [||]
        let isnone (l, _) = l = -1
        let show (_, m) =
            for i = 9 downto 0 do
                for j = 1 to m.(9 - i) do
                    print_char "0123456789".[i]
                done
            done;
            print_newline ()
        end
    in

    let dp = Array.make (n + 1) M.none in
    let hh = [| 6; 2; 5; 5; 4; 5; 6; 3; 7; 6 |] in
    dp.(0) <- M.zero;
    for i = 9 downto 0 do
        let h = hh.(i) in
        for j = 0 to n - h do
            if not (M.isnone dp.(j)) then (
                let nn = M.copy dp.(j) in
                let nn = M.inc i nn in
                dp.(j + h) <- M.max dp.(j + h) nn
            )
        done
    done;
    Array.fold_left M.max M.zero dp |> M.show
)
0