結果

問題 No.2577 Simple Permutation Guess
ユーザー kmjp
提出日時 2023-12-05 00:26:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,508 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,712 KB
平均クエリ数 248.84
最終ジャッジ日時 2024-09-26 23:39:36
合計ジャッジ時間 58,267 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 103 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

N=int(input())

fact = [1]
for i in range(1,501):
	fact.append(fact[-1]*i)

def get(v):
	alive = [1]*N
	ret = []
	for i in range(N,0,-1):
		x = v // fact[i-1] + 1
		v %= fact[i-1]
		for a in range(N):
			if alive[a]==1:
				x -= 1
				if x==0:
					alive[a]=0
					ret.append(str(a+1))
					break
	assert len(ret)==N
	return ret

L=0
R=fact[N]
while L+1<R:
	M=(L+R)//2
	
	arr = get(M)
	print("? "+" ".join(arr))
	ret=int(input())
	if ret==1:
		L=M
	else:
		R=M


arr = get(L)
print("! "+" ".join(arr))





0