結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー sotanishysotanishy
提出日時 2021-07-30 21:39:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 190,164 KB
最終ジャッジ日時 2023-10-14 03:53:03
合計ジャッジ時間 7,449 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,384 KB
testcase_01 AC 72 ms
71,296 KB
testcase_02 AC 71 ms
71,340 KB
testcase_03 AC 72 ms
71,180 KB
testcase_04 AC 74 ms
71,340 KB
testcase_05 AC 74 ms
71,100 KB
testcase_06 AC 73 ms
71,144 KB
testcase_07 AC 72 ms
71,496 KB
testcase_08 AC 73 ms
71,228 KB
testcase_09 AC 72 ms
71,340 KB
testcase_10 AC 75 ms
71,336 KB
testcase_11 AC 73 ms
71,304 KB
testcase_12 AC 73 ms
71,196 KB
testcase_13 AC 73 ms
71,024 KB
testcase_14 AC 86 ms
76,404 KB
testcase_15 AC 81 ms
76,452 KB
testcase_16 AC 419 ms
175,676 KB
testcase_17 AC 396 ms
189,728 KB
testcase_18 AC 416 ms
178,468 KB
testcase_19 AC 404 ms
175,276 KB
testcase_20 AC 382 ms
190,088 KB
testcase_21 AC 388 ms
190,156 KB
testcase_22 AC 381 ms
190,164 KB
testcase_23 WA -
testcase_24 AC 330 ms
167,828 KB
testcase_25 AC 343 ms
153,348 KB
testcase_26 AC 398 ms
175,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def check(i, d):
    s = 0
    for x in range(10)[::-1]:
        s += c[x]
        if x == d:
            s -= 1
        if cnt[i+1][x] > s:
            return False
        if cnt[i+1][x] < s:
            return True
    return False

N, K = input().rstrip().split()
N = int(N)
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])
    ok = False
    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