시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB138861.538%

문제

You may know the game Where is Waldo?. In this game you need to find a person named Waldo in a crowd of people. This problem is kind of similar. You need to find an axis-aligned rectangle of minimal area which contains the letters W, A, L, D and O and those letters are hidden in a crowd of other letters.

Figure L.1: Illustration of the second sample case.

입력

The input consists of:

  • One line with two integers $h$ and $w$ $(1\leq h, w \leq 10^5$, $h\cdot{}w \leq 10^5)$, the height and width of the grid of letters.
  • $h$ lines, each with $w$ upper case letters A-Z, the grid of letters.

출력

Output the area of the smallest axis-aligned rectangle which contains at least one of each of the letters W, A, L, D and O. If there is no rectangle containing those letters, output impossible.

예제 입력 1

5 5
ABCDE
FGHIJ
KLMNO
PQRST
VWXYZ

예제 출력 1

25

예제 입력 2

5 10
ABCDEABCDE
FGHIJFGHIJ
KLMNOKLMNO
PQRSTPQRST
VWXYZVWXYZ

예제 출력 2

20

예제 입력 3

5 10
WAALDLODOW
AWWLAOODOW
LOLADOWALO
ADALLLWWOL
WWOOAAAALO

예제 출력 3

5

예제 입력 4

2 3
WAL
TER

예제 출력 4

impossible

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2021 L번

  • 문제를 만든 사람: Michael Zündorf