結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー chineristACchineristAC
提出日時 2021-07-30 20:47:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 108,724 KB
最終ジャッジ日時 2023-10-14 03:05:30
合計ジャッジ時間 6,447 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
74,232 KB
testcase_01 AC 112 ms
74,624 KB
testcase_02 AC 114 ms
74,264 KB
testcase_03 AC 114 ms
74,368 KB
testcase_04 AC 113 ms
74,600 KB
testcase_05 AC 116 ms
74,076 KB
testcase_06 AC 115 ms
74,432 KB
testcase_07 AC 124 ms
74,308 KB
testcase_08 AC 117 ms
74,456 KB
testcase_09 AC 116 ms
74,196 KB
testcase_10 AC 117 ms
74,584 KB
testcase_11 AC 119 ms
74,420 KB
testcase_12 AC 116 ms
74,320 KB
testcase_13 AC 118 ms
74,072 KB
testcase_14 AC 116 ms
74,428 KB
testcase_15 AC 119 ms
74,192 KB
testcase_16 AC 276 ms
94,588 KB
testcase_17 AC 299 ms
99,228 KB
testcase_18 AC 143 ms
82,596 KB
testcase_19 AC 145 ms
82,624 KB
testcase_20 AC 208 ms
103,988 KB
testcase_21 AC 212 ms
108,288 KB
testcase_22 WA -
testcase_23 AC 119 ms
75,560 KB
testcase_24 AC 327 ms
101,112 KB
testcase_25 AC 325 ms
81,560 KB
testcase_26 AC 144 ms
82,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def solve(N,K,c):
    if len(K) > N:
        return -1

    check_c = [0 for i in range(10)]
    for i in range(len(K)):
        check_c[int(K[i])] += 1

    for d in range(len(K)-1,-1,-1):
        check_c[int(K[d])] -= 1
        if any(c[i] < check_c[i] for i in range(10)):
            continue

        for i in range(int(K[d])+1,10):
            if c[i] > check_c[i]:
                ans = [K[:d],str(i)]
                #print(ans,check_c,c)
                c[i] -= 1
                for j in range(10):
                    c[j] -= check_c[j]
                    ans += [str(j)] * c[j]
                return "".join(ans)

    return -1

N,K = input().split()
N = int(N)
c = [0] + li()
print(solve(N,K,c))
0