Moving people
Practice
3.6 (11 votes)
Basic programming
Basics of implementation
Implementaion
Implementation
Medium
Problem
66% Success 6340 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Updated problem name

Moving people

Updated problem statement

The people of your city are living in a \(N\) x \(M\) grid. If a person is out of the grid after multiple instructions, then that person is not counted in further steps.

Initially, there is at most one person in every cell of this grid. You can perform \(Q\) operations or query of the following types:

  • \(1\ X\ Y\): Move every person that is currently residing in the grid, \(X\) column left of their cells and \(Y\) column above of their cells. If \(X\) is negetive, then move people \(abs(X)\) column right of their cells. Also, if \(Y\) is negative, then move people \(abs(Y)\) column down of their cells.
  • \(2\): Calculate the numbner of people that are currently living in the grid.

Input format

  • First line: Three integers, \(N, M,\ and\ Q\) denoting the number of rows that are available in the grid, number of columns that are available in the grid, and number of instructions
  • Next N lines: A string  consisting of only \(0\ and\ 1\). In the \(i^{th}\) string, the \(j^{th}\) character is \(1\) if there is a person in that cell, otherwise there will be \(0\)
  • Next \(Q\) lines: One of the \(2\) types of operations as stated above. \(\)

Output format
For each \(2^{nd}\) type of query, print the number of persons that are available in the grid at the time of that query.

Constraints

\(1 \leq N, M \leq 10^3\)
\(1 \leq Q \leq 10^5\)
\(-1000 \leq X, Y \leq 1000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
16 votes
Tags:
Basic ProgrammingBasics of ImplementationHash MapsImplementationMedium
Points:30
5 votes
Tags:
Basic Programming
Points:30
3 votes
Tags:
Basic ProgrammingBasics of ImplementationHash MapsImplementationMedium