結果

問題 No.2577 Simple Permutation Guess
ユーザー titia
提出日時 2023-12-05 05:49:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,479 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 94,664 KB
平均クエリ数 248.84
最終ジャッジ日時 2024-09-27 00:03:19
合計ジャッジ時間 57,641 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 103 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())


P=[1]
for i in range(1,n+1):
    P.append(P[-1]*i)
               
OK=1
NG=P[-1]+1

def calc(x):
    x-=1
    ANS=[]
    USE=[0]*(n+1)
    for i in range(n-1,-1,-1):
        k=x//P[i]
        #print(x,k,USE)
        x=x%P[i]

        for j in range(n+1):
            if USE[j]==0:
                k-=1

                if k==-1:
                    ANS.append(j+1)
                    USE[j]=1
                    break

    return ANS
        

while NG>OK+1:
    mid=(OK+NG)//2

    print("?",*calc(mid),flush=True)

    ret=int(input())

    if ret==-1:
        exit()

    if ret==1:
        OK=mid
    else:
        NG=mid

print("!",*calc(OK),flush=True)
    
0