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

21885번 - New Puzzle 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB66573890.476%

문제

Katya has a younger brother Denis, who loves puzzles. It seemed to him that he had already solved all the puzzles in the world. But, one day, returning from school with Katya, he noticed a vending machine with a puzzle that he has never seen before. He asked Katya to play with this machine and win a new puzzle.

Vending machine from the first example, before the start of the game.

The machine has a disk, divided into $n$ sectors, rotating arrow and a button. When the button is pressed, the arrow starts to spin, and the player receives this prize, corresponding to the sector on which it stops. After observing the machine, Katya noticed that it is quite primitive, and after each click of the button the arrow moves $k$ sectors clockwise. Also, Katya realized that the desired puzzle is at sector $x,ドル and it could be impossible to win. And then she asked you to help her.

Help Katya find out whether it is possible to win a puzzle, corresponding to sector $x,ドル if the arrow initially points to the sector $s$. And, if it is possible, calculate the minimal number of button clicks.

입력

A single line contains four integers $n,ドル $k,ドル $s$ and $x$ --- the number of sectors in the machine, number of sectors the arrow moves after one click, number of a sector the arrow points initially to, and the number of a sector corresponding to desired puzzle, respectively (2ドル \leq n \leq 20,000円$; 1ドル \leq k < n$; 0ドル \leq s, x < n$; $x \neq s$).

출력

Output one integer, the minimal number of clicks you need to make to get the desired puzzle, or <<-1>>, if it is impossible.

제한

서브태스크

번호배점제한
110

$k = 1$

215

$k = 2$

315

$s = 0,ドル $x = n-k$

430

It’s possible to get desired puzzle

530

No additional constraints.

예제 입력 1

5 2 0 3

예제 출력 1

4

예제 입력 2

6 3 1 3

예제 출력 2

-1

힌트

In the first example, the arrow will move through the sectors 0ドル \rightarrow 2 \rightarrow 4 \rightarrow 1 \rightarrow 3 \rightarrow \dots$. Thus, after 4ドル$ button clicks you can get a puzzle from sector 3ドル$. The figure in the statement shows the machine from the first example before the game starts.

In the second example, the arrow will move only between the two sectors: 1 and 4. So it's impossible to get puzzle from sector 3.

Notice, that samples do not satisfy the additional constraints of the first, second, third, and fourth subtasks. Your solution will run on tests of the first four subtasks even if it does not pass the sample tests.

출처

Contest > Innopolis Open in Informatics > Innopolis Open, Elimination round 1, 2017-2018 A번

채점 및 기타 정보

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

출처

대학교 대회

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

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