結果

問題 No.792 真理関数をつくろう
ユーザー toshiro_yanagi
提出日時 2019-02-24 20:15:12
言語 Go
(1.23.4)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,975 bytes
コンパイル時間 12,159 ms
コンパイル使用メモリ 231,656 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-23 15:21:01
合計ジャッジ時間 13,196 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func pow(a, b int) int {
	res := 1
	for range make([]struct{}, b) {
		res *= a
	}
	return res
}

func main() {
	io := newIo()
	defer io.flush()

	n := io.nextInt()
	ans := make([][]bool, pow(2, n))

	var notAllOkFlg, notAllNgFlg bool
	for i := range ans {
		q := make([]int, n)
		for j := range q {
			q[j] = io.nextInt()
		}
		r := io.nextInt()
		if r == 1 {
			ans[i] = make([]bool, n)
			for j, v := range q {
				if v == 1 {
					ans[i][j] = true
				}
			}
			notAllNgFlg = true
		} else {
			notAllOkFlg = true
		}
	}

	io.print("A=")
	if !notAllNgFlg {
		io.println("⊥")
	} else if !notAllOkFlg {
		io.println("⊤")
	} else {
		flg := false
		for i := range ans {
			if ans[i] == nil {
				continue
			}
			if flg {
				io.print("∨")
			}
			io.print("(")
			for j, v := range ans[i] {
				if j != 0 {
					io.print("∧")
				}
				if !v {
					io.print("¬")
				}
				io.print("P_")
				io.print(j + 1)
			}
			io.print(")")
			flg = true
		}
		io.println()
	}

}

type _io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *_io {
	return &_io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (_io *_io) flush() {
	_ = _io.writer.Flush()
}

func (_io *_io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := _io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (_io *_io) next() string {
	for _io.nextToken >= len(_io.tokens) {
		line := _io.nextLine()
		_io.tokens = strings.Fields(line)
		_io.nextToken = 0
	}
	r := _io.tokens[_io.nextToken]
	_io.nextToken++
	return r
}

func (_io *_io) nextInt() int {
	i, _ := strconv.Atoi(_io.next())
	return i
}

func (_io *_io) print(a ...interface{}) {
	fmt.Fprint(_io.writer, a...)
}

func (_io *_io) println(a ...interface{}) {
	fmt.Fprintln(_io.writer, a...)
}
0