-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path836.go
58 lines (52 loc) · 937 Bytes
/
836.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
// UVa 836 - Largest Submatrix
package main
import (
"fmt"
"os"
)
func solve(m [][]byte) int {
l := len(m)
dp := make([][]int, l+1)
for i := range dp {
dp[i] = make([]int, l+1)
}
max := 0
for i := 1; i <= l; i++ {
for j := 1; j <= l; j++ {
if m[i-1][j-1] == '1' {
dp[i][j] = min(min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]) + 1
if dp[i][j] > max {
max = dp[i][j]
}
}
}
}
return max * max
}
func main() {
in, _ := os.Open("836.in")
defer in.Close()
out, _ := os.Create("836.out")
defer out.Close()
var c int
var m [][]byte
for fmt.Fscanf(in, "%d\n\n", &c); c > 0; c-- {
first := true
for count := 0; ; count++ {
var l string
if fmt.Fscanf(in, "%s", &l); l == "" {
break
}
if first {
first = false
n := len(l)
m = make([][]byte, n)
for i := range m {
m[i] = make([]byte, n)
}
}
m[count] = []byte(l)
}
fmt.Fprintln(out, solve(m))
}
}