Undergraduate Researcher Minsang
InterviewTime limit1sMemory limit512 MB
Count the cells reached by wind from all air conditioners on a grid where four object types redirect the wind.
- Level
Medium5 of 10
- Topics
- BFS, Simulation, Implementation
- Solved
- No attempts yet
Problem
Minsang has just joined the lab as an undergraduate researcher and is choosing where to sit.
The lab is a grid, and air conditioners blow wind in four directions: up, down, left, and right. Wind also blows in the cell containing an air conditioner.
Minsang gets hot easily, so he will pick one of the cells that the air conditioner wind passes through.
The lab has various objects that change the direction of the wind.
There are four types of objects. The arrows in the table below show how the wind moves at each object.
Minsang can sit in any cell in the lab. That is, he can sit in a cell with an air conditioner and in a cell with an object.
Count how many seats Minsang wants.
Input
The first line gives the vertical size and the horizontal size of the lab, in that order.
From the second line through the -th line, values describing the lab's interior are given on each line.
are the object types described above. denotes an air conditioner, and denotes an empty cell.
There are between and air conditioners.
Output
Print the number of seats Minsang wants.







