結果
問題 | No.83 最大マッチング |
ユーザー |
|
提出日時 | 2020-06-20 01:53:54 |
言語 | OCaml (5.2.1) |
結果 |
AC
|
実行時間 | 192 ms / 5,000 ms |
コード長 | 1,143 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 21,452 KB |
実行使用メモリ | 43,520 KB |
最終ジャッジ日時 | 2024-10-09 01:27:42 |
合計ジャッジ時間 | 1,886 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
Scanf.scanf "%d" (fun n ->let module M = structtype t = int * int arraylet max (la, a) (lb, b) =if la > lb then la, a elseif 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 mlet zero = 0, Array.make 10 0let none = -1, [||]let isnone (l, _) = l = -1let show (_, m) =for i = 9 downto 0 dofor j = 1 to m.(9 - i) doprint_char "0123456789".[i]donedone;print_newline ()endinlet dp = Array.make (n + 1) M.none inlet hh = [| 6; 2; 5; 5; 4; 5; 6; 3; 7; 6 |] indp.(0) <- M.zero;for i = 9 downto 0 dolet h = hh.(i) infor j = 0 to n - h doif not (M.isnone dp.(j)) then (let nn = M.copy dp.(j) inlet nn = M.inc i nn indp.(j + h) <- M.max dp.(j + h) nn)donedone;Array.fold_left M.max M.zero dp |> M.show)