WINDVANE - WIND VANE


Problem Statement:

Wind vane is an instrument for showing the direction of the wind.

 

Dream city is in the shape of a matrix of dimensions mxn. To monitor the direction of the wind in the city, wind vanes are placed in every unit cell of the city. According to the direction of the wind, these wind vanes turn themselves. Lets assume that there are only 4 directions North, East, West and South denoted by (‘N’, ’E’, ’W’, ’S’). We know the initial direction of the wind vanes.

We denote the direction of change of wind by 0 (clockwise) and 1 (anti-clockwise)

Function “Change(x1, y1, x2, y2, direction)”, changes the direction of the vanes in the sub-matrix (from x1, y1 to x2, y2) in the specified ‘direction’

(for example if the initial state of a cell is ‘N’ and the direction is clockwise, then the cell changes to ‘E’)

The ‘Change’ may occur any time. We need to know the direction of the wind at any unit cell at any instant.

Direction (x, y) should print the direction of the vane at the cell (x, y).

Input:

The first line of the input consists two integers m and n - the dimensions of the city. Then follows the description of the matrix which denotes the direction of the vanes. The next line contains an integer c, the number of commands to process. Each command can be either of the format "C x1 y1 x2 y2 d" or "D x y".

Output:

Process the commands and print whenever necessary.

 

Input Constraints:

1<=m<=1000

1<=n<=1000

each character in the matrix is one among {'N','E','W', and 'S'}

1<=c<=10000

1<=x1,y1,x2,y2,x,y<=1000

d= 0(clockwise) or 1(anti-clockwise)

x1<=x2 y1<=y2

 

Sample Input:

5 5
ESWNE
NWWWN
EEESE
SSWSN
SNWEN
5
C 2 1 4 1 1
D 3 1
D 3 3
C 2 1 5 2 0
D 3 1

 

Sample Output:

N

E

E


hide comments
chicku: 2014-04-17 09:52:19

Please check why i am getting WA! my submission id 9678119

Shubham Sharma: 2014-04-17 09:52:19

Getting wa :/ Please check submission id : 9600501

Rahul_Coder: 2014-04-17 09:52:19

using scanf printf still getting tle......please help

Last edit: 2013-06-18 18:19:04
maaz: 2014-04-17 09:52:19

clear the I/O format..

(^_^): 2014-04-17 09:52:19

can anyone confirm the second output of the test case
I think it should be
N

Ehor Nechiporenko: 2014-04-17 09:52:19

@Tjandra, thanks a lot! I thought that x coordinate is number of column not row)

(Tjandra Satria Gunawan)(曾毅昆): 2014-04-17 09:52:19

@Ehor Nechiporenko: No, the initial position on cell (3,1) is E (see, 3th row 1st column)...

Ehor Nechiporenko: 2014-04-17 09:52:19

Guys, could you please clarify test case. Initial position on cell (3,1) is W.
Next query C 2 1 4 1 1 - anti-clockwise, that's why value on (3,1) is changing from W to N.

Next query: C 2 1 5 2 0 - it's clockwise(!!) operation, so value on (3,1) should go back from N to W.
But why we are pringing E on next query (D 3 1)?!
Am I wrong somewhere? As I understood, there should be query C 2 1 4 1 1. Is it right?

Last edit: 2013-01-30 22:30:49

Added by:cegprakash
Date:2013-01-15
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: BF GOSU