結果

問題 No.943 取り調べ
ユーザー ccppjsrbccppjsrb
提出日時 2020-08-17 09:02:44
言語 Go
(1.22.1)
結果
AC  
実行時間 31 ms / 1,206 ms
コード長 2,263 bytes
コンパイル時間 11,942 ms
コンパイル使用メモリ 237,108 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-04-19 18:40:24
合計ジャッジ時間 12,985 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 28 ms
5,760 KB
testcase_05 AC 31 ms
5,888 KB
testcase_06 AC 29 ms
5,760 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 29 ms
5,760 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 27 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	xx := make([]int, n)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			x := getNextInt(scanner)
			if x == 0 {
				continue
			}
			xx[i] = xx[i] | (1 << uint(j))
		}
	}
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	nn := 1 << uint(n)
	lie := make([]int, nn)
	for i := 0; i < nn; i++ {
		for j := 0; j < n; j++ {
			if i>>uint(j)&1 == 0 {
				continue
			}
			lie[i] += aa[j]
		}
	}
	dp := make([]int, nn)
	for i := 1; i < nn; i++ {
		dp[i] = math.MaxInt32
	}
	for i := 0; i < nn; i++ {
		if dp[i] == math.MaxInt32 {
			continue
		}
		for j := 0; j < n; j++ {
			if i>>uint(j)&1 == 1 {
				continue
			}
			if dp[i|(1<<uint(j))|(xx[j]^(xx[j]&i))] > dp[i]+lie[xx[j]^(xx[j]&i)] {
				dp[i|(1<<uint(j))|(xx[j]^(xx[j]&i))] = dp[i] + lie[xx[j]^(xx[j]&i)]
			}
		}
	}
	fmt.Fprintln(writer, dp[nn-1])
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}
0