Logo
(追記) (追記ここまで)

20609번 - It's All Squares 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB511100.000%

문제

One day when Little Q woke up, he found himself being inside a 2D pixel world. The world is a grid with $n \times m$ square cells. Little Q can only walk along the sides of these cells, which means he can stay at a point $(x, y)$ if and only if 0ドル \leq x \leq n$ and 0ドル \leq y \leq m,ドル where $x$ and $y$ are integers. There is a number written at the center of each cell, number $w_{i,j}$ (1ドル \leq i \leq n,ドル 1ドル \leq j \leq m$) is written at the point $(i-0.5, j-0.5)$.

Little Q had no idea about how to escape from the pixel world, so he started wandering. You will be given $q$ queries, each query consists of two integers $(x,y)$ and a string $S,ドル denoting the route of Little Q. Initially, Little Q will stand at $(x,y),ドル then he will do $|S|$ steps of movements $S_1,S_2,\dots,S_{|S|}$ one by one. Here is what he will do for each type of movement:

  • "L" : Move from $(x,y)$ to $(x-1,y)$.
  • "R" : Move from $(x,y)$ to $(x+1,y)$.
  • "D" : Move from $(x,y)$ to $(x,y-1)$.
  • "U" : Move from $(x,y)$ to $(x,y+1)$.

It is guaranteed that Little Q will never walk outside of the pixel world, and the route will form a simple polygon. For each query, please tell Little Q how many distinct numbers there are inside the polygon formed by the route.

Fortunately, after solving this problem, Little Q woke up on his bed. The pixel world had just been a dream!

입력

The first line contains a single integer $T$ (1ドル \leq T \leq 10$), the number of test cases. For each test case:

The first line contains three integers $n,ドル $m,ドル $q$ (1ドル \leq n, m \leq 400,ドル 1ドル \leq q \leq 200,000円$) denoting the dimensions of the pixel world and the number of queries.

Each of the following $n$ lines contains $m$ integers, the $i$-th line contains $m$ integers $w_{i,1},w_{i,2},\dots,w_{i,m}$ (1ドル \leq w_{i,j} \leq n \times m$) denoting the number written in each cell. (Note that you will have to rotate this representation if you want "U" to actually mean "up", etc.)

Each of the following $q$ lines contains two integers $x$ and $y$ (0ドル \leq x \leq n,ドル 0ドル \leq y \leq m$) and a non-empty string $S$ ($S_i\in\{L,R,D,U\}$) describing each query.

It is guaranteed that the total sum of |S| over all test cases is at most 4ドル,000円,000円$.

출력

For each query, output a line with a single integer: how many distinct numbers are inside the polygon.

제한

예제 입력 1

1
3 3 2
1 2 3
1 1 2
7 8 9
0 0 RRRUUULLLDDD
0 0 RRUULLDD

예제 출력 1

6
2

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 3: Songyang Chen Contest 3 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /