結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー とりゐとりゐ
提出日時 2021-07-13 04:17:13
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 782 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 280,920 KB
最終ジャッジ日時 2023-10-14 02:15:47
合計ジャッジ時間 5,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,736 KB
testcase_01 AC 72 ms
71,304 KB
testcase_02 AC 72 ms
71,544 KB
testcase_03 AC 73 ms
71,072 KB
testcase_04 AC 72 ms
71,420 KB
testcase_05 AC 73 ms
71,500 KB
testcase_06 AC 72 ms
71,152 KB
testcase_07 AC 73 ms
71,332 KB
testcase_08 AC 72 ms
71,296 KB
testcase_09 AC 73 ms
71,364 KB
testcase_10 AC 72 ms
71,128 KB
testcase_11 AC 70 ms
71,324 KB
testcase_12 AC 73 ms
71,324 KB
testcase_13 AC 71 ms
71,324 KB
testcase_14 AC 78 ms
76,188 KB
testcase_15 AC 72 ms
71,308 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(str,input().split())
n=int(n)
c=list(map(int,input().split()))
ans='-1'
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
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
for i in range(n):
  if flag:
    if c[int(k[i])-1]==0:
      flag=False
    flag2=True
    for j in range(int(k[i]),9):
      if flag2 and c[j]>0:
        flag2=False
        tmp=k[:i]+str(j+1)
        for h in range(9):
          if j==h:
            tmp+=str(h+1)*(c[h]-1)
          else:
            tmp+=str(h+1)*c[h]
    if flag2==False:
      ans=tmp
    c[int(k[i])-1]-=1
    #print(ans,i,c)
  if k[i]=='0':
    flag=False
print(ans)
0