結果

問題 No.2577 Simple Permutation Guess
ユーザー rlangevin
提出日時 2024-04-04 12:20:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 94,716 KB
平均クエリ数 248.84
最終ジャッジ日時 2024-10-01 00:21:40
合計ジャッジ時間 30,303 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 111
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = fact[i - 1] * i

def lehmer(m, N):
    L = list(range(1, N + 1))
    ret = []
    for i in range(N):
        q = m // fact[N - 1 - i]
        m %= fact[N - 1 - i]
        ret.append(L.pop(q))
    return ret

def check(m):
    print("?", *lehmer(m, N), flush=True)
    return int(input())

def BinarySearch(check, yes = 10 ** 18, no = -1):
    while abs(yes - no) != 1:
        mid = (yes + no)//2
        if check(mid):
            yes = mid
        else:
            no = mid
    return yes
            
ans = BinarySearch(check, 0, fact[N])
        
print("!", *lehmer(ans, N))
0