結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 H20H20
提出日時 2021-07-30 23:42:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 79,564 KB
最終ジャッジ日時 2023-10-14 08:49:29
合計ジャッジ時間 4,468 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,688 KB
testcase_01 AC 80 ms
71,868 KB
testcase_02 AC 77 ms
71,428 KB
testcase_03 AC 84 ms
71,624 KB
testcase_04 AC 76 ms
71,700 KB
testcase_05 AC 76 ms
71,824 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 #

import collections
N,K = map(int, input().split())
K+=1
K = str(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 = collections.deque()
for i in range(N):
    v = int(K[i])
    if A[v]>0:
        ANS.append(v)
        A[v]-=1
    else:
        #より大きい値がある
        for j in range(int(K[i])+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()
        #ないから遡る
        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()
        print(-1)
0