← Home
 ```go
package main

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

type Cell struct {
	x, y int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	m, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	p, _ := strconv.Atoi(scanner.Text())
	
	speeds := make([]int, p)
	for i := 0; i < p; i++ {
		scanner.Scan()
		speeds[i], _ = strconv.Atoi(scanner.Text())
	}
	
	grid := make([][]byte, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		grid[i] = []byte(scanner.Text())
	}
	
	counts := make([]int, p)
	queues := make([][]Cell, p)
	
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			c := grid[i][j]
			if c >= '1' && c <= '9' {
				player := int(c - '1')
				counts[player]++
				queues[player] = append(queues[player], Cell{i, j})
			}
		}
	}
	
	dirs := [][2]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
	
	for {
		anyMoved := false
		for i := 0; i < p; i++ {
			if len(queues[i]) == 0 {
				continue
			}
			anyMoved = true
			
			current := queues[i]
			for step := 0; step < speeds[i] && len(current) > 0; step++ {
				next := make([]Cell, 0)
				for _, cell := range current {
					for _, d := range dirs {
						ni, nj := cell.x+d[0], cell.y+d[1]
						if ni >= 0 && ni < n && nj >= 0 && nj < m && grid[ni][nj] == '.' {
							grid[ni][nj] = byte('1' + i)
							counts[i]++
							next = append(next, Cell{ni, nj})
						}
					}
				}
				current = next
			}
			queues[i] = current
		}
		if !anyMoved {
			break
		}
	}
	
	for i := 0; i < p; i++ {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(counts[i])
	}
	fmt.Println()
}
```