시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 256 MB18000.000%

문제

Jack and Jill play a game called Hotter, Colder. Jill has a number between 1 and N, and Jack makes repeated attempts to guess it.

Each of Jack's guesses is a number between 1 and N. In response to each guess, Jill answers hottercolder or same. For Jack's first guess, Jill answers same. For the remaining guesses Jill answers:

  • hotter if this guess is closer to Jill's number than his previous guess
  • colder if this guess is farther from Jill's number than his previous guess
  • same if this guess is neither closer to nor further from Jill's number than his previous guess.

You are to implement a procedure HC(N) that plays Jack's role. This implementation may repeatedly call Guess(G), with G a number between 1 and N. Guess(G) will return 1 to indicate hotter, -1 to indicate colder or 0 to indicate sameHC(N) must return Jill's number.

예제

As example, assume N=5, and Jill has chosen the number 2. When procedure HC makes the following sequence of calls to Guess, the results in the second column will be returned.

Call Returned value Explanation
Guess(5) 0 Same (first call)
Guess(3) 1 Hotter
Guess(4) -1 Colder
Guess(1) 1 Hotter
Guess(3) 0 Same

At this point Jack knows the answer, and HC should return 2. It has taken Jack 5 guesses to determine Jill's number. You can do better.

서브태스크 1 (25점)

HC(N) must call Guess(G) at most 500 times. There will be at most 125 250 calls to HC(N), with N between 1 and 500.

서브태스크 2 (25점)

HC(N) must call Guess(G) at most 18 times. There will be at most 125 250 calls to HC(N) with N between 1 and 500.

서브태스크 3 (25점)

HC(N) must call Guess(G) at most 16 times. There will be at most 125 250 calls to HC(N) with N between 1 and 500.

서브태스크 4 (25점)

Let W be the largest integer, such that 2W≤3N. For this subtask your solution will score:

  • 0 points, if HC(N) calls Guess(G) 2W times or more,
  • 25α points, where α is the largest real number, such that 0<α<1 and HC(N) calls Guess(G) at most 2W-αW times,
  • 25 points, if HC(N) calls Guess(G) at most W times.

There will be at most 1 000 000 calls to HC(N) with N between 1 and 500 000 000.

Be sure to initialize any variables used by HC every time it is called.

제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.