結果

問題 No.134 走れ!サブロー君
ユーザー aru aruaru aru
提出日時 2020-08-16 17:04:02
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,302 bytes
コンパイル時間 11,985 ms
コンパイル使用メモリ 224,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 18:23:40
合計ジャッジ時間 12,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 21 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func getf() float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

// const inf = math.MaxFloat32
const inf = 10000

func main() {
	sc.Split(bufio.ScanWords)
	x0, y0 := getInt(), getInt()
	N := getInt() + 1
	x := make([]int, N)
	y := make([]int, N)
	c := make([]float64, N)
	tot := 0.0
	x[0], y[0] = x0, y0
	for i := 1; i < N; i++ {
		x[i], y[i], c[i] = getInt(), getInt(), getf()
		tot += c[i]
	}
	// out(x, y, c)
	n := 1 << N
	dp := make([][]float64, N)
	for i := 0; i < N; i++ {
		dp[i] = make([]float64, n)
		for j := 0; j < n; j++ {
			dp[i][j] = inf
		}
	}
	dp[0][0] = 0
	for mask := 0; mask < n; mask++ {
		for i := 0; i < N; i++ {
			if dp[i][mask] == inf {
				continue
			}
			w := tot
			for j := 0; j < N; j++ {
				if mask&(1<<j) != 0 {
					w -= c[j]
				}
			}
			for j := 0; j < N; j++ {
				if mask&(1<<j) == 0 {
					l := float64(abs(x[i]-x[j]) + abs(y[i]-y[j]))
					l *= (w + 100.0) / 120.0
					dp[j][mask|(1<<j)] = math.Min(dp[j][mask|(1<<j)], dp[i][mask]+l+c[j])
				}
			}
		}
	}
	// for i := 0; i < N; i++ {
	// 	out(dp[i])
	// }
	// ans := inf
	// for i := 0; i < N; i++ {
	// 	l := abs(x[i]-x0) + abs(y[i]-y0)
	// 	w := 100 / 120.0
	// 	// out(dp[i][(1<<N)-1] + w*float64(l))
	// 	ans = math.Min(ans, dp[i][(1<<N)-1]+w*float64(l))
	// }
	out(dp[0][(1<<N)-1])
}
0