Fly Swatter
InterviewTime limit1sMemory limit64 MB
Find the K by K placement that encloses the most flies in its strict interior and print the count with the winning border drawn.
- Level
Easy3 of 10
- Topics
- Prefix sum, Matrix, Brute force
- Solved
- No attempts yet
Problem
Marin spends his free time looking out of the window. A few flies have landed on that window and are staring into the distance. Marin picked up his square fly swatter and wondered how many flies he can kill with a single swing.
The picture of the window is pixels, and the side of the swatter is pixels. Find the largest number of flies that one swing can kill, and mark one swatter position that kills that many flies on the picture.
Input
The first line contains three integers , and , the size of the picture and the side length of the swatter (, ).
Each of the next lines contains characters describing the window. A pixel with a fly on it is *, an empty pixel is .. At least one fly can be killed with the swatter.
Output
On the first line print the largest number of flies that a single swing can kill.
On the next lines print the picture with the position of the swatter marked on it. The horizontal sides of the swatter are -, the vertical sides are |, and the four corners are +. These characters overwrite the original pixels.
The swatter must lie completely inside the window. A fly sitting on a side of the swatter has enough time to fly away, so only the flies strictly inside the swatter are killed. With rows and columns counted from , a swatter whose top left corner is kills the flies in rows through and columns through .
If several positions kill the largest number of flies, mark the one whose top left corner has the smallest row index, and among those the one with the smallest column index.