-
Notifications
You must be signed in to change notification settings - Fork 27
/
10074.go
68 lines (61 loc) · 1.16 KB
/
10074.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// UVa 10074 - Take the Land
package main
import (
"fmt"
"os"
)
type cell struct{ tree, up int }
func verticalSum(land [][]cell) {
for i := range land {
for j := range land[i] {
if land[i][j].tree == 1 {
land[i][j].up = 0
} else {
if i == 0 {
land[i][j].up = 1
} else {
land[i][j].up = land[i-1][j].up + 1
}
}
}
}
}
func solve(n int, land [][]cell) int {
verticalSum(land)
var maxArea int
for i := range land {
for j := range land[i] {
sum := land[i][j].up
for k := j + 1; k < n && land[i][k].up >= land[i][j].up; k++ {
sum += land[i][j].up
}
for k := j - 1; k >= 0 && land[i][k].up >= land[i][j].up; k-- {
sum += land[i][j].up
}
if sum > maxArea {
maxArea = sum
}
}
}
return maxArea
}
func main() {
in, _ := os.Open("10074.in")
defer in.Close()
out, _ := os.Create("10074.out")
defer out.Close()
var m, n int
for {
if fmt.Fscanf(in, "%d%d", &m, &n); m == 0 && n == 0 {
break
}
land := make([][]cell, m)
for i := range land {
land[i] = make([]cell, n)
for j := range land[i] {
fmt.Fscanf(in, "%d", &land[i][j].tree)
}
}
fmt.Fprintln(out, solve(n, land))
}
}