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

18318번 - Springboards 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB43014911531.856%

문제

Bessie is in a 2D grid where walking is permitted only in directions parallel to one of the coordinate axes. She starts at the point $(0,0)$ and wishes to reach $(N,N)$ (1ドル\le N\le 10^9$). To help her out, there are $P$ (1ドル\le P\le 10^5$) springboards on the grid. Each springboard is at a fixed point $(x_1,y_1)$ and if Bessie uses it, she will land at a point $(x_2,y_2)$.

Bessie is a progress-oriented cow, so she only permits herself to walk up or right, never left nor down. Likewise, each springboard is configured to never go left nor down. What is the minimum distance Bessie needs to walk?

입력

The fist line contains two space-separated integers $N$ and $P$.

The next $P$ lines each contains four integers, $x_1,ドル $y_1,ドル $x_2,ドル $y_2,ドル where $x_1 \le x_2$ and $y_1 \le y_2.$

All springboard and target locations are distinct.

출력

Output a single integer, the minimum distance Bessie needs to walk to reach $(N,N)$.

제한

예제 입력 1

3 2
0 1 0 2
1 2 2 3

예제 출력 1

3

힌트

Bessie's best path is:

  • Bessie walks from (0,0) to (0,1) (1 unit).
  • Bessie springs to (0,2).
  • Bessie walks from (0,2) to (1,2) (1 unit).
  • Bessie springs to (2,3).
  • Bessie walks from (2,3) to (3,3) (1 unit).

The total walking length of Bessie's path is 3 units.

출처

Olympiad > USA Computing Olympiad > 2019-2020 Season > USACO 2020 January Contest > Gold 3번

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

출처

대학교 대회

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

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