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

Gitara

Silver I 실버 I
난이도
1s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Darko has a new imaginary extraterrestrial friend with a billion fingers. The extraterrestrial soon took hold of his guitar, found a simple melody online, and started playing it.

The guitar, as usual, has six strings denoted by numbers \(1\) through \(6\). Each string is divided into \(P\) frets denoted by numbers \(1\) through \(P\).

A melody is a sequence of tones, where each tone is produced by picking a string pressed on a specific fret (e.g. the \(4\)th string pressed on the \(8\)th fret). If a string is pressed on several frets, the produced tone will be the one corresponding to the highest of those frets.

For instance, if the \(3\)rd string is already pressed on the \(5\)th fret, and the tone which corresponds to the \(7\)th fret is to be produced, the string can be pressed on the \(7\)th fret and picked without releasing the \(5\)th fret, since only the highest one affects the tone produced (\(7\)th in this case). Similarly, if a tone that corresponds to the \(2\)nd fret on the same string is next to be produced, it is necessary to release both the \(5\)th and \(7\)th frets.

Write a program which computes the minimum number of finger movements needed to produce the given melody. Note that pressing or releasing a single fret counts as one finger move. String picking does not count as a finger move.

제약
입력 형식

The first line of input contains two positive integers separated by a single space, \(N\) (\(N \le 500\,000\)) and \(P\) (\(2 \le P \le 300\,000\)). They represent the number of tones in the melody and the number of frets, respectively.

The following \(N\) lines describe the tones — the ordinal of the string and the ordinal of the fret, respectively, in the same order as the extraterrestrial plays them.

출력 형식

In a single line of output, print the minimum number of finger movements.

First sample description: all the tones are produced by picking the \(2\)nd string. First, the frets \(8\), \(10\), \(12\) are pressed, in order (three movements). Then, the \(12\)th fret is released to produce the second tone again (fourth movement). Finally, the \(5\)th fret is pressed followed by the release of frets \(10\) and \(12\) (a total of seven movements).

서브태스크
서브태스크점수설명

Test 1

10점

None

Test 2

10점

None

Test 3

10점

None

Test 4

10점

None

Test 5

10점

None

Test 6

10점

None

Test 7

10점

None

Test 8

10점

None

Test 9

10점

None

Test 10

10점

None

예제 1
입력
5 15
2 8
2 10
2 12
2 10
2 5
출력
7
예제 2
입력
7 15
1 5
2 3
2 5
2 7
2 4
1 5
1 3
출력
9
문제 정보

riseoj 작성

출처 COCI 2010/2011 Contest 7

평가 및 의견

Gitara

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

Log in to rate problems.

개별 의견

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

풀이 제출

Gitara

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