package main import . "fmt" func main() { var h,w int Scan(&h,&w) f:=make([][]byte,h) m:=make([][]int,h) for i:=range f { var s string Scan(&s) f[i]=[]byte(s) m[i]=make([]int,w) } v:=0 t:=make([]int,h*w+1) for r,rr:=range f { for c,cc := range rr { if m[r][c]!=0 { continue } v++ st:=[]int{r*w+c} for len(st)>0 { e:=st[len(st)-1] st=st[:len(st)-1] x,y:=e%w,e/w if f[y][x]!=cc { continue } if m[y][x]!=0 { continue } m[y][x]=v t[v]++ if y>0 { st=append(st,e-w) } if y+10 { st=append(st,e-1) } if x+1=4 { f[r][c]='.' } } Println(string(rr)) } }