結果

問題 No.2771 Personal Space
ユーザー 👑 timitimi
提出日時 2024-06-03 19:07:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,069 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 82,064 KB
実行使用メモリ 129,892 KB
最終ジャッジ日時 2024-06-03 19:07:38
合計ジャッジ時間 26,594 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 1,049 ms
129,204 KB
testcase_02 AC 1,069 ms
129,892 KB
testcase_03 AC 1,028 ms
129,200 KB
testcase_04 AC 1,028 ms
129,336 KB
testcase_05 AC 1,058 ms
129,448 KB
testcase_06 AC 1,055 ms
129,308 KB
testcase_07 AC 522 ms
78,600 KB
testcase_08 AC 469 ms
77,196 KB
testcase_09 AC 529 ms
78,616 KB
testcase_10 AC 912 ms
111,180 KB
testcase_11 AC 1,052 ms
121,648 KB
testcase_12 AC 1,017 ms
115,180 KB
testcase_13 AC 534 ms
78,952 KB
testcase_14 AC 531 ms
78,896 KB
testcase_15 AC 629 ms
83,432 KB
testcase_16 AC 595 ms
82,608 KB
testcase_17 AC 691 ms
89,248 KB
testcase_18 AC 537 ms
78,488 KB
testcase_19 AC 597 ms
78,812 KB
testcase_20 AC 1,061 ms
120,452 KB
testcase_21 AC 973 ms
120,860 KB
testcase_22 AC 1,033 ms
119,756 KB
testcase_23 AC 1,062 ms
124,532 KB
testcase_24 AC 1,034 ms
124,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
import heapq
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