-
Notifications
You must be signed in to change notification settings - Fork 318
/
ch-2.pl
executable file
·44 lines (38 loc) · 1.09 KB
/
ch-2.pl
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
#!/usr/bin/env perl
use v5.30;
use warnings;
my @A = (
[qw/ 0 1 0 1 0 1 /],
[qw/ 1 0 1 0 1 0 /],
[qw/ 0 1 0 1 0 1 /],
[qw/ 1 0 1 0 1 0 /],
);
my $height = @A;
my $width = @{$A[0]};
my $max_solution = [0, 0];
for (my $y0 = 0; $y0 < $height; $y0++) {
for (my $x0 = 0; $x0 < $width; $x0++) {
for (my $y1 = $y0 + 1; $y1 < $height; $y1++) {
X1: for (my $x1 = $x0 + 1; $x1 < $width; $x1++) {
for (my $sy = $y0; $sy <= $y1; $sy++) {
for (my $sx = $x0; $sx <= $x1; $sx++) {
if ($A[$sy][$sx] != 1) {
next X1;
}
}
}
my $area = ($y1 - $y0 + 1) * ($x1 - $x0 + 1);
if ($area > $max_solution->[0] * $max_solution->[1]) {
$max_solution = [$y1 - $y0 + 1, $x1 - $x0 + 1];
}
}
}
}
}
if ($max_solution->[0] == 0) {
print "0\n";
} else {
for (1 .. $max_solution->[0]) {
print "[ ", join(" ", (1) x $max_solution->[1]), " ]\n";
}
}