結果

問題 No.1988 Divisor Tiling
ユーザー simansiman
提出日時 2022-06-30 16:24:25
言語 Ruby
(3.3.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 11,340 KB
実行使用メモリ 16,232 KB
最終ジャッジ日時 2023-08-16 03:20:01
合計ジャッジ時間 5,455 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
15,432 KB
testcase_01 AC 96 ms
15,348 KB
testcase_02 AC 94 ms
15,104 KB
testcase_03 AC 97 ms
15,520 KB
testcase_04 AC 94 ms
15,404 KB
testcase_05 AC 92 ms
15,388 KB
testcase_06 AC 92 ms
15,428 KB
testcase_07 AC 92 ms
15,556 KB
testcase_08 AC 91 ms
15,552 KB
testcase_09 AC 93 ms
15,616 KB
testcase_10 AC 94 ms
15,316 KB
testcase_11 AC 92 ms
15,408 KB
testcase_12 AC 93 ms
15,516 KB
testcase_13 AC 92 ms
15,404 KB
testcase_14 AC 95 ms
15,352 KB
testcase_15 AC 95 ms
15,596 KB
testcase_16 AC 92 ms
15,300 KB
testcase_17 AC 94 ms
15,300 KB
testcase_18 AC 97 ms
15,432 KB
testcase_19 AC 96 ms
15,496 KB
testcase_20 AC 96 ms
15,428 KB
testcase_21 AC 95 ms
15,464 KB
testcase_22 AC 95 ms
15,692 KB
testcase_23 AC 95 ms
15,468 KB
testcase_24 AC 96 ms
15,512 KB
testcase_25 AC 97 ms
15,716 KB
testcase_26 AC 95 ms
15,756 KB
testcase_27 AC 96 ms
15,500 KB
testcase_28 AC 96 ms
15,552 KB
testcase_29 AC 98 ms
15,816 KB
testcase_30 AC 100 ms
15,712 KB
testcase_31 AC 106 ms
16,232 KB
testcase_32 AC 91 ms
15,400 KB
testcase_33 AC 91 ms
15,508 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:18: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N, H = gets.split.map(&:to_i)

if N % H != 0
  puts -1
  exit
end

W = N / H
height, width = [H, W].sort
ans = Array.new(height) { Array.new(width, 0) }
y = 0
x = 0

N.divisor_list.reverse_each do |v|
  next if v == N
  h = v / width
  w = v % width

  if h > 0
    y.upto(y + h - 1) do |cy|
      0.upto(width - 1) do |cx|
        ans[cy][cx] = v
      end
    end
  else
    w.times do
      ans[y][x] = v
      x += 1
    end
  end

  if h > 0
    y += h
    x = 0
  end
end

if H > W
  ans = ans.transpose
end

puts ans.map { |row| row.join(' ') }

0