結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー titiatitia
提出日時 2021-07-30 23:12:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,168 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 48,596 KB
最終ジャッジ日時 2023-10-14 08:11:22
合計ジャッジ時間 9,360 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,240 KB
testcase_01 AC 16 ms
8,204 KB
testcase_02 AC 16 ms
8,384 KB
testcase_03 AC 16 ms
8,240 KB
testcase_04 AC 15 ms
8,120 KB
testcase_05 AC 16 ms
8,372 KB
testcase_06 AC 16 ms
8,188 KB
testcase_07 AC 16 ms
8,352 KB
testcase_08 AC 16 ms
8,200 KB
testcase_09 AC 16 ms
8,124 KB
testcase_10 AC 16 ms
7,856 KB
testcase_11 AC 16 ms
8,208 KB
testcase_12 AC 17 ms
8,364 KB
testcase_13 AC 16 ms
7,816 KB
testcase_14 AC 16 ms
8,212 KB
testcase_15 AC 16 ms
8,220 KB
testcase_16 AC 1,042 ms
48,596 KB
testcase_17 AC 1,274 ms
48,448 KB
testcase_18 AC 552 ms
48,492 KB
testcase_19 AC 539 ms
48,548 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,222 ms
40,376 KB
testcase_25 AC 19 ms
9,512 KB
testcase_26 AC 19 ms
9,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=input().split()
C=list(map(int,input().split()))

ANS=""
for i in range(9):
    ANS+=str(i+1)*C[i]

if ANS>K:
    print(ANS)
    exit()

if ANS[::-1]<=K:
    print(-1)
    exit()

S=K
ANS=[-1]*len(S)

for i in range(len(S)):
    x=int(S[i])

    if C[x-1]>0 and i!=len(S)-1:
        ANS[i]=x
        C[x-1]-=1

    else:        
        for j in range(x,9):
            if C[j]>0:
                C[j]-=1
                ANS[i]=j+1
                break
            
        else:
            for j in range(i-1,-1,-1):
                C[ANS[j]-1]+=1
                ANS[j]=-1

                x=int(S[j])
                flag=0

                for k in range(x,9):
                    if C[k]>0:
                        C[k]-=1
                        ANS[j]=k+1
                        flag=1
                        break

                if flag:
                    break

        break

#print(ANS,C)

for i in range(len(S)):
    if ANS[i]==-1:
        for j in range(9):
            if C[j]>0:
                C[j]-=1
                ANS[i]=j+1
                break

print("".join(map(str,ANS)))
                
                    
                    
0