結果

問題 No.2771 Personal Space
ユーザー 👑 timitimi
提出日時 2024-06-03 19:08:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 925 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 130,028 KB
最終ジャッジ日時 2024-06-03 19:08:25
合計ジャッジ時間 21,197 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,992 KB
testcase_01 AC 896 ms
129,592 KB
testcase_02 AC 898 ms
130,028 KB
testcase_03 AC 893 ms
129,208 KB
testcase_04 AC 867 ms
129,340 KB
testcase_05 AC 882 ms
129,208 KB
testcase_06 AC 911 ms
129,456 KB
testcase_07 AC 471 ms
81,188 KB
testcase_08 AC 166 ms
80,268 KB
testcase_09 AC 489 ms
80,652 KB
testcase_10 AC 747 ms
111,572 KB
testcase_11 AC 875 ms
121,400 KB
testcase_12 AC 865 ms
115,436 KB
testcase_13 AC 443 ms
81,676 KB
testcase_14 AC 486 ms
80,488 KB
testcase_15 AC 544 ms
85,204 KB
testcase_16 AC 553 ms
84,512 KB
testcase_17 AC 637 ms
90,672 KB
testcase_18 AC 482 ms
80,420 KB
testcase_19 AC 510 ms
81,368 KB
testcase_20 AC 910 ms
120,192 KB
testcase_21 AC 862 ms
121,120 KB
testcase_22 AC 888 ms
119,664 KB
testcase_23 AC 925 ms
124,412 KB
testcase_24 AC 893 ms
124,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
import heapq
import heapq 
from heapq import heappop,heappush,heapify
from sys import stdin, setrecursionlimit
input = stdin.readline
readline = stdin.readline

m=-10**10
for i in range(T):
  N,M=map(int, input().split())
  A=[];ans=[-1]*N
  ans[M-1]=1
  if M==1:
    l,r=2,N 
    d=r-l+1
    heapq.heappush(A,(d*m+l,l,r,d))
  elif M==N:
    l,r=1,N-1 
    d=r-l+1
    heapq.heappush(A,(d*m+l,l,r,d))
  else:
    l,r=1,M-1
    d=M-1
    heapq.heappush(A,(d*m+l,l,r,d))
    l,r=M+1,N 
    d=N-M
    heapq.heappush(A,(d*m+l,l,r,d))
  for i in range(N-1):
    d=heapq.heappop(A)
    c,l,r,_=d
    if l!=1 and r!=N:      
      d=(l+r)//2 
      ans[d-1]=i+2
      ll,rr=l,d-1
      if ll<=rr:
        dd=(rr-ll)//2+1
        heapq.heappush(A,(dd*m+ll,ll,rr,dd))
      ll,rr=d+1,r
      if ll<=rr:
        dd=(rr-ll)//2+1
        heapq.heappush(A,(dd*m+ll,ll,rr,dd))
    elif l==1:
      ans[l-1]=i+2
      ll,rr=2,r
      dd=(rr-ll)//2+1
      heapq.heappush(A,(dd*m+ll,ll,rr,dd))
    else:
      ans[r-1]=i+2
      ll,rr=l,r-1
      dd=(rr-ll)//2+1
      heapq.heappush(A,(dd*m+ll,ll,rr,dd))
  print(*ans)
      
      
    
    
0