6 struct point
{ uint8_t x
; uint8_t y
; };
7 bool visited
[102][102] = {0};
10 int basin(int x
, int y
)
12 struct point stack
[100];
16 stack
[sp
++] = (struct point
){.x
=x
, .y
=y
};
19 memset(&p
, 0, sizeof p
);
22 if (visited
[p
.y
][p
.x
])
24 visited
[p
.y
][p
.x
] = true;
26 if (grid
[p
.y
][p
.x
] == 9)
30 if (!visited
[p
.y
][p
.x
+1])
31 stack
[sp
++] = (struct point
){.x
=p
.x
+1, .y
=p
.y
};
32 if (!visited
[p
.y
][p
.x
-1])
33 stack
[sp
++] = (struct point
){.x
=p
.x
-1, .y
=p
.y
};
34 if (!visited
[p
.y
+1][p
.x
])
35 stack
[sp
++] = (struct point
){.x
=p
.x
, .y
=p
.y
+1};
36 if (!visited
[p
.y
-1][p
.x
])
37 stack
[sp
++] = (struct point
){.x
=p
.x
, .y
=p
.y
-1};
44 for (int i
= 0; i
<102; i
++)
45 for (int j
= 0; j
<102; j
++)
50 while((c
= getchar()) != EOF
) {
55 maxx
= x
> maxx
? x
: maxx
;
61 for (int cy
= 1; cy
<y
; cy
++) {
62 for (int cx
= 1; cx
<maxx
+1; cx
++) {
63 if (!visited
[cy
][cx
]) {
64 int s
= basin(cx
, cy
);
69 } else if (s
>= tl
[1]) {
72 } else if (s
> tl
[2]) {
78 printf("%d\n", tl
[0]*tl
[1]*tl
[2]);