結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-30 22:55:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 903 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 148,564 KB
最終ジャッジ日時 2023-10-14 07:29:38
合計ジャッジ時間 6,876 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,276 KB
testcase_01 AC 87 ms
71,480 KB
testcase_02 AC 82 ms
71,104 KB
testcase_03 AC 81 ms
71,364 KB
testcase_04 AC 78 ms
71,528 KB
testcase_05 AC 80 ms
71,152 KB
testcase_06 AC 80 ms
71,528 KB
testcase_07 AC 82 ms
71,372 KB
testcase_08 AC 79 ms
71,492 KB
testcase_09 AC 79 ms
71,220 KB
testcase_10 AC 82 ms
71,324 KB
testcase_11 AC 79 ms
71,200 KB
testcase_12 AC 79 ms
71,324 KB
testcase_13 WA -
testcase_14 AC 85 ms
76,028 KB
testcase_15 AC 80 ms
71,144 KB
testcase_16 WA -
testcase_17 AC 287 ms
144,528 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 195 ms
120,360 KB
testcase_25 WA -
testcase_26 AC 226 ms
131,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = input().split()
C = list(map(int,input().split()))
n = int(n)
ok = []
for i in range(9)[::-1]:
    for j in range(C[i]):
        ok.append(i+1)
for i in range(n):
    x = int(k[i])
    if x > ok[i]:
        print(-1)
        exit()
    if x < ok[i]:
        break


def search(x):
    C2 = C[:]
    for i in range(x):
        num = int(k[i])-1
        C2[num] -= 1
        if C2[num] < 0:
            return False
    num = int(k[x])
    for i in range(num,9):
        if C2[i]:
            return True
    return False

l = 0
r = n

while r > l + 1:
    m = (r+l)//2
    if search(m):
        l = m
    else:
        r = m

ans = []
for i in range(l):
    ans.append(k[i])
    C[int(k[i])-1] -= 1
num = int(k[l])
for j in range(num,9):
    if C[j]:
        ans.append(j+1)
        C[j] -= 1
        break
for i,c in enumerate(C,1):
    for j in range(c):
        ans.append(i)

print(*ans,sep="")
0