結果

問題 No.1635 Let’s Sort Integers!!
ユーザー とりゐとりゐ
提出日時 2021-06-12 15:22:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 734 ms / 2,000 ms
コード長 1,524 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 63,352 KB
最終ジャッジ日時 2023-10-14 01:38:45
合計ジャッジ時間 26,834 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,124 KB
testcase_01 AC 16 ms
8,004 KB
testcase_02 AC 16 ms
8,124 KB
testcase_03 AC 17 ms
8,116 KB
testcase_04 AC 17 ms
8,032 KB
testcase_05 AC 16 ms
8,032 KB
testcase_06 AC 17 ms
8,008 KB
testcase_07 AC 17 ms
8,028 KB
testcase_08 AC 16 ms
8,032 KB
testcase_09 AC 17 ms
8,120 KB
testcase_10 AC 16 ms
7,952 KB
testcase_11 AC 17 ms
8,052 KB
testcase_12 AC 16 ms
8,128 KB
testcase_13 AC 17 ms
8,032 KB
testcase_14 AC 17 ms
8,056 KB
testcase_15 AC 17 ms
8,040 KB
testcase_16 AC 17 ms
8,120 KB
testcase_17 AC 16 ms
7,996 KB
testcase_18 AC 17 ms
8,028 KB
testcase_19 AC 17 ms
8,008 KB
testcase_20 AC 16 ms
8,020 KB
testcase_21 AC 16 ms
8,028 KB
testcase_22 AC 17 ms
8,020 KB
testcase_23 AC 16 ms
8,020 KB
testcase_24 AC 17 ms
7,996 KB
testcase_25 AC 17 ms
8,124 KB
testcase_26 AC 17 ms
8,024 KB
testcase_27 AC 16 ms
8,000 KB
testcase_28 AC 17 ms
7,948 KB
testcase_29 AC 16 ms
8,056 KB
testcase_30 AC 16 ms
8,028 KB
testcase_31 AC 17 ms
8,032 KB
testcase_32 AC 17 ms
7,952 KB
testcase_33 AC 16 ms
8,180 KB
testcase_34 AC 17 ms
8,004 KB
testcase_35 AC 17 ms
8,112 KB
testcase_36 AC 17 ms
8,004 KB
testcase_37 AC 16 ms
8,004 KB
testcase_38 AC 16 ms
8,000 KB
testcase_39 AC 16 ms
7,952 KB
testcase_40 AC 16 ms
8,052 KB
testcase_41 AC 16 ms
8,024 KB
testcase_42 AC 16 ms
8,024 KB
testcase_43 AC 17 ms
8,048 KB
testcase_44 AC 17 ms
8,032 KB
testcase_45 AC 16 ms
8,128 KB
testcase_46 AC 17 ms
8,060 KB
testcase_47 AC 16 ms
8,056 KB
testcase_48 AC 17 ms
8,084 KB
testcase_49 AC 17 ms
8,028 KB
testcase_50 AC 17 ms
8,192 KB
testcase_51 AC 17 ms
8,052 KB
testcase_52 AC 17 ms
8,108 KB
testcase_53 AC 17 ms
8,060 KB
testcase_54 AC 17 ms
8,084 KB
testcase_55 AC 17 ms
8,020 KB
testcase_56 AC 17 ms
8,056 KB
testcase_57 AC 17 ms
8,044 KB
testcase_58 AC 17 ms
8,040 KB
testcase_59 AC 16 ms
8,028 KB
testcase_60 AC 536 ms
63,208 KB
testcase_61 AC 581 ms
63,352 KB
testcase_62 AC 734 ms
63,216 KB
testcase_63 AC 567 ms
63,204 KB
testcase_64 AC 617 ms
63,204 KB
testcase_65 AC 532 ms
55,224 KB
testcase_66 AC 536 ms
55,396 KB
testcase_67 AC 534 ms
55,328 KB
testcase_68 AC 17 ms
8,088 KB
testcase_69 AC 17 ms
8,100 KB
testcase_70 AC 534 ms
63,148 KB
testcase_71 AC 593 ms
63,252 KB
testcase_72 AC 569 ms
63,260 KB
testcase_73 AC 544 ms
63,068 KB
testcase_74 AC 683 ms
63,168 KB
testcase_75 AC 540 ms
55,188 KB
testcase_76 AC 537 ms
55,184 KB
testcase_77 AC 535 ms
55,356 KB
testcase_78 AC 16 ms
8,032 KB
testcase_79 AC 17 ms
8,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n,k):
  #n%2==1 and k>n*(n-1)//2
  if k>(n**2-3)//2:
    return [-1]
  else:
    ans=[0]*n
    ans[0]=n//2+1
    t=(n**2-3)//2-k+n//2+2
    ans[n-1]=t
    a=1
    b=n
    for i in range(1,n-1):
      if i%2==1:
        ans[i]=a
        a+=1
      else:
        if b==t:
          b-=1
        ans[i]=b
        b-=1
    return ans
def f2(n,k):
  #n%2==0 and k>n*(n-1)//2
  if k>n**2//2-1:
    return [-1]
  else:
    ans=[0]*n
    ans[n-1]=n//2
    t=(n**2//2-1)-k+n//2+1
    ans[0]=t
    a=1
    b=n
    for i in range(1,n-1):
      if i%2==1:
        ans[i]=a
        a+=1
      else:
        if b==t:
          b-=1
        ans[i]=b
        b-=1
    return ans

def g(n,k):
  #k<=n*(n-1)//2
  used=[1]*(n+1)
  used[1]=0
  used[n]=0
  cnt=k-(n-1)
  ans=[]
  ans2=[n]
  a=n
  b=1
  for i in range(n-2):
    if cnt!=0:
      if i%2==0:
        if cnt<=(a-1)-b:
          used[b+cnt]=0
          ans.append(b+cnt)
          cnt=0
        else:
          a-=1
          ans.append(a)
          cnt-=a-b
          used[a]=0
      else:
        if cnt<=a-(b+1):
          used[a-cnt]=0
          ans.append(a-cnt)
          cnt=0
        else:
          b+=1
          cnt-=a-b
          used[b]=0
          ans.append(b)
  for i in range(n-1,1,-1):
    if used[i]:
      ans2.append(i)
  ans2.append(1)
  return ans2+ans

n,k=map(int,input().split())
if k<n-1:
  print(-1)
elif n%2==1:
  if k>n*(n-1)//2:
    print(*f(n,k))
  else:
    print(*g(n,k))
else:
  if k>n*(n-1)//2:
    print(*f2(n,k))
  else:
    print(*g(n,k))
0