結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,272 KB
testcase_01 AC 78 ms
71,524 KB
testcase_02 AC 79 ms
71,428 KB
testcase_03 AC 79 ms
71,488 KB
testcase_04 AC 77 ms
71,364 KB
testcase_05 AC 77 ms
71,412 KB
testcase_06 AC 79 ms
71,512 KB
testcase_07 AC 77 ms
71,128 KB
testcase_08 AC 76 ms
71,360 KB
testcase_09 AC 77 ms
71,492 KB
testcase_10 AC 79 ms
71,448 KB
testcase_11 AC 79 ms
71,272 KB
testcase_12 AC 78 ms
71,240 KB
testcase_13 WA -
testcase_14 AC 82 ms
76,044 KB
testcase_15 AC 80 ms
71,388 KB
testcase_16 WA -
testcase_17 AC 269 ms
144,608 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 180 ms
120,368 KB
testcase_25 AC 117 ms
114,392 KB
testcase_26 AC 206 ms
131,500 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)
flag = 0
for i in range(n):
    x = int(k[i])
    if x > ok[i]:
        print(-1)
        exit()
    if x < ok[i]:
        flag = 1
        break
if flag == 0:
    print(-1)
    exit()


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