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

S1. Baby Hop, Giant Hop

Unrated 레이팅 미적용
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Samantha the Frog is hopping between lily pads arranged in a straight
line, evenly spaced. There are an infinite number of lily pads. The lily
pads are numbered, in order, using integers. For every integer, there is
also a lily pad.

Samantha starts on a lily pad numbered \(A\) and would like to hop onto a lily pad
numbered \(B\). She can take a giant
hop of length \(K\), or a baby hop of
length \(1\). Each hop can be either
forwards or backwards.

Samantha would like to know the fewest number of hops needed to get
from \(A\) to \(B\). But sometimes, she would like to know
the second fewest number of hops needed.

제약

\((-10^{18} \leq A \leq 10^{18})\)
\((-10^{18} \leq B \leq 10^{18})\)
\((2 \leq K \leq 10^{18})\)

입력 형식

The first line of input contains a single integer, \(A\), the starting lily pad \((-10^{18} \leq A \leq 10^{18})\).

The second line of input contains a single integer, \(B\), the ending lily pad \((-10^{18} \leq B \leq 10^{18})\).

The third line of input contains a single integer, \(K\), the distance of a giant hop \((2 \leq K \leq 10^{18})\).

The fourth line of input contains the integer, \(T\), which is either \(1\) or \(2\), indicating if the fewest (when \(T=1\)) or second fewest (when \(T=2\)) number of steps should be found.

Note that for full marks, solutions will need to handle 64-bit
integers. For example:

  • in C/C++, the type long long should be
    used;

  • in Java, the type long should be used.

출력 형식

On a single line, output:

  • the fewest number of hops, if \(T=1\)

  • the second fewest number of hops, if \(T=2\)

required to move from lily pad \(A\)
to lily pad \(B\).

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

1

33점

\(0 \le A, B \le 10\)\(K=2\)\(T=1\) — Only hops in the positive direction needed

2

41점

\(-10^{18} \leq A, B \leq 10^{18}\)\(2 \leq K \leq 10^{18}\)\(T=1\) — None

3

13점

\(0 \le A, B\le 100\)\(2 \le K\leq4\)\(T=1\) or \(T=2\) — None

4

13점

\(-10^{18} \leq A, B \leq 10^{18}\)\(2 \leq K\leq 10^{18}\)\(T=1\) or \(T=2\) — None

예제 1
입력
0
10
3
1
출력
4
설명

Samantha hops to lily pads labeled (3), (6), and (9), with three giant hops, and then hops
to the lily pad labeled (10) with one
baby hop.

예제 2
입력
0
11
4
1
출력
4
설명

Samantha hops to lily pads labeled (4), (8), and (12), with three giant hops, and then hops
to the lily pad labeled (11) with one
(backwards) baby hop.

예제 3
입력
0
11
4
2
출력
5
설명

The fewest number of hops needed ((4)) was found in Sample 2. In this input,
the second fewest number of steps is to be found, since (T=2). Samantha hops to lily pads labeled
(4) and (8) with two giant hops, and then hops to
the lily pad labeled (11) with three
baby hops.

예제 4
입력
0
0
3
1
출력
0
문제 정보

생성자가 기록되지 않았습니다.

출처 CCC 2026 Senior

평가 및 의견

S1. Baby Hop, Giant Hop

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

S1. Baby Hop, Giant Hop

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