RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0407 파일 입출력

Springboards

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

의견: 0

설명

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?

Problem credits: Pedro Paredes

제약

SCORING

  • Test cases 2-5 satisfy \(P \le 1000\).
  • Test cases 6-15 satisfy no additional constraints.

Problem credits: Pedro Paredes

입력 형식

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)\).

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 boards.in
출력을 쓸 파일 boards.out
예제 1
입력
3 2
0 1 0 2
1 2 2 3
출력
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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2019-2020 > January > Gold

태그

평가 및 의견

Springboards

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

Log in to rate problems.

개별 의견

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

풀이 제출

Springboards

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