結果

問題 No.792 真理関数をつくろう
ユーザー gemmaro
提出日時 2020-02-17 12:17:24
言語 Ruby
(3.4.1)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-10-06 14:54:18
合計ジャッジ時間 3,772 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

AND = '∧'
OR = '∨'
NOT = '¬'
BOT = '⊥'
TOP = '⊤'

def make_exp(prop, index)
  case prop
  when 0
    "#{NOT}P_#{index + 1}"
  when 1
    "P_#{index + 1}"
  end
end

# ----------------------------------- exec

table = []

N = gets.to_i
(2**N).times do
  input = gets.chomp.split.map(&:to_i)
  qs = input[0..-2]
  r = input[-1]
  table << [qs, r]
end

puts(
  'A=' + if table.map { |r| r[1] }.uniq.size == 1
           if table[0][1].zero?
             BOT
           else
             TOP
           end
         else
           EXPS = table.select { |r| r[1] == 1 }.map do |r|
             r[0].map.with_index { |q, i| make_exp(q, i) }.join(AND)
           end
           EXPS.map { |e| "(#{e})" }.join(OR)
         end
)
0