結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-30 22:44:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 143,180 KB
最終ジャッジ日時 2023-10-14 06:55:32
合計ジャッジ時間 5,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,204 KB
testcase_01 AC 70 ms
71,320 KB
testcase_02 AC 70 ms
71,496 KB
testcase_03 AC 70 ms
71,272 KB
testcase_04 AC 68 ms
71,372 KB
testcase_05 AC 81 ms
71,412 KB
testcase_06 AC 69 ms
70,964 KB
testcase_07 AC 70 ms
71,180 KB
testcase_08 AC 69 ms
71,324 KB
testcase_09 AC 68 ms
71,316 KB
testcase_10 AC 69 ms
71,276 KB
testcase_11 AC 70 ms
71,272 KB
testcase_12 AC 69 ms
71,296 KB
testcase_13 AC 71 ms
71,340 KB
testcase_14 WA -
testcase_15 AC 72 ms
71,200 KB
testcase_16 WA -
testcase_17 AC 232 ms
137,212 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 147 ms
117,284 KB
testcase_25 AC 85 ms
77,936 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = input().split()
C = list(map(int,input().split()))
n = int(n)

def search(x):
    C2 = C[:]
    for i in range(x-1):
        num = int(k[i])-1
        C2[num] -= 1
        if C2[num] < 0:
            return False
    num = int(k[x-1])
    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
if l == 0:
    print(-1)
    exit()

ans = []
for i in range(l-1):
    ans.append(k[i])
    C[int(k[i])-1] -= 1
num = int(k[l-1])
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