結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 H20H20
提出日時 2021-07-30 23:00:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 78,840 KB
最終ジャッジ日時 2023-10-14 07:55:20
合計ジャッジ時間 4,810 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,108 KB
testcase_01 AC 77 ms
71,340 KB
testcase_02 AC 75 ms
71,476 KB
testcase_03 AC 78 ms
71,448 KB
testcase_04 AC 78 ms
71,396 KB
testcase_05 AC 79 ms
71,284 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 #

N,INTK = map(int, input().split())
INTK+=1
K = str(INTK)
K = K.zfill(N)
A = [0] + list(map(int, input().split())) 
for i in range(int(K[0]),10):
    if A[i]>0:
        break
else:
    print(-1)
    exit()

ANS = []
for i in range(N):
    v = int(K[i])
    for j in range(v,10):
        if A[j]>0:
            ANS.append(j)
            A[j]-=1
            if j!=v:
                for k in range(len(ANS),N):
                    for j in range(10):
                        if A[j]>0:
                            ANS.append(j)
                            A[j]-=1
                print(''.join(map(str, ANS)))
                exit()

            break
    else:
        while len(ANS)>0:
            v = ANS.pop()
            A[v]+=1
            for j in range(ANS[-1]+1,10):
                if A[j]>0:
                    ANS.append(j)
                    A[j]-=1
                    for k in range(len(ANS),N):
                        for j in range(10):
                            if A[j]>0:
                                ANS.append(j)
                                A[j]-=1
                    print(''.join(map(str, ANS)))
                    exit()
        if len(ANS)==0:
            print(-1)
            exit()
print(''.join(map(str, ANS)))
0