RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00670

Roboti

Unrated 레이팅 미적용
난이도
2s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Kile, a board games enthusiast, recently discovered the game Robots. The game
consists of a board with \(n\) rows and \(m\) columns and one robot. The field (1, 1) is
the t\(op-le\)ft field of the board, while the field (n, m) is the bott\(om-ri\)ght.
At the beginning, the robot is positioned on some field (x, y) (\(x-th\) row, \(y-th\)
column), and the player can direct it in one of the four directions: up, down, left,
or right. Depending on the chosen direction, it will move in that direction until it
encounters its goal or a special field on the board. If at any point it wants to exit
the board, it wraps around to the other side. For example, if it is located at the field (n, 3) and wants to
move down, it will arrive at the field (1, 3).
The board has three types of fields:
• Empty fie\(ld - th\)e robot continues moving in the same direction
• Left turn fie\(ld - wh\)en the robot steps on this field, it will turn left by 90° and continue moving
• Right turn fie\(ld - wh\)en the robot steps on this field, it will turn right by 90° and continue moving
Most fields on the board are empty, only \(k\) of them are left or right turn fields.
The game consists of \(q\) rounds. In the \(i-th\) round of the game, the robot will be placed on the field
(\(a@@RISE_MATH_BLOCK_0@@i\), d\(i\)) using the minimum number of turns, or determine that it is
impossible.
After playing this game several times, Kile realized that it is more challenging than it initially seemed.
That is why he needs your help now. Help him determine the minimum number of turns required for each
Note: If the robot starts or finishes its path on a left or right turn field, that turn is not counted.

제약

Subtask 1 (10 points): \(k = 0\)

Subtask 2 (13 points): n, \(m \le 300\), \(q \le 10\)

Subtask 3 (49 points): n, \(m \le 300\)

Subtask 4 (38 points): No additional constraints.

입력 형식

The first line contains integers \(n\), \(m\) and \(k\) (\(1 \le n\), \(m \le 10^{6}\), \(0 \le k \le 10^{5}\)), the number of rows, columns
and n\(on-em\)pty fields on the board.
The \(i-th\) of the following \(n\) lines contains integers \(x@@RISE_MATH_BLOCK_0@@i\) (\(1 \le x@@RISE_MATH_BLOCK_1@@i \le m\), s\(i\) =
‘L’ors\(i\) = ‘R’), the row and column of \(i-th\) turn field and the type of turn. If \(s@@RISE_MATH_BLOCK_2@@i\) = ‘R’ then it is a right turn field.
The next line contains integer \(q\) (\(1 \le q \le 3 \cdot 10^{5}\)), the number of rounds.
The \(i-th\) of the following \(q\) lines contains integers \(a@@RISE_MATH_BLOCK_3@@i\), c\(i \le n\), \(1 \le b\)\(i\), d\(i \le m\)), the starting
position and the goal.

출력 형식

In the \(i-th\) of the following \(q\) lines output the minimal number of turns for the \(i-th\) round of the game or
’-1’ if it is impossible to reach the goal.

서브태스크
서브태스크점수설명

1

10점

\(k = 0\)

2

13점

n, \(m \le 300\), \(q \le 10\)

3

49점

n, \(m \le 300\)

4

38점

No additional constraints.

예제 1
입력
2 2 2
1 1 L
2 2 R
5
1 1 2 2
2 1 1 2
1 1 1 2
2 1 1 1
2 2 2 1
출력
-1
1
0
0
0
예제 2
입력
3 3 4
1 1 L
1 3 L
2 1 L
3 3 L
7
1 1 3 3
3 3 2 1
3 1 2 2
2 3 1 2
2 3 3 1
1 2 3 2
3 3 2 2
출력
1
2
1
1
1
0
3
예제 3
입력
4 4 8
1 1 R
1 3 L
2 2 R
2 4 L
3 1 L
3 3 L
4 2 L
4 4 L
7
1 2 1 4
2 2 3 4
4 4 3 2
4 1 4 4
4 2 3 1
1 2 2 3
2 4 2 3
출력
2
1
1
0
-1
5
0
설명

Clarification of the second example:
First round: We start at (1, 1). If we direct the robot to the left, it will arrive at (1, 3) in the next step
because it wanted to exit the board, so it wraps around to the other side. Field (1, 3) is a left turn field,
so the robot is now directed downwards. After two more steps, it will be at the desired goal (3, 3).
Second round: We start at (3, 3). If we direct the robot upwards, it will arrive at (1, 3) in two steps,
where it will be directed to the left due to the left turn field. After two steps, it will be at the field (1, 1),
which is also a left turn field, so it will be directed downwards. In the next step, it will be at the desired
goal (2, 1).

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2023/2024 Contest 4

평가 및 의견

Roboti

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Roboti

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8