loj#P2310. 「APIO2017」斑斓之地
「APIO2017」斑斓之地
Description
A long long time ago, in the Dreamtime, Australia was a flat grid of rows and columns and each grid cell was land. The rows were numbered to from North to South, and the columns were numbered to from West to East. The cell in row and column was denoted as . One day, the great rainbow serpent rose from the earth at , and moved across Australia, creating rivers wherever it slid. The serpent made consecutive moves, each time moving to the cell directly North (N
), South (S
), East (E
) or West (W
), turning the cell into river. The cell was also turned into river.
Now, millions of years later, you would like to purchase a rectangular block of cells to commemorate the creation of the rivers by the rainbow serpent. You will choose a different colour for each land cell inside your rectangular block. You would like to use as many different colours as possible but insist that every pair of adjacent land cells inside your block share the same colour. Two cells are adjacent if they share an edge. You will not choose a colour for any land cells outside your block, nor will you choose a colour for the river cells inside your block.
Given the moves made by the rainbow serpent, you would like to determine the maximum number of different colours you can choose for land cells in each of rectangular blocks of cells.
Input
Line 1: four integers and ;
Line 2: two integers and ;
Line 3: a string consisting of characters, each N
, S
, E
or W
(this line should be left blank if );
Lines 4 to +3: four integers , , and .
Output
For every request, output the maximum number of different colours you can choose for land cells in the rectangular block.
6 4 9 4
3 3
NWESSWEWS
2 3 2 3
3 2 4 4
5 3 6 4
1 2 5 3
0
2
1
3
Limits And Hints
For all subtasks, and .
Subtask | Points | |||
---|---|---|---|---|
1 | 11 | |||
2 | 12 | |||
3 | 24 | |||
4 | 27 | |||
5 | 26 |