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

23568번 - Find the House 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB48638834187.887%

문제

Younghee is currently on a one-dimensional road and looking for her friend Jisun’s house. To know the exact position of Jisun’s house, Younghee sends a message to Jisun with her current position (assume that all the positions are represented as integers). A couple of minutes later, Younghee gets a reply as a list of $n$ triples from Jisun with an additional explanation as follows:

  • For each triple $(i, j, k)$ in the list, $i$ is an integer which denotes the current position, $j$ denotes the direction to move from $i,ドル represented as $L$ (left) or $R$ (right), and $k$ is a positive integer which denotes the distance to move from $i$.
  • For any two triples $(i, j, k)$ and $(i', j', k')$ in the list, $i$ and $i'$ are distinct.
  • If you are currently on the position $i,ドル there always exists a triple $(i, j, k)$ in the list (unless all the triples in the list are referred before). In this case, refer to the triple $(i, j, k)$ and move to $i - k$ (if $j = \texttt{L}$) or $i + k$ (if $j = \texttt{R}$).
  • Each of the triples in the list is referred exactly once.
  • The position after referring to all the triples in the list is a position of Jisun’s house.

For example, suppose Younghee is currently at the position 0 with a list of four triples – $(3, \texttt{R}, 4),ドル $(0, \texttt{L}, 2),ドル $(7, \texttt{L}, 5),ドル and $(-2, \texttt{R}, 5)$. Then Younghee first refers to the triple $(0, \texttt{L}, 2)$ and move to the position 0ドル - 2 = -2$. After that, Younghee refers to the triples $(-2, \texttt{R}, 5),ドル $(3, \texttt{R}, 4),ドル and $(7, \texttt{L}, 5)$ in order and moves to the position 2ドル,ドル which is the position of Jisun’s house. Given $n,ドル Younghee’s current position, and a list of $n$ triples, write a program to find Jisun’s house’s position.

입력

Your program is to read from standard input. The input starts with a line containing an integer $n$ (1ドル ≤ n ≤ 10,000$), where $n$ is the number of triples in the list. In the following $n$ lines, $n$ triples are given where each triple is represented as three values $i,ドル $j,ドル and $k,ドル consisting of two integers $i$ and $j$ and one character $k$ ($-1,000,000 ≤ i ≤ 1,000,000,ドル $j \in \{\texttt{L}, \texttt{R}\},ドル and 1ドル ≤ k ≤ 2,000,000$). After $n$ lines of triples, there is a line containing Younghee’s current position as an integer between $-1,000,000$ and 1,000,000ドル$.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the position of Jisun’s house.

제한

예제 입력 1

4
3 R 4
0 L 2
7 L 5
-2 R 5
0

예제 출력 1

2

예제 입력 2

5
3 L 3
-1 R 11
5 L 6
1 R 4
10 L 7
1

예제 출력 2

0

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Asia Regional - Seoul 2021 C번

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

출처

대학교 대회

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

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