Looking for Waldo
시간 제한: 1000ms메모리 제한: 1024MB출처: GCPC 2021BOJ 25256
문제
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 and , , the height and width of the grid of letters.
- lines, each with 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
출력
25
예제 2
입력
5 10 ABCDEABCDE FGHIJFGHIJ KLMNOKLMNO PQRSTPQRST VWXYZVWXYZ
출력
20
예제 3
입력
5 10 WAALDLODOW AWWLAOODOW LOLADOWALO ADALLLWWOL WWOOAAAALO
출력
5
예제 4
입력
2 3 WAL TER
출력
impossible
코드를 제출하려면 로그인하세요.