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

Walking in Manhattan

Platinum I 플래티넘 I
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John and his \(Q\) (\(1 \leq Q \leq 2 \cdot 10^5\)) cows are in Manhattan on
vacation, but the cows have escaped and are now walking around freely in the
city! Manhattan is huge – so huge that its \(N\) (\(1 \le N \le 2 \cdot 10^5\))
roads stretch infinitely in the \(x\)-\(y\) plane, but conveniently, those roads all
run perfectly horizontally or vertically. Each horizontal and vertical road can
be modeled by an equation of the form \(y = c_i\) or \(x = c_i\), where \(c_i\) is an
integer in the range \(0\) to \(10^9\) inclusive.

Farmer John knows exactly where each cow started walking and how long ago they
escaped. Cows are very predictable, so each of them walks according to the
following pattern:

  • They only walk north (\(+y\)) or east (\(+x\)) at one unit per second.
  • If they are currently on a single road, they continue walking along the road's direction.
  • If they are at the intersection of two roads, they walk north if they have been walking for an even number of seconds and east otherwise.

Given the layout of Manhattan and the information for each cow, help Farmer John
determine where his cows are now!

Problem credits: Benjamin Qi

제약

SCORING

  • Inputs 2-4 satisfy \(N, Q, c_i, x_i, y_i, d_i \leq 100\).
  • Inputs 5-9 satisfy \(N, Q\le 3000\).
  • Inputs 10-20 satisfy no additional constraints.

Problem credits: Benjamin Qi

입력 형식

The first line contains \(N\) and \(Q\).

The next \(N\) lines describe the roads. Each road is described by a direction (H
or V) and a coordinate \(c_i\). It is guaranteed that the roads are unique.

The next \(Q\) lines describe the cows. Each cow is described by three integers
\((x_i, y_i, d_i)\), meaning that they started walking from \((x_i, y_i)\) exactly
\(d_i\) seconds ago. It is guaranteed that \((x_i, y_i)\) lies on some road, and
\(0 \le x_i, y_i, d_i \le 10^9\).

출력 형식

Output \(Q\) lines, where the \(i\)th line contains the current position of the
\(i\)th cow.

예제 1
입력
4 5
V 7
H 4
H 5
V 6
6 3 10
6 4 10
6 5 10
6 6 10
100 4 10
출력
14 5
7 13
6 15
6 16
110 4
설명

The first two cows took the following paths:

(6, 3) -> (6, 4) -> (7, 4) -> (7, 5) -> (8, 5) -> ... -> (14, 5)
(6, 4) -> (6, 5) -> (7, 5) -> (7, 6) -> ... -> (7, 13)
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2023-2024 > January > Gold

태그

평가 및 의견

Walking in Manhattan

개요
출제자 난이도 Platinum I 플래티넘 I 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Walking in Manhattan

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