結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー とりゐとりゐ
提出日時 2021-07-15 15:24:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 843 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 86,588 KB
実行使用メモリ 84,040 KB
最終ジャッジ日時 2023-10-14 02:18:31
合計ジャッジ時間 4,345 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,960 KB
testcase_01 AC 73 ms
71,136 KB
testcase_02 AC 75 ms
71,264 KB
testcase_03 AC 74 ms
71,176 KB
testcase_04 AC 72 ms
70,920 KB
testcase_05 AC 70 ms
71,000 KB
testcase_06 AC 73 ms
71,076 KB
testcase_07 AC 75 ms
70,864 KB
testcase_08 AC 75 ms
71,172 KB
testcase_09 AC 74 ms
71,108 KB
testcase_10 AC 73 ms
71,200 KB
testcase_11 AC 74 ms
70,868 KB
testcase_12 AC 73 ms
70,964 KB
testcase_13 AC 76 ms
71,180 KB
testcase_14 AC 77 ms
70,784 KB
testcase_15 AC 76 ms
71,016 KB
testcase_16 AC 152 ms
81,704 KB
testcase_17 AC 152 ms
81,368 KB
testcase_18 AC 145 ms
83,680 KB
testcase_19 AC 148 ms
84,040 KB
testcase_20 AC 87 ms
81,796 KB
testcase_21 AC 86 ms
81,704 KB
testcase_22 AC 78 ms
75,436 KB
testcase_23 AC 76 ms
72,484 KB
testcase_24 AC 119 ms
79,904 KB
testcase_25 AC 128 ms
78,492 KB
testcase_26 AC 106 ms
78,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(str,input().split())
n=int(n)
c=list(map(int,input().split()))
if len(k)>n:
  print(-1)
  exit()
x=''
for i in range(9):
  x+=str(i+1)*c[i]
if len(k)<n:
  print(x)
  exit()
flag=True
memo=-1
memo2=0
for i in range(n):
  if flag:
    if int(k[i])<int(x[i]):
      print(x)
      exit()
    if int(k[i])>int(x[i]):
      flag=False
flag=True
d=c.copy()
for i in range(n):
  if flag:
    if k[i]=='0':
      flag=False  
    elif c[int(k[i])-1]==0:
      flag=False
    flag2=True
    for j in range(int(k[i]),9):
      if flag2 and c[j]>0:
        memo=i
        memo2=j
        flag2=False
    c[int(k[i])-1]-=1
    #print(ans,i,c)
if memo==-1:
  print(-1)
  exit()
tmp=k[:memo]+str(memo2+1)
for i in range(memo):
  d[int(k[i])-1]-=1
for h in range(9):
  if memo2==h:
    tmp+=str(h+1)*(d[h]-1)
  else:
    tmp+=str(h+1)*d[h]
print(tmp)
0