結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 rin204rin204
提出日時 2021-07-30 20:47:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 920 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 118,804 KB
最終ジャッジ日時 2023-10-14 03:05:08
合計ジャッジ時間 4,508 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,252 KB
testcase_01 WA -
testcase_02 AC 75 ms
71,264 KB
testcase_03 AC 71 ms
71,256 KB
testcase_04 AC 70 ms
71,104 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 71 ms
71,256 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 77 ms
71,048 KB
testcase_13 AC 78 ms
71,248 KB
testcase_14 AC 75 ms
71,308 KB
testcase_15 AC 75 ms
71,352 KB
testcase_16 AC 181 ms
118,804 KB
testcase_17 AC 186 ms
116,124 KB
testcase_18 AC 144 ms
115,156 KB
testcase_19 AC 147 ms
115,396 KB
testcase_20 AC 105 ms
95,128 KB
testcase_21 AC 107 ms
99,676 KB
testcase_22 AC 104 ms
100,504 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 142 ms
115,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, K = input().split()
n = int(n)
K = K.zfill(n)
cnt = [0] + list(map(int, input().split()))
ans = []
for k in K:
    k = int(k)
    if cnt[k] > 0:
        ans.append(str(k))
        cnt[k] -= 1
        continue
    flg = False
    for i in range(k + 1, 10):
        if cnt[i] > 0:
            flg = True
            ans.append(str(i))
            cnt[i] -= 1
            break
    if flg:
        for i, c in enumerate(cnt):
            ans += [str(i)] * c
        break
    while ans:
        p = int(ans.pop())
        cnt[p] += 1
        flg = False
        for i in range(p + 1, 10):
            if cnt[i] > 0:
                flg = True
                ans.append(str(i))
                cnt[i] -= 1
                break
        if flg:
            break
    if ans:
        for i, c in enumerate(cnt):
            ans += [str(i)] * c
        break
    else:
        print(-1)
        exit()
print("".join(ans))

0