結果

問題 No.2771 Personal Space
ユーザー ああいい
提出日時 2024-06-03 19:53:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,156 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 121,536 KB
最終ジャッジ日時 2024-12-23 10:41:41
合計ジャッジ時間 25,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())

import heapq

def calc(N,M):
    ans = [0] * N
    ans[M-1] = 1

    q = []
    if M != 1:
        heapq.heappush(q,(-(M-1),0,-1,M-1))
    if M != N:
        heapq.heappush(q,(-(N - M),N - 1,M-1,N))

    for _ in range(N - 1):
        d,now,a,b = heapq.heappop(q)
        ans[now] = _ + 2
        #print(d,now,a,b)
        if a != -1:
            if now - a == 1:pass
            else:
                u = a + (now - a) // 2
                heapq.heappush(q,(-((now-a)//2),u,a,now))
        if b != N:
            if b - now == 1:pass
            else:
                u = now + (b - now) // 2
                heapq.heappush(q,(-((b-now)//2),u,now,b))
    print(*ans)
for _ in range(T):
    n,m = map(int,input().split())
    calc(n,m)
0