結果

問題 No.792 真理関数をつくろう
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2019-02-24 20:15:12
言語 Go
(1.22.1)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,975 bytes
コンパイル時間 14,586 ms
コンパイル使用メモリ 209,796 KB
実行使用メモリ 5,528 KB
最終ジャッジ日時 2023-08-25 03:17:50
合計ジャッジ時間 13,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 10 ms
5,528 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 4 ms
5,516 KB
testcase_21 AC 17 ms
5,524 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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