結果

問題 No.11 カードマッチ
ユーザー r6ever6eve
提出日時 2017-08-21 18:54:55
言語 OCaml
(5.1.0)
結果
MLE  
実行時間 -
コード長 875 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 22,016 KB
実行使用メモリ 738,796 KB
最終ジャッジ日時 2024-04-17 08:43:14
合計ジャッジ時間 6,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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"
0