結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー ayaoniayaoni
提出日時 2021-07-30 21:54:24
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,591 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 80,336 KB
最終ジャッジ日時 2023-10-14 04:33:06
合計ジャッジ時間 4,822 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,932 KB
testcase_01 AC 75 ms
71,160 KB
testcase_02 AC 76 ms
71,196 KB
testcase_03 AC 72 ms
71,224 KB
testcase_04 AC 74 ms
71,060 KB
testcase_05 AC 75 ms
71,332 KB
testcase_06 AC 77 ms
71,280 KB
testcase_07 AC 76 ms
71,232 KB
testcase_08 AC 71 ms
71,136 KB
testcase_09 AC 74 ms
71,160 KB
testcase_10 AC 80 ms
71,476 KB
testcase_11 AC 76 ms
71,256 KB
testcase_12 AC 77 ms
71,516 KB
testcase_13 AC 75 ms
71,244 KB
testcase_14 AC 79 ms
76,120 KB
testcase_15 AC 77 ms
76,152 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,K = MI()
C = [0]+LI()
str_K = [0]+[int(s) for s in str(K)]
digit_K = len(str_K)-1

if N < digit_K:
    print(-1)
    exit()

if N > digit_K:
    ANS = [0]*N
    idx = 0
    for i in range(1,10):
        c = C[i]
        for j in range(c):
            ANS[idx+j] = str(i)
        idx += c
    ans = ''.join(ANS)
    print(ans)
    exit()

S_count_K = [[0]*10 for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(10):
        S_count_K[i][j] += S_count_K[i-1][j]
    k = str_K[i]
    S_count_K[i][k] += 1

for i in range(N,0,-1):
    if S_count_K[i-1][0]:
        continue
    for j in range(1,10):
        if S_count_K[i-1][j] > C[j]:
            break
    else:
        x = str_K[i]
        for k in range(x+1,10):
            if C[k]-S_count_K[i-1][k]:
                C[k] -= 1
                ANS = str_K[1:i]+[k]
                for l in range(1,10):
                    c = C[l]-S_count_K[i-1][l]
                    for _ in range(c):
                        ANS.append(l)
                str_ANS = [str(a) for a in ANS]
                ans = ''.join(str_ANS)
                print(ans)
                exit()

print(-1)
0