結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,876 KB
testcase_01 AC 73 ms
71,104 KB
testcase_02 AC 73 ms
71,216 KB
testcase_03 AC 73 ms
71,172 KB
testcase_04 AC 73 ms
71,192 KB
testcase_05 AC 73 ms
71,212 KB
testcase_06 AC 74 ms
71,188 KB
testcase_07 AC 72 ms
71,236 KB
testcase_08 AC 76 ms
71,004 KB
testcase_09 AC 73 ms
71,224 KB
testcase_10 AC 74 ms
71,176 KB
testcase_11 AC 74 ms
71,204 KB
testcase_12 AC 74 ms
71,092 KB
testcase_13 AC 72 ms
71,116 KB
testcase_14 WA -
testcase_15 AC 81 ms
76,392 KB
testcase_16 AC 424 ms
175,572 KB
testcase_17 AC 389 ms
189,620 KB
testcase_18 AC 409 ms
178,220 KB
testcase_19 AC 399 ms
175,100 KB
testcase_20 AC 381 ms
190,004 KB
testcase_21 AC 375 ms
190,128 KB
testcase_22 AC 378 ms
190,128 KB
testcase_23 WA -
testcase_24 AC 322 ms
167,896 KB
testcase_25 AC 338 ms
153,072 KB
testcase_26 AC 389 ms
175,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def check(i, d):
    s = 0
    for x in range(d, 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