Virus Experiment
Time limit2sMemory limit512 MB
Given wind directions for each time period and a resistance value per grid cell, find the minimum infected count after a huge horizon and how many starting cells reach it.
- Level
Hard9 of 10
- Topics
- Simulation, Matrix, Implementation
- Solved
- No attempts yet
Statement
Do you know Just Odd Inventions Co., Ltd.? Its business is making 'just odd inventions,' and here we call it JOI Company.
JOI Company developed a new virus, the JOI Virus. The company wants to run an experiment by infecting the inhabitants of IOI Island with it.
IOI Island is rectangular. There are parallel roads running east to west and parallel roads running north to south. They divide the island into sections, and each section has exactly one inhabitant. We call the inhabitant in the section that is the -th from the north and the -th from the west inhabitant , where and .
A day has time periods. We call the -th time period time period . Wind always blows from one of four directions: north, south, east, or west. The direction can change between time periods, but within the same time period, the wind blows from the same direction on every day.
Each inhabitant has a resistance value, a non-negative integer .
- If , inhabitant has high resistance and never gets infected.
- If is positive, inhabitant may get infected. If the neighbor in the direction the wind blows from stays infected for consecutive time periods, inhabitant becomes infected starting from the next time period.
The last time period of a day and the first time period of the next day are consecutive.
The experiment must infect at least one inhabitant, but the goal is to infect as few as possible. At the start, we choose one inhabitant as the first infected person and infect them. We cannot choose an inhabitant with resistance 0 as the first infected person.
Given the wind direction for each time period and the resistance of each inhabitant, compute the minimum number of infected inhabitants after days. Also compute how many choices of first infected inhabitant achieve that minimum.
Input
The first line contains , , and . The second line contains a string of length . The -th character of is the direction the wind blows from during time period . Note that this is the direction the wind comes from, not the direction it blows toward. N means north, S means south, W means west, and E means east.
The next lines each contain integers. The -th integer on the -th line is .
Output
Print two lines. The first line contains the minimum number of infected inhabitants after days. The second line contains the number of inhabitants who reach that minimum when chosen as the first infected person.
Constraints
- has length and contains only N, S, W, and E.
- for and .
- At least one pair satisfies .