結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー ThetaTheta
提出日時 2024-04-16 19:39:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,624 KB
実行使用メモリ 143,948 KB
最終ジャッジ日時 2024-04-16 19:39:11
合計ジャッジ時間 4,901 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,272 KB
testcase_01 AC 44 ms
53,760 KB
testcase_02 AC 42 ms
53,888 KB
testcase_03 AC 44 ms
53,888 KB
testcase_04 AC 42 ms
53,376 KB
testcase_05 AC 42 ms
53,504 KB
testcase_06 AC 44 ms
53,760 KB
testcase_07 AC 42 ms
53,632 KB
testcase_08 AC 40 ms
53,760 KB
testcase_09 AC 41 ms
53,632 KB
testcase_10 AC 41 ms
54,016 KB
testcase_11 AC 44 ms
54,144 KB
testcase_12 AC 43 ms
53,888 KB
testcase_13 AC 42 ms
53,632 KB
testcase_14 AC 45 ms
53,888 KB
testcase_15 AC 41 ms
54,532 KB
testcase_16 AC 252 ms
129,100 KB
testcase_17 AC 311 ms
137,964 KB
testcase_18 AC 175 ms
129,092 KB
testcase_19 AC 161 ms
128,844 KB
testcase_20 AC 295 ms
143,452 KB
testcase_21 AC 291 ms
140,388 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 308 ms
122,308 KB
testcase_25 AC 338 ms
129,220 KB
testcase_26 AC 141 ms
129,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import sys
sys.setrecursionlimit(600000)


def main():
    N, K = input().split()
    N = int(N)
    K = list(map(int, K))
    c = list(map(int, input().split()))

    ctr = Counter(dict(enumerate(c, 1)))
    ctr.subtract(K)

    for idx, digit in reversed(list(enumerate(K))):
        ctr[digit] += 1
        if any(ctr_elm < 0 for ctr_elm in ctr.values()):
            continue
        min_over_n = -1
        for n in range(10):
            if n <= digit:
                continue
            if ctr[n] > 0:
                min_over_n = n
                break
        else:
            continue

        ans = K[:idx]
        ans.append(min_over_n)
        for n in range(10):
            if n == min_over_n:
                for _ in range(ctr[n] - 1):
                    ans.append(n)
            else:
                for _ in range(ctr[n]):
                    ans.append(n)
        print("".join(map(str, ans)))
        return
    print(-1)
    return


if __name__ == "__main__":
    main()
0