結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-09 10:33:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 126,956 KB
最終ジャッジ日時 2023-10-11 11:08:37
合計ジャッジ時間 6,704 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,872 KB
testcase_01 AC 83 ms
71,664 KB
testcase_02 AC 83 ms
71,736 KB
testcase_03 AC 84 ms
71,788 KB
testcase_04 AC 84 ms
71,836 KB
testcase_05 AC 85 ms
71,932 KB
testcase_06 AC 86 ms
71,832 KB
testcase_07 AC 85 ms
71,604 KB
testcase_08 AC 85 ms
71,996 KB
testcase_09 AC 88 ms
71,840 KB
testcase_10 AC 88 ms
71,740 KB
testcase_11 AC 87 ms
71,720 KB
testcase_12 AC 88 ms
71,708 KB
testcase_13 AC 84 ms
71,740 KB
testcase_14 AC 85 ms
71,800 KB
testcase_15 AC 85 ms
71,716 KB
testcase_16 AC 175 ms
126,956 KB
testcase_17 AC 175 ms
126,660 KB
testcase_18 AC 162 ms
117,456 KB
testcase_19 AC 156 ms
117,164 KB
testcase_20 AC 127 ms
107,852 KB
testcase_21 AC 128 ms
112,140 KB
testcase_22 AC 114 ms
100,140 KB
testcase_23 AC 88 ms
73,280 KB
testcase_24 AC 152 ms
109,104 KB
testcase_25 AC 111 ms
90,408 KB
testcase_26 AC 136 ms
107,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(str, input().split())
n = int(n)
C = list(map(int, input().split()))
import copy
D = copy.copy(C)
if n < len(k):
    print(-1)
    exit()

if n > len(k):
    ans = []
    for i, c in enumerate(C):
        ans += [str(i+1)]*c
    print(''.join(ans))
    exit()

l = len(k)
k = list(k)
npd, p = -1, -1
for i in range(l):
    d = int(k[i])
    nd = -1
    for j in range(d+1, 10):
        if C[j-1] > 0:
            nd = j
            break
    if nd != -1:
        p = i
        npd = nd
    if d == 0:
        break
    if not C[d-1]:
        break
    else:
        C[d-1] -= 1
if p == -1:
    print(-1)
    exit()
ans = k[0:p]+[str(npd)]
for d in k[0:p]:
    d = int(d)
    if d != 0:
        D[d-1] -= 1
D[npd-1] -= 1
for i, c in enumerate(D):
    ans += [str(i+1)]*c
print(''.join(ans))
0