結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー yuruhiyayuruhiya
提出日時 2021-07-31 14:01:16
言語 Crystal
(1.11.2)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 18,863 ms
コンパイル使用メモリ 255,404 KB
実行使用メモリ 12,452 KB
最終ジャッジ日時 2023-10-14 14:59:15
合計ジャッジ時間 21,230 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,456 KB
testcase_02 AC 2 ms
4,428 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,456 KB
testcase_07 AC 2 ms
4,392 KB
testcase_08 AC 2 ms
4,460 KB
testcase_09 AC 2 ms
4,436 KB
testcase_10 AC 3 ms
4,436 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 3 ms
4,496 KB
testcase_13 AC 2 ms
4,464 KB
testcase_14 AC 3 ms
4,416 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 39 ms
12,280 KB
testcase_17 AC 38 ms
12,356 KB
testcase_18 AC 42 ms
12,256 KB
testcase_19 AC 41 ms
12,444 KB
testcase_20 AC 19 ms
10,724 KB
testcase_21 AC 19 ms
10,080 KB
testcase_22 AC 10 ms
11,024 KB
testcase_23 AC 8 ms
9,668 KB
testcase_24 AC 32 ms
11,516 KB
testcase_25 AC 20 ms
12,452 KB
testcase_26 AC 28 ms
12,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = read_line.split
n = n.to_i
k = k.chars.map &.to_i
a = [0] + read_line.split.map(&.to_i)
if n < k.size
  puts -1
elsif n > k.size
  puts (1..9).join { |x| x.to_s * a[x] }
else
  b = a.dup
  pos = nil
  k.each_with_index do |x, i|
    pos = i if b[x + 1..].any? &.positive?
    break if b[x] == 0
    b[x] -= 1
  end
  pos ||= p(-1) + exit
  puts (0...n).join { |i|
    f = i < pos ? k[i] : i == pos ? k[i] + 1 : 1
    (f..).find { |i| a[i] > 0 }.try &.tap { |x| a[x] -= 1 }
  }
end
0