結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー とりゐとりゐ
提出日時 2021-07-13 04:17:29
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,044 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 78,928 KB
最終ジャッジ日時 2023-10-14 02:17:12
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,024 KB
testcase_01 AC 72 ms
71,196 KB
testcase_02 AC 72 ms
71,340 KB
testcase_03 AC 73 ms
71,400 KB
testcase_04 AC 76 ms
75,556 KB
testcase_05 AC 76 ms
74,904 KB
testcase_06 AC 77 ms
75,000 KB
testcase_07 AC 78 ms
75,044 KB
testcase_08 AC 79 ms
75,308 KB
testcase_09 AC 80 ms
75,608 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

fact=[1]*17
for i in range(1,17):
  fact[i]=fact[i-1]*i
def f(d,s):
  c=d.copy()
  if len(s)==0:
    return 1
  cnt=0
  if s[0]=='0':
    return 0
  m=sum(c)-1
  for i in range(int(s[0])-1):
    if c[i]>0:
      num=fact[m]
      for j in range(9):
        if i!=j:
          num//=fact[c[j]]
        else:
          num//=fact[c[i]-1]
      cnt+=num
  if c[int(s[0])-1]==0:
    return cnt
  c[int(s[0])-1]-=1
  return cnt+f(c,s[1:])

def is_ok(arg):
  if f(d,str(arg))>x:
    return True
  else:
    return False
def bisect(ng, ok):
  while (abs(ok - ng) > 1):
      mid = (ok + ng) // 2
      if is_ok(mid):
          ok = mid
      else:
          ng = mid
  return ok

def g(c):
  ans=''
  for i in range(9):
    for j in range(c[i]):
      ans+=str(i+1)
  return ans

for _ in range(1):
  n,k=map(int,input().split())
  k=str(k)
  d=list(map(int,input().split()))
  if len(k)>n:
    print(-1)
  elif len(k)<n:
    print(g(d))
  else:
    x=f(d,str(k))
    y=bisect(10**(n-1),10**n)
    if y!=10**n:
      print(y)
    else:
      print(-1)
0