結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-30 23:02:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,056 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 148,780 KB
最終ジャッジ日時 2023-10-14 07:57:08
合計ジャッジ時間 5,858 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,404 KB
testcase_01 AC 75 ms
71,608 KB
testcase_02 AC 75 ms
71,500 KB
testcase_03 AC 74 ms
71,268 KB
testcase_04 AC 74 ms
71,372 KB
testcase_05 AC 73 ms
71,120 KB
testcase_06 AC 72 ms
71,264 KB
testcase_07 AC 75 ms
71,504 KB
testcase_08 AC 74 ms
71,508 KB
testcase_09 AC 75 ms
71,372 KB
testcase_10 AC 76 ms
71,372 KB
testcase_11 AC 74 ms
71,360 KB
testcase_12 AC 74 ms
71,576 KB
testcase_13 WA -
testcase_14 AC 84 ms
76,128 KB
testcase_15 AC 77 ms
71,460 KB
testcase_16 WA -
testcase_17 AC 271 ms
144,368 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 108 ms
113,568 KB
testcase_24 AC 182 ms
120,184 KB
testcase_25 AC 119 ms
114,512 KB
testcase_26 AC 208 ms
131,312 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)
if n > len(k):
    print(*ok,sep="")
    exit()
if n < len(k):
    print(-1)
    exit()
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