結果
問題 | No.1630 Sorting Integers (Greater than K) |
ユーザー | ayaoni |
提出日時 | 2021-07-30 22:16:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 384 ms / 2,000 ms |
コード長 | 1,618 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 86,832 KB |
実行使用メモリ | 214,848 KB |
最終ジャッジ日時 | 2023-10-14 05:18:12 |
合計ジャッジ時間 | 6,290 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,236 KB |
testcase_01 | AC | 74 ms
71,440 KB |
testcase_02 | AC | 80 ms
71,240 KB |
testcase_03 | AC | 74 ms
71,352 KB |
testcase_04 | AC | 73 ms
71,188 KB |
testcase_05 | AC | 73 ms
71,348 KB |
testcase_06 | AC | 72 ms
71,244 KB |
testcase_07 | AC | 73 ms
71,396 KB |
testcase_08 | AC | 75 ms
71,216 KB |
testcase_09 | AC | 74 ms
71,188 KB |
testcase_10 | AC | 77 ms
71,356 KB |
testcase_11 | AC | 74 ms
71,356 KB |
testcase_12 | AC | 76 ms
71,520 KB |
testcase_13 | AC | 75 ms
71,328 KB |
testcase_14 | AC | 82 ms
76,124 KB |
testcase_15 | AC | 82 ms
76,464 KB |
testcase_16 | AC | 374 ms
192,912 KB |
testcase_17 | AC | 384 ms
196,304 KB |
testcase_18 | AC | 348 ms
190,292 KB |
testcase_19 | AC | 345 ms
189,228 KB |
testcase_20 | AC | 359 ms
214,848 KB |
testcase_21 | AC | 359 ms
212,236 KB |
testcase_22 | AC | 117 ms
95,180 KB |
testcase_23 | AC | 88 ms
85,412 KB |
testcase_24 | AC | 340 ms
174,736 KB |
testcase_25 | AC | 324 ms
161,148 KB |
testcase_26 | AC | 338 ms
191,560 KB |
ソースコード
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N,K = S().split() N = int(N) C = [0]+LI() int_K = [0]+[int(s) for s in K] digit_K = len(int_K)-1 if N < digit_K: print(-1) exit() if N > digit_K: ANS = [0]*N idx = 0 for i in range(1,10): c = C[i] s = str(i) for j in range(c): ANS[idx+j] = s idx += c ans = ''.join(ANS) print(ans) exit() S_count_K = [[0]*10 for _ in range(N+1)] for i in range(1,N+1): for j in range(10): S_count_K[i][j] += S_count_K[i-1][j] k = int_K[i] S_count_K[i][k] += 1 for i in range(N,0,-1): if S_count_K[i-1][0]: continue for j in range(1,10): if S_count_K[i-1][j] > C[j]: break else: x = int_K[i] for k in range(x+1,10): if C[k]-S_count_K[i-1][k]: C[k] -= 1 ANS = int_K[1:i]+[k] for l in range(1,10): c = C[l]-S_count_K[i-1][l] for _ in range(c): ANS.append(l) str_ANS = [str(a) for a in ANS] ans = ''.join(str_ANS) print(ans) exit() print(-1)