結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー sotanishysotanishy
提出日時 2021-07-30 21:25:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 79,188 KB
最終ジャッジ日時 2023-10-14 03:19:38
合計ジャッジ時間 5,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,084 KB
testcase_01 AC 75 ms
71,144 KB
testcase_02 AC 75 ms
71,064 KB
testcase_03 AC 74 ms
71,296 KB
testcase_04 AC 76 ms
71,328 KB
testcase_05 AC 75 ms
71,172 KB
testcase_06 WA -
testcase_07 AC 75 ms
71,120 KB
testcase_08 AC 76 ms
71,140 KB
testcase_09 AC 77 ms
71,212 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 84 ms
76,040 KB
testcase_15 AC 85 ms
76,124 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
input = sys.stdin.readline

def check(i, d):
    return cnt[i+1][d] <= sum(c[d:]) - 1 and all(cnt[i+1][j] <= sum(c[j:]) for j in range(d+1, 10))

N, K = map(int, input().split())
K += 1
K = str(K)
K = '0' * (N - len(K)) + K
c = [0] + list(map(int, input().split()))
ans = []
cnt = [[0] * 10 for _ in range(N+1)]
for i in range(N)[::-1]:
    for d in range(10):
        if int(K[i]) >= d:
            cnt[i][d] = cnt[i+1][d] + 1
        else:
            cnt[i][d] = 0
for i in range(N):
    d = int(K[i])
    if c[d] > 0 and check(i, d):
        ans.append(d)
        c[d] -= 1
    else:
        d += 1
        while d < 10 and c[d] == 0:
            d += 1
        if d == 10:
            print(-1)
            exit()
        ans.append(d)
        c[d] -= 1
        break
for d in range(10):
    for _ in range(c[d]):
        ans.append(d)
print(''.join(map(str, ans)))
0