結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-08-08 15:30:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 16,244 KB
最終ジャッジ日時 2023-10-19 15:43:46
合計ジャッジ時間 5,883 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,240 KB
testcase_01 AC 29 ms
10,164 KB
testcase_02 AC 30 ms
10,164 KB
testcase_03 AC 29 ms
10,164 KB
testcase_04 AC 30 ms
10,164 KB
testcase_05 AC 30 ms
10,164 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 29 ms
10,164 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = input().split()
n = int(n)
c = list(map(int, input().split()))
if n < len(k): exit(print(-1))
if n > len(k):
    ans = ""
    for i in range(9):
        ans += str(i + 1) * c[i]
    exit(print(ans))
f1, f2 = False, False
ans = ""
for i in range(n):
    if c[int(k[i]) - 1] > 0:
        ans += k[i]
        c[int(k[i]) - 1] -= 1
    else:
        f1 = True
    if f1 and not f2:
        for j in range(9):
            if j + 1 > int(k[i]) and c[j] > 0:
                ans += str(j + 1)
                c[j] -= 1
                break
        else:
            exit(print(-1))
        f2 = True
    if f1 and f2:
        for j in range(9):
            ans += str(j + 1) * c[j]
        break
if ans == k:
    try:
        ans = list(ans)
        ans[-1], ans[-2] = ans[-2], ans[-1]
        ans = "".join(ans)
    except:
        exit(print(-1))
if ans == k:
    exit(print(-1))
print(ans)
0