結果
問題 | No.1630 Sorting Integers (Greater than K) |
ユーザー | ayaoni |
提出日時 | 2021-07-30 22:11:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,725 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 68,224 KB |
最終ジャッジ日時 | 2024-09-16 00:32:08 |
合計ジャッジ時間 | 3,122 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
51,968 KB |
testcase_01 | AC | 42 ms
52,224 KB |
testcase_02 | AC | 41 ms
51,840 KB |
testcase_03 | AC | 42 ms
52,224 KB |
testcase_04 | AC | 43 ms
52,224 KB |
testcase_05 | AC | 42 ms
52,352 KB |
testcase_06 | AC | 42 ms
51,968 KB |
testcase_07 | AC | 42 ms
51,840 KB |
testcase_08 | AC | 42 ms
52,480 KB |
testcase_09 | AC | 42 ms
52,096 KB |
testcase_10 | AC | 42 ms
52,096 KB |
testcase_11 | AC | 42 ms
52,736 KB |
testcase_12 | AC | 42 ms
52,352 KB |
testcase_13 | AC | 42 ms
52,480 KB |
testcase_14 | WA | - |
testcase_15 | AC | 48 ms
59,008 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
ソースコード
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 = MI() C = [0]+LI() str_K = [0]+[int(s) for s in str(K)] digit_K = len(str_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 = str_K[i] S_count_K[i][k] += 1 ok = 0 ng = N+1 while ok+1 < ng: mid = (ok+ng)//2 if S_count_K[mid-1][0]: ng = mid continue for j in range(1,10): if S_count_K[mid-1][j] > C[j]: ng = mid break else: x = str_K[mid] for k in range(x+1,10): if C[k] > S_count_K[mid-1][k]: ok = mid break else: ng = mid if ok == 0: print(-1) exit() ANS = str_K[1:ok] for i in range(str_K[ok]+1,10): if C[i] > S_count_K[ok-1][i]: ANS.append(i) C[i] -= 1 break for i in range(1,10): for _ in range(C[i]-S_count_K[ok-1][i]): ANS.append(i) str_ANS = [str(s) for s in ANS] ans = ''.join(str_ANS) print(ans)