結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー googol_S0googol_S0
提出日時 2021-07-30 21:54:59
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 104,644 KB
最終ジャッジ日時 2023-10-14 04:33:17
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,716 KB
testcase_01 AC 72 ms
71,296 KB
testcase_02 AC 72 ms
71,160 KB
testcase_03 AC 71 ms
70,720 KB
testcase_04 AC 72 ms
71,176 KB
testcase_05 AC 69 ms
71,184 KB
testcase_06 AC 72 ms
70,940 KB
testcase_07 AC 71 ms
71,128 KB
testcase_08 AC 72 ms
71,264 KB
testcase_09 AC 71 ms
71,316 KB
testcase_10 AC 72 ms
71,140 KB
testcase_11 AC 71 ms
71,140 KB
testcase_12 AC 71 ms
71,240 KB
testcase_13 AC 72 ms
70,856 KB
testcase_14 AC 71 ms
70,900 KB
testcase_15 AC 72 ms
71,108 KB
testcase_16 AC 171 ms
100,056 KB
testcase_17 AC 173 ms
100,852 KB
testcase_18 AC 164 ms
104,644 KB
testcase_19 AC 165 ms
104,424 KB
testcase_20 AC 153 ms
98,616 KB
testcase_21 AC 151 ms
98,272 KB
testcase_22 AC 155 ms
98,484 KB
testcase_23 AC 75 ms
72,196 KB
testcase_24 AC 157 ms
95,628 KB
testcase_25 AC 91 ms
80,924 KB
testcase_26 AC 153 ms
98,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=input().split()
N=int(N)
if len(K)>N:
  print(-1)
  exit()
K=''.join(['0'*(N-len(K)),K])
X=[int(K[i]) for i in range(N)]
X[-1]+=1
for i in range(N-1,-1,-1):
  if X[i]==10:
    X[i]=0
    if i==0:
      print(-1)
      exit()
    X[i-1]+=1
C=[0]+list(map(int,input().split()))
ANS=[0]*N
for i in range(N):
  if C[X[i]]==0:
    for j in range(X[i]+1,10):
      if C[j]:
        ANS[i]=j
        C[j]-=1
        i+=1
        for k in range(10):
          for l in range(C[k]):
            ANS[i]=k
            i+=1
        print(*ANS,sep='')
        exit()
    i-=1
    while 1:
      if i==-1:
        print(-1)
        exit()
      C[ANS[i]]+=1
      ANS[i]=0
      for j in range(X[i]+1,10):
        if C[j]:
          ANS[i]=j
          C[j]-=1
          i+=1
          for k in range(10):
            for l in range(C[k]):
              ANS[i]=k
              i+=1
          print(*ANS,sep='')
          exit()
      i-=1
  else:
    ANS[i]=X[i]
    C[X[i]]-=1
print(*ANS,sep='')
0