結果

問題 No.792 真理関数をつくろう
ユーザー xsdxsd
提出日時 2020-06-30 02:43:07
言語 OCaml
(5.1.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 21,452 KB
実行使用メモリ 10,952 KB
最終ジャッジ日時 2024-04-17 09:04:58
合計ジャッジ時間 1,430 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 6 ms
6,400 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 9 ms
7,040 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 9 ms
7,168 KB
testcase_06 AC 82 ms
9,768 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 23 ms
7,976 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 11 ms
6,272 KB
testcase_21 AC 282 ms
10,952 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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