結果
問題 |
No.11 カードマッチ
|
ユーザー |
![]() |
提出日時 | 2017-08-21 18:54:55 |
言語 | OCaml (5.2.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 875 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 22,000 KB |
実行使用メモリ | 687,984 KB |
最終ジャッジ日時 | 2024-10-09 00:28:00 |
合計ジャッジ時間 | 7,190 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 MLE * 1 -- * 14 |
ソースコード
module S = Set.Make (struct type t = int let compare = (-) end) let () = let w, h, n = Scanf.scanf "%d %d %d " (fun w h n -> w, h, n) in let ss = Array.init w (fun _ -> let rec init i s = if i = h then s else S.add i s |> init (i + 1) in init 0 S.empty) in let a = Array.make w S.empty in let rec read i ks = if i = n then List.length ks else begin let s, k = Scanf.scanf "%d %d " (fun s k -> s, k) in let s, k = s - 1, k - 1 in a.(s) <- S.add (k) a.(s); read (i + 1) (if List.mem k ks then ks else k :: ks) end in let ks = read 0 [] in let rec doit i acc = if i = w then acc else if not (S.is_empty a.(i)) then begin let t = S.diff ss.(i) a.(i) in ss.(i) <- S.empty; doit (i + 1) (acc + S.cardinal t) end else doit (i + 1) (acc + ks) in doit 0 0 |> Printf.printf "%d\n"