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

32042번 - Text editor 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB62101032.258%

문제

Robert is competing in CEOI 2024. He has almost finished his solution to the hardest problem of the day, and not just that, he's pretty sure it will get 100 points! There is just one small issue: He made a typo! What's worse, his favorite computer mouse, which he had been using since 2008, seems to have finally broken and isn't responding at all. Therefore, he will have to navigate to the typo using the arrow keys on his keyboard.

Robert's program has $N$ lines with lengths $l_1, l_2, \ldots, l_N$. Robert always ends his programs with an empty line, therefore $l_N = 0$. The cursor can be placed between two characters, as well as at the start or end of a line. As such, line $i$ has $l_i + 1$ possible cursor positions (called columns) numbered from 1ドル$ to $l_i + 1$. For example, this is what a cursor placed on line 2 in column 6 would look like:

Robert wants to move his cursor from line $s_l$ column $s_c$ to line $e_l$ column $e_c$. He would like to know the minimum number of key presses needed to do so.

The horizontal arrow keys are quite simple. Pressing left will move the cursor to the previous column, unless the cursor was at the start of a line, in which case it will move to the end of the previous line. Similarly, pressing right will move the cursor to the next column, or to the start of the next line if the cursor was at the end of a line.

For example, left presses can look like this:

And right presses can look like this:

Pressing left at the very start of the file or pressing right at the very end of the file will have no effect.

The vertical arrow keys are slightly more complicated. Pressing upwill move the cursor to the previous line and pressing down will move it to the next line, without changing the column number. However, if this would put the cursor past the end of the new line, the cursor will jump to the end of that line instead.

For example, up presses can look like this:

And down presses can look like this:

If pressing up or down would put the cursor on a line that doesn't exist, the cursor won't move at all.

입력

The first line of input contains the integer $N$ — the number of lines of Robert's solution. The second line contains two integers $s_l$ and $s_c$ separated by spaces — the initial cursor position. Similarly, the third line contains two integers $e_l$ and $e_c$ — the target cursor position. The fourth line contains $N$ space-separated integers $l_1, l_2, \ldots, l_N$ — the length of each line.

출력

Your program should output a single line containing a single integer — the minimum number of key presses to move the cursor from $(s_l, s_c)$ to $(e_l, e_c)$.

제한

  • 1ドル \leq N \leq 10^6$
  • 0ドル \leq l_i \leq 10^9$ (for each $i$ such that 1ドル \leq i \leq N$)
  • $l_N = 0$
  • 1ドル \leq s_l, e_l \leq N$
  • 1ドル \leq s_c \leq l_{s_l} + 1$
  • 1ドル \leq e_c \leq l_{e_l} + 1$.

서브태스크

번호배점제한
15

$N \leq 2$

214

$N \leq 1,000円,ドル $l_i \leq 5,000円$ (for each $i$ such that 1ドル \leq i \leq N$)

326

$N \leq 1,000円$

411

$l_i = l_j$ (for each $i, j$ such that 1ドル \leq i, j \leq N - 1$)

544

no additional constraints

예제 입력 1

5
3 1
2 8
7 10 9 9 0

예제 출력 1

3

Robert can move the cursor to the target position using three key presses by pressing up, left and down, in that order:

Alternatively, he could move his cursor to the target position equally quickly by pressing left, up and down. It can be easily shown that it's impossible to reach the target position using at most two key presses.

예제 입력 2

5
1 20
3 25
25 10 40 35 0

예제 출력 2

16

The shortest possible key press sequence consists of two downpresses followed by fourteen right presses.

힌트

출처

Olympiad > Central European Olympiad in Informatics > CEOI 2024 > Day 1 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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