結果
問題 | No.1630 Sorting Integers (Greater than K) |
ユーザー | 👑 H20 |
提出日時 | 2021-07-30 23:57:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,835 bytes |
コンパイル時間 | 436 ms |
コンパイル使用メモリ | 87,020 KB |
実行使用メモリ | 99,236 KB |
最終ジャッジ日時 | 2023-10-14 09:05:34 |
合計ジャッジ時間 | 5,467 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
71,556 KB |
testcase_01 | AC | 96 ms
71,828 KB |
testcase_02 | AC | 95 ms
71,720 KB |
testcase_03 | AC | 97 ms
71,412 KB |
testcase_04 | AC | 95 ms
71,600 KB |
testcase_05 | AC | 94 ms
71,416 KB |
testcase_06 | AC | 97 ms
71,704 KB |
testcase_07 | AC | 96 ms
71,748 KB |
testcase_08 | AC | 95 ms
71,588 KB |
testcase_09 | AC | 95 ms
71,396 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 100 ms
73,708 KB |
testcase_24 | WA | - |
testcase_25 | RE | - |
testcase_26 | AC | 131 ms
84,856 KB |
ソースコード
import collections N,K = input().split() N = int(N) if len(K)>N: print(-1) exit() K = str(K).zfill(N) A = [0] + list(map(int, input().split())) ANS = collections.deque() for i in range(N): v = int(K[i]) if A[v]>0: ANS.append(v) A[v]-=1 else: #より大きい値がある for j in range(int(K[i])+1,10): if A[j]>0: ANS.append(j) A[j]-=1 for k in range(len(ANS),N): for j in range(10): if A[j]>0: ANS.append(j) A[j]-=1 print(''.join(map(str, ANS))) exit() #ないから遡る while len(ANS)>0: v = ANS.pop() A[v]+=1 for j in range(ANS[-1]+1,10): if A[j]>0: temp = ANS.pop() A[temp]+=1 ANS.append(j) A[j]-=1 for k in range(len(ANS),N): for j in range(10): if A[j]>0: ANS.append(j) A[j]-=1 print(''.join(map(str, ANS))) exit() print(-1) exit() while len(ANS)>0: v = ANS.pop() A[v]+=1 for j in range(ANS[-1]+1,10): if A[j]>0: temp = ANS.pop() A[temp]+=1 ANS.append(j) A[j]-=1 for k in range(len(ANS),N): for j in range(10): if A[j]>0: ANS.append(j) A[j]-=1 print(''.join(map(str, ANS))) exit() print(-1) exit()