Cloyster

시간 제한2초메모리 제한512 MB

요약
모든 칸이 인접한 칸 중 더 큰 값을 가진 칸을 하나 이상 가지는 n x n 격자에서 3n + 210번 이하의 질의로 최댓값을 가진 칸을 찾는다.
난이도

어려움10점 중 8점

유형
분할 정복, 그리디, 이분 탐색, 행렬
정답자
아직 제출이 없습니다

문제

You just found yourself in a huge field of Cloyster specimens somewhere on the seabed off the coast of Japan. They're quite mad at you as you tried to catch one of them a moment ago. You must immediately find the leader of the pack and beg him for forgiveness. Where is he, though?

The field contains n2n^2 square cells grouped into nn rows and nn columns. Each cell contains a single Cloyster hidden in its own shell. Now, I can reveal to you a couple of little-known facts about Cloyster:

  • The leader has the largest shell. Obviously.
  • All Cloyster in the pack have shells of different sizes.
  • Each Cloyster other than the leader has a neighbor with a larger shell in some cell adjacent to its own cell by an edge or by a corner.

You can query individual specimens for the sizes of their shells. Use this information to locate the leader of the pack. Be quick, though --- if you don't find him in 3n+2103n + 210 queries, Cloyster will run out of patience and they'll attack you!

힌트

Here are the sizes of each Cloyster in both sample tests:

Note, that the communication in the second sample test is correct --- your program is allowed to make a guess even if it isn't certain about the correctness of the answer.

예제2

  1. 예제 1

    입력
    3
    
    1
    
    4
    
    8
    
    9
    
    5
    
    예상 출력
    ? 1 1
    
    ? 2 3
    
    ? 3 2
    
    ? 3 3
    
    ? 2 2
    
    ! 3 3
    
  2. 예제 2

    입력
    5
    
    2
    
    예상 출력
    ? 4 4
    
    ! 1 1