結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2021-01-07 21:20:39 |
言語 | Go (1.23.4) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,560 bytes |
コンパイル時間 | 13,454 ms |
コンパイル使用メモリ | 235,544 KB |
実行使用メモリ | 542,428 KB |
最終ジャッジ日時 | 2024-11-14 02:05:48 |
合計ジャッジ時間 | 15,221 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 MLE * 1 |
ソースコード
package mainimport ("bufio""fmt""os""sort""strconv")var sc = bufio.NewScanner(os.Stdin)var wr = bufio.NewWriter(os.Stdout)func out(x ...interface{}) {fmt.Fprintln(wr, x...)}func getI() int {sc.Scan()i, e := strconv.Atoi(sc.Text())if e != nil {panic(e)}return i}func getF() float64 {sc.Scan()i, e := strconv.ParseFloat(sc.Text(), 64)if e != nil {panic(e)}return i}func getInts(N int) []int {ret := make([]int, N)for i := 0; i < N; i++ {ret[i] = getI()}return ret}func getS() 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}// min for n entryfunc nmin(a ...int) int {ret := a[0]for _, e := range a {ret = min(ret, e)}return ret}// max for n entryfunc nmax(a ...int) int {ret := a[0]for _, e := range a {ret = max(ret, e)}return ret}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}//---------------------------------------------// priority queue//---------------------------------------------type pqi struct {x, y inta int32}type priorityQueue []pqifunc (pq priorityQueue) Len() int { return len(pq) }func (pq priorityQueue) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] }func (pq priorityQueue) Less(i, j int) bool { return pq[i].a < pq[j].a }func (pq *priorityQueue) Push(x interface{}) { *pq = append(*pq, x.(pqi)) }func (pq *priorityQueue) Pop() interface{} {x := (*pq)[len(*pq)-1]*pq = (*pq)[0 : len(*pq)-1]return x}const inf = 100000type pos struct {x, y int}func main() {defer wr.Flush()sc.Split(bufio.ScanWords)sc.Buffer([]byte{}, 1000000)// this template is new version.// use getI(), getS(), getInts(), getF()H, W := getI(), getI()s := make([]string, H+2)a := make([][]int32, H+2)for i := 0; i < H+2; i++ {a[i] = make([]int32, W+2)for j := 0; j < W+2; j++ {a[i][j] = inf}}for i := 0; i < W+2; i++ {s[0] += "."s[H+1] += "."}for i := 0; i < H; i++ {s[i+1] = "." + getS() + "."}dx := []int{-1, 0, 1, -1, 1, -1, 0, 1}dy := []int{-1, -1, -1, 0, 0, 1, 1, 1}W += 2H += 2// pq := priorityQueue{}q := make([]pos, 0)for i := 0; i < H; i++ {for j := 0; j < W; j++ {if s[i][j] == '.' {ok := falsefor k := 0; k < 8; k++ {px := j + dx[k]py := i + dy[k]if px < 0 || px >= W || py < 0 || py >= H {continue}if s[py][px] != '.' {ok = truebreak}}if ok {// heap.Push(&pq, pqi{j, i, 0})q = append(q, pos{j, i})}a[i][j] = 0}}}for len(q) != 0 {e := q[0]q = q[1:]// heap.Pop(&pq)for i := 0; i < 8; i++ {px := e.x + dx[i]py := e.y + dy[i]if px < 0 || px >= W || py < 0 || py >= H {continue}if a[py][px] > a[e.y][e.x]+1 {a[py][px] = a[e.y][e.x] + 1// heap.Push(&pq, pqi{px, py, a[py][px]})q = append(q, pos{px, py})}}}ans := 0for i := 0; i < H; i++ {for j := 0; j < W; j++ {ans = max(ans, int(a[i][j]))}}// for i := 0; i < H; i++ {// out(i, a[i])// }out(ans)}