結果
| 問題 |
No.1630 Sorting Integers (Greater than K)
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2021-07-13 04:17:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,044 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 82,328 KB |
| 実行使用メモリ | 70,072 KB |
| 最終ジャッジ日時 | 2024-09-15 21:58:31 |
| 合計ジャッジ時間 | 2,661 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 5 RE * 17 |
ソースコード
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)
とりゐ