結果

問題 No.2577 Simple Permutation Guess
ユーザー rlangevin
提出日時 2024-04-04 12:16:39
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 658 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 95,580 KB
平均クエリ数 248.39
最終ジャッジ日時 2024-10-01 00:20:57
合計ジャッジ時間 30,958 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other AC * 1 WA * 59 RE * 51
権限があれば一括ダウンロードができます

ソースコード

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, fact[N], -1)
        
print("!", *lehmer(ans, N))
0