結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー googol_S0googol_S0
提出日時 2021-07-30 21:54:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 966 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 104,952 KB
最終ジャッジ日時 2023-10-14 04:32:56
合計ジャッジ時間 4,713 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,216 KB
testcase_01 AC 71 ms
70,620 KB
testcase_02 AC 72 ms
70,980 KB
testcase_03 AC 71 ms
71,116 KB
testcase_04 AC 71 ms
70,568 KB
testcase_05 AC 75 ms
70,616 KB
testcase_06 AC 72 ms
71,172 KB
testcase_07 AC 72 ms
70,660 KB
testcase_08 AC 71 ms
71,140 KB
testcase_09 AC 71 ms
70,852 KB
testcase_10 AC 72 ms
71,144 KB
testcase_11 AC 71 ms
71,064 KB
testcase_12 AC 71 ms
71,220 KB
testcase_13 AC 71 ms
71,148 KB
testcase_14 AC 73 ms
71,180 KB
testcase_15 AC 72 ms
70,624 KB
testcase_16 AC 178 ms
99,892 KB
testcase_17 AC 176 ms
100,464 KB
testcase_18 AC 166 ms
104,952 KB
testcase_19 AC 164 ms
104,472 KB
testcase_20 AC 153 ms
98,040 KB
testcase_21 AC 154 ms
98,704 KB
testcase_22 AC 151 ms
98,536 KB
testcase_23 AC 73 ms
72,620 KB
testcase_24 AC 158 ms
95,248 KB
testcase_25 AC 94 ms
81,144 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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
0