結果

問題 No.792 真理関数をつくろう
ユーザー xsdxsd
提出日時 2020-06-30 02:43:07
言語 OCaml
(5.2.1)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 21,324 KB
実行使用メモリ 11,076 KB
最終ジャッジ日時 2024-10-09 01:44:12
合計ジャッジ時間 1,668 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

Scanf.scanf "%d" (fun n ->
    let l = 1 lsl n in
    let q = Array.init l (fun _ ->
        let c = Array.init n (fun _ ->
            Scanf.scanf " %d" (fun q -> q))
        in
        let r = Scanf.scanf " %d" (fun r -> r) in
        c, r
    )
    in
    let rec loop i t f =
        if i = l then t, f else
            let (_, r) = q.(i) in
            loop (i + 1) (t land r) (f lor r)
    in
    let t, f = loop 0 1 0 in
    let calc () =
        let str qq =
            let rec loop j acc =
                if j = n then acc ^ ")" else
                    let tmp =
                        if qq.(j) = 1 then Printf.sprintf "P_%d" (j + 1)
                                      else Printf.sprintf "¬P_%d" (j + 1)
                    in
                    let acc = if acc = "" then "(" ^ tmp else acc ^ "∧" ^ tmp in
                    loop (j + 1) acc
            in
            loop 0 ""
        in
        let rec loop i acc =
            if i = l then acc else
                let (qq, r) = q.(i) in
                if r = 0 then loop (i + 1) acc else
                    let s = str qq in
                    let acc = if acc = "" then "A=" ^ s else acc ^ "∨" ^ s in
                    loop (i + 1) acc
        in
        loop 0 ""
    in
    print_endline @@
        if t = 1 then "A=⊤" else
        if f = 0 then "A=⊥" else
            calc ()
)
0