|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "bufio" |
| 5 | + . "fmt" |
| 6 | + "io" |
| 7 | +) |
| 8 | + |
| 9 | +// github.com/EndlessCheng/codeforces-go |
| 10 | +type pair63 struct{ x, y, l, r int } |
| 11 | +type deque63 struct{ l, r []pair63 } |
| 12 | + |
| 13 | +func (q deque63) empty() bool { return len(q.l) == 0 && len(q.r) == 0 } |
| 14 | +func (q *deque63) pushL(v pair63) { q.l = append(q.l, v) } |
| 15 | +func (q *deque63) pushR(v pair63) { q.r = append(q.r, v) } |
| 16 | +func (q *deque63) popL() (v pair63) { |
| 17 | + if len(q.l) > 0 { |
| 18 | + q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1] |
| 19 | + } else { |
| 20 | + v, q.r = q.r[0], q.r[1:] |
| 21 | + } |
| 22 | + return |
| 23 | +} |
| 24 | + |
| 25 | +func CF1063B(_r io.Reader, out io.Writer) { |
| 26 | + in := bufio.NewReader(_r) |
| 27 | + dir4 := []struct{ x, y, l, r int }{{x: -1}, {x: 1}, {0, -1, 1, 0}, {0, 1, 0, 1}} |
| 28 | + |
| 29 | + var n, m, sx, sy, ll, rr, ans int |
| 30 | + Fscan(in, &n, &m, &sx, &sy, &ll, &rr) |
| 31 | + sx-- |
| 32 | + sy-- |
| 33 | + g := make([][]byte, n) |
| 34 | + for i := range g { |
| 35 | + Fscan(in, &g[i]) |
| 36 | + } |
| 37 | + |
| 38 | + q := deque63{} |
| 39 | + q.pushL(pair63{sx, sy, 0, 0}) |
| 40 | + g[sx][sy] = 0 |
| 41 | + for !q.empty() { |
| 42 | + ans++ |
| 43 | + p := q.popL() |
| 44 | + for _, d := range dir4 { |
| 45 | + x, y, l, r := p.x+d.x, p.y+d.y, p.l+d.l, p.r+d.r |
| 46 | + if 0 <= x && x < n && 0 <= y && y < m && l <= ll && r <= rr && g[x][y] == '.' { |
| 47 | + g[x][y] = 0 |
| 48 | + p := pair63{x, y, l, r} |
| 49 | + if d.y == 0 { |
| 50 | + q.pushL(p) |
| 51 | + } else { |
| 52 | + q.pushR(p) |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + Fprint(out, ans) |
| 58 | +} |
| 59 | + |
| 60 | +//func main() { CF1063B(os.Stdin, os.Stdout) } |
0 commit comments