Game With Permutations

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

요약
각 질의 순열 Q에 대해 |P_i - Q_i|를 정렬한 값을 받아 240번 이내의 질의로 숨겨진 순열 P를 알아낸다.
난이도

보통10점 중 7점

유형
구간, 완전 탐색, 구현, 정렬
정답자
아직 제출이 없습니다

문제

This is an interactive problem.

A game with permutations has the following rules. The judge program first generates some permutation pp of length NN and tells you NN. This permutation is never changed throughout the game.

Your task is to guess the permutation. For that purpose, you may use permutations of length NN as queries. Let's see how the jury program answers them.

  • When the jury program receives a permutation qq, it checks positions Q_iQ\_i of each integer from 1 to NN in this permutation. For example, for permutation q=(2,3,1,4,5)q = (2,3,1,4,5), we get Q=(3,1,2,4,5)Q = (3,1,2,4,5).
  • Same calculation is applied to the permutation pp, and integers P_1…P_NP\_1 \ldots P\_N are calculated. For example, for permutation p=(5,2,1,4,3)p = (5,2,1,4,3), we get P=(3,2,5,4,1)P = (3,2,5,4,1).
  • Finally, the jury program calculates an array DD such that D_i=∣P_i−Q_i∣D\_i=|P\_i-Q\_i| and returns it to your program sorted in ascending order.
  • For the example above, D=(0,1,3,0,4)D = (0,1,3,0,4), and you will receive these integers in sorted order: (0,0,1,3,4)(0,0,1,3,4).

Note that you can ask no more than 240 queries before you tell the answer.

예제1

  1. 예제 1

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