| Game of Coders 4 - Over the Garden Wall |
|---|
| Закончено |
The Beast Adhoom, in its never-ending quest to confound, had left behind a large, mysterious grid plastered across a decaying wall in the Unknown. This grid was filled with strange, whispering letters, a silent message from the dark entity.
The three knew that deciphering these messages was crucial for their escape. They also found a smaller, equally cryptic string of characters. It seemed Adhoom had a unique way of hiding clues: a square area within the large grid would hold the next piece of their puzzle, but only if it contained each specific letter from the smaller string at least a certain number of times. The required count for each letter c was exactly F(c), which was the number of times $$$c$$$ appeared in the smaller string.
Their task was to find the smallest possible square area in the grid that met these conditions. If no such square existed anywhere in the vast grid, then Adhoom's riddle would remain unsolved, and they would be truly lost.
Help the three find the minimum possible area of such a square.
The first line of the input contains $$$n$$$ , $$$m$$$ , $$$k$$$ $$$(1 \leq n , m \leq 1000 , 1 \leq k \leq n \cdot{m})$$$.
The next $$$n$$$ lines consist of a string of length $$$m$$$ , describing the grid of lowercase letters.
The next line contains string $$$s$$$ of length $$$k$$$.
All strings consist of lowercase letters.
Print a single integer. The minimum possible area of a square that contains each letter $$$c$$$ at least $$$F(c)$$$ times, where $$$F(c)$$$ is the frequency of $$$c$$$ in $$$s$$$.
If such square doesn't exist , print -1.
5 5 5zzzzzdazzzhdzzzamssszzzzzadham
9
3 3 5sameahhhlsameh
9
| Название |
|---|


